fix(agc): lay out 3D SW_64KB_D_X textures as thick volumes #1609

Merged
kr4y4 merged 1 commit from upstream-pr/1609 into main 2026-10-10 04:19:45 +00:00
kr4y4 commented 2026-10-08 14:24:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by kr4y4 on 2026-10-08T14:24:14Z.


What

DescribeSurface treats 3D SW_64KB_D_X volumes like Z_X and R_X, as a stack of thin 2D slices. In GFX10 a display swizzle on a 3D resource is thick. addrlib's HwlIsThick is IsTex3d(resourceType) && (isStd || isDisp) (gfx10addrlib.h L229-234), and the ADDR_SW_64KB_D_X row has isDisp set (gfx10addrlib.cpp L85). Only Z_X and R_X volumes are thin.

addrlib addresses these volumes with GFX10_SW_64K_D3_X_PATINFO (gfx10SwizzlePattern.h). With the thin layout, every element after the first block row lands elsewhere, and the surface size is wrong:

SW_64KB_D_X 3D addrlib block addrlib surface main surface
32 bpp 64×64×16, 1 level 32×32×16 262,144 1,048,576

For example, in a 32 bpp 1×1×5 volume, element (0,0,1) is at 0x20 in addrlib and 0x10800 on main. The guest allocation is addrlib's size, so the thin layout also reads past it.

D_X volumes now take the thick path, like S_X:

  • ThickBlockExtent gives them the 64 KiB thick block extents.
  • TextureDetiler uses a new equation key 0x11a.
  • TextureSwizzleEquations.hpp gets five rows for that key (1 to 16 bytes per element). They were generated from addrlib's 16-pipe GFX10_SW_64K_D3_X pattern rows, the same way as the existing 0x119 rows.

Some of the pipe bits use x/y bits above the block, which the detiler shader already supports because it passes full coordinates, as for 0x119.

Tests:

  • RunTextureTilingTests pins addrlib's guest size, first tail level and sample element addresses for 32 bpp 64×64×16 (1 level), 8 bpp 100×60×70 (7 levels) and 128 bpp 9×5×3 (4 levels).
  • agc_driver_image_xor_swizzle_volume now also samples a thick D_X volume through the detiler on the GPU.

How it was found: AnyPS5's TextureTiling.cpp and equation tables were compared against Mesa's addrlib, compiled unmodified and called through Addr2ComputeSurfaceInfo / Addr2ComputeSurfaceAddrFromCoord. The config was gfx1013, revision 0x82, GB_ADDR_CONFIG 0x00100044 (16 pipes, non-RB+). Every 2D equation matched bit for bit. For volumes, main has about 4.2 million mismatching SW_64KB_D_X addresses at 4 and at 8 bytes per element. That comparison covers 7616 3D configurations, compared wherever both addrlib and AnyPS5 accept them: the swizzle modes AnyPS5 implements, at 8–128 bpp, 15 sizes, 1, 2, 4 or a full chain of mips, and depths of 1, 5, 16 and 33. With this change, the linear-volume rounding fix from #1602 and the Z_X tail limits from #1590 applied together, it reports 0 mismatches in 143,437,500 addresses.

Tested

Windows 11 (26200), WinLibs GCC 15.2.0 r7, CI configure flags, main at fe9beae0:

  • agc_driver_graphics and agc_driver_image_xor_swizzle_volume pass with --repeat until-fail:3 on an RTX 4070 Laptop GPU and an Intel Raptor Lake-S iGPU.
  • With D_X put back on the thin path, agc_driver_graphics fails with SW_64KB_D_X 32 bpp 64x64x16, 1 level: guest size differs from addrlib.
  • Full suite on the RTX 4070: 456/456 passed.

