feat(agc): detile XOR-swizzled textures whose base carries a pipe/bank XOR #1734

Merged
TheAggie merged 1 commit from upstream-pr/1734 into main 2026-10-10 06:00:46 +00:00
TheAggie commented 2026-10-08 17:52:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TheAggie on 2026-10-08T17:52:03Z.


What

On GFX10 the XOR swizzle modes (SW_4KB_*_X, SW_64KB_*_X, SW_64KB_*_T) add a per-surface pipe/bank XOR to the offset inside each block. AMD addrlib, Gfx10Lib::ComputeSurfaceAddrFromCoordMacroTiled:

pOut->addr = sliceSize * sliceId + mipInfo[pIn->mipId].macroBlockOffset + (blkIdx << blkSizeLog2) + (blkOffset ^ pipeBankXor);

Every mip and slice uses the same pipeBankXor, masked to the block. Mesa stores it in the low bits of the descriptor base: desc[0] |= swizzle in ac_set_mutable_tex_desc_fields, and cb_color_base |= tile_swizzle in ac_set_mutable_cb_surface_fields (src/amd/common/ac_descriptors.c). DecodeTextureResource threw combines an XOR swizzle with a pipe/bank XOR base which is not implemented for those descriptors. Under RADV on the PS5, ccleste (PPSA59322) dropped one such draw every frame: the blit of its rendered image to the display buffer.

  • For XOR modes, DecodeTextureResource splits the base into the block-aligned baseAddress and pipeBankXor, which is the address bits below the block size. Nothing that addresses guest memory moves.
    • A base that is only XOR bits (block address 0) still throws null base address.
  • DetileWindow::pipeBankXor reaches TextureDetile.comp as a new push constant. The equation family XORs it into the block offset, the same place as addrlib, tail mips included. All eight texture detile and retile dispatches in Texture.cpp pass it.
  • Windows and covered-byte ranges stay valid, because they are built from whole blocks and the XOR only permutes 256-byte units inside a block.
  • SurfaceKey folds the XOR into its address word, which is zero there for an aligned base. The view check in Texture.cpp compares it too, so two descriptors that differ only in their XOR do not share an image.
  • Tests:
    • agc_driver_graphics (GuestTextureResource):
      • SW_64KB_R_X, SW_4KB_D_X and SW_64KB_D_T bases split into the expected base and XOR.
      • A non-XOR mode keeps its base.
      • An aligned base has no XOR.
      • An XOR-only base throws.
    • agc_driver_graphics (TextureDetiler): a dispatch without a window pushes 0, and the window's XOR reaches the push constant.
    • New GPU test agc_driver_image_pipe_bank_xor:
      • Fills a 160x70 RGBA8 texture (several blocks) with addrlib's equations, XORing the pipe/bank value into each block offset.
      • Samples it through image_load with the descriptor base raised by that value.
      • Cases: SW_4KB_D_X with XOR 0 and 0xa00, SW_64KB_S_X with 0x5600, SW_64KB_R_X with 0xf100.
      • With the shader's XOR removed, it fails on the first nonzero case.

Color targets with such a base still throw null or misaligned address; #1735 follows on top of this one.

Tested

