fix(agc): render a nonzero slice of an XOR color view with MIP0_DEPTH 0 into its array slice #4937

Closed
Tamalero wants to merge 1 commit from upstream-pr/4937 into main
Tamalero commented 2026-10-13 05:33:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Tamalero on 2026-10-13T05:33:19Z.


What

A color view of a nonzero slice with CB_COLOR_ATTRIB3 MIP0_DEPTH = 0 renders into the wrong bytes under the 64 KiB XOR swizzle modes. High on Life (PPSA15388) draws every face of its sky-light cube this way, and the cube comes back scrambled. That is the stale-mip pattern in #4736.

The downsample pass draws face f with:

  • CB_COLOR_VIEW = 0x1c00a005 for face 5 (slice start = slice end = f);
  • CB_COLOR_ATTRIB3 = 0x4dc6c000 (MIP0_DEPTH 0, 2D, SW_64KB_R_X).

Cause: DecodeColorBuffer keeps the array slice only when MIP0_DEPTH is nonzero. With MIP0_DEPTH 0 it adds slice × slice size to the address and renders a standalone 2D surface there, so the slice term of the swizzle is lost. In the R_X equations in TextureSwizzleEquations.hpp (from addrlib's GFX10 non-RB+ pattern tables), at 8 bytes per element, byte-address bits 8–11 are XORed with slice bits 3–0. Slice 0 is unaffected. For slices 1–5 the bytes land in permuted 256-byte blocks, and the cube texture that later reads slice f sees them in the wrong order. The pass also downsamples into mip tails, which share a 64 KiB block, so the permutation mixes mips there.

Fix: a nonzero slice of an XOR color view with MIP0_DEPTH 0 becomes slice slice of an array of max(slice, last slice) + 1 layers at the surface base. That is the path MIP0_DEPTH ≠ 0 already takes. Linear and non-XOR views are unchanged.

The source is the slice term in the existing addrlib-derived equations. This has not been measured on hardware: I have no capture showing the CB applies the slice term when MIP0_DEPTH is 0. The game's own use is the evidence. It draws face f this way and samples the six faces as a cube, so the slice term must apply.

Tested

  • Linux, GCC 16, Release, RTX 4090 (NVIDIA 615.78).

  • agc_driver_array_layer_target gains a case that draws into slice 1 with MIP0_DEPTH 0 and reads slice 1 back through a 4-layer array texture. It checks the result both while pending and after a re-upload from guest memory.

    • Negative check: without the fix the new case fails ("the color view did not keep its array and slice"). The existing MIP0_DEPTH 3 cases pass with and without the fix.
  • Full agc_ suite on this branch: 464 of 464 pass (agc_driver_stencil_ref_export skipped on this device).

  • tools/check_conventions.py --base origin/main passes.

  • High on Life (PPSA15388), on a local stack: main 3377986a plus #1077, #425, #3202 and this change. The before values come from earlier runs on the same stack without it.

    Sky-light cube Before After
    Faces 1–5 of the downsampled cube mips 3–7: 25–81 % stale texels; face 2 mip 5 holds face 4's data every face smooth from 128² down to 1×1
    Cube B (GGX-filtered) G ≈ 234 on faces 1, 2, 3 and 5 ~2–3 on every face
    1×1 capture brightness 2660 0.73
    Sky SH coefficients (9×1) 65504 / non-finite 2.09, −0.003, −1.16, …

    The scene is still dark, because indirect light is missing (see #4736). Direct light now renders correctly.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: PPSA15388 #4736 (sky-light cube; not the whole black scene)
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4838843207 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4937). Originally posted by [Tamalero](https://github.com/Tamalero) on 2026-10-13T05:33:19Z. --- ### What A color view of a nonzero slice with CB_COLOR_ATTRIB3 MIP0_DEPTH = 0 renders into the wrong bytes under the 64 KiB XOR swizzle modes. High on Life (PPSA15388) draws every face of its sky-light cube this way, and the cube comes back scrambled. That is the stale-mip pattern in #4736. The downsample pass draws face f with: - `CB_COLOR_VIEW` = `0x1c00a005` for face 5 (slice start = slice end = f); - `CB_COLOR_ATTRIB3` = `0x4dc6c000` (MIP0_DEPTH 0, 2D, SW_64KB_R_X). **Cause:** `DecodeColorBuffer` keeps the array slice only when MIP0_DEPTH is nonzero. With MIP0_DEPTH 0 it adds `slice × slice size` to the address and renders a standalone 2D surface there, so the slice term of the swizzle is lost. In the R_X equations in `TextureSwizzleEquations.hpp` (from addrlib's GFX10 non-RB+ pattern tables), at 8 bytes per element, byte-address bits 8–11 are XORed with slice bits 3–0. Slice 0 is unaffected. For slices 1–5 the bytes land in permuted 256-byte blocks, and the cube texture that later reads slice f sees them in the wrong order. The pass also downsamples into mip tails, which share a 64 KiB block, so the permutation mixes mips there. **Fix:** a nonzero slice of an XOR color view with MIP0_DEPTH 0 becomes slice `slice` of an array of `max(slice, last slice) + 1` layers at the surface base. That is the path MIP0_DEPTH ≠ 0 already takes. Linear and non-XOR views are unchanged. The source is the slice term in the existing addrlib-derived equations. This has **not** been measured on hardware: I have no capture showing the CB applies the slice term when MIP0_DEPTH is 0. The game's own use is the evidence. It draws face f this way and samples the six faces as a cube, so the slice term must apply. ### Tested - Linux, GCC 16, Release, RTX 4090 (NVIDIA 615.78). - `agc_driver_array_layer_target` gains a case that draws into slice 1 with MIP0_DEPTH 0 and reads slice 1 back through a 4-layer array texture. It checks the result both while pending and after a re-upload from guest memory. - **Negative check:** without the fix the new case fails ("the color view did not keep its array and slice"). The existing MIP0_DEPTH 3 cases pass with and without the fix. - Full `agc_` suite on this branch: 464 of 464 pass (`agc_driver_stencil_ref_export` skipped on this device). - `tools/check_conventions.py --base origin/main` passes. - **High on Life (PPSA15388)**, on a local stack: `main` `3377986a` plus #1077, #425, #3202 and this change. The before values come from earlier runs on the same stack without it. | Sky-light cube | Before | After | |---|---|---| | Faces 1–5 of the downsampled cube | mips 3–7: 25–81 % stale texels; face 2 mip 5 holds face 4's data | every face smooth from 128² down to 1×1 | | Cube B (GGX-filtered) | G ≈ 234 on faces 1, 2, 3 and 5 | ~2–3 on every face | | 1×1 capture brightness | 2660 | 0.73 | | Sky SH coefficients (9×1) | 65504 / non-finite | 2.09, −0.003, −1.16, … | The scene is still dark, because indirect light is missing (see #4736). Direct light now renders correctly. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: PPSA15388 #4736 (sky-light cube; not the whole black scene) - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
xXPBSXx commented 2026-10-13 07:12:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T07:12:21Z.


Windows test (MinGW GCC 15.2, Release, Windows 10, RTX 4080 SUPER). Built on main 88107b7de together with thirteen other open GPU PRs (their own commits cherry-picked, no merge commits), so only the tests that belong to this PR say something about it:

  • tests/execution/ArrayLayerTarget.cpp (agc_driver_array_layer_target): 3 of 3 runs passed.

Not tested: no game run. The batch was built once, not per PR; nothing failed, so no bisect was needed.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6140322405 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4937#issuecomment-6140322405). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-13T07:12:21Z. --- Windows test (MinGW GCC 15.2, Release, Windows 10, RTX 4080 SUPER). Built on main `88107b7de` together with thirteen other open GPU PRs (their own commits cherry-picked, no merge commits), so only the tests that belong to this PR say something about it: - `tests/execution/ArrayLayerTarget.cpp` (`agc_driver_array_layer_target`): 3 of 3 runs passed. Not tested: no game run. The batch was built once, not per PR; nothing failed, so no bisect was needed. AI-assisted (Claude Code).
Tamalero commented 2026-10-13 18:01:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Tamalero on 2026-10-13T18:01:17Z.


Closing as superseded by #4551, which fixes the same bug (a nonzero slice of an XOR color view with MIP0_DEPTH 0 loses its slice term) and merged today. #4551 keeps the shifted 2D surface and folds the slice's equation bits into the pipe/bank XOR; this PR rendered the view into the array slice instead. Both put the bytes where the hardware does. #4551 was opened first, from Lost Soul Aside's reflection cube (#4387), which is the same symptom as High on Life's in #4736.

Thanks @xXPBSXx for the Windows run. I'll recheck High on Life's cube on main with #4551 and report on #4736.

Tested and written by Claude (AI assistant) on a contributor's machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6151898501 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4937#issuecomment-6151898501). Originally posted by [Tamalero](https://github.com/Tamalero) on 2026-10-13T18:01:17Z. --- Closing as superseded by #4551, which fixes the same bug (a nonzero slice of an XOR color view with MIP0_DEPTH 0 loses its slice term) and merged today. #4551 keeps the shifted 2D surface and folds the slice's equation bits into the pipe/bank XOR; this PR rendered the view into the array slice instead. Both put the bytes where the hardware does. #4551 was opened first, from Lost Soul Aside's reflection cube (#4387), which is the same symptom as High on Life's in #4736. Thanks @xXPBSXx for the Windows run. I'll recheck High on Life's cube on `main` with #4551 and report on #4736. *Tested and written by Claude (AI assistant) on a contributor's machine.*

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!4937
No description provided.