fix(agc): reclaim idle device buffers up to the storage cache's current cap #10551

Merged
JJenkx merged 1 commit from upstream-pr/10551 into main 2026-10-25 20:10:31 +00:00
JJenkx commented 2026-10-24 09:40:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-24T09:40:58Z.


What

#8672 reclaims idle device-tier buffers from the buffer pool when the storage image cache needs more room than its budget gives. The amount is capped at a ceiling: the most the cache may hold. Its debt entry describes this as "the cache's shortfall below its existing ceiling". In storageBudget the ceiling is computed as max(512 MiB, min(TextureCacheBudget, budget / 4)), which is a copy of the storage cache's cap before #10044.

#10044 raised that cap to min(heap / 2, budget / 2) in StorageTextureBudget, but the copy in storageBudget was not updated. On main the two now disagree. When the cache's shortfall lies between a quarter and half of the budget, idle pooled buffers are no longer reclaimed for it, although StorageTextureBudget would let the cache grow into the room they free. Example: an 8 GB GPU with a 6 GiB budget. The cap is 3 GiB, but reclaim stops at 1.5 GiB.

This PR moves the cap into one function, StorageTextureCeiling, used by both StorageTextureBudget and the reclaim ceiling. It returns max(512 MiB, min(heap / 2, budget / 2)), or TextureCacheBudget without VK_EXT_memory_budget. StorageTextureBudget returns the same values as before: min(max(512 MiB, cap), max(512 MiB, free)) equals max(512 MiB, min(cap, free)). The only behavior change is the reclaim ceiling.

Tested

  • storageTextureBudgetTests adds checks for the ceiling: a quarter of the heap without VK_EXT_memory_budget, half of a 6 GiB budget, half of the heap for a 40 GiB budget, and the 512 MiB floor. A sweep over budgets (1-24 GiB) and usage checks that the storage budget never exceeds the ceiling, and that an idle heap reaches it.

  • Focused Vulkan gate. Machine: Linux 7.2.9, RX 6650 XT, RADV (Mesa 26.2.4). Command: ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer ctest -V -j1 -R '^(agc_driver_graphics|agc_buffer_pool.*|agc_driver_sampled_cache_budget_.*)$'.

    arm head result validation layer inserted VUIDs
    main aeeaefad98 6/6 2 tests 0
    this change with the ceiling forced back to a quarter of the budget cc90fbcb7c + one-line edit 5/6: agc_driver_graphics fails with "a 10 GiB budget on the 16 GiB heap does not limit the storage image cache to half of the budget" 2 tests 0
    this change cc90fbcb7c 6/6 2 tests 0

    The head was then rebased on 5d3ab7791d without conflict. None of the four files it touches differ between aeeaefad98 and 5d3ab7791d.

  • Logs: https://github.com/JJenkx/AnyPS5/releases/tag/storage-reclaim-ceiling-evidence

  • This PR makes no performance claim. A title measurement that exercises the changed reclaim condition remains outstanding; the independent Windows report below did not reach it.

  • Related measurement, from a diagnostic and not this change. On the same GPU at its real reported budget (about 6 GiB), shrinking the pool's device and image tiers by override raised the storage cache budget in Echoes from 0.5-0.9 GiB to 1.6-2.2 GiB. That suggests idle pool retention competes with the storage cache there. The throughput effect was within run-to-run spread.

Independent Windows/NVIDIA coverage reported by @Rajkamalcode: exact head 0d6a6f96eeee90b4998deaadae50ef5e3cf01a53 merged onto main 5ed5427ba as 469b28f11, Ryzen 5 5600X / 16 GB RAM, RTX 3070 8 GB, driver 32.0.16.1088, Windows 11 22635. Their focused graphics executable passed, including the StorageTextureCeiling cases. Validation-layer use was not reported for that Windows run; the local layered Linux comparison above remains scoped separately.

Their two 360-second Squirrel with a Gun (PPSA22102, 01.000.000) runs used the same pad schedule/cache/settings and had no fatal/OOM, with 39–41 presents per 10 seconds after load in both arms. The sampled storage cache stayed below its budget and both runs reported zero device-pool evictions, so the changed reclaim branch was not exercised. Pool retention and images-phase differences from that single pair do not establish a benefit. This is attributed independent coverage, not a locally reproduced run or performance evidence.