Windows 11 Pro (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, NVIDIA GeForce RTX 5070 Ti.

  • The full suite (459 tests) passes on this branch. It was run from the generated CTestTestfile.cmake commands because antivirus blocks ctest.exe on this machine.
  • ccleste shows its title screen once this and #1735 are applied with the other changes it needs. That testing was on a local branch with all of them, and RADV_DEBUG=nonggc set.

Not tested on AMD, Intel or Linux.

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 in TechnicalDebt
  • 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
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4790749130 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1734). Originally posted by [TheAggie](https://github.com/TheAggie) on 2026-10-08T17:52:03Z. --- ### What On GFX10 the XOR swizzle modes (`SW_4KB_*_X`, `SW_64KB_*_X`, `SW_64KB_*_T`) add a per-surface pipe/bank XOR to the offset inside each block. AMD addrlib, `Gfx10Lib::ComputeSurfaceAddrFromCoordMacroTiled`: ``` pOut->addr = sliceSize * sliceId + mipInfo[pIn->mipId].macroBlockOffset + (blkIdx << blkSizeLog2) + (blkOffset ^ pipeBankXor); ``` Every mip and slice uses the same `pipeBankXor`, masked to the block. Mesa stores it in the low bits of the descriptor base: `desc[0] |= swizzle` in `ac_set_mutable_tex_desc_fields`, and `cb_color_base |= tile_swizzle` in `ac_set_mutable_cb_surface_fields` (`src/amd/common/ac_descriptors.c`). `DecodeTextureResource` threw `combines an XOR swizzle with a pipe/bank XOR base which is not implemented` for those descriptors. Under RADV on the PS5, ccleste (PPSA59322) dropped one such draw every frame: the blit of its rendered image to the display buffer. - For XOR modes, `DecodeTextureResource` splits the base into the block-aligned `baseAddress` and `pipeBankXor`, which is the address bits below the block size. Nothing that addresses guest memory moves. - A base that is only XOR bits (block address 0) still throws `null base address`. - `DetileWindow::pipeBankXor` reaches `TextureDetile.comp` as a new push constant. The equation family XORs it into the block offset, the same place as addrlib, tail mips included. All eight texture detile and retile dispatches in `Texture.cpp` pass it. - Windows and covered-byte ranges stay valid, because they are built from whole blocks and the XOR only permutes 256-byte units inside a block. - `SurfaceKey` folds the XOR into its address word, which is zero there for an aligned base. The view check in `Texture.cpp` compares it too, so two descriptors that differ only in their XOR do not share an image. - Tests: - `agc_driver_graphics` (`GuestTextureResource`): - `SW_64KB_R_X`, `SW_4KB_D_X` and `SW_64KB_D_T` bases split into the expected base and XOR. - A non-XOR mode keeps its base. - An aligned base has no XOR. - An XOR-only base throws. - `agc_driver_graphics` (`TextureDetiler`): a dispatch without a window pushes 0, and the window's XOR reaches the push constant. - New GPU test `agc_driver_image_pipe_bank_xor`: - Fills a 160x70 RGBA8 texture (several blocks) with addrlib's equations, XORing the pipe/bank value into each block offset. - Samples it through `image_load` with the descriptor base raised by that value. - Cases: `SW_4KB_D_X` with XOR 0 and 0xa00, `SW_64KB_S_X` with 0x5600, `SW_64KB_R_X` with 0xf100. - With the shader's XOR removed, it fails on the first nonzero case. Color targets with such a base still throw `null or misaligned address`; #1735 follows on top of this one. ### Tested Windows 11 Pro (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, NVIDIA GeForce RTX 5070 Ti. - The full suite (459 tests) passes on this branch. It was run from the generated `CTestTestfile.cmake` commands because antivirus blocks `ctest.exe` on this machine. - ccleste shows its title screen once this and #1735 are applied with the other changes it needs. That testing was on a local branch with all of them, and `RADV_DEBUG=nonggc` set. Not tested on AMD, Intel or Linux. ### 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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
johnmaia commented 2026-10-08 18:59:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by johnmaia on 2026-10-08T18:59:05Z.


Linux run, since the description lists AMD and Linux as not tested: Ubuntu 24.04.5 (kernel 6.8), GCC 13.3, Release, AMD Radeon RX 7600 (RADV NAVI33, Mesa 25.2.8). This PR's head 512f8c0e, merged onto main 6b56175a.

Full ctest: 479 of 480 pass. The new agc_driver_image_pipe_bank_xor fails at its first case, the one without an XOR:

AGC graphics: SW_4KB_D_X without a pipe/bank XOR: texel (0, 0) component 0 is -255.000000/255, expected 1/255

It fails the same way on llvmpipe (MESA_VK_DEVICE_SELECT=10005:0!), so it isn't specific to AMD. -255/255 is the -1.0f that Run fills Output with, so the shader's store never landed.

The cause seems to be the test's buffer descriptors. BufferDescriptor sets word 3 to 0x01016fac, which means OUT_OF_BOUNDS_SELECT 0 (structured: index and offset are both checked) with a stride of 0. With that, every access counts as out of bounds. ImageXorSwizzleVolume.cpp, which uses the same shader, uses 0x31016fac (OOB_SELECT 3, raw). ImageSint8.cpp picks stride == 0u ? 0x31016facu : 0x01016facu.

With only that value changed to 0x31016facu, all four cases pass on the RX 7600 and on llvmpipe, including the XOR 0xa00, 0x5600 and 0xf100 ones. So the detile change itself checks out here.

-    return {static_cast<std::uint32_t>(address), static_cast<std::uint32_t>((address >> 32u) & 0xffffu), bytes, 0x01016facu};
+    return {static_cast<std::uint32_t>(address), static_cast<std::uint32_t>((address >> 32u) & 0xffffu), bytes, 0x31016facu};

I haven't worked out why the original passes on your Windows machine. If it helps, I can run it on Windows with an RTX 4080.

All other tests pass, including agc_driver_graphics with the new GuestTextureResource and TextureDetiler cases.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6066955295 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1734#issuecomment-6066955295). Originally posted by [johnmaia](https://github.com/johnmaia) on 2026-10-08T18:59:05Z. --- Linux run, since the description lists AMD and Linux as not tested: Ubuntu 24.04.5 (kernel 6.8), GCC 13.3, Release, AMD Radeon RX 7600 (RADV NAVI33, Mesa 25.2.8). This PR's head `512f8c0e`, merged onto main `6b56175a`. Full ctest: 479 of 480 pass. The new `agc_driver_image_pipe_bank_xor` fails at its first case, the one without an XOR: ``` AGC graphics: SW_4KB_D_X without a pipe/bank XOR: texel (0, 0) component 0 is -255.000000/255, expected 1/255 ``` It fails the same way on llvmpipe (`MESA_VK_DEVICE_SELECT=10005:0!`), so it isn't specific to AMD. -255/255 is the `-1.0f` that `Run` fills `Output` with, so the shader's store never landed. The cause seems to be the test's buffer descriptors. `BufferDescriptor` sets word 3 to `0x01016fac`, which means `OUT_OF_BOUNDS_SELECT` 0 (structured: index and offset are both checked) with a stride of 0. With that, every access counts as out of bounds. `ImageXorSwizzleVolume.cpp`, which uses the same shader, uses `0x31016fac` (`OOB_SELECT` 3, raw). `ImageSint8.cpp` picks `stride == 0u ? 0x31016facu : 0x01016facu`. With only that value changed to `0x31016facu`, all four cases pass on the RX 7600 and on llvmpipe, including the XOR 0xa00, 0x5600 and 0xf100 ones. So the detile change itself checks out here. ```diff - return {static_cast<std::uint32_t>(address), static_cast<std::uint32_t>((address >> 32u) & 0xffffu), bytes, 0x01016facu}; + return {static_cast<std::uint32_t>(address), static_cast<std::uint32_t>((address >> 32u) & 0xffffu), bytes, 0x31016facu}; ``` I haven't worked out why the original passes on your Windows machine. If it helps, I can run it on Windows with an RTX 4080. All other tests pass, including `agc_driver_graphics` with the new `GuestTextureResource` and `TextureDetiler` cases.
TheAggie commented 2026-10-08 19:43:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TheAggie on 2026-10-08T19:43:18Z.


The red Linux CI here was my test's fault: its buffer V#s used OOB_SELECT 0 (structured with offset) with stride 0, so every access is out of bounds on GFX10 ((index >= NUM_RECORDS) || (offset >= STRIDE), per Mesa's ac_descriptors.c), and since #639 AnyPS5 honours that. The test now builds them as raw buffers (OOB_SELECT 3, as Mesa does). Rebased onto current main; the full suite (478 tests) passes, and the test still fails with the detile shader's pipe/bank XOR removed.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6067712638 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1734#issuecomment-6067712638). Originally posted by [TheAggie](https://github.com/TheAggie) on 2026-10-08T19:43:18Z. --- The red Linux CI here was my test's fault: its buffer V#s used `OOB_SELECT` 0 (structured with offset) with stride 0, so every access is out of bounds on GFX10 (`(index >= NUM_RECORDS) || (offset >= STRIDE)`, per Mesa's `ac_descriptors.c`), and since #639 AnyPS5 honours that. The test now builds them as raw buffers (`OOB_SELECT` 3, as Mesa does). Rebased onto current `main`; the full suite (478 tests) passes, and the test still fails with the detile shader's pipe/bank XOR removed.
johnmaia commented 2026-10-08 20:13:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by johnmaia on 2026-10-08T20:13:14Z.


