Skip to content

feat(agc): mipmapped 3D textures - #394

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
MichonGoddijn231849:feat/mipmapped-3d-textures
Oct 4, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
MichonGoddijn231849:feat/mipmapped-3d-textures

Conversation

@MichonGoddijn231849

Copy link
Copy Markdown
Contributor

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.

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

@oneandonlydean

Copy link
Copy Markdown
Collaborator

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

Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
Collaborator

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 and others added 2 commits October 4, 2026 10:27
3D textures with more than one mip level were refused. Each slab of
blockDepth slices of a thick (SW_4KB_S / SW_64KB_S) volume now holds the
whole mip chain, smallest level first and level 0 last, as 2D chains are
laid out. A level's depth halves per level, so the texture loops skip the
slices a level does not have. Thin 3D (D/R 64KB_X) chains use the 2D mip
layout per depth slice. Thick mip tails still throw.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…lib does

addrlib sizes a non-tail level with ShiftCeil; the layout used the image's
rounded-down extent, so volumes with a non-power-of-two width or height (33x20x12
in the new test) got a different layout.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@MichonGoddijn231849

MichonGoddijn231849 commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for checking it against addrlib. I folded the fix in here (66a4625): 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.

@MichonGoddijn231849
MichonGoddijn231849 force-pushed the feat/mipmapped-3d-textures branch from a8f91ac to 66a4625 Compare October 4, 2026 08:30
oneandonlydean added a commit to oneandonlydean/AnyPS5 that referenced this pull request Oct 4, 2026
3D textures in SW_4KB_S or SW_64KB_S whose smaller levels reach the mip
tail were refused ("3D texture mip tails are not implemented"). The
tail now follows addrlib's GFX10 thick layout
(Gfx10Lib::ComputeSurfaceInfoMacroTiled):

- a level enters the tail once its size, rounded up, fits the thick
  tail extent (the block with its height halved for 4 KiB blocks and
  its width halved for 64 KiB blocks) and at most GetMaxNumMipsInTail
  levels remain (5 for 4 KiB, 10 for 64 KiB);
- each slab starts with one tail block, then the other levels from the
  smallest to level 0;
- tail level i sits in slot maxMipsInTail - 1 - i, at the element offset
  addrlib derives from that slot's byte offset and the 256-byte thick
  micro block, at every depth slice.

Levels outside the tail are padded from their rounded-up size, as
addrlib's GetMipSize does; this changes the layout only for sizes that
are not powers of two.

The tests check element addresses of five volumes (4 KiB and 64 KiB
blocks, 1 to 16 bytes per element, odd sizes, a chain that starts in
the tail) against Mesa addrlib's Addr2ComputeSurfaceAddrFromCoord for
a Navi10 configuration.

(cherry picked from commit 0e531c1)

integ: boykopovar#394 now carries 66a4625 (levels padded from their rounded-up
size), which this branch already took through the follow-up; the
follow-up is rebased over it: same ComputeThickLayout, boykopovar#394's 33x20x12
padding test kept, its 8x8x8 tail refusal test dropped (tails are now
laid out).
@oneandonlydean
oneandonlydean merged commit 0bd5766 into boykopovar:main Oct 4, 2026
3 checks passed
SP4C3B4R-8 pushed a commit to SP4C3B4R-8/AnyPS5 that referenced this pull request Oct 6, 2026
Takes the 13 gate-batch PRs that merged upstream (boykopovar#319 boykopovar#329 boykopovar#330 boykopovar#331 boykopovar#325
boykopovar#435 boykopovar#471 boykopovar#294 boykopovar#376 boykopovar#404 boykopovar#394 boykopovar#401 boykopovar#446) in place of astrobot's local
versions, as integ/gate-batch cab0eab had them: boykopovar#294 and boykopovar#376 in
astrobot's depth model (DepthTarget, state.depth), boykopovar#394 with the thick mip
tails, boykopovar#401 over astrobot's slab pool, boykopovar#471 keeping the settled single-lane
path. Also takes the rest of main since a818bee (boykopovar#532 boykopovar#340 boykopovar#486 boykopovar#484 boykopovar#316
boykopovar#243 boykopovar#334 boykopovar#434 boykopovar#437 boykopovar#470 boykopovar#373 boykopovar#452 boykopovar#455 and our upstreamed PRs, where
astrobot keeps its later revisions and env switches).

Resolution notes: relinker converter/matcher/tests are upstream's (boykopovar#432
decoder covers VEX RIP-relative followers); RecompileResult gains boykopovar#316's
hostSubgroupSize (set from request.target.subgroupSize); shader disk cache
format 9; boykopovar#452's scissor message; upstream's later live-stack and
memory-copy decode tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Mgp3oZvembQziVNE2xARQK
@MichonGoddijn231849
MichonGoddijn231849 deleted the feat/mipmapped-3d-textures branch October 9, 2026 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc*

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants