fix(agc): grow the storage cache budget while it evicts under pressure #6194

Closed
Thunderhawkk wants to merge 7 commits from upstream-pr/6194 into main
Thunderhawkk commented 2026-10-15 01:43:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Thunderhawkk on 2026-10-15T01:43:22Z.


What

The storage image cache's budget grows while it evicts entries under its own budget and shrinks while the device-local heap is under memory pressure, so a title whose storage working set does not fit the initial share (a quarter of the heap or of the reported budget) stops recreating the same surfaces every frame.

Growth: 16 or more budget evictions in one second, one eighth of the budget per step (at least 64 MiB), capped at half the heap's size or half the reported budget, only while the step plus a reserve of 2 GiB or an eighth of the reported budget stays within the reported budget. Shrink: the same step while the reported usage plus the reserve exceeds the reported budget, never below the existing formula. Every change logs [textures] storage cache budget X MiB -> Y MiB (...).

The churn this addresses and the measurements behind the thresholds are in #5961.

Tested

Windows 11 (26200), RTX 5070 Ti 16 GiB, NVIDIA 617.42, MinGW GCC 15.2.0; Marvel's Wolverine PPSA03671 01.001.005 converted with --windows, 180 s window, warm shader cache, no environment overrides:

  • main: 44,776 storage-image creations, 249 unique surfaces, 1 presented frame, peak reported heap usage 14,605 MiB.
  • this PR: the budget grew 3807 -> 4283 -> 4818 -> 5420 -> 6098 MiB in four steps, creations fell to 1,845, 83 frames were presented (frame p50 ~1.1 s at the plateau), peak reported heap usage 9,555 MiB. The same window with APS5_TEXTURE_CACHE_MIB=6144 on main produces a similar creation count, so the growth reproduces the manual budget.
  • 10-minute run with #6174 merged: no crash and no allocation failures; the budget oscillated (85 grow / 88 shrink events) as the title's total demand exceeded the card, and the frame rate degraded late; that limit is the title's total memory demand, not the budget.
  • agc_driver_graphics_tests passes (new NextStorageBudget cases); python3 tools/check_conventions.py --base origin/main passes; tools/pr_overlap.py --branch fix-storage-budget reports no overlap with open pull requests.