Confirmed on the RX 7600 (RADV, Mesa 25.2.8) with 8eb2c3d5 merged onto main 4b6ab6bb: the full suite passes (486/486), including agc_driver_image_pipe_bank_xor, which also passes on llvmpipe. #1735 (fc103d99) passes 486/486 on the same setup.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6068201215 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1734#issuecomment-6068201215). Originally posted by [johnmaia](https://github.com/johnmaia) on 2026-10-08T20:13:14Z. --- Confirmed on the RX 7600 (RADV, Mesa 25.2.8) with `8eb2c3d5` merged onto `main` `4b6ab6bb`: the full suite passes (486/486), including `agc_driver_image_pipe_bank_xor`, which also passes on llvmpipe. #1735 (`fc103d99`) passes 486/486 on the same setup.
TheAggie commented 2026-10-08 20:25:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TheAggie on 2026-10-08T20:25:43Z.


Thanks for testing on the RX 7600 and for pinning down the OOB_SELECT cause before I got there. That's the fix I pushed, and good to have it confirmed on AMD and llvmpipe.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6068407675 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1734#issuecomment-6068407675). Originally posted by [TheAggie](https://github.com/TheAggie) on 2026-10-08T20:25:43Z. --- Thanks for testing on the RX 7600 and for pinning down the `OOB_SELECT` cause before I got there. That's the fix I pushed, and good to have it confirmed on AMD and llvmpipe.
adriadam10 commented 2026-10-10 06:00:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T06:00:41Z.


Checked: build and agc_driver_graphics + agc_driver_image_pipe_bank_xor on RADV (Rembrandt), plus the OOB_SELECT 3 fix; the new tests don't compile without the change. Matches the AMD/llvmpipe full-suite run from @johnmaia and the Windows RTX run in the description. Merging; #1735 can rebase on top.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6094447198 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1734#issuecomment-6094447198). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T06:00:41Z. --- Checked: build and `agc_driver_graphics` + `agc_driver_image_pipe_bank_xor` on RADV (Rembrandt), plus the `OOB_SELECT` 3 fix; the new tests don't compile without the change. Matches the AMD/llvmpipe full-suite run from @johnmaia and the Windows RTX run in the description. Merging; #1735 can rebase on top.
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!1734
No description provided.