perf(agc): size the storage and sampled texture caches to the device #1059

Merged
Celegans12 merged 1 commit from upstream-pr/1059 into main 2026-10-09 09:40:40 +00:00
Celegans12 commented 2026-10-07 06:24:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-07T06:24:39Z.


What

The storage image and sampled texture caches each evict least recently used entries past a fixed 2 GiB, and a sampled view of a storage image counts that image again. In the PPSA26344 open world a 16,386-entry image table is remade every frame (about 16,400 textures, 5 s); its textures take up to about 5 GiB, which the cache never keeps.

  • Storage image cache: a quarter of the largest device-local heap, at least 2 GiB (TextureCacheBudget).
  • Sampled cache (SampledTextureBudget): what VK_EXT_memory_budget leaves on that heap after the memory used outside sampled textures and cached storage images, the storage budget and an eighth of the budget, read at most once a second, at least 2 GiB; else the storage rule. Nonzero APS5_TEXTURE_CACHE_MIB sets both. Moves over 10% are logged, at most every 10 s.
  • Sampled memory (SampledTextureMemory) is every snapshot's allocation, cached or still bound after eviction. A view of a cached storage image counts 0 and leaves with its image.
  • #290 adds the same StorageTexture::memoryBytes, and #293 and #1184 add a clear to ClearCachedTextures. With #1484, whichever lands second adds the blocks' free bytes to the sampled memory. #1619 adds depth copies in the same lines; whichever lands second counts a copy's image, since views count 0 here.
Details

With #1484 the budget settled near 2.1 GiB, since the blocks' free part counted as outside use. The 2.27 M snapshots were of 22,512 textures; the median one was made in each of the last 69 frames.

Tested

  • Windows 11, MinGW-w64 GCC 15.2.0, based on main 6b56175a: configure -DBUILD_TESTING=ON, full build, --target libs, ctest:
  • 476/476 tests pass (ctest --output-on-failure)
  • Same build on lavapipe (Mesa 26.2.4 llvmpipe, 8-wide subgroups, VK_DRIVER_FILES): 475/475 pass; agc_driver_flat_store is left out there because it takes several minutes on Windows llvmpipe
  • New agc_driver_sampled_cache_budget_memory (a reported heap budget): a texture still held after it left the cache counts as sampled memory; fails with only the cache's bytes counted.
  • agc_driver_sampled_cache_budget: snapshots count their image's allocation, not their guest bytes, and leave in LRU order; views count 0 and leave with their image.
  • agc_driver_graphics: mocked-heap budgets and the 10% / 10 s report rule (does not link on main).
  • PPSA26344 v1.008 (3,600 s, with a local eviction change): the sampled budget follows VK_EXT_memory_budget from 9.2 GiB at boot to 4.0-5.0 GiB in the world, where the device-local heap uses 14.4-16.0 of its 15.0 GiB; a frame makes about 2,900 textures instead of 16,600; no vkAllocateMemory failure.
  • Not tested: Linux (CI), console behaviour.

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 in TechnicalDebt
  • 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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4768824833 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1059). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-07T06:24:39Z. --- ### What The storage image and sampled texture caches each evict least recently used entries past a fixed 2 GiB, and a sampled view of a storage image counts that image again. In the PPSA26344 open world a 16,386-entry image table is remade every frame (about 16,400 textures, 5 s); its textures take up to about 5 GiB, which the cache never keeps. - Storage image cache: a quarter of the largest device-local heap, at least 2 GiB (`TextureCacheBudget`). - Sampled cache (`SampledTextureBudget`): what `VK_EXT_memory_budget` leaves on that heap after the memory used outside sampled textures and cached storage images, the storage budget and an eighth of the budget, read at most once a second, at least 2 GiB; else the storage rule. Nonzero `APS5_TEXTURE_CACHE_MIB` sets both. Moves over 10% are logged, at most every 10 s. - Sampled memory (`SampledTextureMemory`) is every snapshot's allocation, cached or still bound after eviction. A view of a cached storage image counts 0 and leaves with its image. - #290 adds the same `StorageTexture::memoryBytes`, and #293 and #1184 add a clear to `ClearCachedTextures`. With #1484, whichever lands second adds the blocks' free bytes to the sampled memory. #1619 adds depth copies in the same lines; whichever lands second counts a copy's image, since views count 0 here. <details><summary>Details</summary> With #1484 the budget settled near 2.1 GiB, since the blocks' free part counted as outside use. The 2.27 M snapshots were of 22,512 textures; the median one was made in each of the last 69 frames. </details> ### Tested - Windows 11, MinGW-w64 GCC 15.2.0, based on `main` 6b56175a: configure `-DBUILD_TESTING=ON`, full build, `--target libs`, `ctest`: - 476/476 tests pass (`ctest --output-on-failure`) - Same build on lavapipe (Mesa 26.2.4 llvmpipe, 8-wide subgroups, `VK_DRIVER_FILES`): 475/475 pass; `agc_driver_flat_store` is left out there because it takes several minutes on Windows llvmpipe - New `agc_driver_sampled_cache_budget_memory` (a reported heap budget): a texture still held after it left the cache counts as sampled memory; fails with only the cache's bytes counted. - `agc_driver_sampled_cache_budget`: snapshots count their image's allocation, not their guest bytes, and leave in LRU order; views count 0 and leave with their image. - `agc_driver_graphics`: mocked-heap budgets and the 10% / 10 s report rule (does not link on main). - PPSA26344 v1.008 (3,600 s, with a local eviction change): the sampled budget follows `VK_EXT_memory_budget` from 9.2 GiB at boot to 4.0-5.0 GiB in the world, where the device-local heap uses 14.4-16.0 of its 15.0 GiB; a frame makes about 2,900 textures instead of 16,600; no `vkAllocateMemory` failure. - Not tested: Linux (CI), console behaviour. ### 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) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] AI-assisted: yes
github-actions[bot] commented 2026-10-07 19:36:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-07T19:36:08Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#1181 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp L442, L609-611
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6045385059 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1059#issuecomment-6045385059). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-07T19:36:08Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #1181 | `core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp` [L442](https://github.com/boykopovar/AnyPS5/blob/df16c4c256be3c44e03eb9149a6ce5f8e8a038b2/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp#L442), [L609-611](https://github.com/boykopovar/AnyPS5/blob/df16c4c256be3c44e03eb9149a6ce5f8e8a038b2/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp#L609-L611) | | |
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!1059
No description provided.