perf(agc): keep storage images in use past the cache entry cap #27987
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/27987"
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 oneandonlydean on 2026-11-28T00:56:00Z.
What
The storage image cache's entry cap (
APS5_STORAGE_CACHE_ENTRIES, default 2048) evicted the least recently used surface even when that surface was in use. An image table that needs more storage images at once than the cap lost every one of them while it was walked: each new image evicted an older one of the same table, the eviction dropped the sampled view over it, and the next dispatch walked the same order and created all of them again.Measured by Flamingo-Socks on PPSA38500 in #27759 (AMD, table of 18,488 textures, address-based compute program): 8,931 and 9,497 sampled textures created over storage images per dispatch, 16 to 21 s in the image phase of every dispatch, under the GPU mutex.
The cap now takes idle surfaces only:
Why 120 presents and not one: with a window of one present, a table used every second frame is idle by that rule when a single unrelated surface is created; that eviction makes the next dispatch create one element again, which evicts the next element in walk order, and the chain runs through the whole table. 120 presents is 2 s at 60 fps.
The leak the cap was added for (
55d3875c32: small surfaces at new addresses that are never used again and never reach the byte budget) stays guarded: such a surface is idle after 120 presents and is evicted as before once the cache is over the cap. At the 50 new surfaces a minute measured there, that is a few entries more than before.APS5_STORAGE_CACHE_ENTRIES=0still turns the cap off.Tested
Linux, NVIDIA.
agc_driver_storage_cache_entries_in_use(new): six surfaces under a cap of four all stay cached in the present that uses them and are found again in the next; after 121 idle presents the two not used again leave when a new surface arrives and the four in use stay. With only the cache loop reverted it fails:surface 0 was evicted by a limit of 4 entries in the present that used it.agc_driver_storage_cache_entries_in_use_budget(new): under a 4 MiB budget a surface used in the current present is still evicted by bytes.agc_driver_storage_cache_*tests pass unchanged.agc_driversuite: 1,682 tests, 0 failed (24 skipped as on main: tests this host cannot run).agc_driver_image_table_reuse_entry_limit(new): one table of 48 storage-viewed entries under a cap of four, dispatched twice in the same present. Every entry is still cached after the first dispatch and is the same image after the second. With only the cache loop reverted it fails:entry 0 of a table of 48 storage-viewed entries was evicted inside the dispatch that selected the table, under a limit of 4 entries.APS5_STORAGE_CACHE_ENTRIES=512,APS5_TEXTURE_CACHE_MIB=3072, one run): a table of 15,029 textures took 4819 ms on its first dispatch and 144 to 209 ms on the next six. With the budget forced to 1536 MiB the table does not fit and the repeats stay at 5.2 to 5.7 s: that is the byte budget, as described above.APS5_STORAGE_CACHE_ENTRIES=0, not with this PR:storage images createdrose by 8,856, 9,157 and 10,386 per dispatch with the cap on and stayed flat at 12,220 after the first build with it off; the image phase of the repeat dispatches fell from 16 to 21 s to 1,080 to 1,245 ms. The first build keeps its 22.3 s.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)Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-28T01:05:00Z.
Review: COMMENTED
Actionable comments posted: 2
e1195399-0590-4ab0-a916-9d26433d9fc9Reviewing files that changed from the base of the PR and between
4814cae855ande55f5d8fd0.core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_storage_cache_budget_tests.cmakecore/libs/prx/libSceAgcDriver/tests/execution/StorageCacheEntries.cppdocs/dev/ENVIRONMENT.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-11-28T07:01:41Z.
Review: APPROVED
Checked head
e55f5d8fd0. All on Windows 11 with WinLibs GCC 15.2 (Release), applied tomain4c7578e0a4together with #28006, #27985, #28002, #28001, #27991, #28007, #27994.tools/check_conventions.py --headandtools/debt_fold.py --checkpassed and the full build succeeded. In the full CPU suite (5,135 tests) the only failure iswindows_read_trap_unknown, which fails onmaintoo (fixed in #28028). The full GPU suite (2,249 tests) on both GPUs, withANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layerand the 1.4.363 layer inserted, matchesmainon the same machine. The GPUs were an NVIDIA RTX 5080 (621.24) and an AMD Radeon gfx1036 iGPU (26.11.2). Onlyagc_driver_linear_target_import_creationfails, as onmain(fixed in #28029), and neither log has aVUID-orSYNC-HAZARDline.agc_driver_storage_cache_entries_in_useandagc_driver_storage_cache_entries_in_use_budgetpass. The GPU suite list above predates the new tests, so I applied this PR again with #28001 and #28007 and ran the new tests 3 times on each GPU with the same environment: all pass, with the layer inserted and noVUID-orSYNC-HAZARDline.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T07:28:36Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the review found no verified defects in the changed behavior.
What I ran
Reviewed head
e55f5d8fd0ea749ba59202c4a772f4878622becdusingrepo_read.pyto inspect the prepared diff, changed lines, and targeted callers. No tests or build commands were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Runtime behavior, test results reported in the PR description, and the full
ShaderResources.cppoutside the targeted insertion and eviction ranges were not independently verified. Read changed files:core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp,core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp(targeted ranges only),core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_storage_cache_budget_tests.cmake,core/libs/prx/libSceAgcDriver/tests/execution/StorageCacheEntries.cpp, anddocs/dev/ENVIRONMENT.md. No changed files were excluded from the review;ShaderResources.cppwas excluded from the prepared full-file bundle because it was too large, and was read through the pinned reader where needed.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T10:01:09Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change; the inspected cache logic and regression tests support the described behavior.
What I ran
Reviewed head
69c3e0236071d38953d5b872c9125c6f3bd0dac8. No commands or tests were run; the author-reported tests and measurements were not independently verified.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Full source of
ShaderResources.cppwas excluded by the review folder size limit; only the changed cache loop and related cache-entry definitions and call sites were read throughrepo_read.py. The remaining portions ofImageTableReuse.cppandStorageCacheEntries.cpp, along with other full changed-file text, were not read. Tests and performance measurements in the description are author-reported and not independently confirmed. No runtime behavior, hardware, or operating system checks were performed.Files read:
description.md,commits.md,manifest.json,diff.patch; changed source ranges inTexture.hpp,ShaderResources.cpp,Texture.cpp,ImageTableReuse.cpp, andStorageCacheEntries.cpp; the changed CMake test files and the relevantENVIRONMENT.mdrange. Excluded from the review folder: fullShaderResources.cpp(too large);files.jsonwas not present in the review folder listing.To get this to a good state
Nothing is required.