Checklist

  • Based on current main; no other open PR implements the same functions. #6194 also changes the storage budget, but it grows the budget while evicting and does not touch the reclaim ceiling.
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • 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 (attach them to this PR)
  • New third-party code is a submodule built from source (not applicable)
  • Generic behaviour, not specific to one title
  • Depends on: none (follows #8672 and #10044, both merged)
  • Fixes: none
  • Unblocks: none claimed
  • GPUs tested: AMD Radeon RX 6650 XT, RADV Mesa 26.2.4, Linux 7.2.9
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4994313667 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10551). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-24T09:40:58Z. --- ### What #8672 reclaims idle device-tier buffers from the buffer pool when the storage image cache needs more room than its budget gives. The amount is capped at a ceiling: the most the cache may hold. Its debt entry describes this as "the cache's shortfall below its existing ceiling". In `storageBudget` the ceiling is computed as `max(512 MiB, min(TextureCacheBudget, budget / 4))`, which is a copy of the storage cache's cap before #10044. #10044 raised that cap to `min(heap / 2, budget / 2)` in `StorageTextureBudget`, but the copy in `storageBudget` was not updated. On main the two now disagree. When the cache's shortfall lies between a quarter and half of the budget, idle pooled buffers are no longer reclaimed for it, although `StorageTextureBudget` would let the cache grow into the room they free. Example: an 8 GB GPU with a 6 GiB budget. The cap is 3 GiB, but reclaim stops at 1.5 GiB. This PR moves the cap into one function, `StorageTextureCeiling`, used by both `StorageTextureBudget` and the reclaim ceiling. It returns `max(512 MiB, min(heap / 2, budget / 2))`, or `TextureCacheBudget` without `VK_EXT_memory_budget`. `StorageTextureBudget` returns the same values as before: `min(max(512 MiB, cap), max(512 MiB, free))` equals `max(512 MiB, min(cap, free))`. The only behavior change is the reclaim ceiling. ### Tested - `storageTextureBudgetTests` adds checks for the ceiling: a quarter of the heap without `VK_EXT_memory_budget`, half of a 6 GiB budget, half of the heap for a 40 GiB budget, and the 512 MiB floor. A sweep over budgets (1-24 GiB) and usage checks that the storage budget never exceeds the ceiling, and that an idle heap reaches it. - Focused Vulkan gate. Machine: Linux 7.2.9, RX 6650 XT, RADV (Mesa 26.2.4). Command: `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer ctest -V -j1 -R '^(agc_driver_graphics|agc_buffer_pool.*|agc_driver_sampled_cache_budget_.*)$'`. | arm | head | result | validation layer inserted | VUIDs | |---|---|---|---|---| | main | `aeeaefad98` | 6/6 | 2 tests | 0 | | this change with the ceiling forced back to a quarter of the budget | `cc90fbcb7c` + one-line edit | 5/6: `agc_driver_graphics` fails with "a 10 GiB budget on the 16 GiB heap does not limit the storage image cache to half of the budget" | 2 tests | 0 | | this change | `cc90fbcb7c` | 6/6 | 2 tests | 0 | The head was then rebased on `5d3ab7791d` without conflict. None of the four files it touches differ between `aeeaefad98` and `5d3ab7791d`. - Logs: https://github.com/JJenkx/AnyPS5/releases/tag/storage-reclaim-ceiling-evidence - This PR makes no performance claim. A title measurement that exercises the changed reclaim condition remains outstanding; the independent Windows report below did not reach it. - Related measurement, from a diagnostic and not this change. On the same GPU at its real reported budget (about 6 GiB), shrinking the pool's device and image tiers by override raised the storage cache budget in Echoes from 0.5-0.9 GiB to 1.6-2.2 GiB. That suggests idle pool retention competes with the storage cache there. The throughput effect was within run-to-run spread. Independent Windows/NVIDIA coverage reported by [@Rajkamalcode](https://github.com/boykopovar/AnyPS5/pull/10551#issuecomment-6385586208): exact head `0d6a6f96eeee90b4998deaadae50ef5e3cf01a53` merged onto main `5ed5427ba` as `469b28f11`, Ryzen 5 5600X / 16 GB RAM, RTX 3070 8 GB, driver 32.0.16.1088, Windows 11 22635. Their focused graphics executable passed, including the StorageTextureCeiling cases. Validation-layer use was not reported for that Windows run; the local layered Linux comparison above remains scoped separately. Their two 360-second Squirrel with a Gun (PPSA22102, 01.000.000) runs used the same pad schedule/cache/settings and had no fatal/OOM, with 39–41 presents per 10 seconds after load in both arms. The sampled storage cache stayed below its budget and both runs reported zero device-pool evictions, so the changed reclaim branch was not exercised. Pool retention and images-phase differences from that single pair do not establish a benefit. This is attributed independent coverage, not a locally reproduced run or performance evidence. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions. #6194 also changes the storage budget, but it grows the budget while evicting and does not touch the reclaim ceiling. - [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) - [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 (attach them to this PR) - [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 (follows #8672 and #10044, both merged) - [x] Fixes: none - [x] Unblocks: none claimed - [x] GPUs tested: AMD Radeon RX 6650 XT, RADV Mesa 26.2.4, Linux 7.2.9 - [x] AI-assisted: yes
MarcZX10 commented 2026-10-24 10:36:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T10:36:54Z.

Review: APPROVED


Reviewed the ceiling calculation and its use in both cache budgeting and idle-buffer reclamation. The shared StorageTextureCeiling preserves the former StorageTextureBudget cap/floor behavior while removing the stale quarter-budget reclaim limit; the added sweep checks the invariant across heap budgets and usage levels. The contributor reports the focused Vulkan suite passing 6/6 with validation enabled on RADV, including a one-line mutation that makes the expected half-budget case fail. I did not rerun the GPU test locally.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5637946747 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10551#pullrequestreview-5637946747). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T10:36:54Z. **Review:** APPROVED --- Reviewed the ceiling calculation and its use in both cache budgeting and idle-buffer reclamation. The shared `StorageTextureCeiling` preserves the former `StorageTextureBudget` cap/floor behavior while removing the stale quarter-budget reclaim limit; the added sweep checks the invariant across heap budgets and usage levels. The contributor reports the focused Vulkan suite passing 6/6 with validation enabled on RADV, including a one-line mutation that makes the expected half-budget case fail. I did not rerun the GPU test locally.
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!10551
No description provided.