fix(agc): build sampled array views from the slices they read #7258
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7258"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Pipodi on 2026-10-17T20:04:29Z.
What
A sampled array texture was built from slice 0 to the last slice its T# names, whatever slices the view actually reads. Two cases in Ghost of Yōtei (PPSA26344) made that the largest memory cost of its loading phase:
How
ViewedArrayWindow(TextureTiling.cpp) rebases a sampled 2D array, 1D array or cube view to its viewed slices, at the guest address of its base slice. It applies only when the window is exact: a thin surface with no DCC metadata and, for a 64 KiB XOR swizzle, a base slice that keeps the equation's slice bits at zero. Anything else keeps the whole array.FirstLayerDescriptor(GuestTextureResource.cpp) narrows a 2D array T# to its base slice. The sampled lookups apply it before the decode, cache key and image are made when the shader shape is 2D. That covers stage A records, stage B bindings, revalidation and image tables. A whole-array read of the same T# keeps its own cache entry.ShaderResources::Revalidatenarrows the T# words of an image table element withfirstLayerWordsbefore decoding, as the other paths do. Without it the whole array was rebuilt and compared against the narrowed texture, so an image table holding a 2D read of a 2D array never revalidated.This is independent of #6772, which serves storage views past
maxImageArrayLayersand refuses cubes and slice-dependent XOR swizzles, and of #6481, which faults image table entries the device or guest memory cannot hold. The 1537-slice image is below the 4090's 2048-layer limit and lies in readable memory, so neither one catches it.Tested
agc_driver_graphics:FirstLayerDescriptornarrowing, including a separate cache entry from the whole array.imageTableFirstLayerRevalidateTests(run byagc_draw_descriptors): an image table holding a 2D read of a 2D array must revalidate on the full proof path and keep its texture across a second revalidation. Without theRevalidatefix it fails withAGC graphics: an image table holding a 2D read of a 2D array did not revalidate.ed01d79d3+ these commits): 1471 of 1471 pass.The loading phase starts around frame 620, so run204 presented 371 frames in it against 343 for run201 (+8%) and built 24% more resource sets.
Log lines from run204
Technical debt
Added to
docs/dev/debt/libSceAgcDriver.md:Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T20:34:28Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)docs/dev/debt/libSceAgcDriver.mdL206docs/dev/debt/libSceAgcDriver.mdL206core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppL4889core/libs/prx/libSceAgcDriver/Graphics/include/TextureTiling.hppL77core/libs/prx/libSceAgcDriver/Graphics/src/TextureTiling.cppL3, L467core/libs/prx/libSceAgcDriver/tests/TextureTiling.cppL390docs/dev/debt/libSceAgcDriver.mdL206core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppL1058-1060core/libs/prx/libSceAgcDriver/Graphics/include/TextureTiling.hppL77core/libs/prx/libSceAgcDriver/Graphics/src/TextureTiling.cppL467docs/dev/debt/libSceAgcDriver.mdL206docs/dev/debt/libSceAgcDriver.mdL206docs/dev/debt/libSceAgcDriver.mdL206Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/include/TextureTiling.hppcore/libs/prx/libSceAgcDriver/Graphics/src/TextureTiling.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/GuestTextureResource.hppcore/libs/prx/libSceAgcDriver/Graphics/include/TextureTiling.hppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestTextureResource.cppcore/libs/prx/libSceAgcDriver/Graphics/src/TextureTiling.cppcore/libs/prx/libSceAgcDriver/tests/TextureTiling.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdImported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T21:39:53Z.
Review of 2b2f0601c. The window math, the XOR slice guard, the texture-relative view ranges and flush coherence all check out. On a local merge with main,
agc_driver_graphicspasses, and the PR merges cleanly on top of #7189, #7148 and #7089. One blocking issue:The image-table revalidation path still builds from the un-narrowed words. The image-table slow path in
ShaderResources::Revalidate(ShaderResources.cpp:2959-2963 at this head) still callscachedTexture(context, words, DecodeTextureResource(words), …)with the raw table words, whileresolveImageTables(4340-4367) now binds the narrowed texture. For a table element that is a 2D read of a 2D-array T#, every revalidation that misses the reused-table fast path:Revalidatereturns false and the full resolve runs every time.On main both paths used the raw words and agreed, so the mismatch is new. Only the binding revalidation (around 2914) is narrowed so far.
Suggested fix: apply the same
firstLayerWords(words, images->imageShapes.at(element), narrowed, false)before the decode at 2961.imagesis the table'sDescriptorBinding, which hasimageShapes, used the same way at 4328 and 4340. A test that revalidates an image table holding a 2D read of a 2D array would cover it; the current unit tests cover the window math and narrowing but don't reach this path.Imported from boykopovar/AnyPS5. Originally posted by Pipodi on 2026-10-18T08:12:42Z.
Thanks, you were right: Revalidate rebuilt an image table element from the raw T# words, while resolveImageTables binds the first-layer texture for a 2D read of a 2D array. The whole array was compared against the narrowed texture, so the proof always failed.
Fixed in 0b3603b5d (branch rebased on main
ed01d79d3): Revalidate now narrows the words with firstLayerWords before decoding, like the other paths.Added imageTableFirstLayerRevalidateTests, run by agc_draw_descriptors. It requires the table to revalidate on the full proof path and to keep its texture on a second pass. Without the fix it fails with "AGC graphics: an image table holding a 2D read of a 2D array did not revalidate". With it, ctest passes 1471 of 1471.
The debt entry for views of 1 GiB or more now also covers storage views, which are logged too.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T19:18:18Z.
Rebased onto current main (conflicts in
ShaderResources.cppwith the depth-surface retire andmultisampleViewTypechanges, and in the debt file; no logic changes on top of yours). Checked the window math and XOR slice guard, the narrowing at every lookup site, and that the image-table revalidation fix from the last round is in with a test that fails without it. ctest passes after the rebase; merged.