fix(agc): let a kept descriptor set's table record hold its textures weakly #7802
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7802"
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 ionut27001 on 2026-10-19T08:10:29Z.
What
Since #6454, a freed dedicated descriptor set kept for reuse (
APS5_KEPT_DESCRIPTOR_SETS, 8 by default) carries aTableDescriptorsrecord whosetexturesis every sampled texture of theShaderResourcesthat freed it:keptTablemovestexturesinto it.ReleaseTextureCachescounts an evicted sampled entry as freed only when it held the last reference, so the textures these records hold leave the cache but keep their memory. On Marvel's Wolverine, heap 0 overruns its budget within a minute, allocations move to system memory, andvkAllocateMemoryfails with -2 (bisect and logs in #7801).The record now holds
std::weak_ptr<Texture>. The build compares a kept table's views only while every recorded texture is still alive. Two live textures cannot share a view handle, so an equal handle is still the same view, which is what the strong references were there to guarantee. When a recorded texture has died, the table is written in full, as for any other change. The rest of the kept-set path is unchanged.ImageTableReuse.cppgains two steps after its existing ones, as asked in review. A fullReleaseTextureCaches(~std::uint64_t{0})must leaveSampledTextureMemory()at 0. Then a table is built twice, and the second build must keep its table write, so the set it leaves holds a record that matches while its textures live. A full release then destroys every texture (checked again throughSampledTextureMemory()), and the next build of the table must make one table write and keep none.Tested
NVIDIA GeForce RTX 4080 SUPER 16 GB (driver 617.42), Windows 11 Pro 26300, Ryzen 7 5800X3D, WinLibs GCC 15.2.0 r7, Release.
ctest -R '^agc_driver_(graphics|image_table_reuse)$'passes with this change onmainfb0dc118fand on676d42396(both with #6901 and #6308 merged, as for the game). These are the descriptor cache's kept-set unit test and the image table reuse execution test, run on the GPU.main6030b31e0(this branch):agc_driver_image_table_reusepasses in 3 of 3 runs, and in 3 of 3 withAPS5_KEPT_DESCRIPTOR_SETS=0;agc_driver_graphicspasses. WithShaderResources.cppandShaderResources.hppreverted to6030b31e0and the new steps kept,agc_driver_image_table_reusefails in 3 of 3 runs: "96256 bytes of sampled textures outlived a full release of the texture caches after the kept-table steps".heldAlivecheck removed (the record still weak), the new steps pass in 3 of 3 runs on this card: the second build kept its write, and the build after the textures were destroyed made one table write and kept none, so it was written in full anyway. Without the check the step can fail only on a driver that gives every new view of the table the handle that the destroyed view in the same slot had; that did not happen here, so on this card the step does not catch a missing check.python tools/check_conventions.pypasses.fb0dc118fthe first runs spend 35 s and more on each new compute pipeline until the Vulkan pipeline cache holds them; thefb0dc118frows are runs after that.676d42396vkAllocateMemory ... memoryType=0 ... initialResult=-2)676d42396+ this change676d42396,APS5_KEPT_DESCRIPTOR_SETS=0fb0dc118ffb0dc118f+ this changeFrame times on the card with this change are the same as with
APS5_KEPT_DESCRIPTOR_SETS=0and as before #6454: on676d42396, about 5.8 s per present once warm (31 presents in the 252 s after the first one, in the 300 s run).Not checked: Linux, lavapipe and other vendors; #6454's lavapipe timings with this change; how often the comparison now falls back to a full write (the kept and made counters are only exposed to tests).
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)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-19T08:19:06Z.
Some 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/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/execution/ImageTableReuse.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/execution/ImageTableReuse.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/execution/ImageTableReuse.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/execution/ImageTableReuse.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppImported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-19T08:53:29Z.
Thanks, the cause and the fix both check out here.
One ask: nothing in the PR fails on main yet. Both of these fit in tests/execution/ImageTableReuse.cpp:
ReleaseTextureCaches(~std::uint64_t{0})should leaveSampledTextureMemory() == 0. With a print at the end ofmain()on an RTX 4090, main still counts 96256 of 98304 sampled bytes after a full release, and this PR counts 0.heldAlivecheck removed.Imported from boykopovar/AnyPS5. Originally posted by ionut27001 on 2026-10-19T10:27:53Z.
Thanks. Both are in
ImageTableReuse.cppnow, after the existing steps:ReleaseTextureCaches(~std::uint64_t{0})must leaveSampledTextureMemory() == 0. WithShaderResources.cppand.hppreverted tomain6030b31e0, it fails in 3 of 3 runs on an RTX 4080 SUPER (617.42, Windows): "96256 bytes of sampled textures outlived a full release of the texture caches after the kept-table steps". With this PR it passes.SampledTextureMemory() == 0, so nothing else holds them), and the next build must make one table write and keep none. It passes with this PR, also withAPS5_KEPT_DESCRIPTOR_SETS=0.On this card, step 2 also passes with the
heldAlivecheck removed (3 of 3): the rebuilt table never matched the kept record, so it was written in full anyway. Without the check it could fail only on a driver that gives every new view the handle of the destroyed view in the same slot, so on its own it doesn't catch the removal. If you want a test that does, I can count the full writes made because a recorded texture expired, next to the kept and made counters, and expect one there.The runs are in the Tested section.
Imported from boykopovar/AnyPS5. Originally posted by fogydes on 2026-10-19T12:14:58Z.
Review: APPROVED
Reviewed the updated head addressing
@oneandonlydean's feedback:ReleaseTextureCaches, directly resolving the device memory exhaustion observed in Marvel's Wolverine (Issue #7801).ImageTableReuse.cpp:SampledTextureMemory() == 0afterReleaseTextureCaches(~0ull)(which failed with 96,256 outliving bytes on main).Ready to merge.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-19T14:39:33Z.
AMD and Intel Windows data: with this PR's test change,
agc_driver_image_table_reusefails onmainand passes with the PR, on an AMD RX 9070 XT and an Intel UHD 770.Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7, Release, every execution test built,
ANYPS5_NO_SHADER_CACHE=1, serial CTest. Intel UHD Graphics 770 (8086:a780), driver 32.0.101.7088. AMD Radeon RX 9070 XT (1002:7550), driver 32.0.31041.1004, withVkCacheemptied first. This head15c6c9ff1merged intomain85029a00f. "Without" means only this PR's diff totests/execution/ImageTableReuse.cpp, applied tomain85029a00f.agc_driver_image_table_reuseimage table reuse: 385024 bytes of sampled textures outlived a full release of the texture caches after the kept-table steps96256 bytesAI-assisted: yes (Claude Code)