Checklist

  • Based on current main; no other open PR implements the same thing
  • One topic per PR
  • No comments in code except technical debt
  • No silent stubs added
  • No notes, investigation files or images added to the repository
  • No new third-party code
  • Generic, not specific to one title
  • Depends on: none (touches the same test function as #1602; the two merge cleanly)
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4788267166 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1609). Originally posted by [kr4y4](https://github.com/kr4y4) on 2026-10-08T14:24:14Z. --- ### What `DescribeSurface` treats 3D `SW_64KB_D_X` volumes like `Z_X` and `R_X`, as a stack of thin 2D slices. In GFX10 a display swizzle on a 3D resource is thick. addrlib's `HwlIsThick` is `IsTex3d(resourceType) && (isStd || isDisp)` (`gfx10addrlib.h` L229-234), and the `ADDR_SW_64KB_D_X` row has `isDisp` set (`gfx10addrlib.cpp` L85). Only `Z_X` and `R_X` volumes are thin. addrlib addresses these volumes with `GFX10_SW_64K_D3_X_PATINFO` (`gfx10SwizzlePattern.h`). With the thin layout, every element after the first block row lands elsewhere, and the surface size is wrong: | `SW_64KB_D_X` 3D | addrlib block | addrlib surface | main surface | |---|---|---|---| | 32 bpp 64×64×16, 1 level | 32×32×16 | 262,144 | 1,048,576 | For example, in a 32 bpp 1×1×5 volume, element (0,0,1) is at 0x20 in addrlib and 0x10800 on main. The guest allocation is addrlib's size, so the thin layout also reads past it. `D_X` volumes now take the thick path, like `S_X`: - `ThickBlockExtent` gives them the 64 KiB thick block extents. - `TextureDetiler` uses a new equation key 0x11a. - `TextureSwizzleEquations.hpp` gets five rows for that key (1 to 16 bytes per element). They were generated from addrlib's 16-pipe `GFX10_SW_64K_D3_X` pattern rows, the same way as the existing 0x119 rows. Some of the pipe bits use x/y bits above the block, which the detiler shader already supports because it passes full coordinates, as for 0x119. Tests: - `RunTextureTilingTests` pins addrlib's guest size, first tail level and sample element addresses for 32 bpp 64×64×16 (1 level), 8 bpp 100×60×70 (7 levels) and 128 bpp 9×5×3 (4 levels). - `agc_driver_image_xor_swizzle_volume` now also samples a thick `D_X` volume through the detiler on the GPU. How it was found: AnyPS5's `TextureTiling.cpp` and equation tables were compared against Mesa's addrlib, compiled unmodified and called through `Addr2ComputeSurfaceInfo` / `Addr2ComputeSurfaceAddrFromCoord`. The config was gfx1013, revision 0x82, GB_ADDR_CONFIG 0x00100044 (16 pipes, non-RB+). Every 2D equation matched bit for bit. For volumes, main has about 4.2 million mismatching `SW_64KB_D_X` addresses at 4 and at 8 bytes per element. That comparison covers 7616 3D configurations, compared wherever both addrlib and AnyPS5 accept them: the swizzle modes AnyPS5 implements, at 8–128 bpp, 15 sizes, 1, 2, 4 or a full chain of mips, and depths of 1, 5, 16 and 33. With this change, the linear-volume rounding fix from #1602 and the Z_X tail limits from #1590 applied together, it reports 0 mismatches in 143,437,500 addresses. ### Tested Windows 11 (26200), WinLibs GCC 15.2.0 r7, CI configure flags, main at fe9beae0: - `agc_driver_graphics` and `agc_driver_image_xor_swizzle_volume` pass with `--repeat until-fail:3` on an RTX 4070 Laptop GPU and an Intel Raptor Lake-S iGPU. - With `D_X` put back on the thin path, `agc_driver_graphics` fails with `SW_64KB_D_X 32 bpp 64x64x16, 1 level: guest size differs from addrlib`. - Full suite on the RTX 4070: 456/456 passed. ### Checklist - [x] Based on current `main`; no other open PR implements the same thing - [x] One topic per PR - [x] No comments in code except technical debt - [x] No silent stubs added - [x] No notes, investigation files or images added to the repository - [x] No new third-party code - [x] Generic, not specific to one title - [x] Depends on: none (touches the same test function as #1602; the two merge cleanly) - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
fisherjoey commented 2026-10-09 04:22:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-09T04:22:30Z.


Linux results, since this was tested on Windows only. Everything passes here, including agc_driver_graphics and agc_driver_image_xor_swizzle_volume.

Nobara 44 (Linux 7.2), GCC 16.2.1, Release, BUILD_TESTING=ON. PR head merged onto main 29e533ac.

ctest -R agc_driver -j1
RTX 5070 Ti, driver 595.91.07 183 / 183
RADV, Ryzen 5 7600X iGPU (gfx1036), Mesa 26.2.1 183 / 183

CPU tests (-E agc_driver): 279 / 280. The one failure is guest_dynamic_loader (subprocess aborted), which fails the same way on main 29e533ac.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6074209681 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1609#issuecomment-6074209681). Originally posted by [fisherjoey](https://github.com/fisherjoey) on 2026-10-09T04:22:30Z. --- Linux results, since this was tested on Windows only. Everything passes here, including `agc_driver_graphics` and `agc_driver_image_xor_swizzle_volume`. Nobara 44 (Linux 7.2), GCC 16.2.1, Release, `BUILD_TESTING=ON`. PR head merged onto `main` 29e533ac. | | `ctest -R agc_driver -j1` | |---|---| | RTX 5070 Ti, driver 595.91.07 | 183 / 183 | | RADV, Ryzen 5 7600X iGPU (gfx1036), Mesa 26.2.1 | 183 / 183 | CPU tests (`-E agc_driver`): 279 / 280. The one failure is `guest_dynamic_loader` (subprocess aborted), which fails the same way on `main` 29e533ac.
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!1609
No description provided.