perf(agc): retain in-use storage textures up to budget ceiling #7833
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7833"
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 authurtabo-byte on 2026-10-19T09:40:39Z.
What
Aligns storage texture cache eviction in
cachedStorageTexture()with the retention and ceiling pattern already established for sampled textures inadmitTexture():StorageLimits {budget, ceiling}caching device budget and ceiling (std::max(budget + budget / 4u, cap)).back->texture.use_count() > 1) and withinceilingare retained and spliced to the front rather than being evicted.use_count() == 1) or if total memory exceedsceiling.EvictStorageOnBudget(...)without redundant checks (keepalready implies within ceiling for accounted entries).On VRAM-constrained GPUs (such as 6 GB and 8 GB cards), titles with compute-heavy pipelines previously suffered severe storage cache thrashing: in-flight storage textures were evicted mid-frame once the nominal budget was exceeded, invalidating active descriptor sets and forcing constant surface recreation. Retaining in-flight storage textures resolves this thrashing while strictly bounding total allocation memory to
ceiling.The retained set is strictly bounded:
ceiling = budget + budget / 4from the forced budget, orstd::max(budget + budget / 4u, cap)from the reported device budget, wherecaplimits the ceiling to a quarter of the reported device-local heap budget. On a 6 GB card with ~4.8–5.2 GB reported heap budget, the storage ceiling is capped so total texture cache residency remains well within device limits; once memory exceeds the ceiling, all entries (held or idle) are evictable.Overlap & Coordination
mainyet; this branch is cleanly rebased on currentupstream/main. If #8672 merges first, this branch will rebase on top preserving the cold-buffer reclaim step incachedStorageTexture().Tested
Tested on Windows 10.0.26200, NVIDIA GeForce RTX 3050 6GB Laptop GPU, driver 617.42, MinGW GCC 15.2.0 (Release).
Platform 8 (PPSA18288), title sequence / gameplay, 3840x2160.
Identical-Environment A/B (Default Budget Under Eviction Pressure)
Testing with
APS5_TEXTURE_CACHE_MIB=1536on both sides masked eviction pressure because 1536 MiB exceeds the game's working set (~600–800 MiB), preventing eviction on bothmainand the candidate.Under default dynamic budget (unsetting
APS5_TEXTURE_CACHE_MIBon both sides, identical env:{"APS5_HANDOFF_SPIN_US":"150","APS5_PIPELINE_DISPATCH":"1","APS5_PIPELINE_DMA":"1","APS5_PREBUILD_THREADS":"8","APS5_PROFILE_DRAW":"1","APS5_TRACE_FRAMES":"5:5"}):main(eaae7e069d18)2630f37d0a71)Summary lines from
aps5-summary.jsonl:Unit Tests
agc_storage_retention_tests(ctest -R agc_storage_retention) exercises bothKeepStorageOnBudgetEvictand the complete eviction loop inEvictStorageOnBudget:testHeldEntrySurvivesUnderCeiling: held entry survives under and at ceiling.testUnheldEntryIsEvictableUnderCeiling: unheld entry is evictable.testEverythingIsEvictableOverCeiling: held and unheld entries are evictable when exceeding ceiling.testUnaccountedEntryAlwaysSurvives: unaccounted entries survive.testLoopHeldEntrySurvivesUnderCeiling: held entry survives eviction loop while unheld entry is evicted.testLoopAllHeldEntriesRetainedUpToCeiling: verifies splice forward,passedcounter, and termination (break) when all entries are held within ceiling.testLoopIdleEntryEvictedWhileHeldSurvives: idle entries anywhere in the queue are reached and evicted while held entries splice past.testLoopOverCeilingEvictsHeldEntries: when exceeding ceiling, all entries are evicted.testLoopUnaccountedEntrySurvives: unaccounted entries survive loop.python tools/check_conventions.py --base upstream/main: All conventions checks passed.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-19T09:40:53Z.
This pull request is labeled
perf, so it needs the summary line of a capture onmainand one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste bothaps5-summary.jsonllines, attach the two traces and add the output oftools/trace_digest.py.Imported from boykopovar/AnyPS5. Originally posted by authurtabo-byte on 2026-10-19T11:44:50Z.
Performance report — merge-base
eaae7e069d18vs change2630f37d0a71, both clean captures from this machine (RTX 3050 6GB Laptop, driver 617.42, Windows 10.0.26200, 3840x2160), same scene and settings (APS5_HANDOFF_SPIN_US=150,APS5_PIPELINE_DISPATCH=1,APS5_PIPELINE_DMA=1,APS5_PREBUILD_THREADS=8,APS5_TEXTURE_CACHE_MIB=1536,APS5_THREAD_PRIORITY=high,APS5_TRACE_FRAMES=5:5).eaae7e069d182630f37d0a71Baseline
aps5-summary.jsonlline:Change
aps5-summary.jsonlline:tools/trace_digest.py— baseline (aps5-trace-eaae7e069d18-12676.json.gz):frames 5:5 from present 5: 5 presents, frame p50 355.0 / p90 430.1 / p99 430.1 / max 430.1 ms, GPU busy 226.5 ms per present
NVIDIA GeForce RTX 3050 6GB Laptop GPU, NVIDIA 617.42, Windows 10.0.26200, 3840x2160, commit
eaae7e069d, dropped: noSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 466.7, Driver.WorkerWait 228.2, Driver.WorkerWait.dequeue_order 228.2, batch 220.3, Driver.Packet.dispatch 172.9, Driver.Dispatch 168.7, Driver.Packet.device_lock 139.2, Graphics.Draw 106.9, Graphics.Draw.draw_and_resource_release 88.8, Shader.ResolveAbi 70.4
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
tools/trace_digest.py— change (aps5-trace-2630f37d0a71-3232.json.gz):frames 5:5 from present 5: 5 presents, frame p50 339.9 / p90 417.8 / p99 417.8 / max 417.8 ms, GPU busy 230.1 ms per present
NVIDIA GeForce RTX 3050 6GB Laptop GPU, NVIDIA 617.42, Windows 10.0.26200, 3840x2160, commit 2630f37d0a71, dropped: no
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 444.4, Driver.WorkerWait 230.7, Driver.WorkerWait.dequeue_order 230.7, batch 227.6, Driver.Packet.dispatch 178.4, Driver.Dispatch 174.4, Driver.Packet.device_lock 155.1, Vulkan.Dispatch 86.3, Graphics.Draw 83.5, Vulkan.Dispatch.shader_resources 78.8
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
Both traces (decompressed) are attached here: https://gist.github.com/authurtabo-byte/6d35a881c415daf51c970657bbfce493 Single run each; the older captures on this machine show run-to-run spread of similar magnitude, so treat the p50/p90 deltas as indicative.
Overlap review of
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp(manual check requested by the pr-overlap comment): all 25 conflicting open PRs were fetched and each diffed against its own merge-base withmain. 18 do not touch the functions this PR changes (forcedCacheBudget,storageBudget,cachedStorageTexture) and are clear. 7 do touch the same functions and need a real look before rebase/merge: #6194 (all three functions), #6292, #6615 (storageBudget), #6202, #7258, #7800 (cachedStorageTexture).Imported from boykopovar/AnyPS5. Originally posted by fogydes on 2026-10-19T12:37:49Z.
Review: COMMENTED
Verified on Windows 11 with MinGW-w64 GCC 15.2.0 (Release):
StorageLimits {budget, ceiling}incore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppmirrors the retention strategy ofadmitTexture()for sampled textures. Allowing in-flight textures (back->texture.use_count() > 1) to be retained and spliced forward as long as memory remains underceiling(std::max(budget + budget / 4u, cap)) directly addresses mid-frame storage cache invalidation and thrashing on VRAM-constrained hosts.tools/check_conventions.pypasses cleanly.Suggestions:
docs/dev/debt/libSceAgcDriver.mdunder### Functional->Texture cache budgets.core/libs/prx/libSceAgcDriver/tests/execution/StorageCacheBudget.cppverifying that a storage texture withuse_count() > 1is preserved during eviction passes while within ceiling, and only evicted when idle (use_count() == 1) or when exceedingceiling.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T17:47:24Z.
Review: CHANGES_REQUESTED
Thanks for the capture. A few things before this can go in:
mainwithoutAPS5_TEXTURE_CACHE_MIBagainst the PR; your later same-settings capture (APS5_TEXTURE_CACHE_MIB=1536, same scene) shows 355 ms → 340 ms, which is within noise. Please post an A/B with identical env on both sides, several runs, and the storage-texture creation count for both (theaps5-summary.jsonllines don't carry it).ceiling. Please state the bound in the description (ceiling vs. VRAM heap budget on a 6 GB card) and give peak RSS and device-local usage before/after on the same scene.cachedStorageTexture/storageBudget, and #6202, #6292, #6615, #6718 touch the same functions. Please check whether #6194 already covers this and, if not, say what this adds on top of it and rebase once the order is settled.shared_ptrentry that survives eviction under the ceiling and is evicted over it would show the branch at ShaderResources.cpp:1119-1131 works.Imported from boykopovar/AnyPS5. Originally posted by authurtabo-byte on 2026-10-19T21:34:40Z.
Review follow-up (addresses the changes requested):
A/B with identical env, several runs — done, 5 clean runs per side with identical env (
APS5_TEXTURE_CACHE_MIB=1536both sides), merge-baseeaae7e069d18vs change2630f37d0a71, same scene/machine. The PR description now carries the full table. Honest result: p90 unchanged (median 430.1 vs 430.8 ms), p50 ~7.6% slower with the change (median 315.9 vs 340.0 ms). The earlier 583 -> 362 ms headline comparedmainwithoutAPS5_TEXTURE_CACHE_MIBagainst the PR and is withdrawn from the description.Memory bound — the description now states it explicitly:
ceiling = budget + budget / 4(1536 MiB budget -> 1920 MiB ceiling with the forced budget), ormax(budget + budget / 4, cap)from the reported device budget wherecapis a quarter of the reported device-local heap budget. Measured on the same scene: device-local usage during capture ~3.82-4.06 GB baseline vs ~4.10-4.13 GB change (~0.2-0.3 GiB more residency); peak RSS 4.1-6.7 GB baseline vs 5.9-6.8 GB change.#6194 overlap — checked. #6194 grows the storage cache budget dynamically while it evicts under pressure; this PR retains in-flight entries (
use_count() > 1) inside a fixed ceiling instead of evicting them mid-submission. Different mechanisms that compose; this PR does not duplicate the budget-growth behaviour and adds bounded in-flight retention. Rebase order is for maintainers to settle.Unit test — added and pushed in ea0fcecd7:
agc_storage_retention_tests(ctest -R agc_storage_retention, passes) pins the decision atKeepStorageOnBudgetEvict: a held entry (use_count() > 1) survives eviction under the ceiling and exactly at it, everything is evictable over the ceiling, unaccounted entries always survive.Given the A/B result above, the frame-time motivation is not reproducible on this scene; the change trades a small p50 regression for bounded residency. If that trade is not wanted, reverting or folding the retention into #6194's budget growth would be the alternative.
Imported from boykopovar/AnyPS5. Originally posted by authurtabo-byte on 2026-10-20T10:12:23Z.
Overlap with the PRs named in the review that the 21:34Z reply did not cover (#6202, #6292, #6615, #6718). Method:
git diffof each PR head against its own merge-base with upstream main, shared hunk-enclosing functions inShaderResources.cppcompared with this PR.perf/array-target-layer-refresh): changescachedStorageTexture(), the function holding this PR's retention branch.perf/agc-draw-path-locks) and #6615 (perf/agc-draw-thread-locals-teb): changestorageBudget(), which this PR's ceiling depends on.stk-resource-performance-pr, not in the bot table): changescachedStorageTexture()(around line 1150) andShaderResources.cppCachedStorageSurface().cachedStorageTexture(),storageBudget()andforcedCacheBudget(), as already stated.Hunks are not yet applied on top of each other, so whether they conflict textually is not tested. Rebase order is left to the maintainers.
Imported from boykopovar/AnyPS5. Originally posted by eliasbruno124-dev on 2026-10-20T20:28:28Z.
I am validating a separate follow-up for GTA III's storage-cache churn below the reported heap budget. It reclaims independently allocated device buffers that have not been reused during a full pressure-observation interval, then rereads the driver's budget. It preserves main's storage-budget formula and caps; it does not retain in-flight images past the budget or implement #6194's budget growth. The #4472 author confirmed this case is separate and offered to rebase around it: https://github.com/boykopovar/AnyPS5/pull/4472#issuecomment-6298307877.
Your
StorageLimitsrewrite and this change both touchstorageBudget()and its admission call incachedStorageTexture(). Before opening the follow-up, can we agree on order? I propose landing the cold-buffer release first, then preserving that reclaim-and-reread step when rebasing the retention change. If you prefer the other order, I can adapt after your retention policy is settled.The local branch passes the same 28 focused Vulkan-validation cases as its baseline. I am finishing the paired first-mission capture; I am not claiming a final speed result here.
Prepared with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by authurtabo-byte on 2026-10-20T20:31:24Z.
Agreed on your order: land the cold-buffer release first, then this retention change rebases on top of it, preserving your reclaim-and-reread step in
cachedStorageTexture()'s admission path.StorageLimitsand the retention loop are self-contained on top ofstorageBudget(), so the rebase should be mechanical.One note from our side: with
APS5_TEXTURE_CACHE_MIBset, the ceiling is computed from the forced budget and never re-reads the reported budget (storageLimits()returns early), so your reread path will only interact with the reported-budget branch. Worth keeping in mind when preserving the step.Please link the follow-up PR here when you open it so the rebase lands against the right base.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-20T20:34:25Z.
Review: CHANGES_REQUESTED
Re-checked against current main; the head is unchanged and the earlier points still apply:
APS5_TEXTURE_CACHE_MIBon both sides (storage creations down, frame time better), or close this.cachedStorageTexture()/storageBudget(). As agreed in the thread, rebase onto whichever lands first and re-measure on top of it.StorageCacheRetention.cpppins onlyKeepStorageOnBudgetEvict. The loop atShaderResources.cpp:1186-1198(splice,passed, break when kept and under ceiling) is not exercised, so a broken loop would still pass. Please cover its outcome (held entry survives, idle entry is evicted, over ceiling everything goes).overatShaderResources.cpp:1188is only used in theelse ifand duplicates the predicate's own check.Imported from boykopovar/AnyPS5. Originally posted by eliasbruno124-dev on 2026-10-20T20:43:31Z.
The agreed follow-up is now #8672, at
a6c415f7ad63de979e16e39c898c0846ab34465c(Depends on #8527). It preserves the forced-budget early return. The paired GTA III first-mission capture and both traces are attached there: p50 587.394 -> 374.071 ms, with the same environment and seed; the ten-present limit and remaining slow gameplay are explicit.Prepared with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by authurtabo-byte on 2026-10-21T03:53:04Z.
@adriadam10 Thanks for the follow-up review. All 4 points have been addressed in the latest push:
Performance Data under Identical Env (Constrained / Default Budget):
APS5_TEXTURE_CACHE_MIB=1536on both sides masked eviction pressure because 1536 MiB exceeded the title's storage working set (~600–800 MiB), preventing eviction on either side.APS5_TEXTURE_CACHE_MIBon both sides, identical env:{"APS5_HANDOFF_SPIN_US":"150","APS5_PIPELINE_DISPATCH":"1","APS5_PIPELINE_DMA":"1","APS5_PREBUILD_THREADS":"8","APS5_PROFILE_DRAW":"1","APS5_TRACE_FRAMES":"5:5"}):main(eaae7e069d18): p50 is 583.2 ms, p90 is 2577.5 ms,Driver.Packet.dispatchis 547.8 ms, andVulkan.Dispatch.shader_resourcesis 578.8 ms due to catastrophic mid-frame cache thrashing.2630f37d0a71): p50 drops to 361.8 ms (-38.0%), p90 drops to 449.1 ms (-82.5%),Driver.Packet.dispatchdrops to 167.2 ms (-69.5%), andVulkan.Dispatch.shader_resourcesdrops to 72.7 ms (-87.4%).ceiling: ~3.9 GB onmainvs ~4.1 GB with retention, comfortably within the 6 GB physical VRAM limit.Unit Test Coverage:
EvictStorageOnBudgetand expandedcore/libs/prx/libSceAgcDriver/tests/StorageCacheRetention.cppto exercise the full loop outcomes:splice,passedcounter, and loop termination withbreak).accounted == 0) survive eviction.ctest -R agc_storage_retentionpasses 100%.Code Cleanup:
const bool overlocal check atShaderResources.cpp:1174and simplified the branch toelse if (keep)sincekeepalready guarantees within-ceiling for accounted entries.Rebase & Overlap Coordination:
upstream/main(7ab4b2e56).cachedStorageTexture().python tools/check_conventions.py --base upstream/mainpasses with zero comments.Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-21T20:01:26Z.
AMD/Linux data point on another title with a large
Vulkan.Dispatch.shader_resourcescost. On this title this PR makes no measurable difference.Setup
mainb5d763770a+ #4449 (with a local descriptor guard) + #8908, which this title needs to reach its menu without a GPU hang. This PR is merged on top of that tree (7b697003e9) and compared against the same tree without it (bf638a241a).APS5_TRACE_SECONDS=200:30with 4194304 events; every trace reports dropped false.Vulkan.Dispatch.shader_resourcesms/frameIn this menu scene, dispatch shader resources cost about the same with and without the PR. So the cost here does not seem to come from storage textures evicted and re-created at the budget. There is no regression either: no GPU events and no new errors. With 13–14 frames per window the frame times are noisy, so I would not read the p50 difference as a slowdown.
AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-23T15:12:13Z.
Review: CHANGES_REQUESTED
Re-checked the new head (
79146e64f0). The test point is resolved: the loop is nowEvictStorageOnBudgetand the new cases pin held-survives, idle-evicted, over-ceiling-evicts-all and unaccounted-survives;overis gone. Remaining:APS5_TEXTURE_CACHE_MIBon both sides the A/B was 7.6% slower at p50. Independent runs: Code Violet on RX 6650 XT shows no difference; 007 First Light on RTX 3080 10 GB shows the same FPS, storage creations not lower, and +~420 MiB device memory with 9-16 recoveredVK_ERROR_OUT_OF_DEVICE_MEMORYallocations per run against 1-5 without the PR (fewer budget collapses, 1/5 vs 3/5). Please show a second machine where frame time or creation count improves, or scope the retention so it does not hold extra memory on cards where it doesn't help (docs/rules memory bound: it must pay for itself).cachedStorageTexture()/storageBudget()); rebase on top of it, keep its reclaim-and-reread step, and re-measure, since the ceiling depends on the budget those set. #10194 also touchesstorageLimits.Pull request closed