fix(agc): use gfx1013's smaller mip tail limits for 8 and 16 bpp SW_64KB_Z_X #1639

Merged
gerardlesan merged 1 commit from upstream-pr/1639 into main 2026-10-10 04:40:18 +00:00
gerardlesan commented 2026-10-08 15:24:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gerardlesan on 2026-10-08T15:24:42Z.


What

GetMipTailLayout gave SW_64KB_Z_X the same mip tail limits as the other 64 KiB modes. In addrlib that is only the case on Navi10. On every other GFX10 chip, including the PS5's gfx1013, addrlib uses smaller limits for 8 and 16 bpp Z-order surfaces. As a result, mipmapped 8 and 16 bpp Z_X textures (D16 depth, R8, R16, R8G8 and so on) started their tail too early, and every level was read and written back at the wrong offset.

Source, Mesa src/amd/addrlib/src/gfx10/gfx10addrlib.cpp at d778ede7:

  • HwlConvertChipFamily (L1003-1010) sets dsMipmapHtileFix and clears it only for Navi10.
  • ComputeSurfaceInfoMacroTiled (L3923-3926): with the setting on, for a Z-order swizzle at 8 or 16 bpp, the tail limits are divided by Block256_2d[index] / Block256_2d[2]. That halves the width at 8 and 16 bpp, and also the height at 8 bpp.

GetMipTailLayout now halves the limits the same way. Only the level where the tail starts changes. The tail slot positions stay the same, because addrlib computes them from each level's index inside the tail, not from the limits (L3999-4001).

Results from #1590, SW_64KB_Z_X 8 bpp 256x256, 9 levels:

surface size first tail mip mip 0 at (0,0) mip 1 at (0,0)
addrlib, gfx1013 196,608 2 0x20000 0x10000
main 131,072 1 0x10000 0x8000
this PR 196,608 2 0x20000 0x10000

For 16 bpp 128x128 with a full mip chain, mip 0 now starts at 0x10000, as in addrlib, instead of 0x8000.

This follows addrlib's setting for gfx1013. The console's own layout has not been measured, as #1590 also notes.

Fixes #1590

Tested

CachyOS Linux (kernel 7.2.9), GCC 16.2.1, CMake 4.4.4, Ninja, Release with BUILD_TESTING=ON, on main f8c2f072. No GPU was needed: agc_driver_graphics runs against MockVulkan.

  • agc_driver_graphics gets two new cases: 8 bpp 256x256 with 9 levels, and 16 bpp 128x128 with 8 levels.
  • With only the tests applied (red), it fails with swizzle mode 24, 1 bytes, 256x256, 9 levels, 1 slices: surface or slice size differs from addrlib.
  • With the fix (green), it passes.
  • Full suite: 512/513 passed on an RTX 4060 Laptop GPU (NVIDIA 615.71.09). The one failure, agc_driver_dcc_keys_first_write (an unchanged pending image was uploaded again), fails the same way on main without this change.
  • python3 tools/check_conventions.py --base origin/main: all checks passed.

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); no silent stubs added
  • No notes, investigation .md files or images added to the repository
  • No new third-party code
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4789062922 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1639). Originally posted by [gerardlesan](https://github.com/gerardlesan) on 2026-10-08T15:24:42Z. --- ### What `GetMipTailLayout` gave `SW_64KB_Z_X` the same mip tail limits as the other 64 KiB modes. In addrlib that is only the case on Navi10. On every other GFX10 chip, including the PS5's gfx1013, addrlib uses smaller limits for 8 and 16 bpp Z-order surfaces. As a result, mipmapped 8 and 16 bpp `Z_X` textures (D16 depth, R8, R16, R8G8 and so on) started their tail too early, and every level was read and written back at the wrong offset. Source, Mesa `src/amd/addrlib/src/gfx10/gfx10addrlib.cpp` at `d778ede7`: - `HwlConvertChipFamily` ([L1003-1010](https://gitlab.freedesktop.org/mesa/mesa/-/blob/d778ede72c4c31bf4ed80578688c3e78d9af2dfa/src/amd/addrlib/src/gfx10/gfx10addrlib.cpp#L1003-1010)) sets `dsMipmapHtileFix` and clears it only for Navi10. - `ComputeSurfaceInfoMacroTiled` ([L3923-3926](https://gitlab.freedesktop.org/mesa/mesa/-/blob/d778ede72c4c31bf4ed80578688c3e78d9af2dfa/src/amd/addrlib/src/gfx10/gfx10addrlib.cpp#L3923-3926)): with the setting on, for a Z-order swizzle at 8 or 16 bpp, the tail limits are divided by `Block256_2d[index] / Block256_2d[2]`. That halves the width at 8 and 16 bpp, and also the height at 8 bpp. `GetMipTailLayout` now halves the limits the same way. Only the level where the tail starts changes. The tail slot positions stay the same, because addrlib computes them from each level's index inside the tail, not from the limits ([L3999-4001](https://gitlab.freedesktop.org/mesa/mesa/-/blob/d778ede72c4c31bf4ed80578688c3e78d9af2dfa/src/amd/addrlib/src/gfx10/gfx10addrlib.cpp#L3999-4001)). Results from #1590, `SW_64KB_Z_X` 8 bpp 256x256, 9 levels: | | surface size | first tail mip | mip 0 at (0,0) | mip 1 at (0,0) | |---|---|---|---|---| | addrlib, gfx1013 | 196,608 | 2 | 0x20000 | 0x10000 | | main | 131,072 | 1 | 0x10000 | 0x8000 | | this PR | 196,608 | 2 | 0x20000 | 0x10000 | For 16 bpp 128x128 with a full mip chain, mip 0 now starts at 0x10000, as in addrlib, instead of 0x8000. This follows addrlib's setting for gfx1013. The console's own layout has not been measured, as #1590 also notes. Fixes #1590 ### Tested CachyOS Linux (kernel 7.2.9), GCC 16.2.1, CMake 4.4.4, Ninja, Release with `BUILD_TESTING=ON`, on `main` f8c2f072. No GPU was needed: `agc_driver_graphics` runs against `MockVulkan`. - `agc_driver_graphics` gets two new cases: 8 bpp 256x256 with 9 levels, and 16 bpp 128x128 with 8 levels. - With only the tests applied (red), it fails with `swizzle mode 24, 1 bytes, 256x256, 9 levels, 1 slices: surface or slice size differs from addrlib`. - With the fix (green), it passes. - Full suite: 512/513 passed on an RTX 4060 Laptop GPU (NVIDIA 615.71.09). The one failure, `agc_driver_dcc_keys_first_write` (`an unchanged pending image was uploaded again`), fails the same way on `main` without this change. - `python3 tools/check_conventions.py --base origin/main`: all checks passed. ### 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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); no silent stubs added - [x] No notes, investigation `.md` files or images added to the repository - [x] No new third-party code - [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)
klosixgaming-arch commented 2026-10-08 15:32:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-08T15:32:06Z.

Review: APPROVED


LGTM. Well-researched fix that correctly applies gfx1013's smaller mip tail limits for 8 and 16 bpp SW_64KB_Z_X textures, matching Mesa addrlib behavior. The block size ratio calculation is correct, and the test cases with specific surface sizes and first-tail-mip levels provide good validation against known-good reference values. Good documentation of the issue and fix rationale.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5459108301 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1639#pullrequestreview-5459108301). Originally posted by [klosixgaming-arch](https://github.com/klosixgaming-arch) on 2026-10-08T15:32:06Z. **Review:** APPROVED --- LGTM. Well-researched fix that correctly applies gfx1013's smaller mip tail limits for 8 and 16 bpp SW_64KB_Z_X textures, matching Mesa addrlib behavior. The block size ratio calculation is correct, and the test cases with specific surface sizes and first-tail-mip levels provide good validation against known-good reference values. Good documentation of the issue and fix rationale.
oneandonlydean commented 2026-10-09 09:22:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T09:22:24Z.


Please drop the merge commit (d6c57f4) and rebase onto main instead; the branch history has to stay linear. The fix itself is fine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6078122340 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1639#issuecomment-6078122340). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T09:22:24Z. --- Please drop the merge commit (d6c57f4) and rebase onto main instead; the branch history has to stay linear. The fix itself is fine.
popcoder565 commented 2026-10-09 15:22:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T15:22:46Z.


Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head d6c57f46, merged onto main d70b8998 in one build with 33 other AGC/shader PRs that had no Windows run.

  • This PR's tests pass: agc_driver_graphics. None of them reported skipping a case.
  • Full ctest in that build: 514 of 515. The one failure is #2257's new test, which is registered without the Windows PATH setup.

No title was run.

🤖 Addressed by Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6083878920 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1639#issuecomment-6083878920). Originally posted by [popcoder565](https://github.com/popcoder565) on 2026-10-09T15:22:46Z. --- Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head `d6c57f46`, merged onto `main` d70b8998 in one build with 33 other AGC/shader PRs that had no Windows run. - This PR's tests pass: `agc_driver_graphics`. None of them reported skipping a case. - Full ctest in that build: 514 of 515. The one failure is #2257's new test, which is registered without the Windows `PATH` setup. No title was run. _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_
gerardlesan commented 2026-10-09 18:18:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gerardlesan on 2026-10-09T18:18:05Z.


@oneandonlydean Dropped the merge commit and rebased onto main (f8c2f072). The branch is now the single commit b6a95307.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6086711665 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1639#issuecomment-6086711665). Originally posted by [gerardlesan](https://github.com/gerardlesan) on 2026-10-09T18:18:05Z. --- @oneandonlydean Dropped the merge commit and rebased onto `main` (f8c2f072). The branch is now the single commit b6a95307.
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!1639
No description provided.