feat(agc): mipmapped 3D textures #394

Merged
MichonGoddijn231849 merged 2 commits from upstream-pr/394 into main 2026-10-04 09:56:32 +00:00
MichonGoddijn231849 commented 2026-10-02 17:51:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-02T17:51:16Z.


What

3D textures with more than one mip level were refused ("mipmapped 3D textures are not implemented").

  • Thick volumes (SW_4KB_S / SW_64KB_S): each slab of blockDepth slices holds the whole mip chain. The smallest level comes first and level 0 last, the order 2D chains use. A level's width and height are padded to the 3D block, and the slab stride is the size of the whole chain. A level has max(depth >> level, 1) slices, so it uses only the first slabs.
  • Thin volumes (D/R 64KB_X): each depth slice holds the 2D mip chain, as array layers do.
  • SurfaceGeometry::HasLayer(level, layer) tells the texture upload, write-back and copy loops which depth slices a level has. For anything that is not 3D, and for single-mip 3D textures, it is always true.
  • Thick mip tails still throw ("3D texture mip tails are not implemented"). In a 4 KiB block a level enters the tail only once it fits half a block, e.g. 8x8 at 32 bpp.

GTA V's character shaders sample a 64x64x32 RGBA8 volume in SW_4KB_S with 3 levels. Every character draw into the G-buffer was skipped, about 900 every 10 s in the Prologue, so only the characters' eyes rendered. With this PR the characters render.

Tested

Windows 11 Pro, AMD Ryzen 5 7600, NVIDIA GeForce RTX 5080 (driver 32.0.16.1074), 32 GB DDR5-5600, MinGW-w64 GCC 15.2.0.

  • GTA V (PPSA04264), with #373–#377 and the other fixes still in progress: the Prologue's characters render. Before, their draws were refused.
  • Other titles were not re-run. The change only affects 3D textures with more than one level, which were refused before.
  • ctest: all tests pass. A new tiling test covers the slab layout of a 3-level SW_4KB_S volume, the per-level depth and the tail refusal.

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
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes. Written with Claude (Anthropic) under my direction; I reviewed and tested it.

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4719632355 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/394). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-02T17:51:16Z. --- ### What 3D textures with more than one mip level were refused ("mipmapped 3D textures are not implemented"). - **Thick volumes (SW_4KB_S / SW_64KB_S):** each slab of `blockDepth` slices holds the whole mip chain. The smallest level comes first and level 0 last, the order 2D chains use. A level's width and height are padded to the 3D block, and the slab stride is the size of the whole chain. A level has `max(depth >> level, 1)` slices, so it uses only the first slabs. - **Thin volumes (D/R 64KB_X):** each depth slice holds the 2D mip chain, as array layers do. - `SurfaceGeometry::HasLayer(level, layer)` tells the texture upload, write-back and copy loops which depth slices a level has. For anything that is not 3D, and for single-mip 3D textures, it is always true. - Thick mip tails still throw ("3D texture mip tails are not implemented"). In a 4 KiB block a level enters the tail only once it fits half a block, e.g. 8x8 at 32 bpp. GTA V's character shaders sample a 64x64x32 RGBA8 volume in SW_4KB_S with 3 levels. Every character draw into the G-buffer was skipped, about 900 every 10 s in the Prologue, so only the characters' eyes rendered. With this PR the characters render. ### Tested Windows 11 Pro, AMD Ryzen 5 7600, NVIDIA GeForce RTX 5080 (driver 32.0.16.1074), 32 GB DDR5-5600, MinGW-w64 GCC 15.2.0. - GTA V (PPSA04264), with #373–#377 and the other fixes still in progress: the Prologue's characters render. Before, their draws were refused. - Other titles were not re-run. The change only affects 3D textures with more than one level, which were refused before. - `ctest`: all tests pass. A new tiling test covers the slab layout of a 3-level SW_4KB_S volume, the per-level depth and the tail refusal. ### 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`); silent stubs are listed in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository - [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. Written with Claude (Anthropic) under my direction; I reviewed and tested it. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
oneandonlydean commented 2026-10-03 06:28:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-03T06:28:27Z.


This refuses 3D textures whose mips reach the mip tail. My integration branch has the thick (3D) mip tail layout, with tests checked against addrlib's Navi10 output. I can send it as a follow-up once this lands, if that's useful.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5966361958 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/394#issuecomment-5966361958). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-03T06:28:27Z. --- This refuses 3D textures whose mips reach the mip tail. My integration branch has the thick (3D) mip tail layout, with tests checked against addrlib's Navi10 output. I can send it as a follow-up once this lands, if that's useful.
MichonGoddijn231849 commented 2026-10-03 08:43:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-03T08:43:26Z.


Yes please, a follow-up with the thick mip tail would be useful; checking it against addrlib's Navi10 output is better than anything I'd have done here. I'll leave this PR refusing the tail until then.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5967289289 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/394#issuecomment-5967289289). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-03T08:43:26Z. --- Yes please, a follow-up with the thick mip tail would be useful; checking it against addrlib's Navi10 output is better than anything I'd have done here. I'll leave this PR refusing the tail until then.
oneandonlydean commented 2026-10-04 07:43:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T07:43:52Z.


While preparing the thick-tail follow-up I checked #394's 3D layout against addrlib (Navi10, built from Mesa e5f06878): the non-tail levels are padded to the rounded-down level size, but addrlib rounds up, so any volume whose width or height isn't a power of two gets a different layout (33x20x12 is one; 50 of 680 test volumes differed). Rounding the padded level size up matches addrlib on all of them. Happy to fold it into the follow-up instead if you'd rather keep this PR as is.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5977805714 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/394#issuecomment-5977805714). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-04T07:43:52Z. --- While preparing the thick-tail follow-up I checked #394's 3D layout against addrlib (Navi10, built from Mesa e5f06878): the non-tail levels are padded to the rounded-down level size, but addrlib rounds up, so any volume whose width or height isn't a power of two gets a different layout (33x20x12 is one; 50 of 680 test volumes differed). Rounding the padded level size up matches addrlib on all of them. Happy to fold it into the follow-up instead if you'd rather keep this PR as is.
MichonGoddijn231849 commented 2026-10-04 08:30:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-04T08:30:52Z.


Thanks for checking it against addrlib. I folded the fix in here (66a46259): a tiled level's padding now comes from its size rounded up (ShiftCeil), while the image extents stay rounded down. Linear layouts are unchanged. The test adds a 33x20x12 volume in 4 KiB thick blocks, where level 1 is padded from 17 texels (3 blocks per row, not 2). I also rebased onto main.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5978126020 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/394#issuecomment-5978126020). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-04T08:30:52Z. --- Thanks for checking it against addrlib. I folded the fix in here (66a46259): a tiled level's padding now comes from its size rounded up (ShiftCeil), while the image extents stay rounded down. Linear layouts are unchanged. The test adds a 33x20x12 volume in 4 KiB thick blocks, where level 1 is padded from 17 texels (3 blocks per row, not 2). I also rebased onto `main`.
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!394
No description provided.