fix(agc): let the storage image cache budget follow the heap's use like the sampled one #7071
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7071"
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 SleglJan on 2026-10-17T10:13:45Z.
What
StorageTextureBudgetgave the storage image cache a quarter of theVK_EXT_memory_budgetbudget of the largest device-localheap (capped at
TextureCacheBudget, never below 512 MiB) whatever else the heap held, whileSampledTextureBudgettakes whatthat budget leaves after the heap's other use. On a 10 GB card the storage cache kept 2024-2170 MiB into a level load whose depth
and render target allocations then failed with
VK_ERROR_OUT_OF_DEVICE_MEMORY, the heap at its reported budget where a runlogged it (eight runs below).
The storage image budget is now what the reported budget leaves after the heap's use other than the cached storage images, the
unused part of the sampled textures' 2 GiB floor and an eighth of the budget; the caps at a quarter of the budget and at
TextureCacheBudgetand the 512 MiB floor stay. The sampled budget still reservesTextureCacheBudgetfor the storage cache(at least the storage cap) and the storage budget reserves the sampled textures alive, so neither counts bytes the other may
take; while the sampled textures alive stay within their floor the sampled budget falls first, then the storage budget, and
above it both fall together. Each cache trims at its next insert and both budgets are read at most once a second, as before.
The
[gpu] sampled texture cache budgetline now also prints when the storage image budget moves by more than a tenth, withits previous value, and
StorageTextureCacheBudgetis exported for the execution test.The debt entry "Texture cache budgets" records what is a choice here: the 2 GiB floor and the eighth are the sampled formula's
values reused, the 512 MiB floor and the caps the earlier ones, none measured beyond one title on one 10 GB GPU; a title whose
storage working set exceeds the shrunk budget re-creates storage images at each use.
Measured
007 First Light (PPSA11386) on Linux (CachyOS 7.2.10), NVIDIA GeForce RTX 3080 10 GB (driver 615.78.08), 3840x2160 render
resolution, warm shader cache, scripted pad input, the same save in each pair, logging on. None of the runs is on
mainalone(the title does not reach these points there); every stack is given. "X of Y MiB" figures are the heap's use and budget from the
driver's
[gpu] sampled texture cache budgetlines (printed when a budget moved, so a run's last line is earlier than its stop)or from its host-placement lines; "card use" is
nvidia-smimemory for the whole card, about 885 MiB of it other processes. Thehost-placement counters print at 1-5 allocations and then at powers of two, so they are lower bounds; reclaim lines are exact.
main4186f06a9plus the open PRs thetitle needs to reach its level load (the stack of the bring-up thread, discussions/5714), local functional commits (one-slice
volume sampling among them) and diagnostic logging, the executable patched as in #6172 (two feedback-wait limits widened):
one on the base alone, one on the base + #6402 + #6364, three on that + #6174 (two with trace logging), one on the base +
#6364 + #6174, one on the latter with #6346 reverted, one on the base + #6174. All eight stopped at the first gameplay presents
(1114-1279):
vkAllocateMemory render target: Vulkan result -2in the two without #6174,vkAllocateMemory depth target: Vulkan result -2in the six with it. Their last budget lines hold 2024-2170 MiB of cached storage images at storage budgetsof 2053-2192 MiB, with 5542-6305 of 8215-8723 MiB in use; the five runs that placed an allocation in host memory through
the budget check (a path already on
main) logged the heap at 8233 of 8259, 8491 of 8491, 8456 of 8457, 8326 of 8364 and7982 of 8022 MiB on that line, 0-14 presents before the stop.
#5987 (a refused device allocation, depth, render and copy targets included, is placed in host memory instead of failing;
the budget check's up-front placement is limited to host heaps with room), so the entry no longer stops. One run each:
3600 s without, 1500 s with, same cache, save, input and environment; the card's reported budget at start was 9195 MiB
without and 8934 MiB with. The frame-rate drop of the entry starts at present 1270 without and 1250 with (presents 1274 and
1257 at the 600 s sample in both) and the frame rate after it is within 6 %: 0.13 FPS falling to 0.05-0.06 by 1440 s, 77
presents without and 72 with between the 600 s and 1442 s samples, so the slowness there is not this memory. The memory
moves: through present 1332 (the last of the run with the change) the run without had placed at least 128 refused texture
or storage-texture allocations (1204 MiB) and at least 512 refused device buffers of the pool in host memory, with 60 pool
reclaim-and-retry cycles, the first placement at present 1289, and no up-front placement; the run with it placed at least
32 refused allocations (434 MiB, the last a depth copy) and at least 32 allocations (1252 MiB) up front through the budget
check, no pool buffer, with 3 reclaims, the first placement at present 1319. With the change the heap was at its budget at
those placements (8260-8330 of 8284-8334 MiB); the run without logs no heap figure at its refusals. The budget lines in
between show 300-1500 MiB of room at the moments a sampled texture was inserted. The storage budget read 2184 MiB on the
last line before the entry, 1795 MiB at the entry (present 1250) and reached its 512 MiB floor at present 1298, about six
minutes after the entry, leaving it twice (873 and 944 MiB); from the entry on the sampled textures alive were 2009-2404 MiB
(12 of 26 lines below their 2 GiB floor) and the heap's other use 3491-5241 MiB. A storage cache that small re-creates its
images more often: through present 1332 the run without created 7,440 storage images from present 1274 on, the run with
10,942 (47 % more per present; by about 1500 s of run time, 42,260 against 43,712). So on this stack the change means fewer
and later host placements and reclaims at the price of more storage re-creation, with the frame rate within 6 %.
mainbc3c0fc13+ #5799 #6317 #6332 #6881 + #6947 (which carries #6946 and rebased#5656/#6632),
APS5_PIPELINED_DRAWS=32 APS5_PIPELINE_DISPATCH=1, no executable patch, one run without and one with thechange from the same cache (two more runs without, with
APS5_DRAW_PIPELINE=1, give the spread). No change the runs canresolve: card use peaks at 8622 MiB without and 8554 MiB with (the two other runs 8553 and 8646), the main menu reached at
~1113 s without and ~1125 s with, 0.48-0.59 FPS (mean 0.56) in the menu without and 0.45-0.58 (mean 0.53) with, 35,364
storage images created in 24 minutes without and 35,192 with. The last budget line of each run, about 210 s in, has the
storage budget at its cap (2172 MiB without, 2175 with); what the budget did in the menu itself is not in these logs, since
the line prints only at sampled-cache lookups.
APS5_DRAW_PIPELINE=1 APS5_GPU_HEAP=1(the same stack's two switches, both off by default): three runs withoutthe change (one also with
APS5_VERIFY_GPU_HEAP=1, one with a different trace window) all stopped between their last presentand the driver's give-up, about 735-785 s, with
vkAllocateMemory storage texture: Vulkan result -2right after a ~7.5minute stall, their last budget lines at 7654 of 8765, 7020 of 8783 and 6202 of 8785 MiB in use with 2184-2194 MiB of
cached storage images at 2191-2196 MiB budgets (a fourth run with the switches on a colder cache stopped at about 835-845 s
on
vkAllocateMemory texture: Vulkan result -2). The run with the change, from the same cache as the first, went to its1800 s limit without a refusal and 0 faults, through the same stall (present 222 from 241 s to 694 s), and on to present 604
at 0.28-0.38 FPS (the runs without died at presents 180-260): at the first pressure peak after the stall (7981 of 8767 MiB
in use, 1427 MiB of sampled textures, 490 MiB of cached storage) the storage budget was at its 512 MiB floor, and afterwards
it moved between 1084 and 2188 MiB as the heap's use swung between 5646 and 7880 MiB (40 of 81 budget lines below
2100 MiB); 24,658 storage images were created in 30 minutes. Card use rose to 9363 MiB by the end; no run without the
change lived long enough with the switches to compare.
The runs show, on a 10 GB card, that the storage cache now gives its memory back when the heap fills, down to its floor, that
the refusals the fixed quarter left to the allocations outside the caches no longer appear in these runs, and that the cost is
storage re-creation when the budget sits at the floor. A run on an 8 GB card, where the budget sits below the cap sooner, or on
RADV would be welcome.
Tested
agc_driver_graphics(newStorageTextureBudgetcases),agc_driver_sampled_cache_budget,agc_driver_sampled_cache_budget_memory(new storage case with a fakeVK_EXT_memory_budgetreporter) andagc_driver_storage_cache_budget: pass on the RTX 3080 (Linux, GCC 16.2.1, Release withBUILD_TESTING=ON) and on lavapipe(Mesa 26.2.4, LLVM 23.1.1, Arch Linux container), on the revision before this commit's final docs-and-message amend (same
code). The two new cases were written first and failed on the previous formula (the quarter where 1792 MiB and 1024 MiB
were expected) before the change; the clamp case fails when the clamp is removed.
ctest -R agc_driver(481 tests, 16 jobs), on the first revision of this commit (same budget code; it lacked only the previous value on the budget line): 11failures, the same 11 on
main6a32550fd(msaa_dcc_clear_2/4/8,bc_block_copy,depth_compare_copy,native_multisample_depth,staged_clear_sampled_read,storage_write_back_overhang,native_depth_retirement,native_depth_clears,native_depth_clear_refusals).python3 tools/check_conventions.py --base upstream/mainpasses.value on the budget line.
39c23664bmerged onmainc9e6c45de): Windows 11, NVIDIA GeForce RTX 4070 12 GB (596.21), WinLibs GCC 15.2.0, Release withBUILD_TESTING=ON.StorageTextureBudget's body put back tomain's formula,agc_driver_graphicsandagc_driver_sampled_cache_budget_memoryfail on the new cases; restored, all four pass.^agc_driver_serial: 488 of 490; the two FMA denormal failures also fail onmainon that GPU (#7100).[gpu]errors, a 2810 MiB storage image budget in every run on both builds, and 17-23 (PPSA99005) and 13 (PPSA99420) storage images created per run on both. The heap was at 68-1347 of 11243 MiB, so the new formula stayed at its quarter cap; only the tests exercise the shrink path on that card.Related
recovery path; depth and render targets allocate outside that path on
main, and six of the eight stops above ran with#6174. This change keeps the storage cache from holding the room in the first place; the two compose.
StorageTextureBudget; this change moves that base with the heap's use, so the two compose. It replaces thecached.budget = StorageTextureBudget(...)line with its own and calls the two-argumentStorageTextureBudgeton a newfloorline, which would take the two byte arguments here; whichever merges second needs that one-line rebase.TextureCacheBudget, with a thirty-second of headroom, and calls the two-argumentStorageTextureBudgetinsideSampledTextureBudget, so it does not build on top of this change as is. On top of this change its reserve would follow ashrinking storage budget, so the sampled budget grows as the storage budget falls and, if the sampled cache fills it, pushes
the storage budget further down; one side has to keep reserving the other's maximum (here the sampled side reserves
TextureCacheBudget). Worth deciding together if both are wanted.USAGE.md; the paragraph is updated here.Checklist
main; no other open PR implements the same functions (#6194 changesstorageBudgetaround the samebase; see Related)
reserve, floors and eighth are a debt entry)
NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library'stechnical debt file (none added)
.mdfiles or images added to the repositoryLLVM 23.1.1, Arch Linux container). AMD/RADV: not tested here; a run on RADV would be welcome
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T10:26:33Z.
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)core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppL34core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppL1032docs/dev/debt/libSceAgcDriver.mdL47docs/dev/debt/libSceAgcDriver.mdL47-48Some 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/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mddocs/user/USAGE.mdcore/libs/prx/libSceAgcDriver/tests/execution/SampledCacheBudget.cppdocs/user/USAGE.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mddocs/user/USAGE.mddocs/user/USAGE.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mddocs/user/USAGE.mdcore/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/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/execution/SampledCacheBudget.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/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/src/ShaderResources.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/execution/SampledCacheBudget.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/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/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.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/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/execution/SampledCacheBudget.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/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.cppdocs/dev/debt/libSceAgcDriver.mddocs/user/USAGE.mdcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppdocs/dev/debt/libSceAgcDriver.mddocs/user/USAGE.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/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppdocs/dev/debt/libSceAgcDriver.mdImported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-17T14:06:14Z.
Cross-validation on Windows 11 Pro 26220, NVIDIA GeForce RTX 4070 12 GB (driver 596.21), WinLibs MinGW-w64 GCC 15.2.0, Release with
BUILD_TESTING=ON. PR head39c23664bmerged on mainc9e6c45de(clean). PPSA11386 is not available to me, so this covers the tests and a no-regression check on other titles, not the out-of-memory stops.libspass.agc_driver_graphics,agc_driver_sampled_cache_budget,agc_driver_sampled_cache_budget_memory,agc_driver_storage_cache_budget,--repeat until-fail:3: 3 of 3 each. The memory case runs here (not skipped):reported heap budget 65536 MiB with 54272 MiB in use: storage image cache budget 1024 MiB.StorageTextureBudgetbody back to main'smax(512 MiB, min(TextureCacheBudget, budget / 4))and kept the tests.agc_driver_graphicsthen fails ona 10 GiB budget with 5 GiB used outside the texture caches does not leave 1792 MiB ..., andagc_driver_sampled_cache_budget_memoryfails on53 GiB in use of a 64 GiB budget leaves the storage image cache 3002 MiB, not the 1024 MiB .... Restored, all four pass 3 of 3.^agc_driver_(storage|sampled|image|cache|budget|resource_cache|graphics$)56 of 56. Full^agc_driver_serial: 488 of 490. The two failures areagc_driver_f16_fma_denormal_modesandagc_driver_fma_mix_f16_denormal_modes, which fail on main on this GPU (#7100).-j8): 852 pass first time. The other 31 were load timeouts or load crashes on a shared host, and all pass when rerun serially. Theconventions_function_bodies*shards andhardware_oracle_comparewere run directly with python (26-69 s).tools/check_conventions.pyandgit diff --checkpass.APS5_PROFILE_DRAW=1 APS5_PROFILE_GPU=1 APS5_TRACE_SUMMARY_EVERY=10. The PR ran against the same tree with only the formula reverted, alternating.[gpu]errors.storage image cache budget 2810 MiBon both builds. The heap is at 68-1347 of 11243 MiB, so the new formula stays at its cap (a quarter of the budget). Storage images created per run: 17-23 (PPSA99005) and 13 (PPSA99420) on both.Written with Claude Code assistance (validation by a subagent, reviewed in this session).
Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-17T14:12:47Z.
Thanks @screamm, especially for the negative control with only the formula reverted, and for two more titles on a 12 GB card. Your results are added under Tested.
AI-assisted: yes (Claude Code)