Not checked on Linux, macOS or a console; one GPU was available.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt (the growth rationale is a debt entry)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file (no unimplemented path added)
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (not applicable)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: PPSA03671 #5516
  • GPUs tested: NVIDIA RTX 5070 Ti, driver 617.42, Windows 11 26200
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4866962146 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6194). Originally posted by [Thunderhawkk](https://github.com/Thunderhawkk) on 2026-10-15T01:43:22Z. --- ### What The storage image cache's budget grows while it evicts entries under its own budget and shrinks while the device-local heap is under memory pressure, so a title whose storage working set does not fit the initial share (a quarter of the heap or of the reported budget) stops recreating the same surfaces every frame. Growth: 16 or more budget evictions in one second, one eighth of the budget per step (at least 64 MiB), capped at half the heap's size or half the reported budget, only while the step plus a reserve of 2 GiB or an eighth of the reported budget stays within the reported budget. Shrink: the same step while the reported usage plus the reserve exceeds the reported budget, never below the existing formula. Every change logs `[textures] storage cache budget X MiB -> Y MiB (...)`. The churn this addresses and the measurements behind the thresholds are in #5961. ### Tested Windows 11 (26200), RTX 5070 Ti 16 GiB, NVIDIA 617.42, MinGW GCC 15.2.0; Marvel's Wolverine PPSA03671 01.001.005 converted with `--windows`, 180 s window, warm shader cache, no environment overrides: - main: 44,776 storage-image creations, 249 unique surfaces, 1 presented frame, peak reported heap usage 14,605 MiB. - this PR: the budget grew 3807 -> 4283 -> 4818 -> 5420 -> 6098 MiB in four steps, creations fell to 1,845, 83 frames were presented (frame p50 ~1.1 s at the plateau), peak reported heap usage 9,555 MiB. The same window with `APS5_TEXTURE_CACHE_MIB=6144` on main produces a similar creation count, so the growth reproduces the manual budget. - 10-minute run with #6174 merged: no crash and no allocation failures; the budget oscillated (85 grow / 88 shrink events) as the title's total demand exceeded the card, and the frame rate degraded late; that limit is the title's total memory demand, not the budget. - `agc_driver_graphics_tests` passes (new `NextStorageBudget` cases); `python3 tools/check_conventions.py --base origin/main` passes; `tools/pr_overlap.py --branch fix-storage-budget` reports no overlap with open pull requests. Not checked on Linux, macOS or a console; one GPU was available. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) (the growth rationale is a debt entry) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file (no unimplemented path added) - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (not applicable) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: PPSA03671 #5516 - [x] GPUs tested: NVIDIA RTX 5070 Ti, driver 617.42, Windows 11 26200 - [x] AI-assisted: yes
ee6aba54 commented 2026-10-15 04:11:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ee6aba54 on 2026-10-15T04:11:04Z.


Tested on Linux: Ubuntu 24.04, kernel 7.0, RTX 5080 16 GiB, NVIDIA 595.99.02, PPSA15304. Base: ab9a47684 plus my open #6174, #6185 and #6186, with this PR's three commits on top (no conflicts). The fixed-camera window was 200 s after loading the save, with a warm shader cache and no environment overrides. Presents are counted per 10 s.

No VRAM pressure. The desktop held 0.9 GiB, the reported budget was 14.8 GiB and the storage budget 3.7 GiB. The cache saw 0 to 40 cache-eviction write-backs per 10 s, far below the growth threshold, so this PR has nothing to do there.

Another process holding 3 GiB of device memory. This is a plain CUDA allocation, similar to a browser on the desktop. The reported budget was 11.5 GiB and the storage budget 2877 MiB.

presents / 10 s cache-eviction write-backs / 10 s heap reached its budget crashes
base, 3 runs 6 / 15 / 16 (median 15) 385 to 1038 (5.3 to 12.3 GB) 0 of 3 0
base + #6194, 4 runs 24 (the only run that completed the window) none in that window 3 of 4 2

Of the three #6194 runs without a complete window, two crashed (below) and one stayed in the menu for 10 minutes because of my input script, without a crash.

The growth works as described: 2887 -> 3248 -> 3654 -> 4111 -> 4625 -> 5203 MiB within the first minutes, and the churn disappears.

Cost. In three of the four runs the device-local heap then reached its budget (heap 0 uses 11260 of its 11261 MiB budget). Device buffers were then placed in host memory (7 to 9 allocations per run), and the pool recovered from VK_ERROR_OUT_OF_DEVICE_MEMORY once or twice per run. Two of those runs crashed: a guest general protection fault right when gameplay started, and a segfault in the menu. Without this PR none of the runs reached the heap budget.

The budget kept oscillating between 4.3 and 5.6 GiB. A grow step is only checked against the usage at that moment, and other consumers grow afterwards (sampled textures, device buffers, the staging pool). The shrink comes only at the next budget read, after allocations have already failed.

The crashes may well be in my own reclaim path from #6174, which is in this base, so I would not blame them on this PR. Reaching the heap budget, however, comes from the growth.

Suggestions:

  • Cap growth by what the other caches may still claim, for example reported budget minus usage minus the reserve minus the sampled cache's remaining budget, instead of half the budget.
  • Or make the shrink step react to the allocation recovery path, not only to the next budget read.

With either, the gain shown above should hold without the heap running full. #6174 and this PR merge cleanly with each other, so neither needs a "Depends on".

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6184215458 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6194#issuecomment-6184215458). Originally posted by [ee6aba54](https://github.com/ee6aba54) on 2026-10-15T04:11:04Z. --- Tested on Linux: Ubuntu 24.04, kernel 7.0, RTX 5080 16 GiB, NVIDIA 595.99.02, PPSA15304. Base: ab9a47684 plus my open #6174, #6185 and #6186, with this PR's three commits on top (no conflicts). The fixed-camera window was 200 s after loading the save, with a warm shader cache and no environment overrides. Presents are counted per 10 s. **No VRAM pressure.** The desktop held 0.9 GiB, the reported budget was 14.8 GiB and the storage budget 3.7 GiB. The cache saw 0 to 40 cache-eviction write-backs per 10 s, far below the growth threshold, so this PR has nothing to do there. **Another process holding 3 GiB of device memory.** This is a plain CUDA allocation, similar to a browser on the desktop. The reported budget was 11.5 GiB and the storage budget 2877 MiB. | | presents / 10 s | cache-eviction write-backs / 10 s | heap reached its budget | crashes | |---|---|---|---|---| | base, 3 runs | 6 / 15 / 16 (median 15) | 385 to 1038 (5.3 to 12.3 GB) | 0 of 3 | 0 | | base + #6194, 4 runs | 24 (the only run that completed the window) | none in that window | 3 of 4 | 2 | Of the three #6194 runs without a complete window, two crashed (below) and one stayed in the menu for 10 minutes because of my input script, without a crash. The growth works as described: 2887 -> 3248 -> 3654 -> 4111 -> 4625 -> 5203 MiB within the first minutes, and the churn disappears. **Cost.** In three of the four runs the device-local heap then reached its budget (`heap 0 uses 11260 of its 11261 MiB budget`). Device buffers were then placed in host memory (7 to 9 allocations per run), and the pool recovered from `VK_ERROR_OUT_OF_DEVICE_MEMORY` once or twice per run. Two of those runs crashed: a guest general protection fault right when gameplay started, and a segfault in the menu. Without this PR none of the runs reached the heap budget. The budget kept oscillating between 4.3 and 5.6 GiB. A grow step is only checked against the usage at that moment, and other consumers grow afterwards (sampled textures, device buffers, the staging pool). The shrink comes only at the next budget read, after allocations have already failed. The crashes may well be in my own reclaim path from #6174, which is in this base, so I would not blame them on this PR. Reaching the heap budget, however, comes from the growth. Suggestions: - Cap growth by what the other caches may still claim, for example reported budget minus usage minus the reserve minus the sampled cache's remaining budget, instead of half the budget. - Or make the shrink step react to the allocation recovery path, not only to the next budget read. With either, the gain shown above should hold without the heap running full. #6174 and this PR merge cleanly with each other, so neither needs a "Depends on".
Thunderhawkk commented 2026-10-15 05:31:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Thunderhawkk on 2026-10-15T05:31:58Z.


Implemented suggestion 1 in StorageBudgetCap (ShaderResources.hpp): the cap now takes the space outside both texture caches, the sampled cache's remaining headroom and the growth check's reserve out of the reported budget, instead of half the reported budget.

cap = min(heap / 2, reported − (usage − both caches' bytes) − reserve − sampledRemaining)

sampledRemaining is the sampled cache's budget minus its bytes, i.e. only what it can still claim; a sampled cache at or over its budget holds back nothing. My first cut held back the sampled cache's whole budget — which in this codebase covers both caches — and that clamped the storage budget to its floor on the title the thresholds come from and the churn came back, so the remaining-headroom reading is the one that works.

Suggestion 2 (shrink on the allocation-recovery path) is not wired: with the cap the growth no longer walks into the sampled cache's claim or the reserve, so the fill-then-fail-then-shrink cycle should not start from this cache. If it still does in your setup I'll wire the shrink next.

Validation on Wolverine PPSA03671 (Windows 11, RTX 5070 Ti 16 GiB, driver 617.42), 12-minute run with the default registration admission:

  • the budget grew 3807 -> 4283 -> 4818 -> 5420 -> 5533 MiB (four steps) and shrank 5533 -> 4842 -> 4236 -> 3707 -> 3652 MiB as the heap filled to 13,885 of 14,609 MiB — the growth still reaches the working set, and the shrink still yields to the heap;
  • no allocation failures and no crash; the process commit oscillated 29 to 41 GiB with the page file raised to 64 GiB;
  • five unit cases in Graphics.cpp cover the roomy, busy, no-room, raised-floor and no-reported-budget paths; agc_driver_graphics_tests passes.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6185199455 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6194#issuecomment-6185199455). Originally posted by [Thunderhawkk](https://github.com/Thunderhawkk) on 2026-10-15T05:31:58Z. --- Implemented suggestion 1 in `StorageBudgetCap` (`ShaderResources.hpp`): the cap now takes the space outside both texture caches, the sampled cache's **remaining headroom** and the growth check's reserve out of the reported budget, instead of half the reported budget. ``` cap = min(heap / 2, reported − (usage − both caches' bytes) − reserve − sampledRemaining) ``` `sampledRemaining` is the sampled cache's budget minus its bytes, i.e. only what it can still claim; a sampled cache at or over its budget holds back nothing. My first cut held back the sampled cache's whole budget — which in this codebase covers *both* caches — and that clamped the storage budget to its floor on the title the thresholds come from and the churn came back, so the remaining-headroom reading is the one that works. Suggestion 2 (shrink on the allocation-recovery path) is not wired: with the cap the growth no longer walks into the sampled cache's claim or the reserve, so the fill-then-fail-then-shrink cycle should not start from this cache. If it still does in your setup I'll wire the shrink next. Validation on Wolverine PPSA03671 (Windows 11, RTX 5070 Ti 16 GiB, driver 617.42), 12-minute run with the default registration admission: - the budget grew `3807 -> 4283 -> 4818 -> 5420 -> 5533 MiB` (four steps) and shrank `5533 -> 4842 -> 4236 -> 3707 -> 3652 MiB` as the heap filled to 13,885 of 14,609 MiB — the growth still reaches the working set, and the shrink still yields to the heap; - no allocation failures and no crash; the process commit oscillated 29 to 41 GiB with the page file raised to 64 GiB; - five unit cases in `Graphics.cpp` cover the roomy, busy, no-room, raised-floor and no-reported-budget paths; `agc_driver_graphics_tests` passes. AI-assisted: yes.
AlxcBTW commented 2026-10-15 17:51:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-15T17:51:52Z.


Measured this PR on two 8 GB cards with Minecraft Dungeons II (PPSA16064 01.100.100, title screen, Windows 11, NVIDIA 617.42). On both the storage budget never grows, and the eviction loop it targets is the whole frame-rate gap there. Two root causes, a proposed change, and numbers.

title, steady 10 s windows RTX 5070 Laptop 8 GB (budget 7123 MiB) RTX 4060 8 GB (budget 7189 MiB, measured by @parl0v)
main 636b1b93c 2.1 FPS, ~4,500 storage-image creations / 10 s 3.1 FPS, ~4,450 / 10 s
main + this PR (+ #6197) 2.0-2.5 FPS, no budget change in 240 s -
+ change 1 (headroom = min(remaining, sampled)) grows to 2535 MiB, shrinks back to 1780 6.4 FPS, grows to 2878 MiB
+ change 1 + reserve max(1 GiB, budget / 8) 7.0-7.7 FPS, 1780 -> 3208 MiB, no shrink 6.6 FPS, 1797 -> 3238 MiB, no evictions
proposed revision below 7.5-8.0 FPS, 1780 -> 3610 MiB in six steps, no shrink, 650 storage images created in 220 s -
main + APS5_TEXTURE_CACHE_MIB=3072 (reference) 7.8 FPS 6.8 FPS

Why it does not grow on 8 GB. storageBudgetCap holds back SampledTextureBudget(...) - sampled. SampledTextureBudget already takes TextureCacheBudget (2 GiB on these cards, the storage cache's share) and budget / 8 out, and then floors at 2048 MiB; at this title the sampled cache holds ~33 MiB, so ~2 GiB is held back for a cache that is nearly empty, on top of the 2 GiB reserve. With ~2.3 GiB used outside both caches the cap comes out at ~700 MiB, below the 1780 MiB floor, so current < cap never holds. The two caches each reserve room for the other; on 16 GB there is space for both, on 8 GB there is not.

Why the 2 GiB reserve shrinks it back. With the headroom fixed, the budget grew 1780 -> 2003 -> 2253 -> 2535 MiB and then shrank back to 1780 once heap usage passed ~5.1 GiB: a fixed 2 GiB is 29 % of a 7.1 GiB budget.

Proposed revision (branch AlxcBTW/AnyPS5:lab/md2-evict-cap3, on top of this PR; an independent review of the simpler min(remaining, sampled) version found that it removes the cap's forward-looking bound, and this revision answers that):

  1. The held-back headroom is the way back to the sampled cache's recent peak plus one step: SampledCacheHeadroom(sampledBudget, sampled, peak) = min(sampledBudget, peak + max(peak / 8, 64 MiB)) - sampled (0 when the sampled cache is at or over it). The peak is the maximum of SampledTextureMemory() and the previous peak minus 1/64, taken once per budget read (once per second), so a sampled cache that was large before keeps its claim immediately, and a one-off spike stops reserving after a minute or so.
  2. The reserve in StorageBudgetCap and NextStorageBudget is max(1 GiB, budget / 8). On a 15229 MiB budget that is 1903 MiB (was 2048); on a 7123 MiB budget 1024 MiB (was 2048).
  3. A budget above a cap that fell steps down toward it, one step per read (NextStorageBudget, after the pressure check). Without it a grown budget stays above the cap until usage itself crosses the shrink line, so the cap only limits growth, not what was already taken.

Tests (tests/Graphics.cpp): the two StorageBudgetCap expectations that pinned the 2 GiB reserve are corrected (the first now meets half the heap, so a 2x heap case pins the pool arithmetic again), and 12 cases are added: the 8 GiB card (full headroom held back stays at the floor; small headroom leaves 3515 MiB), growth and shrink lines under the 1 GiB reserve, SampledCacheHeadroom (small cache, below its peak, capped at the sampled budget, over budget), and the step-down to a fallen cap. All 24 budget assertions pass against these function bodies; the full agc_driver_graphics_tests target was not built here.

Trade-off to weigh. In the review case above (16 GB, another process holding 3 GiB, reported budget ~11.5 GiB) the reserve goes from 2048 to ~1470 MiB, and a sampled cache that has not been large yet holds back less than before. The step-down in 3 and the peak in 1 make the cap respond before usage crosses the shrink line, but I could not run that setup. If you prefer to keep 2 GiB there, a reserve floor that scales with the budget (1 GiB at 8 GB, 2 GiB from about 12 GB) keeps the 8 GB case working.

Patch against this PR's head 8bb130068 (applies cleanly; code, tests and the debt entry):

diff
diff --git a/core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp b/core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
index 31acc5298..731b4c5be 100644
--- a/core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
+++ b/core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
@@ -32,6 +32,7 @@ std::uint64_t TextureCacheBudget(const VkPhysicalDeviceMemoryProperties& memory)
 std::uint64_t StorageTextureBudget(const VkPhysicalDeviceMemoryProperties& memory, const VkPhysicalDeviceMemoryBudgetPropertiesEXT* reported);
 std::uint64_t NextStorageBudget(std::uint64_t current, std::uint64_t floor, std::uint64_t cap, std::uint64_t reportedBudget, std::uint64_t usage, std::uint64_t evictions);
 std::uint64_t StorageBudgetCap(std::uint64_t heapBytes, std::uint64_t reportedBudget, std::uint64_t usage, std::uint64_t cacheBytes, std::uint64_t sampledRemaining, std::uint64_t floor);
+std::uint64_t SampledCacheHeadroom(std::uint64_t sampledBudget, std::uint64_t sampled, std::uint64_t sampledPeak);
 std::uint64_t SampledTextureBudget(const VkPhysicalDeviceMemoryProperties& memory, const VkPhysicalDeviceMemoryBudgetPropertiesEXT* reported, std::uint64_t textureBytes);
 bool SampledBudgetReportDue(std::uint64_t reported, std::uint64_t budget, std::chrono::steady_clock::duration sinceReport);
 struct TextureCacheUse {
diff --git a/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp b/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
index 3922262b1..29f3f137e 100644
--- a/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
+++ b/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
@@ -503,11 +503,14 @@ std::uint64_t storageBudgetCap(const VkPhysicalDeviceMemoryProperties& memory, c
     const auto heap = largestDeviceLocalHeap(memory);
     const auto heapBytes = heap ? memory.memoryHeaps[*heap].size : 0u;
     if (reported == nullptr || !heap) return StorageBudgetCap(heapBytes, 0u, 0u, 0u, 0u, floor);
+    static std::atomic<std::uint64_t> sampledPeak{0};
     const auto sampled = SampledTextureMemory();
+    const auto previousPeak = sampledPeak.load(std::memory_order_relaxed);
+    const auto peak = std::max(sampled, previousPeak - previousPeak / 64u);
+    sampledPeak.store(peak, std::memory_order_relaxed);
     const auto caches = sampled + storageCacheBytes();
     const auto sampledBudget = SampledTextureBudget(memory, reported, caches);
-    const auto sampledRemaining = sampledBudget > sampled ? sampledBudget - sampled : 0u;
-    return StorageBudgetCap(heapBytes, reported->heapBudget[*heap], reported->heapUsage[*heap], caches, sampledRemaining, floor);
+    return StorageBudgetCap(heapBytes, reported->heapBudget[*heap], reported->heapUsage[*heap], caches, SampledCacheHeadroom(sampledBudget, sampled, peak), floor);
 }
 
 std::uint64_t storageBudget(const Context& context) {
@@ -1042,7 +1045,7 @@ std::shared_ptr<StorageTexture> cachedStorageTexture(const Context& context, std
 std::uint64_t StorageBudgetCap(const std::uint64_t heapBytes, const std::uint64_t reportedBudget, const std::uint64_t usage, const std::uint64_t cacheBytes, const std::uint64_t sampledRemaining, const std::uint64_t floor) {
     std::uint64_t cap = heapBytes / 2u;
     if (reportedBudget != 0) {
-        const auto reserve = std::max<std::uint64_t>(2048ull << 20u, reportedBudget / 8u);
+        const auto reserve = std::max<std::uint64_t>(1024ull << 20u, reportedBudget / 8u);
         const auto outside = usage - std::min(usage, cacheBytes);
         const auto pool = reportedBudget > outside + reserve ? reportedBudget - outside - reserve : 0u;
         cap = std::min(cap, pool > sampledRemaining ? pool - sampledRemaining : 0u);
@@ -1050,6 +1053,11 @@ std::uint64_t StorageBudgetCap(const std::uint64_t heapBytes, const std::uint64_
     return std::max(cap, floor);
 }
 
+std::uint64_t SampledCacheHeadroom(const std::uint64_t sampledBudget, const std::uint64_t sampled, const std::uint64_t sampledPeak) {
+    const auto expected = std::min(sampledBudget, sampledPeak + std::max<std::uint64_t>(sampledPeak / 8u, 64ull << 20u));
+    return expected > sampled ? expected - sampled : 0u;
+}
+
 std::uint64_t TextureCacheBudget(const VkPhysicalDeviceMemoryProperties& memory) {
     const auto heap = largestDeviceLocalHeap(memory);
     return std::max<std::uint64_t>(2048ull << 20u, heap ? memory.memoryHeaps[*heap].size / 4u : 0u);
@@ -1067,9 +1075,10 @@ std::uint64_t StorageTextureBudget(const VkPhysicalDeviceMemoryProperties& memor
 // and the cap come from the measurement in the storage-cache debt entry.
 std::uint64_t NextStorageBudget(const std::uint64_t current, const std::uint64_t floor, const std::uint64_t cap, const std::uint64_t reportedBudget, const std::uint64_t usage, const std::uint64_t evictions) {
     if (reportedBudget == 0) return current;
-    const auto reserve = std::max<std::uint64_t>(2048ull << 20u, reportedBudget / 8u);
+    const auto reserve = std::max<std::uint64_t>(1024ull << 20u, reportedBudget / 8u);
     const auto step = std::max<std::uint64_t>(current / 8u, 64ull << 20u);
     if (usage + reserve > reportedBudget) return std::max(floor, current > step ? current - step : floor);
+    if (current > cap) return std::max({floor, cap, current > step ? current - step : floor});
     if (evictions >= 16u && current < cap && usage + step + reserve <= reportedBudget) return std::min(cap, current + step);
     return current;
 }
diff --git a/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp b/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
index 6a2ac3143..deeefa675 100644
--- a/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
+++ b/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
@@ -7497,18 +7497,42 @@ int main(int argc, char** argv) {
             Require(AgcDriver::Graphics::NextStorageBudget(floor, floor, cap, reported, 14000u * MiB, 0u) == floor, "a storage budget does not shrink past its floor");
             Require(AgcDriver::Graphics::NextStorageBudget(floor, floor, cap, 0u, 0u, 1000u) == floor, "a storage budget without a reported budget does not change");
             Require(AgcDriver::Graphics::NextStorageBudget(floor, floor, cap, reported, 13000u * MiB, 16u) == floor, "a storage budget without growth headroom does not grow");
+            Require(AgcDriver::Graphics::NextStorageBudget(5000u * MiB, floor, 4000u * MiB, reported, roomy, 0u) == 4375u * MiB, "a storage budget above a cap that fell steps down one step");
+            Require(AgcDriver::Graphics::NextStorageBudget(4100u * MiB, floor, 4000u * MiB, reported, roomy, 1000u) == 4000u * MiB, "a storage budget above its cap does not step below the cap");
+        }
+        {
+            constexpr std::uint64_t MiB = 1ull << 20u;
+            const std::uint64_t floor = 1780u * MiB;
+            const std::uint64_t cap = 3515u * MiB;
+            const std::uint64_t reported = 7123u * MiB;
+            Require(AgcDriver::Graphics::NextStorageBudget(floor, floor, cap, reported, 5400u * MiB, 16u) == floor + floor / 8u, "a storage budget on an 8 GiB card grows under a reserve of 1 GiB");
+            Require(AgcDriver::Graphics::NextStorageBudget(3208u * MiB, floor, cap, reported, 6000u * MiB, 0u) == 3208u * MiB, "a storage budget on an 8 GiB card holds while usage and the reserve fit the reported budget");
+            Require(AgcDriver::Graphics::NextStorageBudget(3208u * MiB, floor, cap, reported, 6200u * MiB, 0u) == 2807u * MiB, "a storage budget on an 8 GiB card shrinks once usage and the reserve pass the reported budget");
         }
         {
             constexpr std::uint64_t MiB = 1ull << 20u;
             const std::uint64_t floor = 3807u * MiB;
             const std::uint64_t heap = 16384u * MiB;
             const std::uint64_t reported = 15229u * MiB;
-            Require(AgcDriver::Graphics::StorageBudgetCap(heap, reported, 4000u * MiB, 3000u * MiB, 4000u * MiB, floor) == 8181u * MiB, "a storage cap leaves the sampled cache's remaining headroom and the reserve out of the device budget");
-            Require(AgcDriver::Graphics::StorageBudgetCap(heap, reported, 14000u * MiB, 10000u * MiB, 5000u * MiB, floor) == 4181u * MiB, "a storage cap shrinks as the other usage grows");
+            Require(AgcDriver::Graphics::StorageBudgetCap(heap, reported, 4000u * MiB, 3000u * MiB, 4000u * MiB, floor) == heap / 2u, "a storage cap is at most half the heap");
+            Require(AgcDriver::Graphics::StorageBudgetCap(2u * heap, reported, 4000u * MiB, 3000u * MiB, 4000u * MiB, floor) == reported - 5000u * MiB - reported / 8u, "a storage cap leaves the sampled cache's headroom and the reserve out of the device budget");
+            Require(AgcDriver::Graphics::StorageBudgetCap(heap, reported, 14000u * MiB, 10000u * MiB, 5000u * MiB, floor) == reported - 9000u * MiB - reported / 8u, "a storage cap shrinks as the other usage grows");
             Require(AgcDriver::Graphics::StorageBudgetCap(heap, reported, 14000u * MiB, 10000u * MiB, 9181u * MiB, floor) == floor, "a storage cap never falls below the floor");
             Require(AgcDriver::Graphics::StorageBudgetCap(heap, reported, 4000u * MiB, 3000u * MiB, 4000u * MiB, 12288u * MiB) == 12288u * MiB, "a storage cap keeps a floor above the computed cap");
             Require(AgcDriver::Graphics::StorageBudgetCap(heap, 0u, 0u, 0u, 0u, floor) == heap / 2u, "a storage cap without a reported budget is half the heap");
         }
+        {
+            constexpr std::uint64_t MiB = 1ull << 20u;
+            const std::uint64_t floor = 1780u * MiB;
+            const std::uint64_t heap = 8192u * MiB;
+            const std::uint64_t reported = 7123u * MiB;
+            Require(AgcDriver::Graphics::StorageBudgetCap(heap, reported, 4500u * MiB, 1980u * MiB, 1848u * MiB, floor) == floor, "a storage cap on an 8 GiB card that holds back the sampled cache's whole remaining budget stays at the floor");
+            Require(AgcDriver::Graphics::StorageBudgetCap(heap, reported, 4500u * MiB, 1980u * MiB, 64u * MiB, floor) == 3515u * MiB, "a storage cap on an 8 GiB card leaves a reserve of 1 GiB and the sampled headroom out of the reported budget");
+            Require(AgcDriver::Graphics::SampledCacheHeadroom(2048u * MiB, 33u * MiB, 33u * MiB) == 64u * MiB, "a small sampled cache keeps one growth step of headroom");
+            Require(AgcDriver::Graphics::SampledCacheHeadroom(2048u * MiB, 200u * MiB, 1500u * MiB) == 1500u * MiB + 1500u * MiB / 8u - 200u * MiB, "a sampled cache below its recent peak keeps the headroom to return to it");
+            Require(AgcDriver::Graphics::SampledCacheHeadroom(1000u * MiB, 100u * MiB, 950u * MiB) == 900u * MiB, "the sampled headroom stays within the sampled budget");
+            Require(AgcDriver::Graphics::SampledCacheHeadroom(2048u * MiB, 2100u * MiB, 2100u * MiB) == 0u, "a sampled cache over its budget holds no headroom back");
+        }
         std::cout << "Graphics validation tests passed\n";
         return 0;
     } catch (const std::exception& error) {
diff --git a/docs/dev/debt/libSceAgcDriver.md b/docs/dev/debt/libSceAgcDriver.md
index dfe0e79fd..c901f8924 100644
--- a/docs/dev/debt/libSceAgcDriver.md
+++ b/docs/dev/debt/libSceAgcDriver.md
@@ -150,4 +150,4 @@
 - [Flip packets raise the graphics end-of-pipe event](../../../core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cpp) (libSceAgcDriver) - a flip delivers the queue's end-of-pipe event (`sceAgcDriverAddEqEvent`) once the work recorded before it completes, as a `RELEASE_MEM` with `INT_SEL` does. Minecraft (PPSA17221) registers the graphics event, never requests an interrupt in its releases, and waits on the event after every flip while holding its render lock, so without this it never presents a second frame. Whether the console raises the event from the flip itself or from an interrupt its flip sequence contains is not measured; a title that waits only on release interrupts sees one extra event per flip, with `data` counting it.
 - [Host import windows and budget](../../../core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp) (libSceAgcDriver): a registered range larger than 64 MiB is imported one 64 MiB window at a time for buffer and fill accesses; an access across window edges imports the cells it touches, grown to the union of the range's imports it overlaps. An address-based build (`AcquireRegistered`) imports the range whole and replaces its windows. Live imports stay under a budget: `APS5_HOST_IMPORT_MIB`, else the larger of 6 GiB and half the physical memory, at most the largest host heap less 2 GiB (imports and type-3 mirrors share it; #167's rule). A new import beyond it retires the least recently used imports not used in the last 256 lookups; one that would not fit even then is refused before anything is retired, and imports made when a range is mapped never evict. A refused import is tried again at its next use. The 64 MiB window, the 256-lookup protection and the 2 GiB reserve are choices, not measured.
 - [Registration preparation at submit](../../../core/libs/prx/libSceAgcDriver/Execution/src/Driver/Queues/Submission.cpp) (libSceAgcDriver) - `Driver::Submit` waits for every registration-time shader preparation queued before the call, not only those of the shaders the commands use, so a submission behind a long queue of unrelated preparations waits for all of them on the submitting thread. Waiting there instead of in the queue worker keeps the GPU side of a submission short: a title that sees a submission take seconds treats the GPU as hung (Goat Simulator 3, PPSA04159, then stops submitting and its garbage collector fails a 10 s timeout). On the console shaders are compiled ahead of time, so neither wait exists; how long a title tolerates a slow submit call is not known.
-- [Storage cache budget](../../../core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp) (libSceAgcDriver) - the storage image cache's budget grows while it evicts entries under its own budget (16 or more in one second, by an eighth of the budget per step, at least 64 MiB, capped at half the device-local heap's size and at what the reported budget leaves once the space outside both texture caches, the sampled cache's remaining headroom and the reserve are taken out) and shrinks the same way while the heap's reported usage plus a reserve of 2 GiB or an eighth of the reported budget exceeds the reported budget, so a title whose storage working set does not fit the initial share stops recreating the same surfaces every frame. The thresholds follow the Wolverine PPSA03671 measurement on Windows (RTX 5070 Ti, 16 GiB, driver 617.42): the budget grew from 3807 MiB to 6098 MiB in four steps, 44,776 storage-image creations in 180 s fell to 1,845 and the peak reported heap usage from 14,605 MiB to 9,555 MiB; no other title and no console hardware were measured. On PPSA15304 (Linux, RTX 5080, review on #6194) the growth walked the device heap to its budget while another process held 3 GiB, which is why the cap also leaves the sampled cache's remaining headroom and the reserve out.
+- [Storage cache budget](../../../core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp) (libSceAgcDriver) - the storage image cache's budget grows while it evicts entries under its own budget (16 or more in one second, by an eighth of the budget per step, at least 64 MiB, capped at half the device-local heap's size and at what the reported budget leaves once the space outside both texture caches, the headroom the sampled cache needs to return to its recent peak plus one step, and the reserve are taken out), steps down the same way while it is above a cap that fell, and shrinks the same way while the heap's reported usage plus a reserve of 1 GiB or an eighth of the reported budget exceeds the reported budget, so a title whose storage working set does not fit the initial share stops recreating the same surfaces every frame. The sampled cache's peak is the larger of its current size and the previous peak less a sixty-fourth, read once a second with the budget. The thresholds follow the Wolverine PPSA03671 measurement on Windows (RTX 5070 Ti, 16 GiB, driver 617.42): the budget grew from 3807 MiB to 6098 MiB in four steps, 44,776 storage-image creations in 180 s fell to 1,845 and the peak reported heap usage from 14,605 MiB to 9,555 MiB. On PPSA15304 (Linux, RTX 5080, review on #6194) the growth walked the device heap to its budget while another process held 3 GiB, which is why the cap also leaves the sampled cache's headroom and the reserve out. On Minecraft Dungeons II PPSA16064 (Windows, RTX 5070 Laptop 8 GiB, reported budget 7123 MiB, title screen) a cap that held back the sampled cache's whole remaining budget (2 GiB, that budget's floor, while the cache held about 33 MiB) plus a 2 GiB reserve stayed at the 1780 MiB floor, with about 4,500 storage-image creations per 10 s and 2.1 FPS; with the peak-based headroom and the 1 GiB reserve the budget grew to 3610 MiB in six steps, 650 storage images were created in 220 s and the title ran at 7.5-8.0 FPS (7.8 with the budget forced to 3072 MiB). The step-down to a fallen cap, the peak decay and the 1 GiB reserve are choices; they were not measured on other cards, on Linux or on console hardware.

Not checked: Linux, 12 and 16 GB cards with this revision, gameplay (title screen only), the full test target.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6198634040 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6194#issuecomment-6198634040). Originally posted by [AlxcBTW](https://github.com/AlxcBTW) on 2026-10-15T17:51:52Z. --- Measured this PR on two 8 GB cards with Minecraft Dungeons II (PPSA16064 01.100.100, title screen, Windows 11, NVIDIA 617.42). On both the storage budget never grows, and the eviction loop it targets is the whole frame-rate gap there. Two root causes, a proposed change, and numbers. | title, steady 10 s windows | RTX 5070 Laptop 8 GB (budget 7123 MiB) | RTX 4060 8 GB (budget 7189 MiB, measured by @parl0v) | |---|---|---| | `main` 636b1b93c | 2.1 FPS, ~4,500 storage-image creations / 10 s | 3.1 FPS, ~4,450 / 10 s | | `main` + this PR (+ #6197) | 2.0-2.5 FPS, no budget change in 240 s | - | | + change 1 (headroom = min(remaining, sampled)) | grows to 2535 MiB, shrinks back to 1780 | 6.4 FPS, grows to 2878 MiB | | + change 1 + reserve max(1 GiB, budget / 8) | 7.0-7.7 FPS, 1780 -> 3208 MiB, no shrink | 6.6 FPS, 1797 -> 3238 MiB, no evictions | | **proposed revision below** | **7.5-8.0 FPS, 1780 -> 3610 MiB in six steps, no shrink, 650 storage images created in 220 s** | - | | `main` + `APS5_TEXTURE_CACHE_MIB=3072` (reference) | 7.8 FPS | 6.8 FPS | **Why it does not grow on 8 GB.** `storageBudgetCap` holds back `SampledTextureBudget(...) - sampled`. `SampledTextureBudget` already takes `TextureCacheBudget` (2 GiB on these cards, the storage cache's share) and budget / 8 out, and then floors at 2048 MiB; at this title the sampled cache holds ~33 MiB, so ~2 GiB is held back for a cache that is nearly empty, on top of the 2 GiB reserve. With ~2.3 GiB used outside both caches the cap comes out at ~700 MiB, below the 1780 MiB floor, so `current < cap` never holds. The two caches each reserve room for the other; on 16 GB there is space for both, on 8 GB there is not. **Why the 2 GiB reserve shrinks it back.** With the headroom fixed, the budget grew 1780 -> 2003 -> 2253 -> 2535 MiB and then shrank back to 1780 once heap usage passed ~5.1 GiB: a fixed 2 GiB is 29 % of a 7.1 GiB budget. **Proposed revision** (branch `AlxcBTW/AnyPS5:lab/md2-evict-cap3`, on top of this PR; an independent review of the simpler `min(remaining, sampled)` version found that it removes the cap's forward-looking bound, and this revision answers that): 1. The held-back headroom is the way back to the sampled cache's recent peak plus one step: `SampledCacheHeadroom(sampledBudget, sampled, peak) = min(sampledBudget, peak + max(peak / 8, 64 MiB)) - sampled` (0 when the sampled cache is at or over it). The peak is the maximum of `SampledTextureMemory()` and the previous peak minus 1/64, taken once per budget read (once per second), so a sampled cache that was large before keeps its claim immediately, and a one-off spike stops reserving after a minute or so. 2. The reserve in `StorageBudgetCap` and `NextStorageBudget` is max(1 GiB, budget / 8). On a 15229 MiB budget that is 1903 MiB (was 2048); on a 7123 MiB budget 1024 MiB (was 2048). 3. A budget above a cap that fell steps down toward it, one step per read (`NextStorageBudget`, after the pressure check). Without it a grown budget stays above the cap until usage itself crosses the shrink line, so the cap only limits growth, not what was already taken. Tests (`tests/Graphics.cpp`): the two `StorageBudgetCap` expectations that pinned the 2 GiB reserve are corrected (the first now meets half the heap, so a 2x heap case pins the pool arithmetic again), and 12 cases are added: the 8 GiB card (full headroom held back stays at the floor; small headroom leaves 3515 MiB), growth and shrink lines under the 1 GiB reserve, `SampledCacheHeadroom` (small cache, below its peak, capped at the sampled budget, over budget), and the step-down to a fallen cap. All 24 budget assertions pass against these function bodies; the full `agc_driver_graphics_tests` target was not built here. **Trade-off to weigh.** In the review case above (16 GB, another process holding 3 GiB, reported budget ~11.5 GiB) the reserve goes from 2048 to ~1470 MiB, and a sampled cache that has not been large yet holds back less than before. The step-down in 3 and the peak in 1 make the cap respond before usage crosses the shrink line, but I could not run that setup. If you prefer to keep 2 GiB there, a reserve floor that scales with the budget (1 GiB at 8 GB, 2 GiB from about 12 GB) keeps the 8 GB case working. Patch against this PR's head 8bb130068 (applies cleanly; code, tests and the debt entry): <details><summary>diff</summary> ```diff diff --git a/core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp b/core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp index 31acc5298..731b4c5be 100644 --- a/core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp +++ b/core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp @@ -32,6 +32,7 @@ std::uint64_t TextureCacheBudget(const VkPhysicalDeviceMemoryProperties& memory) std::uint64_t StorageTextureBudget(const VkPhysicalDeviceMemoryProperties& memory, const VkPhysicalDeviceMemoryBudgetPropertiesEXT* reported); std::uint64_t NextStorageBudget(std::uint64_t current, std::uint64_t floor, std::uint64_t cap, std::uint64_t reportedBudget, std::uint64_t usage, std::uint64_t evictions); std::uint64_t StorageBudgetCap(std::uint64_t heapBytes, std::uint64_t reportedBudget, std::uint64_t usage, std::uint64_t cacheBytes, std::uint64_t sampledRemaining, std::uint64_t floor); +std::uint64_t SampledCacheHeadroom(std::uint64_t sampledBudget, std::uint64_t sampled, std::uint64_t sampledPeak); std::uint64_t SampledTextureBudget(const VkPhysicalDeviceMemoryProperties& memory, const VkPhysicalDeviceMemoryBudgetPropertiesEXT* reported, std::uint64_t textureBytes); bool SampledBudgetReportDue(std::uint64_t reported, std::uint64_t budget, std::chrono::steady_clock::duration sinceReport); struct TextureCacheUse { diff --git a/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp b/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp index 3922262b1..29f3f137e 100644 --- a/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp +++ b/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp @@ -503,11 +503,14 @@ std::uint64_t storageBudgetCap(const VkPhysicalDeviceMemoryProperties& memory, c const auto heap = largestDeviceLocalHeap(memory); const auto heapBytes = heap ? memory.memoryHeaps[*heap].size : 0u; if (reported == nullptr || !heap) return StorageBudgetCap(heapBytes, 0u, 0u, 0u, 0u, floor); + static std::atomic<std::uint64_t> sampledPeak{0}; const auto sampled = SampledTextureMemory(); + const auto previousPeak = sampledPeak.load(std::memory_order_relaxed); + const auto peak = std::max(sampled, previousPeak - previousPeak / 64u); + sampledPeak.store(peak, std::memory_order_relaxed); const auto caches = sampled + storageCacheBytes(); const auto sampledBudget = SampledTextureBudget(memory, reported, caches); - const auto sampledRemaining = sampledBudget > sampled ? sampledBudget - sampled : 0u; - return StorageBudgetCap(heapBytes, reported->heapBudget[*heap], reported->heapUsage[*heap], caches, sampledRemaining, floor); + return StorageBudgetCap(heapBytes, reported->heapBudget[*heap], reported->heapUsage[*heap], caches, SampledCacheHeadroom(sampledBudget, sampled, peak), floor); } std::uint64_t storageBudget(const Context& context) { @@ -1042,7 +1045,7 @@ std::shared_ptr<StorageTexture> cachedStorageTexture(const Context& context, std std::uint64_t StorageBudgetCap(const std::uint64_t heapBytes, const std::uint64_t reportedBudget, const std::uint64_t usage, const std::uint64_t cacheBytes, const std::uint64_t sampledRemaining, const std::uint64_t floor) { std::uint64_t cap = heapBytes / 2u; if (reportedBudget != 0) { - const auto reserve = std::max<std::uint64_t>(2048ull << 20u, reportedBudget / 8u); + const auto reserve = std::max<std::uint64_t>(1024ull << 20u, reportedBudget / 8u); const auto outside = usage - std::min(usage, cacheBytes); const auto pool = reportedBudget > outside + reserve ? reportedBudget - outside - reserve : 0u; cap = std::min(cap, pool > sampledRemaining ? pool - sampledRemaining : 0u); @@ -1050,6 +1053,11 @@ std::uint64_t StorageBudgetCap(const std::uint64_t heapBytes, const std::uint64_ return std::max(cap, floor); } +std::uint64_t SampledCacheHeadroom(const std::uint64_t sampledBudget, const std::uint64_t sampled, const std::uint64_t sampledPeak) { + const auto expected = std::min(sampledBudget, sampledPeak + std::max<std::uint64_t>(sampledPeak / 8u, 64ull << 20u)); + return expected > sampled ? expected - sampled : 0u; +} + std::uint64_t TextureCacheBudget(const VkPhysicalDeviceMemoryProperties& memory) { const auto heap = largestDeviceLocalHeap(memory); return std::max<std::uint64_t>(2048ull << 20u, heap ? memory.memoryHeaps[*heap].size / 4u : 0u); @@ -1067,9 +1075,10 @@ std::uint64_t StorageTextureBudget(const VkPhysicalDeviceMemoryProperties& memor // and the cap come from the measurement in the storage-cache debt entry. std::uint64_t NextStorageBudget(const std::uint64_t current, const std::uint64_t floor, const std::uint64_t cap, const std::uint64_t reportedBudget, const std::uint64_t usage, const std::uint64_t evictions) { if (reportedBudget == 0) return current; - const auto reserve = std::max<std::uint64_t>(2048ull << 20u, reportedBudget / 8u); + const auto reserve = std::max<std::uint64_t>(1024ull << 20u, reportedBudget / 8u); const auto step = std::max<std::uint64_t>(current / 8u, 64ull << 20u); if (usage + reserve > reportedBudget) return std::max(floor, current > step ? current - step : floor); + if (current > cap) return std::max({floor, cap, current > step ? current - step : floor}); if (evictions >= 16u && current < cap && usage + step + reserve <= reportedBudget) return std::min(cap, current + step); return current; } diff --git a/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp b/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp index 6a2ac3143..deeefa675 100644 --- a/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp +++ b/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp @@ -7497,18 +7497,42 @@ int main(int argc, char** argv) { Require(AgcDriver::Graphics::NextStorageBudget(floor, floor, cap, reported, 14000u * MiB, 0u) == floor, "a storage budget does not shrink past its floor"); Require(AgcDriver::Graphics::NextStorageBudget(floor, floor, cap, 0u, 0u, 1000u) == floor, "a storage budget without a reported budget does not change"); Require(AgcDriver::Graphics::NextStorageBudget(floor, floor, cap, reported, 13000u * MiB, 16u) == floor, "a storage budget without growth headroom does not grow"); + Require(AgcDriver::Graphics::NextStorageBudget(5000u * MiB, floor, 4000u * MiB, reported, roomy, 0u) == 4375u * MiB, "a storage budget above a cap that fell steps down one step"); + Require(AgcDriver::Graphics::NextStorageBudget(4100u * MiB, floor, 4000u * MiB, reported, roomy, 1000u) == 4000u * MiB, "a storage budget above its cap does not step below the cap"); + } + { + constexpr std::uint64_t MiB = 1ull << 20u; + const std::uint64_t floor = 1780u * MiB; + const std::uint64_t cap = 3515u * MiB; + const std::uint64_t reported = 7123u * MiB; + Require(AgcDriver::Graphics::NextStorageBudget(floor, floor, cap, reported, 5400u * MiB, 16u) == floor + floor / 8u, "a storage budget on an 8 GiB card grows under a reserve of 1 GiB"); + Require(AgcDriver::Graphics::NextStorageBudget(3208u * MiB, floor, cap, reported, 6000u * MiB, 0u) == 3208u * MiB, "a storage budget on an 8 GiB card holds while usage and the reserve fit the reported budget"); + Require(AgcDriver::Graphics::NextStorageBudget(3208u * MiB, floor, cap, reported, 6200u * MiB, 0u) == 2807u * MiB, "a storage budget on an 8 GiB card shrinks once usage and the reserve pass the reported budget"); } { constexpr std::uint64_t MiB = 1ull << 20u; const std::uint64_t floor = 3807u * MiB; const std::uint64_t heap = 16384u * MiB; const std::uint64_t reported = 15229u * MiB; - Require(AgcDriver::Graphics::StorageBudgetCap(heap, reported, 4000u * MiB, 3000u * MiB, 4000u * MiB, floor) == 8181u * MiB, "a storage cap leaves the sampled cache's remaining headroom and the reserve out of the device budget"); - Require(AgcDriver::Graphics::StorageBudgetCap(heap, reported, 14000u * MiB, 10000u * MiB, 5000u * MiB, floor) == 4181u * MiB, "a storage cap shrinks as the other usage grows"); + Require(AgcDriver::Graphics::StorageBudgetCap(heap, reported, 4000u * MiB, 3000u * MiB, 4000u * MiB, floor) == heap / 2u, "a storage cap is at most half the heap"); + Require(AgcDriver::Graphics::StorageBudgetCap(2u * heap, reported, 4000u * MiB, 3000u * MiB, 4000u * MiB, floor) == reported - 5000u * MiB - reported / 8u, "a storage cap leaves the sampled cache's headroom and the reserve out of the device budget"); + Require(AgcDriver::Graphics::StorageBudgetCap(heap, reported, 14000u * MiB, 10000u * MiB, 5000u * MiB, floor) == reported - 9000u * MiB - reported / 8u, "a storage cap shrinks as the other usage grows"); Require(AgcDriver::Graphics::StorageBudgetCap(heap, reported, 14000u * MiB, 10000u * MiB, 9181u * MiB, floor) == floor, "a storage cap never falls below the floor"); Require(AgcDriver::Graphics::StorageBudgetCap(heap, reported, 4000u * MiB, 3000u * MiB, 4000u * MiB, 12288u * MiB) == 12288u * MiB, "a storage cap keeps a floor above the computed cap"); Require(AgcDriver::Graphics::StorageBudgetCap(heap, 0u, 0u, 0u, 0u, floor) == heap / 2u, "a storage cap without a reported budget is half the heap"); } + { + constexpr std::uint64_t MiB = 1ull << 20u; + const std::uint64_t floor = 1780u * MiB; + const std::uint64_t heap = 8192u * MiB; + const std::uint64_t reported = 7123u * MiB; + Require(AgcDriver::Graphics::StorageBudgetCap(heap, reported, 4500u * MiB, 1980u * MiB, 1848u * MiB, floor) == floor, "a storage cap on an 8 GiB card that holds back the sampled cache's whole remaining budget stays at the floor"); + Require(AgcDriver::Graphics::StorageBudgetCap(heap, reported, 4500u * MiB, 1980u * MiB, 64u * MiB, floor) == 3515u * MiB, "a storage cap on an 8 GiB card leaves a reserve of 1 GiB and the sampled headroom out of the reported budget"); + Require(AgcDriver::Graphics::SampledCacheHeadroom(2048u * MiB, 33u * MiB, 33u * MiB) == 64u * MiB, "a small sampled cache keeps one growth step of headroom"); + Require(AgcDriver::Graphics::SampledCacheHeadroom(2048u * MiB, 200u * MiB, 1500u * MiB) == 1500u * MiB + 1500u * MiB / 8u - 200u * MiB, "a sampled cache below its recent peak keeps the headroom to return to it"); + Require(AgcDriver::Graphics::SampledCacheHeadroom(1000u * MiB, 100u * MiB, 950u * MiB) == 900u * MiB, "the sampled headroom stays within the sampled budget"); + Require(AgcDriver::Graphics::SampledCacheHeadroom(2048u * MiB, 2100u * MiB, 2100u * MiB) == 0u, "a sampled cache over its budget holds no headroom back"); + } std::cout << "Graphics validation tests passed\n"; return 0; } catch (const std::exception& error) { diff --git a/docs/dev/debt/libSceAgcDriver.md b/docs/dev/debt/libSceAgcDriver.md index dfe0e79fd..c901f8924 100644 --- a/docs/dev/debt/libSceAgcDriver.md +++ b/docs/dev/debt/libSceAgcDriver.md @@ -150,4 +150,4 @@ - [Flip packets raise the graphics end-of-pipe event](../../../core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cpp) (libSceAgcDriver) - a flip delivers the queue's end-of-pipe event (`sceAgcDriverAddEqEvent`) once the work recorded before it completes, as a `RELEASE_MEM` with `INT_SEL` does. Minecraft (PPSA17221) registers the graphics event, never requests an interrupt in its releases, and waits on the event after every flip while holding its render lock, so without this it never presents a second frame. Whether the console raises the event from the flip itself or from an interrupt its flip sequence contains is not measured; a title that waits only on release interrupts sees one extra event per flip, with `data` counting it. - [Host import windows and budget](../../../core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp) (libSceAgcDriver): a registered range larger than 64 MiB is imported one 64 MiB window at a time for buffer and fill accesses; an access across window edges imports the cells it touches, grown to the union of the range's imports it overlaps. An address-based build (`AcquireRegistered`) imports the range whole and replaces its windows. Live imports stay under a budget: `APS5_HOST_IMPORT_MIB`, else the larger of 6 GiB and half the physical memory, at most the largest host heap less 2 GiB (imports and type-3 mirrors share it; #167's rule). A new import beyond it retires the least recently used imports not used in the last 256 lookups; one that would not fit even then is refused before anything is retired, and imports made when a range is mapped never evict. A refused import is tried again at its next use. The 64 MiB window, the 256-lookup protection and the 2 GiB reserve are choices, not measured. - [Registration preparation at submit](../../../core/libs/prx/libSceAgcDriver/Execution/src/Driver/Queues/Submission.cpp) (libSceAgcDriver) - `Driver::Submit` waits for every registration-time shader preparation queued before the call, not only those of the shaders the commands use, so a submission behind a long queue of unrelated preparations waits for all of them on the submitting thread. Waiting there instead of in the queue worker keeps the GPU side of a submission short: a title that sees a submission take seconds treats the GPU as hung (Goat Simulator 3, PPSA04159, then stops submitting and its garbage collector fails a 10 s timeout). On the console shaders are compiled ahead of time, so neither wait exists; how long a title tolerates a slow submit call is not known. -- [Storage cache budget](../../../core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp) (libSceAgcDriver) - the storage image cache's budget grows while it evicts entries under its own budget (16 or more in one second, by an eighth of the budget per step, at least 64 MiB, capped at half the device-local heap's size and at what the reported budget leaves once the space outside both texture caches, the sampled cache's remaining headroom and the reserve are taken out) and shrinks the same way while the heap's reported usage plus a reserve of 2 GiB or an eighth of the reported budget exceeds the reported budget, so a title whose storage working set does not fit the initial share stops recreating the same surfaces every frame. The thresholds follow the Wolverine PPSA03671 measurement on Windows (RTX 5070 Ti, 16 GiB, driver 617.42): the budget grew from 3807 MiB to 6098 MiB in four steps, 44,776 storage-image creations in 180 s fell to 1,845 and the peak reported heap usage from 14,605 MiB to 9,555 MiB; no other title and no console hardware were measured. On PPSA15304 (Linux, RTX 5080, review on #6194) the growth walked the device heap to its budget while another process held 3 GiB, which is why the cap also leaves the sampled cache's remaining headroom and the reserve out. +- [Storage cache budget](../../../core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp) (libSceAgcDriver) - the storage image cache's budget grows while it evicts entries under its own budget (16 or more in one second, by an eighth of the budget per step, at least 64 MiB, capped at half the device-local heap's size and at what the reported budget leaves once the space outside both texture caches, the headroom the sampled cache needs to return to its recent peak plus one step, and the reserve are taken out), steps down the same way while it is above a cap that fell, and shrinks the same way while the heap's reported usage plus a reserve of 1 GiB or an eighth of the reported budget exceeds the reported budget, so a title whose storage working set does not fit the initial share stops recreating the same surfaces every frame. The sampled cache's peak is the larger of its current size and the previous peak less a sixty-fourth, read once a second with the budget. The thresholds follow the Wolverine PPSA03671 measurement on Windows (RTX 5070 Ti, 16 GiB, driver 617.42): the budget grew from 3807 MiB to 6098 MiB in four steps, 44,776 storage-image creations in 180 s fell to 1,845 and the peak reported heap usage from 14,605 MiB to 9,555 MiB. On PPSA15304 (Linux, RTX 5080, review on #6194) the growth walked the device heap to its budget while another process held 3 GiB, which is why the cap also leaves the sampled cache's headroom and the reserve out. On Minecraft Dungeons II PPSA16064 (Windows, RTX 5070 Laptop 8 GiB, reported budget 7123 MiB, title screen) a cap that held back the sampled cache's whole remaining budget (2 GiB, that budget's floor, while the cache held about 33 MiB) plus a 2 GiB reserve stayed at the 1780 MiB floor, with about 4,500 storage-image creations per 10 s and 2.1 FPS; with the peak-based headroom and the 1 GiB reserve the budget grew to 3610 MiB in six steps, 650 storage images were created in 220 s and the title ran at 7.5-8.0 FPS (7.8 with the budget forced to 3072 MiB). The step-down to a fallen cap, the peak decay and the 1 GiB reserve are choices; they were not measured on other cards, on Linux or on console hardware. ``` </details> Not checked: Linux, 12 and 16 GB cards with this revision, gameplay (title screen only), the full test target. AI-assisted: yes
coltken95 commented 2026-10-15 18:56:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by coltken95 on 2026-10-15T18:56:25Z.


Tested on Linux x86-64 (Release build, lavapipe / llvmpipe LLVM 20.1.2), with 8bb130068 merged into main b7cedd900:

  • agc_driver_graphics, including the new NextStorageBudget and StorageBudgetCap cases, and the other 7 tests built from Graphics.cpp, pass.
  • Without the PR's ShaderResources.cpp/.hpp, the test file doesn't link (undefined symbol: AgcDriver::Graphics::NextStorageBudget), since both functions are new in this PR.

This is the submitted head, not AlxcBTW's 8 GB revision. No title run here.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6199908654 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6194#issuecomment-6199908654). Originally posted by [coltken95](https://github.com/coltken95) on 2026-10-15T18:56:25Z. --- Tested on Linux x86-64 (Release build, lavapipe / llvmpipe LLVM 20.1.2), with 8bb130068 merged into main b7cedd900: - `agc_driver_graphics`, including the new `NextStorageBudget` and `StorageBudgetCap` cases, and the other 7 tests built from `Graphics.cpp`, pass. - Without the PR's `ShaderResources.cpp/.hpp`, the test file doesn't link (`undefined symbol: AgcDriver::Graphics::NextStorageBudget`), since both functions are new in this PR. This is the submitted head, not AlxcBTW's 8 GB revision. No title run here. AI-assisted: yes (Claude Code)
ee6aba54 commented 2026-10-15 19:06:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ee6aba54 on 2026-10-15T19:06:27Z.


@AlxcBTW I ran your revision in the case from my earlier review, where another process holds 3 GiB of device memory.

Setup: Linux, Ubuntu 24.04, RTX 5080 16 GiB, NVIDIA 595.99.02, PPSA15304. Base: main at 92e50418f plus my open #6174, #6185 and #6186 and two local changes. On top of that: this PR at 8bb130068 plus the four commits of lab/md2-evict-cap3 (b8463e6e5, aaa99479a, 77ade4ef5, 56c26e54e), no conflicts. A CUDA allocation held 3072 MiB, and the desktop used 6.6 GiB of device memory before the start. The reported budget was 8.8 to 9.1 GiB. The fixed-camera window was 300 s after loading the save, with a warm shader cache. One run.

presents / 10 s cache-eviction write-backs / 10 s heap reached its budget crashes
base, no 3 GiB holder, budget 48 MiB short of the working set 7 167 (2.1 GB) no 0
this PR at its earlier head, 3 GiB holder (my earlier review) 24 in the one complete run none 3 of 4 runs 2
this PR + revision, 3 GiB holder 24 (21 to 24) 4 no 0

With the revision the budget grew 2291 -> 2577 -> 2899 -> 3262 -> 3669 -> 4128 -> 4644 MiB. After that the shrink rule took over, and the budget moved between 3359 and 4000 MiB for the rest of the run, 15 changes in total. The highest heap usage was 7889 of 8945 MiB. There was no out-of-memory recovery, no device buffer was placed in host memory, and the image was correct.

The base row shows that this scene sits on a cliff. The same build ran at 22 presents per 10 s with a 3228 MiB storage budget and at 7 with 3180 MiB, after the desktop took 370 MiB more device memory. So the growth matters here even without another process.

Not checked: more than one run, other scenes, and the variant that keeps the 2 GiB reserve.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6200114263 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6194#issuecomment-6200114263). Originally posted by [ee6aba54](https://github.com/ee6aba54) on 2026-10-15T19:06:27Z. --- @AlxcBTW I ran your revision in the case from my earlier review, where another process holds 3 GiB of device memory. Setup: Linux, Ubuntu 24.04, RTX 5080 16 GiB, NVIDIA 595.99.02, PPSA15304. Base: main at 92e50418f plus my open #6174, #6185 and #6186 and two local changes. On top of that: this PR at 8bb130068 plus the four commits of `lab/md2-evict-cap3` (b8463e6e5, aaa99479a, 77ade4ef5, 56c26e54e), no conflicts. A CUDA allocation held 3072 MiB, and the desktop used 6.6 GiB of device memory before the start. The reported budget was 8.8 to 9.1 GiB. The fixed-camera window was 300 s after loading the save, with a warm shader cache. One run. | | presents / 10 s | cache-eviction write-backs / 10 s | heap reached its budget | crashes | |---|---|---|---|---| | base, no 3 GiB holder, budget 48 MiB short of the working set | 7 | 167 (2.1 GB) | no | 0 | | this PR at its earlier head, 3 GiB holder (my earlier review) | 24 in the one complete run | none | 3 of 4 runs | 2 | | this PR + revision, 3 GiB holder | 24 (21 to 24) | 4 | no | 0 | With the revision the budget grew 2291 -> 2577 -> 2899 -> 3262 -> 3669 -> 4128 -> 4644 MiB. After that the shrink rule took over, and the budget moved between 3359 and 4000 MiB for the rest of the run, 15 changes in total. The highest heap usage was 7889 of 8945 MiB. There was no out-of-memory recovery, no device buffer was placed in host memory, and the image was correct. The base row shows that this scene sits on a cliff. The same build ran at 22 presents per 10 s with a 3228 MiB storage budget and at 7 with 3180 MiB, after the desktop took 370 MiB more device memory. So the growth matters here even without another process. Not checked: more than one run, other scenes, and the variant that keeps the 2 GiB reserve.
ee6aba54 commented 2026-10-15 21:42:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ee6aba54 on 2026-10-15T21:42:02Z.


Correction to my previous comment: the base row (7 presents per 10 s) does not show a budget cliff. In a later run the same scene ran at 8 presents per 10 s with a storage budget of 5.9 to 6.8 GB, far above its working set. The slow runs have a different cause that I am still looking into: about 1 s of GPU idle time per frame, with the compute queue waiting in WAIT_REG_MEM. The evictions in that run came with the slow state and did not cause it.

The measurement of the revision itself stands: 24 presents per 10 s with the 3 GiB holder, with no heap at its budget, no out-of-memory recovery and no crash. It does not show how much of the gain comes from the budget growth.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6202879478 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6194#issuecomment-6202879478). Originally posted by [ee6aba54](https://github.com/ee6aba54) on 2026-10-15T21:42:02Z. --- Correction to my previous comment: the base row (7 presents per 10 s) does not show a budget cliff. In a later run the same scene ran at 8 presents per 10 s with a storage budget of 5.9 to 6.8 GB, far above its working set. The slow runs have a different cause that I am still looking into: about 1 s of GPU idle time per frame, with the compute queue waiting in `WAIT_REG_MEM`. The evictions in that run came with the slow state and did not cause it. The measurement of the revision itself stands: 24 presents per 10 s with the 3 GiB holder, with no heap at its budget, no out-of-memory recovery and no crash. It does not show how much of the gain comes from the budget growth.
parl0v commented 2026-10-16 15:40:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-16T15:40:18Z.


Data from a third 8 GB card on where the budget can go: RTX 4060 8 GB (NVIDIA 617.42), 16 GB RAM, Windows 10, Minecraft Dungeons II (PPSA16064 01.100.100), first world load and a 120 s walk, main 5d9dcc42d + #6308 + #5372 + #6490 + #4472 + #6631 + #6632 (not this PR). Heap 0 reports a 7189 MiB budget, so main's automatic storage image budget is 1797 MiB. Rows interleaved:

storage budget placed in host memory walk FPS
3072 MiB (APS5_TEXTURE_CACHE_MIB=3072) 868 / 878 MiB 4.46 / 4.83
automatic, 1797 MiB none 6.48 / 6.07

So on this card a storage budget ~1.3 GB above main's is enough to push the heap past its budget: storage textures are then created in host memory and sampled over PCIe (GPU busy ~165 ms per frame instead of ~90 in earlier rows). On a 16 GB machine it also fills heap 1 (2 of 3 first loads aborted with a host-type VK_ERROR_OUT_OF_DEVICE_MEMORY, details on #6553). That fits what AlxcBTW found on the 5070 Laptop (a growing budget re-creating a 256 MiB 3D storage texture in host memory, then a TDR, which #4472 prevented). Whatever the growth rule ends up being, a cap that stays under the heap's remaining budget, not only under the total, would keep it out of that state on 8 GB cards.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6219055257 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6194#issuecomment-6219055257). Originally posted by [parl0v](https://github.com/parl0v) on 2026-10-16T15:40:18Z. --- Data from a third 8 GB card on where the budget can go: RTX 4060 8 GB (NVIDIA 617.42), 16 GB RAM, Windows 10, Minecraft Dungeons II (PPSA16064 01.100.100), first world load and a 120 s walk, `main` 5d9dcc42d + #6308 + #5372 + #6490 + #4472 + #6631 + #6632 (not this PR). Heap 0 reports a 7189 MiB budget, so `main`'s automatic storage image budget is 1797 MiB. Rows interleaved: | storage budget | placed in host memory | walk FPS | |---|---|---| | 3072 MiB (`APS5_TEXTURE_CACHE_MIB=3072`) | 868 / 878 MiB | 4.46 / 4.83 | | automatic, 1797 MiB | none | 6.48 / 6.07 | So on this card a storage budget ~1.3 GB above `main`'s is enough to push the heap past its budget: storage textures are then created in host memory and sampled over PCIe (GPU busy ~165 ms per frame instead of ~90 in earlier rows). On a 16 GB machine it also fills heap 1 (2 of 3 first loads aborted with a host-type `VK_ERROR_OUT_OF_DEVICE_MEMORY`, details on #6553). That fits what AlxcBTW found on the 5070 Laptop (a growing budget re-creating a 256 MiB 3D storage texture in host memory, then a TDR, which #4472 prevented). Whatever the growth rule ends up being, a cap that stays under the heap's remaining budget, not only under the total, would keep it out of that state on 8 GB cards. AI-assisted: yes (Claude Code)
parl0v commented 2026-10-18 03:07:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-18T03:07:39Z.


Data from an 8 GB card, where this PR matters most but doesn't trigger yet. RTX 4060 8 GB (NVIDIA 617.42), Windows 10, Minecraft Dungeons II (PPSA16064 01.100.100) title screen, 150 s rows, arms alternating, main b39d90bf1. I rebased this PR locally onto it; the only conflict was main's 4-argument StorageTextureBudget, which I kept as the floor.

storage cache FPS GPU busy first uploads / 10 s cache-eviction write-backs / 10 s
main, automatic (1797 MiB) 3.00 / 2.98 195 / 197 ms 5,257 (51 GB) 1,649 (26 GB)
APS5_TEXTURE_CACHE_MIB=2560 6.68 / 7.33 97 / 95 ms 914 (7.3 GB) 88 (0.8 GB)
APS5_TEXTURE_CACHE_MIB=3072 7.12 / 6.82 96 / 97 ms — 0
this PR, rebased 3.20 184 ms 5,399 1,660

The working set needs about 2.5 GB, and the heap has room: it reports 4.0–4.4 GB used of a 7189 MiB budget. With this PR the budget never moves (no [textures] storage cache budget line in the run), although the cache evicts ~165 entries a second. The cap stops it: storageBudgetCap holds back the sampled cache's remaining headroom, and on main SampledTextureBudget never goes below 2048 MiB. With 36 MiB of sampled textures, about 2 GB stays reserved for textures the title doesn't have, so the cap lands at or below the 1797 MiB floor. The same 2 GiB minimum is in main's StorageTextureBudget (std::max(2048 MiB, sampledBytes) in reserved). Holding back what the sampled cache actually uses, plus a margin, instead of its 2 GiB minimum would let this grow to ~2.5 GB here, and that's worth 2.3x on this card.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6245029920 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6194#issuecomment-6245029920). Originally posted by [parl0v](https://github.com/parl0v) on 2026-10-18T03:07:39Z. --- Data from an 8 GB card, where this PR matters most but doesn't trigger yet. RTX 4060 8 GB (NVIDIA 617.42), Windows 10, Minecraft Dungeons II (PPSA16064 01.100.100) title screen, 150 s rows, arms alternating, `main` b39d90bf1. I rebased this PR locally onto it; the only conflict was `main`'s 4-argument `StorageTextureBudget`, which I kept as the floor. | storage cache | FPS | GPU busy | first uploads / 10 s | cache-eviction write-backs / 10 s | |---|---|---|---|---| | `main`, automatic (1797 MiB) | 3.00 / 2.98 | 195 / 197 ms | 5,257 (51 GB) | 1,649 (26 GB) | | `APS5_TEXTURE_CACHE_MIB=2560` | **6.68 / 7.33** | 97 / 95 ms | 914 (7.3 GB) | 88 (0.8 GB) | | `APS5_TEXTURE_CACHE_MIB=3072` | **7.12 / 6.82** | 96 / 97 ms | — | 0 | | this PR, rebased | 3.20 | 184 ms | 5,399 | 1,660 | The working set needs about 2.5 GB, and the heap has room: it reports 4.0–4.4 GB used of a 7189 MiB budget. With this PR the budget never moves (no `[textures] storage cache budget` line in the run), although the cache evicts ~165 entries a second. The cap stops it: `storageBudgetCap` holds back the sampled cache's remaining headroom, and on `main` `SampledTextureBudget` never goes below 2048 MiB. With 36 MiB of sampled textures, about 2 GB stays reserved for textures the title doesn't have, so the cap lands at or below the 1797 MiB floor. The same 2 GiB minimum is in `main`'s `StorageTextureBudget` (`std::max(2048 MiB, sampledBytes)` in `reserved`). Holding back what the sampled cache actually uses, plus a margin, instead of its 2 GiB minimum would let this grow to ~2.5 GB here, and that's worth 2.3x on this card. AI-assisted: yes (Claude Code)
adriadam10 commented 2026-10-18 17:08:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-18T17:08:23Z.

Review: CHANGES_REQUESTED


Thanks for the measurements. Findings on 8bb130068:

  • The branch conflicts with main: StorageTextureBudget now takes (memory, reported, sampledBytes, storageBytes) and already subtracts the usage outside both caches plus a 2 GiB-or-sampled reserve and budget / 8. Please rebase and reconcile: the floor passed to NextStorageBudget/StorageBudgetCap should be that function's result, and StorageBudgetCap's outside + reserve term should reuse its logic instead of repeating it (ShaderResources.cpp:1027, :1030-1033).
  • On the 8 GB cards this targets it never grows. parl0v rebased it onto main on an RTX 4060 8 GB (Minecraft Dungeons II): no [textures] storage cache budget line in 150 s while evicting ~165 entries/s, 3.2 FPS vs 6.7-7.3 with APS5_TEXTURE_CACHE_MIB=2560. Cause per that comment: sampledRemaining is computed from SampledTextureBudget, which never goes below 2048 MiB, so ~2 GB stays held back for a sampled cache holding 36 MiB and the cap lands at or below the floor. Hold back what the sampled cache actually uses plus a margin rather than its minimum budget, and add a test row for a small sampled cache on a ~7 GiB reported budget.
  • No code comments: ShaderResources.cpp:1020-1026 and :1049-1052 add // comments. The rationale already lives in the debt entry; drop the comments.
  • Please keep the debt entry in sync once the cap changes (it describes the current cap wording), and re-run agc_driver_graphics after the rebase.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5563996263 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6194#pullrequestreview-5563996263). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-18T17:08:23Z. **Review:** CHANGES_REQUESTED --- Thanks for the measurements. Findings on 8bb130068: - The branch conflicts with `main`: `StorageTextureBudget` now takes `(memory, reported, sampledBytes, storageBytes)` and already subtracts the usage outside both caches plus a 2 GiB-or-sampled reserve and `budget / 8`. Please rebase and reconcile: the floor passed to `NextStorageBudget`/`StorageBudgetCap` should be that function's result, and `StorageBudgetCap`'s `outside + reserve` term should reuse its logic instead of repeating it (`ShaderResources.cpp:1027`, `:1030-1033`). - On the 8 GB cards this targets it never grows. parl0v rebased it onto `main` on an RTX 4060 8 GB (Minecraft Dungeons II): no `[textures] storage cache budget` line in 150 s while evicting ~165 entries/s, 3.2 FPS vs 6.7-7.3 with `APS5_TEXTURE_CACHE_MIB=2560`. Cause per that comment: `sampledRemaining` is computed from `SampledTextureBudget`, which never goes below 2048 MiB, so ~2 GB stays held back for a sampled cache holding 36 MiB and the cap lands at or below the floor. Hold back what the sampled cache actually uses plus a margin rather than its minimum budget, and add a test row for a small sampled cache on a ~7 GiB reported budget. - No code comments: `ShaderResources.cpp:1020-1026` and `:1049-1052` add `//` comments. The rationale already lives in the debt entry; drop the comments. - Please keep the debt entry in sync once the cap changes (it describes the current cap wording), and re-run `agc_driver_graphics` after the rebase.
Rajkamalcode commented 2026-10-20 14:31:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Rajkamalcode on 2026-10-20T14:31:09Z.


SWAG (PPSA22102 01.000.000), 8 GB RTX 3070: the revision reaches the working set, then the pressure shrink collapses it

Build. Ported 8bb1300680 plus the 8 GB revision from https://github.com/boykopovar/AnyPS5/pull/6194#issuecomment-6198634040 onto old base b6dd2f9e3 (current main cannot be run on this host while the game's libkernel.prx/libc.prx do not match it). libs and agc_driver_graphics_tests built; ctest -R '^agc_driver_graphics$' passed 1/1 in 8.28 s. PR prx logs/game-libSceAgcDriver-pr6194rev.prx, SHA-256 FB534996...C88FD9.

Host. Ryzen 5 5600X, 16 GB RAM, RTX 3070 8 GB (heap 0 8018 MiB; driver 32.0.16.1088), Windows 11 22635. Guest 3840x2160 presented at 1060x596. Stock gameusersettings.ini 0156186E (VSync on); warm caches.

Run. 360 s, same pad schedule (Cross at 15/30/45/60 s), APS5_PROFILE_DRAW=1, no trace/worker sampler. The save folder has no checkpoint, so every launch starts the same tutorial; game speed changes how far the pads reach, so scene progression is not matched. Four interleaved runs (baseline, PR, baseline, PR), no fatal or OOM.

Measured

run build storage images create ms images phase ms builds final presents/10 s
28 baseline 5AB0413B 47,750 (646,320 MiB) 68,870 147,887 111,649 7
33 baseline 5AB0413B 48,100 (661,715 MiB) 54,905 122,725 119,867 9
32 PR 36,650 (371,772 MiB) 21,740 68,673 187,276 13
34 PR 52,150 (590,231 MiB) 41,278 111,866 157,374 10
  • run32 budget: 1812 -> 2039 -> 2293 -> 2580 -> 2903 -> 3266 MiB, then oscillated roughly 1.7-2.9 GB.
  • run34 budget: 1812 -> ... -> 3266 -> 2857 -> 2827 -> 2473 -> 2164 -> 1893 -> ... -> 1058 -> ... -> 564 MiB (112 change lines). [gpu] shows the sampled budget dropping from 4070 to its 2048 MiB floor; the dynamic storage floor itself falls below the original 1812 MiB.
  • Creation CPU per image is lower in both PR runs (0.59 and 0.79 ms vs 1.44 and 1.14 ms), so the growth path does help per recreate; it is the collapse that brings the churn back.

Fixed-budget diagnostic (not a PR A/B). With the baseline prx and the supported APS5_TEXTURE_CACHE_MIB=2560 (which forces both caches to 2560 MiB; the sampled cache stayed at ~504 MiB in 600 entries, so this is a storage-budget effect), two 360 s runs:

run storage images create ms images phase ms builds final presents/10 s
35 3,750 (27,755 MiB) 2,191 12,157 320,972 25-28
36 3,400 (25,903 MiB) 2,106 10,519 256,945 23-26

No fatal/OOM. The fixed runs progressed much farther than baseline (320k/257k builds vs 120k), so the later scene is heavier; this is a diagnostic for the working-set size, not a PR validation.

AI-assisted analysis (separate from the measured data)

  1. The growth rule finds the working set on this title: 3266 MiB is close to the 2560 MiB fixed point that removes the churn. But NextStorageBudget shrinks immediately when usage + 1 GiB > reportedBudget, while growth needs 16 evictions. That asymmetry, plus the dynamic floor, creates a limit cycle: the cache grows to 3266, pressure shrinks it, evictions trigger growth, pressure shrinks it again. run32 stayed in the upper half of the cycle and run34 fell to 564 MiB; that explains the large run-to-run spread.
  2. The fixed 2560 run indicates this title's storage working set is about 2.5 GB and that the 8 GB heap can hold it without host spill on this host. It also matches parl0v's Minecraft Dungeons II data (2560-3072 MiB fixed is much faster, while the original PR never grows).
  3. Suggested next step: add hysteresis (do not shrink a cache that has evicted since the last read; shrink only under a harder pressure threshold, or require pressure on several consecutive reads), and keep the lower bound at least the budget the cache had before growth. A step-down to a fallen cap is fine, but it should not run at the same time as the pressure shrink.
  4. Caveat: fixed 2560 MiB is not a universal value; parl0v saw host-memory spill at 3072 MiB on another 8 GB card. The adaptive rule still needs a safe upper bound.

I can attach the five run logs and the port diff if useful.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6293287541 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6194#issuecomment-6293287541). Originally posted by [Rajkamalcode](https://github.com/Rajkamalcode) on 2026-10-20T14:31:09Z. --- ## SWAG (PPSA22102 01.000.000), 8 GB RTX 3070: the revision reaches the working set, then the pressure shrink collapses it **Build.** Ported `8bb1300680` plus the 8 GB revision from https://github.com/boykopovar/AnyPS5/pull/6194#issuecomment-6198634040 onto old base `b6dd2f9e3` (current `main` cannot be run on this host while the game's `libkernel.prx`/`libc.prx` do not match it). `libs` and `agc_driver_graphics_tests` built; `ctest -R '^agc_driver_graphics$'` passed 1/1 in 8.28 s. PR prx `logs/game-libSceAgcDriver-pr6194rev.prx`, SHA-256 `FB534996...C88FD9`. **Host.** Ryzen 5 5600X, 16 GB RAM, RTX 3070 8 GB (heap 0 8018 MiB; driver 32.0.16.1088), Windows 11 22635. Guest 3840x2160 presented at 1060x596. Stock `gameusersettings.ini` `0156186E` (VSync on); warm caches. **Run.** 360 s, same pad schedule (Cross at 15/30/45/60 s), `APS5_PROFILE_DRAW=1`, no trace/worker sampler. The save folder has no checkpoint, so every launch starts the same tutorial; game speed changes how far the pads reach, so scene progression is not matched. Four interleaved runs (baseline, PR, baseline, PR), no fatal or OOM. ### Measured | run | build | storage images | create ms | images phase ms | builds | final presents/10 s | |---|---|---|---:|---:|---:|---:| | 28 | baseline `5AB0413B` | 47,750 (646,320 MiB) | 68,870 | 147,887 | 111,649 | 7 | | 33 | baseline `5AB0413B` | 48,100 (661,715 MiB) | 54,905 | 122,725 | 119,867 | 9 | | 32 | PR | 36,650 (371,772 MiB) | 21,740 | 68,673 | 187,276 | 13 | | 34 | PR | 52,150 (590,231 MiB) | 41,278 | 111,866 | 157,374 | 10 | - run32 budget: `1812 -> 2039 -> 2293 -> 2580 -> 2903 -> 3266 MiB`, then oscillated roughly 1.7-2.9 GB. - run34 budget: `1812 -> ... -> 3266 -> 2857 -> 2827 -> 2473 -> 2164 -> 1893 -> ... -> 1058 -> ... -> 564 MiB` (112 change lines). `[gpu]` shows the sampled budget dropping from 4070 to its 2048 MiB floor; the dynamic storage floor itself falls below the original 1812 MiB. - Creation CPU per image is lower in both PR runs (0.59 and 0.79 ms vs 1.44 and 1.14 ms), so the growth path does help per recreate; it is the collapse that brings the churn back. **Fixed-budget diagnostic (not a PR A/B).** With the baseline prx and the supported `APS5_TEXTURE_CACHE_MIB=2560` (which forces both caches to 2560 MiB; the sampled cache stayed at ~504 MiB in 600 entries, so this is a storage-budget effect), two 360 s runs: | run | storage images | create ms | images phase ms | builds | final presents/10 s | |---|---|---:|---:|---:|---:| | 35 | 3,750 (27,755 MiB) | 2,191 | 12,157 | 320,972 | 25-28 | | 36 | 3,400 (25,903 MiB) | 2,106 | 10,519 | 256,945 | 23-26 | No fatal/OOM. The fixed runs progressed much farther than baseline (320k/257k builds vs 120k), so the later scene is heavier; this is a diagnostic for the working-set size, not a PR validation. ### AI-assisted analysis (separate from the measured data) 1. The growth rule finds the working set on this title: 3266 MiB is close to the 2560 MiB fixed point that removes the churn. But `NextStorageBudget` shrinks immediately when `usage + 1 GiB > reportedBudget`, while growth needs 16 evictions. That asymmetry, plus the dynamic floor, creates a limit cycle: the cache grows to 3266, pressure shrinks it, evictions trigger growth, pressure shrinks it again. run32 stayed in the upper half of the cycle and run34 fell to 564 MiB; that explains the large run-to-run spread. 2. The fixed 2560 run indicates this title's storage working set is about 2.5 GB and that the 8 GB heap can hold it without host spill on this host. It also matches parl0v's Minecraft Dungeons II data (2560-3072 MiB fixed is much faster, while the original PR never grows). 3. Suggested next step: add hysteresis (do not shrink a cache that has evicted since the last read; shrink only under a harder pressure threshold, or require pressure on several consecutive reads), and keep the lower bound at least the budget the cache had before growth. A step-down to a fallen cap is fine, but it should not run at the same time as the pressure shrink. 4. Caveat: fixed 2560 MiB is not a universal value; parl0v saw host-memory spill at 3072 MiB on another 8 GB card. The adaptive rule still needs a safe upper bound. I can attach the five run logs and the port diff if useful. AI-assisted: yes.
JJenkx commented 2026-10-21 12:48:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-21T12:48:59Z.


Linux / AMD data point for the same title, where the automatic storage budget is lower than on the 8 GB NVIDIA cards above.

Setup: Minecraft Dungeons II (PPSA16064) 01.000.000 (not 01.100.100), on Linux 7.2.9 with a Radeon RX 6650 XT 8 GB (RADV Mesa 26.2.4). Heap 1 reports a 5172 MiB budget, so main's automatic storage image budget is 1291 MiB. The scene is the first Accessibility menu, with seeded caches and saves. On Linux this scene is dominated by refused host imports on main (about 2.6 s per frame), so these runs are on #8091 71d29197ff (its base 7ab4b2e561 + its one commit). Trace 90:30, APS5_TRACE_EVENTS=4194304, dropped: no, plus APS5_PROFILE_GPU. Single diagnostic runs, not this PR.

storage cache presents in 30 s frame p50 GPU busy per present storage-upload / present storage-writeback / present shadow-publish / present
automatic, 1291 MiB 182-185 (two runs) 162.0 / 164.9 ms 138 ms 983 MiB 1574 MiB 649 MiB
APS5_TEXTURE_CACHE_MIB=3500 453 65.5 ms 54 ms 74 MiB 213 MiB 66 MiB

Draws themselves take about 14-16 ms of GPU time per present in both rows; dcc-clear stays at about 2.5 ms (863 MiB). Logging every storage upload and write-back with the automatic budget showed whole 4096x4096 (64 MiB) and 4352x4352 images in a strict write-back then re-create and upload cycle on every frame. That is the cache-eviction churn this PR targets.

Caveats:

  • APS5_TEXTURE_CACHE_MIB also forces the sampled cache's budget.
  • I did not record heap usage in the forced row. GPU busy fell from 138 to 54 ms, so I saw no sign of storage images landing in host memory as @parl0v saw at 3072 MiB on the RTX 4060. This card's working set may simply fit.

I can run this PR's latest revision, or @AlxcBTW's proposed one, on this RADV setup (composed with #8091, disclosed) if a head is named.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6316368328 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6194#issuecomment-6316368328). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-21T12:48:59Z. --- Linux / AMD data point for the same title, where the automatic storage budget is lower than on the 8 GB NVIDIA cards above. **Setup**: Minecraft Dungeons II (PPSA16064) **01.000.000** (not 01.100.100), on Linux 7.2.9 with a Radeon RX 6650 XT 8 GB (RADV Mesa 26.2.4). Heap 1 reports a 5172 MiB budget, so `main`'s automatic storage image budget is **1291 MiB**. The scene is the first Accessibility menu, with seeded caches and saves. On Linux this scene is dominated by refused host imports on `main` (about 2.6 s per frame), so these runs are on #8091 `71d29197ff` (its base `7ab4b2e561` + its one commit). Trace `90:30`, `APS5_TRACE_EVENTS=4194304`, `dropped: no`, plus `APS5_PROFILE_GPU`. Single diagnostic runs, not this PR. | storage cache | presents in 30 s | frame p50 | GPU busy per present | storage-upload / present | storage-writeback / present | shadow-publish / present | |---|---|---|---|---|---|---| | automatic, 1291 MiB | 182-185 (two runs) | 162.0 / 164.9 ms | 138 ms | 983 MiB | 1574 MiB | 649 MiB | | `APS5_TEXTURE_CACHE_MIB=3500` | 453 | 65.5 ms | 54 ms | 74 MiB | 213 MiB | 66 MiB | Draws themselves take about 14-16 ms of GPU time per present in both rows; dcc-clear stays at about 2.5 ms (863 MiB). Logging every storage upload and write-back with the automatic budget showed whole 4096x4096 (64 MiB) and 4352x4352 images in a strict write-back then re-create and upload cycle on every frame. That is the cache-eviction churn this PR targets. Caveats: - `APS5_TEXTURE_CACHE_MIB` also forces the sampled cache's budget. - I did not record heap usage in the forced row. GPU busy fell from 138 to 54 ms, so I saw no sign of storage images landing in host memory as @parl0v saw at 3072 MiB on the RTX 4060. This card's working set may simply fit. I can run this PR's latest revision, or @AlxcBTW's proposed one, on this RADV setup (composed with #8091, disclosed) if a head is named.
Queuse commented 2026-10-21 23:36:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Queuse on 2026-10-21T23:36:31Z.


Rebased branch and boundary tests, ea6d165422, main a6dcea9279; authorship preserved.

Adds immediate clamping above a fallen cap: current 2048/floor 512/cap 1200 MiB now yields 1200, instead of 2048 without pressure or 1792 under pressure. Exact-body native C++ controls: 4 failures before, 17/17 after. Baseline/candidate pass the same 10 graphics/cache CTests (Windows 11, RTX 3050 Laptop/617.42, GCC 15.2.0-r7), no skips, missing validation layer or VUID errors.

Small-sampled-cache growth and pressure oscillation remain unresolved. No new thresholds, title or speed claim. AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6328969175 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6194#issuecomment-6328969175). Originally posted by [Queuse](https://github.com/Queuse) on 2026-10-21T23:36:31Z. --- [Rebased branch and boundary tests](https://github.com/Queuse/AnyPS5/tree/codex/validate-pr-6194), `ea6d165422`, main `a6dcea9279`; authorship preserved. Adds immediate clamping above a fallen cap: current 2048/floor 512/cap 1200 MiB now yields 1200, instead of 2048 without pressure or 1792 under pressure. Exact-body native C++ controls: 4 failures before, 17/17 after. Baseline/candidate pass the same 10 graphics/cache CTests (Windows 11, RTX 3050 Laptop/617.42, GCC 15.2.0-r7), no skips, missing validation layer or VUID errors. Small-sampled-cache growth and pressure oscillation remain unresolved. No new thresholds, title or speed claim. AI-assisted: yes.
JJenkx commented 2026-10-22 09:08:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T09:08:31Z.


@Thunderhawkk data from a second title, vendor and OS, in case it is useful for this PR. In short: the storage image cache thrashes here, a larger storage budget measurably helps, and this PR's reserve condition would not let the budget grow on this card.

Setup

  • Echoes of the End (PPSA25636), RX 6650 XT (8 GiB), RADV Mesa 26.2.4, Linux 7.2.9.
  • Integration tree based on main (17f5335562 era) plus the PRs the title needs.
  • main's budget rule, not this PR's.

The thrash (APS5_PROFILE_DRAW, per 10 s, late in the run)

  • First uploads of storage images: about 3,200-4,100 (37-56 GiB). Write-backs for cache eviction: about 900-1,300 (16-26 GiB).
  • Storage uploads take about 2.5 s of GPU time per 10 s, against about 0.14 s for the title's draws (APS5_PROFILE_GPU).
  • The budget line: sampled texture cache budget 2048 MiB: device-local heap 1 has a VK_EXT_memory_budget budget of 5766 MiB and uses 5101 MiB ... storage image cache budget 512 MiB (was 717 MiB). The storage cache sits at its 512 MiB floor while the sampled cache holds about 1.9 GiB with 0 evictions.

Matched comparison

  • Both arms: same seed of shader caches and save state, APS5_TRACE_FRAMES=560:100, the same build. The only difference is a private override that sets the storage budget alone to 2048 MiB.
  • Two pairs:
Pair Default mean frame 2048 MiB mean frame Change
1 814.8 ms 751.9 ms -7.7 %
2 799.0 ms 717.8 ms -10.2 %
  • In pair 2, p90 falls 19.4 % and p99 22.9 %. GPU busy per present falls 4-7 %.
  • 0 amdgpu kernel events in all four runs, even though the 2048 MiB arm runs past the reported heap budget.

Relevance to this PR: the growth step requires the step plus a reserve (2 GiB, or an eighth of the reported budget) to stay within the reported budget. Here the headroom is about 665 MiB, so the budget would never grow, although growing it is what helps. Perhaps the reserve should be smaller when the sampled cache is not evicting, or a storage cache under heavy eviction should be allowed some overcommit. I can rerun this pair on a rebased version of this PR if that helps.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6337052633 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6194#issuecomment-6337052633). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-22T09:08:31Z. --- @Thunderhawkk data from a second title, vendor and OS, in case it is useful for this PR. In short: the storage image cache thrashes here, a larger storage budget measurably helps, and this PR's reserve condition would not let the budget grow on this card. **Setup** - Echoes of the End (PPSA25636), RX 6650 XT (8 GiB), RADV Mesa 26.2.4, Linux 7.2.9. - Integration tree based on `main` (`17f5335562` era) plus the PRs the title needs. - `main`'s budget rule, not this PR's. **The thrash** (`APS5_PROFILE_DRAW`, per 10 s, late in the run) - First uploads of storage images: about 3,200-4,100 (37-56 GiB). Write-backs for cache eviction: about 900-1,300 (16-26 GiB). - Storage uploads take about 2.5 s of GPU time per 10 s, against about 0.14 s for the title's draws (`APS5_PROFILE_GPU`). - The budget line: `sampled texture cache budget 2048 MiB: device-local heap 1 has a VK_EXT_memory_budget budget of 5766 MiB and uses 5101 MiB ... storage image cache budget 512 MiB (was 717 MiB)`. The storage cache sits at its 512 MiB floor while the sampled cache holds about 1.9 GiB with 0 evictions. **Matched comparison** - Both arms: same seed of shader caches and save state, `APS5_TRACE_FRAMES=560:100`, the same build. The only difference is a private override that sets the storage budget alone to 2048 MiB. - Two pairs: | Pair | Default mean frame | 2048 MiB mean frame | Change | |---|---:|---:|---:| | 1 | 814.8 ms | 751.9 ms | -7.7 % | | 2 | 799.0 ms | 717.8 ms | -10.2 % | - In pair 2, p90 falls 19.4 % and p99 22.9 %. GPU busy per present falls 4-7 %. - 0 amdgpu kernel events in all four runs, even though the 2048 MiB arm runs past the reported heap budget. **Relevance to this PR:** the growth step requires the step plus a reserve (2 GiB, or an eighth of the reported budget) to stay within the reported budget. Here the headroom is about 665 MiB, so the budget would never grow, although growing it is what helps. Perhaps the reserve should be smaller when the sampled cache is not evicting, or a storage cache under heavy eviction should be allowed some overcommit. I can rerun this pair on a rebased version of this PR if that helps.
JJenkx commented 2026-10-22 14:42:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T14:42:50Z.


A follow-up to my earlier comment, with a correction.

I cherry-picked the source commits of @Queuse's rebase of this PR (add7f9a8eb, c3c8b135ed, a5397d276d, 9c12b3ca99, 5bffb6b637) onto my current Echoes of the End (PPSA25636) integration tree. I then ran a matched pair: same seed, APS5_TRACE_FRAMES=560:100, APS5_PROFILE_DRAW=1, RX 6650 XT / RADV.

without this PR with it
storage image cache budget over the run 1424-1656 MiB 1272-1656 MiB
frame p50 / p90 / p99 (ms) 722.5 / 956.8 / 1492.2 689.9 / 1036.0 / 1832.0
GPU busy per present 374.8 ms 379.2 ms
  • 0 amdgpu kernel events in either run.
  • The growth rule does not change the budget on this build, and the frame-time differences are mixed and within run-to-run variance.

Correction: in my earlier comment the storage budget sat at its 512 MiB floor. That was on an older integration tree. With #9551 and #9652 on the tree, which remove large host-visible copies and repeated heap mirror rebuilds, the automatic budget now stays around 1.4-1.65 GiB on the same card. The earlier gain from forcing 2 GiB therefore mostly reflected starvation that those fixes have since reduced. So on Echoes today I can no longer show this PR (or a larger storage budget) helping. I'm reporting that so the earlier comment does not overstate the case.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6343541511 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6194#issuecomment-6343541511). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-22T14:42:50Z. --- A follow-up to my earlier comment, with a correction. I cherry-picked the source commits of @Queuse's rebase of this PR (`add7f9a8eb`, `c3c8b135ed`, `a5397d276d`, `9c12b3ca99`, `5bffb6b637`) onto my current Echoes of the End (PPSA25636) integration tree. I then ran a matched pair: same seed, `APS5_TRACE_FRAMES=560:100`, `APS5_PROFILE_DRAW=1`, RX 6650 XT / RADV. | | without this PR | with it | |---|---|---| | storage image cache budget over the run | 1424-1656 MiB | 1272-1656 MiB | | frame p50 / p90 / p99 (ms) | 722.5 / 956.8 / 1492.2 | 689.9 / 1036.0 / 1832.0 | | GPU busy per present | 374.8 ms | 379.2 ms | - 0 amdgpu kernel events in either run. - The growth rule does not change the budget on this build, and the frame-time differences are mixed and within run-to-run variance. **Correction:** in my earlier comment the storage budget sat at its 512 MiB floor. That was on an older integration tree. With #9551 and #9652 on the tree, which remove large host-visible copies and repeated heap mirror rebuilds, the automatic budget now stays around 1.4-1.65 GiB on the same card. The earlier gain from forcing 2 GiB therefore mostly reflected starvation that those fixes have since reduced. So on Echoes today I can no longer show this PR (or a larger storage budget) helping. I'm reporting that so the earlier comment does not overstate the case.
adriadam10 commented 2026-10-24 01:39:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-24T01:39:52Z.

Review: CHANGES_REQUESTED


Checked 8bb130068 again against main and the measurements in the thread. Still needs changes, and some of them are design decisions rather than mechanical fixes:

  • The branch conflicts with main: StorageTextureBudget now takes (memory, reported, sampledBytes, storageBytes) and already subtracts the usage outside both caches plus the reserve. The floor passed to NextStorageBudget/StorageBudgetCap should be that function's result, and StorageBudgetCap (ShaderResources.cpp:1027-1033) should reuse its logic instead of repeating outside + reserve.
  • On the 8 GB cards this targets the budget does not grow: sampledRemaining comes from SampledTextureBudget, which never goes below 2048 MiB, so ~2 GiB stays held back for a sampled cache that holds tens of MiB (RTX 4060 in this thread; RX 6650 XT, where the 2 GiB/eighth reserve also blocks the growth step). Hold back what the sampled cache actually uses plus a margin, and add a test row for a small sampled cache on a ~7 GiB reported budget.
  • Where it does grow (RTX 3070, SWAG), the pressure shrink then walks the budget down again: 1812 → 3266 MiB, then to 564 MiB in 112 changes. Growth and shrink need hysteresis or a shared target so they do not chase each other; the 10-minute Wolverine run shows the same 85/88 oscillation.
  • No code comments: ShaderResources.cpp:1020-1026 and :1049-1052. The rationale already lives in the debt entry.
  • Keep the debt entry in sync once the cap changes, and re-run agc_driver_graphics after the rebase. @Queuse's rebase adds clamping to a fallen cap with boundary tests that are worth taking.
  • #10044 attacks the same churn by raising the caps of the existing formula; please say how this PR differs or coordinate with it, as the two overlap in ShaderResources.cpp.

Feel free to push a revised head; a rebased branch with the points above is welcome.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5636216282 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6194#pullrequestreview-5636216282). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-24T01:39:52Z. **Review:** CHANGES_REQUESTED --- Checked 8bb130068 again against `main` and the measurements in the thread. Still needs changes, and some of them are design decisions rather than mechanical fixes: - The branch conflicts with `main`: `StorageTextureBudget` now takes `(memory, reported, sampledBytes, storageBytes)` and already subtracts the usage outside both caches plus the reserve. The floor passed to `NextStorageBudget`/`StorageBudgetCap` should be that function's result, and `StorageBudgetCap` (`ShaderResources.cpp:1027-1033`) should reuse its logic instead of repeating `outside + reserve`. - On the 8 GB cards this targets the budget does not grow: `sampledRemaining` comes from `SampledTextureBudget`, which never goes below 2048 MiB, so ~2 GiB stays held back for a sampled cache that holds tens of MiB (RTX 4060 in this thread; RX 6650 XT, where the 2 GiB/eighth reserve also blocks the growth step). Hold back what the sampled cache actually uses plus a margin, and add a test row for a small sampled cache on a ~7 GiB reported budget. - Where it does grow (RTX 3070, SWAG), the pressure shrink then walks the budget down again: 1812 → 3266 MiB, then to 564 MiB in 112 changes. Growth and shrink need hysteresis or a shared target so they do not chase each other; the 10-minute Wolverine run shows the same 85/88 oscillation. - No code comments: `ShaderResources.cpp:1020-1026` and `:1049-1052`. The rationale already lives in the debt entry. - Keep the debt entry in sync once the cap changes, and re-run `agc_driver_graphics` after the rebase. @Queuse's rebase adds clamping to a fallen cap with boundary tests that are worth taking. - #10044 attacks the same churn by raising the caps of the existing formula; please say how this PR differs or coordinate with it, as the two overlap in `ShaderResources.cpp`. Feel free to push a revised head; a rebased branch with the points above is welcome.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!6194
No description provided.