fix(agc): round linear volume mip extents up as addrlib does #1602

Merged
kr4y4 merged 1 commit from upstream-pr/1602 into main 2026-10-10 01:14:02 +00:00
kr4y4 commented 2026-10-08 14:07:20 +00:00 (Migrated from github.com)

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


What

ComputeThickLayout sizes the mips of a linear 3D texture from mip.width and mip.height, which round down (max(dim >> level, 1)). Its tiled modes, and the 2D linear path in ComputeLinearMipLayout, use the rounded-up element extent (ShiftCeil). addrlib rounds up for linear as well: its linear mip loop calls GetMipSize (gfx10addrlib.cpp L5090), which is ShiftCeil(Max(mip0Width, 1u), mipId) (gfx10addrlib.h L376-377).

For any level that halves an odd size, the row count, mip offsets and slice size therefore come out smaller than the guest's. Linear 8 bpp 100×60×8 with 4 levels:

slice size surface mip 0 mip 1 mip 2
addrlib 28,928 231,424 0x3500 0x1700 0x800
main 28,672 229,376 0x3400 0x1600 0x700

The linear levels now use the same rounded-up extent as the tiled ones, for the pitch and for the level's rows. A test in RunTextureTilingTests pins addrlib's values for that volume.

How it was found: AnyPS5's TextureTiling.cpp was compared against Mesa's addrlib, compiled unmodified and called through Addr2ComputeSurfaceInfo / Addr2ComputeSurfaceAddrFromCoord. The config was gfx1013, revision 0x82, GB_ADDR_CONFIG 0x00100044 (16 pipes).

Tested

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

  • agc_driver_graphics (includes the tiling tests) passes on an RTX 4070 Laptop GPU and an Intel Raptor Lake-S iGPU. With the old rounding put back, it fails with linear 8 bpp 100x60x8, 4 levels: slice size differs from addrlib.
  • Full suite on the RTX 4070: 454/454 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
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4788038858 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1602). Originally posted by [kr4y4](https://github.com/kr4y4) on 2026-10-08T14:07:20Z. --- ### What `ComputeThickLayout` sizes the mips of a linear 3D texture from `mip.width` and `mip.height`, which round down (`max(dim >> level, 1)`). Its tiled modes, and the 2D linear path in `ComputeLinearMipLayout`, use the rounded-up element extent (`ShiftCeil`). addrlib rounds up for linear as well: its linear mip loop calls `GetMipSize` (`gfx10addrlib.cpp` L5090), which is `ShiftCeil(Max(mip0Width, 1u), mipId)` (`gfx10addrlib.h` L376-377). For any level that halves an odd size, the row count, mip offsets and slice size therefore come out smaller than the guest's. Linear 8 bpp 100×60×8 with 4 levels: | | slice size | surface | mip 0 | mip 1 | mip 2 | |---|---|---|---|---|---| | addrlib | 28,928 | 231,424 | 0x3500 | 0x1700 | 0x800 | | main | 28,672 | 229,376 | 0x3400 | 0x1600 | 0x700 | The linear levels now use the same rounded-up extent as the tiled ones, for the pitch and for the level's rows. A test in `RunTextureTilingTests` pins addrlib's values for that volume. How it was found: AnyPS5's `TextureTiling.cpp` was compared against Mesa's addrlib, compiled unmodified and called through `Addr2ComputeSurfaceInfo` / `Addr2ComputeSurfaceAddrFromCoord`. The config was gfx1013, revision 0x82, GB_ADDR_CONFIG 0x00100044 (16 pipes). ### Tested Windows 11 (26200), WinLibs GCC 15.2.0 r7, CI configure flags, main at 63c57d22: - `agc_driver_graphics` (includes the tiling tests) passes on an RTX 4070 Laptop GPU and an Intel Raptor Lake-S iGPU. With the old rounding put back, it fails with `linear 8 bpp 100x60x8, 4 levels: slice size differs from addrlib`. - Full suite on the RTX 4070: 454/454 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 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
fisherjoey commented 2026-10-08 23:06:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-08T23:06:46Z.


Linux results, since this was tested on Windows only. Everything passes here, including agc_driver_graphics with the new tiling checks.

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 205 / 205
RADV, Ryzen 5 7600X iGPU (gfx1036), Mesa 26.2.1 205 / 205

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

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6070812291 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1602#issuecomment-6070812291). Originally posted by [fisherjoey](https://github.com/fisherjoey) on 2026-10-08T23:06:46Z. --- Linux results, since this was tested on Windows only. Everything passes here, including `agc_driver_graphics` with the new tiling checks. 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 | 205 / 205 | | RADV, Ryzen 5 7600X iGPU (gfx1036), Mesa 26.2.1 | 205 / 205 | CPU tests (`-E agc_driver`): 286 / 287. The one failure is `guest_dynamic_loader` (subprocess aborted), which fails the same way on `main` 29e533ac.
adriadam10 commented 2026-10-10 01:13:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T01:13:59Z.


Checked the addrlib reference (GetMipSize uses ShiftCeil), built and ran the AGC driver tests, and confirmed the new check fails without the fix; CI is green and it doesn't conflict with #1609. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6092053318 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1602#issuecomment-6092053318). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T01:13:59Z. --- Checked the addrlib reference (`GetMipSize` uses `ShiftCeil`), built and ran the AGC driver tests, and confirmed the new check fails without the fix; CI is green and it doesn't conflict with #1609. Merging.
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!1602
No description provided.