fix(agc-driver): size the storage image cache from the device's reported memory budget #5483

Merged
ee6aba54 merged 1 commit from upstream-pr/5483 into main 2026-10-14 22:26:11 +00:00
ee6aba54 commented 2026-10-13 20:58:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ee6aba54 on 2026-10-13T20:58:11Z.


What

The storage image cache keeps a quarter of the largest device-local heap (4 GiB on a 16 GiB card) regardless of how much of that heap the driver reports as usable through VK_EXT_memory_budget. With a desktop and other processes the reported budget on a 16 GiB card is about 10 GiB; the cache stayed full at 4 GiB next to the 2 GiB staging pool and the title's own allocations, and after minutes of a cutscene a 20 MiB device buffer allocation failed with VK_ERROR_OUT_OF_DEVICE_MEMORY, which ends presentation.

The storage image cache budget is now the smaller of that quarter of the heap and a quarter of the reported budget, at least 512 MiB, read once per second like the sampled texture budget. A card whose budget is below 8 GiB therefore gets a cache below the 2 GiB that main keeps (6 GiB of budget: 1.5 GiB). APS5_TEXTURE_CACHE_MIB still overrides it, and the budget report line names the storage budget in use.

Tested

  • Ubuntu 24.04, Linux 7.0, GCC 13.3, Release, based on 0aa4cb1c2. agc_driver_graphics gains storageTextureBudgetTests: without the extension or with a zero budget a quarter of the heap, a 10 GiB budget gives 2560 MiB, a 6 GiB budget gives 1536 MiB, a 1 GiB budget keeps the 512 MiB floor, a budget above the heap size stays at a quarter of the heap, no device-local heap keeps 2 GiB.
  • PPSA15304 (engine: Unreal Engine 5), RTX 5080 with a reported budget of 10.2 to 11.1 GiB: three cutscene runs on main ended after 4 to 6 minutes with vkAllocateMemory device buffer: allocation=20971520 ... Vulkan result -2 at a heap usage of about 8.2 GiB (4074 MiB of it cached storage images); with the change a 15 minute run through the menu into the cutscene stayed below 6.6 GiB and completed, the storage cache holding 2.5 GiB. Evictions that had to store pending results (cache eviction on the [storage] write-back line): 1 in the 2.5 minutes a main run lasted, 45 to 49 per 15 minute run with the change (0.4 to 0.8 GB), next to 6 GB of storage refresh write-backs in the same runs.
  • Windows not built or tested.

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
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • 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
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: PPSA15304 (device memory exhausted in cutscenes)
  • GPUs tested: NVIDIA GeForce RTX 5080, driver 595.99.02, Ubuntu 24.04
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4849390711 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5483). Originally posted by [ee6aba54](https://github.com/ee6aba54) on 2026-10-13T20:58:11Z. --- ### What The storage image cache keeps a quarter of the largest device-local heap (4 GiB on a 16 GiB card) regardless of how much of that heap the driver reports as usable through `VK_EXT_memory_budget`. With a desktop and other processes the reported budget on a 16 GiB card is about 10 GiB; the cache stayed full at 4 GiB next to the 2 GiB staging pool and the title's own allocations, and after minutes of a cutscene a 20 MiB device buffer allocation failed with `VK_ERROR_OUT_OF_DEVICE_MEMORY`, which ends presentation. The storage image cache budget is now the smaller of that quarter of the heap and a quarter of the reported budget, at least 512 MiB, read once per second like the sampled texture budget. A card whose budget is below 8 GiB therefore gets a cache below the 2 GiB that `main` keeps (6 GiB of budget: 1.5 GiB). `APS5_TEXTURE_CACHE_MIB` still overrides it, and the budget report line names the storage budget in use. ### Tested - Ubuntu 24.04, Linux 7.0, GCC 13.3, Release, based on `0aa4cb1c2`. `agc_driver_graphics` gains `storageTextureBudgetTests`: without the extension or with a zero budget a quarter of the heap, a 10 GiB budget gives 2560 MiB, a 6 GiB budget gives 1536 MiB, a 1 GiB budget keeps the 512 MiB floor, a budget above the heap size stays at a quarter of the heap, no device-local heap keeps 2 GiB. - PPSA15304 (engine: Unreal Engine 5), RTX 5080 with a reported budget of 10.2 to 11.1 GiB: three cutscene runs on `main` ended after 4 to 6 minutes with `vkAllocateMemory device buffer: allocation=20971520 ... Vulkan result -2` at a heap usage of about 8.2 GiB (4074 MiB of it cached storage images); with the change a 15 minute run through the menu into the cutscene stayed below 6.6 GiB and completed, the storage cache holding 2.5 GiB. Evictions that had to store pending results (`cache eviction` on the `[storage]` write-back line): 1 in the 2.5 minutes a `main` run lasted, 45 to 49 per 15 minute run with the change (0.4 to 0.8 GB), next to 6 GB of `storage refresh` write-backs in the same runs. - Windows not built or tested. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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) - [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 - [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 - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: PPSA15304 (device memory exhausted in cutscenes) - [x] GPUs tested: NVIDIA GeForce RTX 5080, driver 595.99.02, Ubuntu 24.04 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
CnRJay commented 2026-10-14 01:02:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-14T01:02:41Z.

Review: COMMENTED


Using VK_EXT_memory_budget here is the right signal. The heap size says nothing about what the process can actually use next to the desktop and other applications.

Two things to consider:

  • Because of the 2 GiB floor, the change only takes effect on large cards. On an 8 GiB card with a typical budget of 6–7 GiB, a quarter of the budget is under 2 GiB, so the result is the same 2 GiB as main. Only cards with a budget above 8 GiB see a lower cap. The OOM described here (cache + 2 GiB staging pool + title allocations > budget) is more likely on 6–8 GiB cards than on the RTX 5080 where it was seen. Scaling the floor down with the budget, or dropping it when the budget is small, would cover them too.
  • Several caches now budget against the same heap independently. The sampled-texture budget, this storage-image budget, and #4472's buffer-pool target each read the same heapBudget and take their own share, with no view of what the others hold. Together they can still exceed the budget. Not necessarily for this PR, but a shared accounting point (one budget reader that each cache asks for its share, reporting total use in the [gpu] budget line) would keep #4472 and this from fighting, so whichever lands second should probably be built on the other.

One run-time cost to watch: a lower cap means more evictions. Evicting a storage image with pending results forces its write-back, a GPU→CPU round trip. In the PPSA15304 cutscene run, the count of evictions that had to write back (if the [gpu] storage cache line reports it), before and after, would show whether the lower cap costs frame time.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5511867147 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5483#pullrequestreview-5511867147). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-10-14T01:02:41Z. **Review:** COMMENTED --- Using `VK_EXT_memory_budget` here is the right signal. The heap size says nothing about what the process can actually use next to the desktop and other applications. Two things to consider: - **Because of the 2 GiB floor, the change only takes effect on large cards.** On an 8 GiB card with a typical budget of 6–7 GiB, a quarter of the budget is under 2 GiB, so the result is the same 2 GiB as `main`. Only cards with a budget above 8 GiB see a lower cap. The OOM described here (cache + 2 GiB staging pool + title allocations > budget) is more likely on 6–8 GiB cards than on the RTX 5080 where it was seen. Scaling the floor down with the budget, or dropping it when the budget is small, would cover them too. - **Several caches now budget against the same heap independently.** The sampled-texture budget, this storage-image budget, and #4472's buffer-pool target each read the same `heapBudget` and take their own share, with no view of what the others hold. Together they can still exceed the budget. Not necessarily for this PR, but a shared accounting point (one budget reader that each cache asks for its share, reporting total use in the `[gpu]` budget line) would keep #4472 and this from fighting, so whichever lands second should probably be built on the other. One run-time cost to watch: a lower cap means more evictions. Evicting a storage image with pending results forces its write-back, a GPU→CPU round trip. In the PPSA15304 cutscene run, the count of evictions that had to write back (if the `[gpu]` storage cache line reports it), before and after, would show whether the lower cap costs frame time.
ee6aba54 commented 2026-10-14 10:10:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ee6aba54 on 2026-10-14T10:10:53Z.


Thanks, both points taken.

  • Floor: 64ffeb8c9 lowers it to 512 MiB, so the cap applies on small cards too: a 6 GiB budget now gives 1.5 GiB instead of the 2 GiB main keeps, a 1 GiB budget 512 MiB. The test and the description are updated.
  • Shared accounting: agreed, the sampled cache, this cache and the buffer pool each take their share of the same heapBudget without seeing each other. I would make that a follow-up that lands on whichever of #4472 and this one merges first: one budget reader that hands out the shares and prints the total on the [gpu] budget line. The staging pool is the next consumer I have locally (an eighth of the reported budget instead of an eighth of the heap) and would go into that follow-up.
  • Eviction cost in the PPSA15304 runs: write-backs forced by cache eviction (cache eviction on the [storage] line) were 1 in the 2.5 minutes a main run lasted before the OOM, and 45 to 49 per 15 minute run with the change (0.4 to 0.8 GB), next to about 6 GB of storage refresh write-backs in the same runs, so the lower cap is not what costs frame time there. Added to the description.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6165978493 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5483#issuecomment-6165978493). Originally posted by [ee6aba54](https://github.com/ee6aba54) on 2026-10-14T10:10:53Z. --- Thanks, both points taken. - Floor: `64ffeb8c9` lowers it to 512 MiB, so the cap applies on small cards too: a 6 GiB budget now gives 1.5 GiB instead of the 2 GiB `main` keeps, a 1 GiB budget 512 MiB. The test and the description are updated. - Shared accounting: agreed, the sampled cache, this cache and the buffer pool each take their share of the same `heapBudget` without seeing each other. I would make that a follow-up that lands on whichever of #4472 and this one merges first: one budget reader that hands out the shares and prints the total on the `[gpu]` budget line. The staging pool is the next consumer I have locally (an eighth of the reported budget instead of an eighth of the heap) and would go into that follow-up. - Eviction cost in the PPSA15304 runs: write-backs forced by cache eviction (`cache eviction` on the `[storage]` line) were 1 in the 2.5 minutes a `main` run lasted before the OOM, and 45 to 49 per 15 minute run with the change (0.4 to 0.8 GB), next to about 6 GB of `storage refresh` write-backs in the same runs, so the lower cap is not what costs frame time there. Added to the description. AI-assisted: yes
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!5483
No description provided.