fix(agc): cap the storage-image cache by entry count #14220
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14220"
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 EagleBearerYS on 2026-11-01T00:42:00Z.
What
The storage-image cache (
cachedStorageTextureinShaderResources.cpp) is bounded by bytes only. Its byte budget follows the device's reported memory budget, so small surfaces created at new addresses never reach it. Each stays cached and alive with its Vulkan objects, sampled view and CPU memory, none of which the byte count sees.The cache now also evicts its least recently used surface once it holds
APS5_STORAGE_CACHE_ENTRIESentries (default 2048;0turns the limit off, and unset keeps 2048). Eviction goes throughevictStorageas before: pending results are flushed first and the sampled views over the image are dropped. The variable is documented indocs/dev/ENVIRONMENT.md, and the cap has an entry in the AGC debt file.Counters. With
APS5_PROFILE_DRAW=1, the[storage]profile line now also lists evictions by reason, with the MiB each reason's evictions wrote back.entry capcounts this cap's evictions, and every otherStorageTexture::Flush(the byte budget, cache clears and the other evictions) keeps thecache evictionlabel it had onmain. An entry evicted with nothing pending counts at 0 MiB, so the MiB figure is write-back traffic, not the size of what was evicted. On macOS, an entry-cap eviction's trapped-overlap stores also count underentry cap; that path is macOS-only and isn't run on GitHub's runners.Commits since
55d3875c32:06ae2f4b58lets0turn the limit off.d285e5fecamergesmaine0caf13600, whose #13678 changed the first line ofStorageTexture::Flush, so thatd2cad15101, which adds the counters, applies tomain'sFlush.Where the growth was seen. On a Planet of Lana (PPSA19450) build of a local tree,
stack/lanaae134a7ec, which is not main, the liveStorageTexturecount rose from 698 to 1,017 in 5.5 minutes of gameplay, about 50 a minute. It was not measured on main, and the cap has not been run in game. 2048 is a choice, not a measured value.Overlaps.
ShaderResources.cpp,ShaderResources.hppand the debt file. The merge order proposed on #6194 (comment) is this PR first, with #6194's rebase keeping the entry-count term in the loop's condition.storageBudget's body and the budget helpers, not the eviction loop or the entry count, so the two don't conflict: they change different functions and merge cleanly in either order.APS5_STORAGE_CACHE_ENTRIES=1024as a run switch in their texts. The variable is not on main, and this PR adds it.Tested
New tests:
agc_driver_storage_cache_entriesstores six small surfaces under a limit of 4 entries and a 1024 MiB byte budget. It checks that the two least recently used are evicted and their images released, and that the other four stay cached.agc_driver_storage_cache_entries_unlimitedstores the same six withAPS5_STORAGE_CACHE_ENTRIES=0and requires all six to stay cached. It can't go red on the old code, which read0as 2048.agc_driver_storage_cache_entries_profileleaves six 1 MiB surfaces pending under the limit of 4, withAPS5_PROFILE_DRAW=1, and requires the[storage]line to showentry cap 2/in both the write-backs and the evictions.GitHub's runners (https://github.com/EagleBearerYS/AnyPS5/actions/runs/41252017132, commit
55d3875c32on main381891927c,^agc_driver_storage_cache, 10 repeats, "before" is main's implementation with the new test):agc_driver_storage_cache_entriesfails.Validation layers at
55d3875c32(https://github.com/EagleBearerYS/AnyPS5/actions/runs/41252017908, Linux,VK_LAYER_KHRONOS_validationinserted on main and the fix,agc_driver_storage_cache_entries|agc_driver_storage_cache_budget, 3 repeats): both pass, and the fix adds no VUID.VUID-VkDeviceCreateInfo-pNext-pNextis in both logs. On main onlyagc_driver_storage_cache_budgetran, because the new test is not in main's tree; this run is not a red/green arm.AMD Radeon RX 9060 XT (RADV GFX1200), Mesa 26.2.5, CachyOS Linux, in RNK123's run (comment):
55d3875c32merged ontomain9335acf79d, Release, withVK_LAYER_KHRONOS_validationinserted in every test process.main's code,agc_driver_storage_cache_entriesfails 3 of 3 ("surface 0 is still cached after 6 small surfaces under a limit of 4 entries and a 1024 MiB budget"). With the change it passes 3 of 3.agc_driver_storage_cache_budgetandagc_driver_storage_cache_retained_batchpass 3 of 3 both ways.VUID-in either tree. The test checks the cache's entries and their images' release, not when the VRAM is physically freed.NVIDIA RTX 2000 Ada Generation, driver 595.99.02, Ubuntu 26.04.1, from TechLevelZero's NVIDIA bot (report):
55d3875c32merged ontomain3741ca9, 2,522 of 3,121 tests selected.main, and 2 are unstable onmain.VK_LAYER_KHRONOS_validation, over 930 tests on the GPU, there are no new validation IDs againstmain.GitHub's runners at
d2cad15101(run, onmaine0caf13600,^agc_driver_storage_cache, 10 repeats, "before" ismain's implementation with the new tests):agc_driver_storage_cache_entriesandagc_driver_storage_cache_entries_profilefail. After, 5 run, 5 pass, 0 skipped, 0 failed. Suites: libc 208 run, libkernel 309 run, 0 failed.APS5_SKIP_TIMING_TESTS=1, which relaxesprecise_wait's median bounds on GitHub's hosted runners.Validation layers at
d2cad15101(run, GitHub's Linux runner,VK_LAYER_KHRONOS_validation,maine0caf13600against the change,^agc_driver_storage_cache): all 5 pass with the layer, and the change adds no VUID: both logs report onlyVUID-VkDeviceCreateInfo-pNext-pNext. The layer was inserted 2 times onmain, which has only the two older storage-cache tests, and 5 times with the change; neither log says "was not found".Not tested: in game with the fix, a long session with the counters, on Windows with a GPU, on main with the Lana workload.
d5152eeb7c, a merge ofmain4f41f4c375(run).docs/dev/debt/libSceAgcDriver.md, where this PR's storage-image cache entry andmain's new entries are adjacent. The resolution keeps both, and this PR's own lines are unchanged.^agc_driver_storage_cacheor^agc_storage_shadow, which takes in this PR's two tests. Linux: 5 run, 5 pass, 0 skip, 0 fail. Windows: 5 run, 0 pass, 5 skip (no Vulkan device), 0 fail. The libc and libkernel suites run 300 and 322 tests on Linux and 327 and 342 on Windows, with 0 failed. The suites ran withAPS5_SKIP_TIMING_TESTS=1, which relaxesprecise_wait's median bounds on GitHub's hosted runners.530ca15048, a merge ofmain1c8c0efc8c, which brings PrivacyOnion's #14868 (×10, everyagctest).Texture.hpp,ShaderResources.cppandTexture.cpp, all with #14868. #14868 letsevictStoragedetach an image instead of storing it (astoreflag andStorageTexture::Detach()), and makesFlushfirst flush the sources an image adopted. Both PRs' changes stay:evictStorage(cache, it, bool store = true, const char* reason = "cache eviction"): #14868'sstoreflag first, then this PR's reason. Withstore, it callsFlush(reason); without,Detach(). #14868's caller, which passesfalse, is unchanged, and this PR's entry-cap caller now passestruebefore its reason.Flush(const char* reason)runs #14868's flush of the adopted sources first, then this PR'sstoreTrappedOverlaps(reason)andcountStorageEviction(reason).Texture.hppdeclares bothFlush(const char* reason = "cache eviction")andDetach().cache evictiononly if a laterFlushstores it. Apart from the caller line, this PR's diff overmainis unchanged.^agc_driver_storage_cacheor^agc_storage, withagc_driver_recorder(the whole recorder run, which takes in #14868's changed cases). Linux: 23 run, 22 pass, 1 skip (agc_storage_clear_hand_over), 0 fail. Windows: 24 run, 0 pass, 24 skip (no Vulkan device), 0 fail. The libc and libkernel suites run 300 and 324 tests on Linux and 330 and 342 on Windows, with 0 failed. The suites ran withAPS5_SKIP_TIMING_TESTS=1, which relaxesprecise_wait's median bounds on GitHub's hosted runners.agctest, once: Linux: 1,296 run, 1,210 pass, 85 skip, 1 fail. Windows: 1,333 run, 400 pass, 933 skip (no Vulkan device), 0 fail. The one failure isagc_driver_pipeline_journal's 120-second timeout (764/1296 Test #1393: agc_driver_pipeline_journal ***Timeout 120.06 sec). It ismain's own cold run, near the limit:main086c0686c8times out the same way underctest -V(run). With a 300-second limit, underctest -V, 5 runs each, alone on GitHub's Linux runner, both pass 5 of 5:agc_driver_pipeline_journal530ca15048(run)main1c8c0efc8c(run)9efdd61615, a merge ofmainacf7ac208a, which brings nikhilpanchal1's #10472, the suballocation of sampled and storage image memory (×10).tests/cmake/agc_driver_storage_cache_budget_tests.cmake. #10472 setsAPS5_NO_IMAGE_SLABS=1onagc_driver_storage_cache_budgetand addsagc_driver_storage_cache_budget_slabsright after itsTIMEOUTline, which this PR extends toagc_driver_storage_cache_entries. The merge keeps this PR'sTIMEOUTline and #10472's lines after it. This PR's diff overmainis unchanged.agc_driver_storage_cache_entriestests now run with #10472's slabs on,main's default. They cap and count entries, not bytes, so they take no slab opt-out.agc_driver_recorderand every test matching^agc_driver_storage_cache,^agc_storage,^agc_image_memoryor^agc_driver_image_memory, which takes in #10472's image-memory tests. Linux: 35 run, 34 pass, 1 skip (agc_storage_clear_hand_over), 0 fail. Windows: 36 run, 3 pass, 33 skip (no Vulkan device), 0 fail. The libc and libkernel suites run 301 and 325 tests on Linux and 331 and 343 on Windows, with 0 failed. The suites ran withAPS5_SKIP_TIMING_TESTS=1, which relaxesprecise_wait's median bounds on GitHub's hosted runners.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 MarcZX10 on 2026-11-01T01:17:47Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The unresolved overlap with #6194 conflicts in shared implementation files, but the PR does not declare an agreed landing order.
What I ran
Reviewed PR head
55d3875c32c747a16eb63cd4b5776e21ae30c17aagainst basecae3edaf11db8c6c1694c2d772d07c079755a71f; the PR's merge base is381891927c2b3ff494a9853cb79fde8d5342b92d. Environment: Debian 12 x86_64, Python 3.11.2, GCC 12.2.0. The preview onto currentmainmerged cleanly. The pairwise preview against open #6194 produced conflicts. I did not build locally.Results
354bb1b4dc3beb518e0b314c7e96e5c4fe15112a.ShaderResources.hpp,ShaderResources.cpp, anddocs/dev/debt/libSceAgcDriver.md.Selected unedited output
Negative control
Findings
Blocking
The PR identifies #6194 as an open change to the same storage-cache eviction loop. The pairwise merge preview confirms conflicts in
ShaderResources.hpp,ShaderResources.cpp, and the AGC debt file. The repository requires overlapping PR authors to agree which lands first and declare that order inDepends on; this PR currently saysDepends on: noneand the discussion does not record an agreed order. Please coordinate with the author of #6194 and update the checklist to reflect the agreed order before this stack proceeds.Non-blocking
The PR's proposed 2048-entry default is explicitly documented as a choice rather than a measured threshold and can be overridden by
APS5_STORAGE_CACHE_ENTRIES. The new test checks LRU eviction and image release with six surfaces under a limit of four.Sources
Not verified
No local build, CTest, or GPU run. The author-reported lavapipe and validation-layer outputs were not independently checked because the linked Actions records returned HTTP 404. Windows CI skipped the Vulkan tests.
To get this to a good state
Agree with the author of #6194 which PR lands first and record the agreed dependency/order in the checklist. I will rerun the pairwise preview on the updated heads.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-01T03:36:18Z.
Review: CHANGES_REQUESTED
Re-checked — changes requested
The updated description records #14220-first as a proposed landing order, but #6194's author has not confirmed that order, so the overlap agreement is still outstanding.
What I ran
55d3875c32c747a16eb63cd4b5776e21ae30c17a, based oncae3edaf11db8c6c1694c2d772d07c079755a71f.main6135e61f4538611fc82aeb69dbf73f36221b1aec; a later refresh sawmainadvance to3741ca9327246d0df81638726a986cef862b6db5, so I do not claim the earlier preview is against that later tip.Results
ShaderResources.hpp,ShaderResources.cpp, anddocs/dev/debt/libSceAgcDriver.md; the proposed first/second order does not itself resolve those conflicts.main6135e61, butmainadvanced afterward; not verified against the later3741ca9tip.Unedited pairwise merge-check output
Findings
Blocking
The repo asks overlapping PR authors to agree which change lands first and record the order. The latest #6194 discussion contains EagleBearerYS's proposal to land #14220 first and hamb3r's separate request to land #14219 first, both explicitly awaiting confirmation from #6194's author, Thunderhawkk. I found no response confirming either sequence. The new checklist line records the proposal, but not agreement. Please get agreement from the affected author(s) and record the agreed order consistently in the overlapping PR descriptions; if this PR must wait for another one, reflect that in its
Depends online.Non-blocking
The #14219/#14220 pairwise preview is clean. The #14220 preview against the
mainsnapshot used by the precheck was also clean. No code changed since the earlier review.Sources
mainNot verified
No build or C++ tests were run for this description-only update. The current-main merge preview was not rerun after
mainadvanced from6135e61to3741ca9.To get this to a good state
Confirm the landing order with the authors of the overlapping PRs, record that agreement and any required dependency consistently, and refresh the branch when its turn is ready. I will recheck the current heads and order before another review.
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T19:42:46Z.
Review: COMMENTED
A cap on live
StorageTextureobjects is reasonable, since each one pins Vulkan objects and CPU memory the byte budget cannot see. The number and the eviction cost are not supported yet.1. 2048 is a choice, and the working set is not shown to sit below it. The only data is one title's count on a local tree rising from 698 to 1,017 in 5.5 minutes, about 50 per minute, not on
main, and the cap was not run in game. At that rate the cap is reached after about 20 more minutes, and from then on every new surface evicts another. Please run a long session and report how often the cap fires and what it evicts.2. Eviction is not free.
evictStorageflushes pending results first, which is a GPU to CPU write-back, and drops the sampled views over the image. An LRU cap that sits just below a title's per-frame working set evicts and re-creates the same surfaces each frame: a flush, avkCreateImage, a view and an upload per frame. That is far worse than holding a few hundred more. Please add counters for evictions caused by the entry cap and the bytes they flushed to the[buffers]profile line, and give them for the Lana run. Show the same line from a title with a high live count so the cap's effect there is visible.3. LRU by entry count ignores size. A 256-entry cache of 8 MB surfaces is evicted as readily as one of 4 KB. Weight each entry by a minimum cost (for example
max(bytes, 64 KiB)against the existing byte budget) or evict the smallest and oldest first, so the cap removes the small leaked surfaces it was added for and not large live targets.4. No way to turn it off.
0or unset selects 2048, soAPS5_STORAGE_CACHE_ENTRIES=0cannot disable the cap. Someone comparing against the old behaviour needs a way to do that.