fix(agc): drop resource-cache entries that hold released sampled textures #6492
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6492"
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-15T17:29:48Z.
What
A
ResourceCacheentry keeps every sampled texture of its descriptor sets alive. The sampled texture cache passes over textures something else still holds, and once it is a quarter over its budget it drops them anyway. Textures it makes without caching (a first use while the least recently used entry was used this frame or the last) are never in it at all. In both cases the only owner left is the resource-cache entry, so the texture stays in device memory with no budget counting it. Nothing limits that except the 1,024-entry and 65,536-table-element counts. This is the sampled-texture side of #3256, which #3473 and #3474 fixed for storage images.Texturegets a released flag.eraseTexturesets it on a texture something else still holds, and the sampled lookup sets it on a textureadmitTexturerefused.ResourceCache::Insertrefuses descriptor sets that hold a released texture. When a texture was released since the last insert, it also removes the entries holding one and hands them back throughevicted, likeRemoveImagedoes for evicted storage images. The caller then passes them to the recorder.releasedTestsinagc_driver_sampled_cache_budget: an entry whose texture the cache drops is handed back and stops keeping the texture alive, and a descriptor set holding a released texture is not admitted. Without the change toShaderResources.cpp, the test fails at "the sampled texture cache dropped a texture the resource cache holds without marking it released".Technical debt
New entry "Resource cache entries holding released textures" in
docs/dev/debt/libSceAgcDriver.md:Findcan still return those entries until then;Tested
Windows 11, NVIDIA GeForce RTX 4090, driver 617.42.
349420af7(mainec1193dc3), fullBUILD_TESTING=ONbuild: 1295/1296 pass. The other one isagc_driver_gpu_indirect_arguments_misaligned_writer_ahead, whose source fails to compile with MinGW onmaintoo (requested alignment '65536' exceeds object file maximum 8192,GpuIndirectArgumentsMisalignedWriterAhead.cpp:25).0dab493f5+ #5815 #5781 #6227 #5405 #6402 #6174 + local patches; the runs differ only in what the table says. The wolf brightness screen fades in from frame 821. Values come from the[gpu] sampled texture cache budgetlines (device-local heap 0,VK_EXT_memory_budgetbudget about 22.9 GB).vkAllocateMemoryreturnsVK_ERROR_OUT_OF_DEVICE_MEMORYrun165 frames and memory
[texture-cache]at frame 841: 1,662 cached, 7,001 used uncached, 1,154 evicted, 5,407 held ones passed over in 10 s; 6,572 MiB in 26,466 entries, budget 6,432 MiB. run162 passed over 72,852 to 166,319 held textures per 10 s at frame 824.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-15T18:26:57Z.
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.mdL177docs/dev/debt/libSceAgcDriver.mdL177docs/dev/debt/libSceAgcDriver.mdL177docs/dev/debt/libSceAgcDriver.mdL177docs/dev/debt/libSceAgcDriver.mdL177docs/dev/debt/libSceAgcDriver.mdL177docs/dev/debt/libSceAgcDriver.mdL177Some 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/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/execution/SampledCacheBudget.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppdocs/dev/debt/libSceAgcDriver.mdcore/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/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/execution/SampledCacheBudget.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/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.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdImported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-16T10:45:41Z.
Death Stranding 2 (PPSA02015) reaches this on its loading screen, and with this PR it still runs out of device memory, only later. This is a local stack, since the title needs several unmerged PRs and a few local skips of refusals to get that far. Linux, RTX 5080, NVIDIA 615.78.08.
I counted live
VkDeviceMemoryper allocating call site. Without the PR, device-local memory is 14.0 GiB at 330 s andvkAllocateMemory texturefails with -2 at about 390 s. With it, the same run is at 6.8 GiB at 330 s, then climbs again and fails at 416 s.At 405 s with the PR, allocations made by
Texture::Texturehold 9.4 GiB (37,387 made, 23,255 freed), while[texture-cache]reports 6,373 MiB in the cache against a 6,201 MiB budget, with44837 held ones passed overin that 10 s window. So about 3 GiB of sampled textures still live outside the cache. Re-creations of the same address and shape made up 42 of the 51.5 GB of texture allocations in the run without the PR.Imported from boykopovar/AnyPS5. Originally posted by Pipodi on 2026-10-16T11:39:57Z.
Another data point from today, from a different integration base, so not a clean A/B:
APS5_SPANNED_WAVE=1)vkAllocateMemory device buffer ... VK_ERROR_OUT_OF_DEVICE_MEMORY, abort. Device-local heap 25,281 MiB used of a 22,913 MiB budget, 13,149 MiB of it sampled texturesThe two bases also differ in #6416 and a few local commits, so this only supports the earlier run162 and run165 comparison in the description. It doesn't replace it.
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by mrfelek on 2026-10-16T14:47:07Z.
Hot Wheels Infinite Rush (PPSA22408): still runs out of device memory on the loading screen with this PR, VRAM split by allocating call site
Setup
main5d9dcc42dmerged with #6160, #5998, #5997, this PR (349420af7) and #6465, all clean merges. #6160 is needed to get this title past thes_swappc_b64abort from #6117.prx/modules.APS5_STORE_AT_FLIP=1,APS5_HOST_IMPORT_MIB=16384.vkAllocateMemoryandvkFreeMemoryas returned byContext::Function, and keeps live bytes per calling address and memory type.Result
vkAllocateMemory device buffer: allocation=9437184 memoryType=1 reclaimed=663412736 initialResult=-2 attempts=2: Vulkan result -2.Device-local memory (type 1) held by the driver at the failed allocation: 7.0 GB
makeSlab(buffer slabs)StorageTexture::StorageTextureBufferPool::AllocateMemoryTexture::Texturenvidia-smishowed about 11.4 GB in use at the end. About 1.7 GB of that is the desktop, so roughly 2.7 GB was the NVIDIA driver's own memory (pipelines and pools), which the counter does not see.bindImport, host-visible type 3) held 8.2 GB, in system RAM, not VRAM.Observations
AI-assisted: this comment was drafted with the help of Claude Code and checked against the logs by us.
Imported from boykopovar/AnyPS5. Originally posted by Pipodi on 2026-10-16T21:20:26Z.
Thanks for splitting it by call site, that answers the question this PR can't.
By your table, sampled textures (
Texture::Texture) hold 1.0 GB of the 7.0 GB device-local memory at the failure. This PR only stops resource-cache entries from keeping sampled textures alive after the texture cache has let go of them. So it can't get this title under 12 GB, and its earlier stop without the PR is consistent with that. On our 24 GB card, the same holder was what overflowed (7.8 GB of sampled textures held outside the texture cache, in the table above). On yours, the other three holders are the larger part.Of the four holders, only the sampled texture cache reads
VK_EXT_memory_budget; #6783 adjusts how its budget leaves room for storage textures. The other three allocate without any device-memory budget:makeSlabinUnitShadow.cpp);BufferPool.They react only once
vkAllocateMemoryfails. ThenBufferPoolreclaims what it can and retries; your log shows that reclaim freed 633 MiB, not enough for the 9 MiB request plus everything still growing. With about 2.7 GB of the driver's own memory and 1.7 GB of desktop on a 12 GB card, the four holders together cross the limit, as you say, without any of them leaking.I'd treat that as its own issue: no device-memory budget across holders, so a 12 GB card runs out where a 24 GB one doesn't. It's a different change from this PR. Your table and the churn numbers (26,130 slabs and 11,501 storage textures made in one loading) are exactly what that issue needs. Do you want to open it, or should I, quoting your comment?
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T21:41:07Z.
This now conflicts with main (after #6875 and #4339 merged). Could you rebase onto current main? We'll re-run full CI and the gate on the new head.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-18T10:52:06Z.
Thanks, this is ready apart from one line. The project keeps specific game titles out of its docs, and the new
docs/dev/debt/libSceAgcDriver.mdentry says "Measured only on