fix(agc): evict resource-cache images with storage entries #3474

Merged
014-code merged 1 commit from upstream-pr/3474 into main 2026-10-11 11:50:50 +00:00
014-code commented 2026-10-11 11:09:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by 014-code on 2026-10-11T11:09:03Z.


What

Fixes #3256.

The storage-image cache evicts images by its byte budget, but ResourceCache can retain the same StorageTexture through a cached ShaderResources object. Those entries are bounded only by count, so an image can remain alive after storage-cache eviction and its Vulkan allocation is not reflected in the storage-cache budget. A title that creates storage images for changing extents or addresses can therefore accumulate device-local allocations until vkAllocateMemory fails.

This change removes resource-cache entries that reference an image immediately after that image leaves the storage cache. The implementation:

  • keeps strong references to evicted storage images while the storage-cache mutex is held;
  • releases that mutex before taking the resource-cache mutex, avoiding a storage-cache/resource-cache lock-order inversion;
  • adds ResourceCache::RemoveImage() to remove all entries that read the evicted image;
  • retains removed ShaderResources objects through the active Recorder, so Vulkan resources are destroyed only after submitted work can no longer use them.

The regression test now uses a storage-image-only compute shader with the resource cache enabled. It verifies that the workload populates ResourceCache, exercises the storage-cache budget, and checks both cache membership and weak_ptr lifetime after eviction. The test no longer depends on a host-imported output buffer or a specific discrete GPU.

Tested

  • Ubuntu 24.04 Docker container, Vulkan lavapipe/llvmpipe (LLVM 20.1.2), no RTX 3080:
    • cmake --build build --target agc_driver_storage_cache_budget_tests --parallel 4
    • VK_ICD_FILENAMES=/usr/share/vulkan/icd.d/lvp_icd.json SDL_VIDEODRIVER=dummy ./build/tests/agc_driver_storage_cache_budget_tests
    • Result: storage cache budget tests passed
  • python tools/check_conventions.py --base origin/main
  • git diff --check

The full project test suite was not run.

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
  • 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:4818612548 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3474). Originally posted by [014-code](https://github.com/014-code) on 2026-10-11T11:09:03Z. --- ### What Fixes #3256. The storage-image cache evicts images by its byte budget, but `ResourceCache` can retain the same `StorageTexture` through a cached `ShaderResources` object. Those entries are bounded only by count, so an image can remain alive after storage-cache eviction and its Vulkan allocation is not reflected in the storage-cache budget. A title that creates storage images for changing extents or addresses can therefore accumulate device-local allocations until `vkAllocateMemory` fails. This change removes resource-cache entries that reference an image immediately after that image leaves the storage cache. The implementation: - keeps strong references to evicted storage images while the storage-cache mutex is held; - releases that mutex before taking the resource-cache mutex, avoiding a storage-cache/resource-cache lock-order inversion; - adds `ResourceCache::RemoveImage()` to remove all entries that read the evicted image; - retains removed `ShaderResources` objects through the active `Recorder`, so Vulkan resources are destroyed only after submitted work can no longer use them. The regression test now uses a storage-image-only compute shader with the resource cache enabled. It verifies that the workload populates `ResourceCache`, exercises the storage-cache budget, and checks both cache membership and `weak_ptr` lifetime after eviction. The test no longer depends on a host-imported output buffer or a specific discrete GPU. ### Tested - Ubuntu 24.04 Docker container, Vulkan lavapipe/llvmpipe (LLVM 20.1.2), no RTX 3080: - `cmake --build build --target agc_driver_storage_cache_budget_tests --parallel 4` - `VK_ICD_FILENAMES=/usr/share/vulkan/icd.d/lvp_icd.json SDL_VIDEODRIVER=dummy ./build/tests/agc_driver_storage_cache_budget_tests` - Result: `storage cache budget tests passed` - `python tools/check_conventions.py --base origin/main` - `git diff --check` The full project test suite was not run. ### 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 - [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-11 11:26:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T11:26:16Z.


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
#3473 core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp L525
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp L2550
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6108524070 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3474#issuecomment-6108524070). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T11:26:16Z. --- <!-- 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 | |---|---|---|---| | #3473 | `core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp` [L525](https://github.com/boykopovar/AnyPS5/blob/b33b1b8e666b7c1523ec30c41deac262ef987dd2/core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp#L525)<br>`core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp` [L2550](https://github.com/boykopovar/AnyPS5/blob/b33b1b8e666b7c1523ec30c41deac262ef987dd2/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp#L2550) | | |
adriadam10 commented 2026-10-11 11:50:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T11:50:46Z.


Checked on RADV and CI's lavapipe: agc_driver_storage_cache_budget passes, fails without the change (negative check), and storage_one_slice_alias / storage_baseline_settled still pass; conventions green. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6108718400 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3474#issuecomment-6108718400). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T11:50:46Z. --- Checked on RADV and CI's lavapipe: `agc_driver_storage_cache_budget` passes, fails without the change (negative check), and `storage_one_slice_alias` / `storage_baseline_settled` still pass; conventions green. Merging.
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!3474
No description provided.