Skip to content

fix(agc): let the storage image cache budget follow the heap's use like the sampled one - #7071

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
SleglJan:fix/storage-budget-pressure
Oct 17, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
SleglJan:fix/storage-budget-pressure

Conversation

@SleglJan

@SleglJan SleglJan commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

What

StorageTextureBudget gave the storage image cache a quarter of the VK_EXT_memory_budget budget of the largest device-local
heap (capped at TextureCacheBudget, never below 512 MiB) whatever else the heap held, while SampledTextureBudget takes what
that 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 run
logged 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
TextureCacheBudget and the 512 MiB floor stay. The sampled budget still reserves TextureCacheBudget for 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 budget line now also prints when the storage image budget moves by more than a tenth, with
its previous value, and StorageTextureCacheBudget is 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 main alone
(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 budget lines (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-smi memory for the whole card, about 885 MiB of it other processes. The
host-placement counters print at 1-5 allocations and then at powers of two, so they are lower bounds; reclaim lines are exact.

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 (new StorageTextureBudget cases), agc_driver_sampled_cache_budget,
    agc_driver_sampled_cache_budget_memory (new storage case with a fake VK_EXT_memory_budget reporter) and
    agc_driver_storage_cache_budget: pass on the RTX 3080 (Linux, GCC 16.2.1, Release with BUILD_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.
  • lavapipe, 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): 11
    failures, the same 11 on main 6a32550 (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/main passes.
  • In game: the runs above; the budget code of this commit is the code they ran; the menu runs' revision lacked only the previous
    value on the budget line.
  • Independent check by screamm (head 39c2366 merged on main c9e6c45): Windows 11, NVIDIA GeForce RTX 4070 12 GB (596.21), WinLibs GCC 15.2.0, Release with BUILD_TESTING=ON.

Related

Checklist

  • Based on current main; no other open PR implements the same functions (fix(agc): grow the storage cache budget while it evicts under pressure #6194 changes storageBudget around the same
    base; see Related)
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt (the
    reserve, floors and eighth are a debt entry)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's
    technical debt file (none added)
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: nothing shown by these runs; the title measured is PPSA11386 (bring-up thread discussions/5714)
  • GPUs tested: NVIDIA GeForce RTX 3080 10 GB, driver 615.78.08, Linux (CachyOS, GCC 16.2.1); lavapipe (Mesa 26.2.4,
    LLVM 23.1.1, Arch Linux container). AMD/RADV: not tested here; a run on RADV would be welcome
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

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.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 6012 core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp L34
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp L1032
PR 7175 docs/dev/debt/libSceAgcDriver.md L47
PR 7250 docs/dev/debt/libSceAgcDriver.md L47-48

Some 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.

Pull request Shared files not compared
PR 1395 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 2434 docs/dev/debt/libSceAgcDriver.md
PR 4040 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 4448 docs/dev/debt/libSceAgcDriver.md
PR 4650 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 4891 docs/user/USAGE.md
PR 5021 core/libs/prx/libSceAgcDriver/tests/execution/SampledCacheBudget.cpp
docs/user/USAGE.md
PR 5058 docs/dev/debt/libSceAgcDriver.md
PR 5372 docs/dev/debt/libSceAgcDriver.md
PR 5441 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 5499 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 5500 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 5925 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
docs/user/USAGE.md
PR 6111 docs/user/USAGE.md
PR 6146 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6171 docs/user/USAGE.md
PR 6177 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 6188 core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6194 core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6222 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
core/libs/prx/libSceAgcDriver/tests/execution/SampledCacheBudget.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6234 docs/dev/debt/libSceAgcDriver.md
PR 6235 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6273 docs/dev/debt/libSceAgcDriver.md
PR 6297 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6300 docs/dev/debt/libSceAgcDriver.md
PR 6320 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6373 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 6412 core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6414 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 6445 docs/dev/debt/libSceAgcDriver.md
PR 6492 core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
core/libs/prx/libSceAgcDriver/tests/execution/SampledCacheBudget.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6535 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6548 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6563 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6601 docs/dev/debt/libSceAgcDriver.md
PR 6636 core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6647 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6718 core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 6727 docs/dev/debt/libSceAgcDriver.md
PR 6783 core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
core/libs/prx/libSceAgcDriver/tests/execution/SampledCacheBudget.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6808 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6867 docs/dev/debt/libSceAgcDriver.md
PR 6887 docs/dev/debt/libSceAgcDriver.md
PR 6946 core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
docs/dev/debt/libSceAgcDriver.md
docs/user/USAGE.md
PR 6947 core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
docs/dev/debt/libSceAgcDriver.md
docs/user/USAGE.md
PR 6959 docs/dev/debt/libSceAgcDriver.md
PR 6965 docs/dev/debt/libSceAgcDriver.md
PR 6973 core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6987 core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6989 core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6995 core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 7002 core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 7154 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
docs/dev/debt/libSceAgcDriver.md
PR 7178 docs/dev/debt/libSceAgcDriver.md
PR 7256 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 7258 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
docs/dev/debt/libSceAgcDriver.md

…ke the sampled one

StorageTextureBudget gave the storage image cache a quarter of the VK_EXT_memory_budget
budget of the largest device-local heap (capped at TextureCacheBudget, never below 512 MiB)
whatever else the heap held, while SampledTextureBudget takes what that 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
with the heap at its reported budget where a run logged it.

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 TextureCacheBudget and the
512 MiB floor stay. The sampled budget still reserves TextureCacheBudget for 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. The budget line also prints when the storage image budget moves by more than a
tenth, with its previous value, and StorageTextureCacheBudget is exported for the execution
test.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions github-actions Bot added docs agc libSceAgc* labels Oct 17, 2026
@SleglJan
SleglJan force-pushed the fix/storage-budget-pressure branch from 7342518 to 39c2366 Compare October 17, 2026 10:56
@screamm

screamm commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

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 head 39c23664b merged on main c9e6c45de (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.

  • Build: full build and libs pass.
  • 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.
  • Negative control: I put only the StorageTextureBudget body back to main's max(512 MiB, min(TextureCacheBudget, budget / 4)) and kept the tests. agc_driver_graphics then fails on a 10 GiB budget with 5 GiB used outside the texture caches does not leave 1792 MiB ..., and agc_driver_sampled_cache_budget_memory fails on 53 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.
  • GPU: ^agc_driver_(storage|sampled|image|cache|budget|resource_cache|graphics$) 56 of 56. Full ^agc_driver_ serial: 488 of 490. The two failures are agc_driver_f16_fma_denormal_modes and agc_driver_fma_mix_f16_denormal_modes, which fail on main on this GPU (test: agc_driver_f16_fma_denormal_modes and agc_driver_fma_mix_f16_denormal_modes fail on NVIDIA (NaN sign/payload differs from the AMD table) #7100).
  • Non-GPU suite (883 tests, -j8): 852 pass first time. The other 31 were load timeouts or load crashes on a shared host, and all pass when rerun serially. The conventions_function_bodies* shards and hardware_oracle_compare were run directly with python (26-69 s). tools/check_conventions.py and git diff --check pass.
  • Titles: PS5 OpenGL Showcase (PPSA99005) and PS5MC (PPSA99420), the heaviest storage-image users I have.
    • Setup: 65 s per run, 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.
    • 10 runs, no stop line, no [gpu] errors.
    • Every run reports storage image cache budget 2810 MiB on 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.
    • Low-load pair of PPSA99005, PR vs reverted: 430 vs 425 frames in 65 s, frame p50 142 vs 139 ms, p90 164 vs 156 ms. app.exe private bytes 3747/3889 MiB vs 3807/3948 MiB at 30/60 s.
    • The other runs were taken during builds and are dominated by host load; they show the same budgets and no errors.
  • On this card the new budget only drops below its cap once the heap's use outside the caches plus max(2 GiB, sampled textures alive) passes about 7 GiB. None of my titles reach that, so only the tests exercise the shrink path here.
  • Not checked: PPSA11386, any title near the heap budget, 8 GB cards, AMD/RADV, Intel, Linux.

Written with Claude Code assistance (validation by a subagent, reviewed in this session).

@SleglJan

Copy link
Copy Markdown
Contributor Author

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants