fix(agc): keep uncached storage images out of the resource cache #3473

Merged
superhe11 merged 2 commits from upstream-pr/3473 into main 2026-10-11 21:24:33 +00:00
superhe11 commented 2026-10-11 11:07:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by superhe11 on 2026-10-11T11:07:57Z.


What

Follow-up to #3474; related to #3256.

A descriptor set can still bind an already-uncached storage image when it reaches ResourceCache::Insert, including an early image evicted while building an oversized set. Reject these sets before inserting or replacing a key. Check both direct storage bindings and sampled views backed by storage images.

ClearCachedTextures also leaves resource-cache entries holding the images it clears. Invalidate those entries using the existing ResourceCache::RemoveImage from #3474. Collect cleared images under the storage-cache mutex, release it before accessing the resource cache, and retain removed resource objects through an active recorder as #3474 does.

The duplicate RemoveStorageImage and its eviction notification are removed. The ordinary storage-cache eviction implementation is unchanged from main. The regression tests cover only stale admission, admission across a build-time eviction, and explicit cache clear.

Tested

Our earlier Windows baseline before the test-only follow-up showed both changes are necessary on main a11c8f7f, which includes merged #3474. With production ShaderResources.cpp and ShaderResources.hpp exactly from that main and only the initial regression fixture/registrations added, all three focused regressions failed at their intended assertions:

  • agc_driver_resource_cache_storage_admission: an uncached image was admitted to the resource cache.
  • agc_driver_resource_cache_oversized_storage_admission: an oversized storage descriptor set entered the resource cache (12 images, 1 MiB storage-cache budget; an early bound image is confirmed uncached before insertion).
  • agc_driver_resource_cache_storage_clear: clearing storage images left their resources cached.

With this PR, the three regressions pass. They additionally cover sampled views, preserving a live entry when a stale replacement is rejected, and keeping a cleared image alive for an active caller until that caller releases it. The oversized case checks both direct storage bindings and sampled views.

Windows x64 (10.0.26100), WinLibs GCC 15.2.0 ucrt-posix-seh r7, Ninja, Release, NVIDIA GeForce RTX 3080. Built the production driver and both targeted test executables. With ANYPS5_REQUIRE_VULKAN=1, all six focused Vulkan tests passed without skips: the three above, agc_driver_sampled_cache_budget, agc_driver_sampled_cache_budget_memory, and agc_driver_storage_cache_budget (including #3474's regression).

Test-only lifetime coverage from @jweidenh's 1305a0652 is included with the original author retained. Production files are unchanged from 83c9eb7af. The assertions check that rejected insertion/replacement yields no displaced resource, an active sampled caller retains the evicted image after the storage caller releases it, and the last caller releases that image. Oversized direct and sampled sets release the early evicted image before cache teardown. The fixture also checks cache eligibility/storage-backed sampled views and fails mandatory Vulkan runs if host imports are unavailable.

The strengthened tests were rerun locally on updated head 07297a54a in a fresh isolated worktree/build: WinLibs GCC 15.2.0, Windows x64 Release, NVIDIA RTX 3080, SPIR-V Tools off. Built the production driver and both focused test executables; all six focused tests passed without skips (0.25-2.57 seconds each) with ANYPS5_REQUIRE_VULKAN=1, --parallel 3, --timeout 30, and --no-tests=error. The test source exactly matches the contributor's commit; the production Git blobs match 83c9eb7af.

Separate contributor-reported Linux validation: jweidenh's review comment reports Ubuntu 24.04 x86-64, GCC 13.3, Release, Mesa 25.2.8 lavapipe (LLVM 20.1.2), SPIR-V Tools enabled, with the test executables and libs built. All six focused tests passed without skips with ANYPS5_REQUIRE_VULKAN=1. Replacing only the two production files with exact main a11c8f7f blobs made all three regressions fail at the intended assertions; restoring the PR files and rebuilding made all six pass again. This Linux run was performed by the contributor, not repeated locally.

Conventions/template checks and git diff --check passed. Full ctest, macOS, and the affected-title/OOM scenario were not run locally. The Linux evidence uses software Vulkan and does not establish that every cause of #3256 is resolved.

Checklist

  • Based on current main (a11c8f7f); 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:4818605321 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3473). Originally posted by [superhe11](https://github.com/superhe11) on 2026-10-11T11:07:57Z. --- ### What Follow-up to #3474; related to #3256. A descriptor set can still bind an already-uncached storage image when it reaches `ResourceCache::Insert`, including an early image evicted while building an oversized set. Reject these sets before inserting or replacing a key. Check both direct storage bindings and sampled views backed by storage images. `ClearCachedTextures` also leaves resource-cache entries holding the images it clears. Invalidate those entries using the existing `ResourceCache::RemoveImage` from #3474. Collect cleared images under the storage-cache mutex, release it before accessing the resource cache, and retain removed resource objects through an active recorder as #3474 does. The duplicate `RemoveStorageImage` and its eviction notification are removed. The ordinary storage-cache eviction implementation is unchanged from main. The regression tests cover only stale admission, admission across a build-time eviction, and explicit cache clear. ### Tested Our earlier Windows baseline before the test-only follow-up showed both changes are necessary on main `a11c8f7f`, which includes merged #3474. With production `ShaderResources.cpp` and `ShaderResources.hpp` exactly from that main and only the initial regression fixture/registrations added, all three focused regressions failed at their intended assertions: - `agc_driver_resource_cache_storage_admission`: `an uncached image was admitted to the resource cache`. - `agc_driver_resource_cache_oversized_storage_admission`: `an oversized storage descriptor set entered the resource cache` (12 images, 1 MiB storage-cache budget; an early bound image is confirmed uncached before insertion). - `agc_driver_resource_cache_storage_clear`: `clearing storage images left their resources cached`. With this PR, the three regressions pass. They additionally cover sampled views, preserving a live entry when a stale replacement is rejected, and keeping a cleared image alive for an active caller until that caller releases it. The oversized case checks both direct storage bindings and sampled views. Windows x64 (10.0.26100), WinLibs GCC 15.2.0 ucrt-posix-seh r7, Ninja, Release, NVIDIA GeForce RTX 3080. Built the production driver and both targeted test executables. With `ANYPS5_REQUIRE_VULKAN=1`, all six focused Vulkan tests passed without skips: the three above, `agc_driver_sampled_cache_budget`, `agc_driver_sampled_cache_budget_memory`, and `agc_driver_storage_cache_budget` (including #3474's regression). Test-only lifetime coverage from @jweidenh's [1305a0652](https://github.com/jweidenh/AnyPS5/commit/1305a065214b84aa0e544739a135c8ca4418644f) is included with the original author retained. Production files are unchanged from `83c9eb7af`. The assertions check that rejected insertion/replacement yields no displaced resource, an active sampled caller retains the evicted image after the storage caller releases it, and the last caller releases that image. Oversized direct and sampled sets release the early evicted image before cache teardown. The fixture also checks cache eligibility/storage-backed sampled views and fails mandatory Vulkan runs if host imports are unavailable. The strengthened tests were rerun locally on updated head `07297a54a` in a fresh isolated worktree/build: WinLibs GCC 15.2.0, Windows x64 Release, NVIDIA RTX 3080, SPIR-V Tools off. Built the production driver and both focused test executables; all six focused tests passed without skips (0.25-2.57 seconds each) with `ANYPS5_REQUIRE_VULKAN=1`, `--parallel 3`, `--timeout 30`, and `--no-tests=error`. The test source exactly matches the contributor's commit; the production Git blobs match `83c9eb7af`. Separate contributor-reported Linux validation: [jweidenh's review comment](https://github.com/boykopovar/AnyPS5/pull/3473#issuecomment-6109599765) reports Ubuntu 24.04 x86-64, GCC 13.3, Release, Mesa 25.2.8 lavapipe (LLVM 20.1.2), SPIR-V Tools enabled, with the test executables and `libs` built. All six focused tests passed without skips with `ANYPS5_REQUIRE_VULKAN=1`. Replacing only the two production files with exact main `a11c8f7f` blobs made all three regressions fail at the intended assertions; restoring the PR files and rebuilding made all six pass again. This Linux run was performed by the contributor, not repeated locally. Conventions/template checks and `git diff --check` passed. Full ctest, macOS, and the affected-title/OOM scenario were not run locally. The Linux evidence uses software Vulkan and does not establish that every cause of #3256 is resolved. ### Checklist - [x] Based on current `main` (`a11c8f7f`); 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
adriadam10 commented 2026-10-11 11:54:47 +00:00 (Migrated from github.com)

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

Review: CHANGES_REQUESTED


This now conflicts with main: #3474 (merged) fixes the same #3256 retention path with ResourceCache::RemoveImage, so RemoveStorageImage duplicates it.

Please rebase on main and drop the duplicate removal. What I'd keep, if it is still needed on top of #3474:

  • the insertion guard (HasCachedStorageImages) that rejects sets binding an already-uncached storage image, including the early image evicted while building an oversized set;
  • the invalidation in ClearCachedTextures.

Please say in the description which of the two still fails on main after #3474 (a test that fails on main is enough), and keep the regression test for only that part.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5483200741 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3473#pullrequestreview-5483200741). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T11:54:47Z. **Review:** CHANGES_REQUESTED --- This now conflicts with main: #3474 (merged) fixes the same #3256 retention path with `ResourceCache::RemoveImage`, so `RemoveStorageImage` duplicates it. Please rebase on main and drop the duplicate removal. What I'd keep, if it is still needed on top of #3474: - the insertion guard (`HasCachedStorageImages`) that rejects sets binding an already-uncached storage image, including the early image evicted while building an oversized set; - the invalidation in `ClearCachedTextures`. Please say in the description which of the two still fails on main after #3474 (a test that fails on main is enough), and keep the regression test for only that part.
superhe11 commented 2026-10-11 13:14:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by superhe11 on 2026-10-11T13:14:16Z.


@adriadam10 Updated in 83c9eb7af. Rebased onto main a11c8f7f (including #3474) and removed the duplicate RemoveStorageImage implementation and eviction notification. The ordinary eviction path is now unchanged from main; ClearCachedTextures uses the existing RemoveImage, with the storage mutex released before resource-cache invalidation and recorder retention preserved.

Both remaining gaps reproduce on that main with unchanged production code and only the new regression fixture added:

  • stale insertion: an uncached image was admitted to the resource cache;
  • insertion after an early image is evicted while building an oversized set: an oversized storage descriptor set entered the resource cache;
  • explicit cache clear: clearing storage images left their resources cached.

Kept only regressions for those cases and updated the PR title/description with the baseline failures. With the fix, all six focused Vulkan tests pass on Windows/RTX 3080 without skips, including #3474's storage-cache regression; GitHub Conventions also passed. Full ctest and the game scenario were not run.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6109402334 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3473#issuecomment-6109402334). Originally posted by [superhe11](https://github.com/superhe11) on 2026-10-11T13:14:16Z. --- @adriadam10 Updated in 83c9eb7af. Rebased onto main `a11c8f7f` (including #3474) and removed the duplicate `RemoveStorageImage` implementation and eviction notification. The ordinary eviction path is now unchanged from main; `ClearCachedTextures` uses the existing `RemoveImage`, with the storage mutex released before resource-cache invalidation and recorder retention preserved. Both remaining gaps reproduce on that main with unchanged production code and only the new regression fixture added: - stale insertion: `an uncached image was admitted to the resource cache`; - insertion after an early image is evicted while building an oversized set: `an oversized storage descriptor set entered the resource cache`; - explicit cache clear: `clearing storage images left their resources cached`. Kept only regressions for those cases and updated the PR title/description with the baseline failures. With the fix, all six focused Vulkan tests pass on Windows/RTX 3080 without skips, including #3474's storage-cache regression; GitHub Conventions also passed. Full ctest and the game scenario were not run.
jweidenh commented 2026-10-11 13:36:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jweidenh on 2026-10-11T13:36:52Z.


I checked the rebased 83c9eb7af102d6cb9265fe09ea70faf1acf63cb3 and prepared a small test-only follow-up. Production files are byte-for-byte unchanged from that PR head:

The added assertions verify that rejected insertion/replacement produces no displaced entry, that an active sampled caller keeps the evicted image alive after its storage caller releases it, and that the image is freed when the last caller releases it. Oversized storage and sampled sets must also release the early evicted image before cache teardown. The fixture now asserts that these sets are eligible for caching and actually use storage-backed sampled views; mandatory Vulkan runs fail if host imports are unavailable.

Validated on an Ubuntu 24.04 x86-64 self-hosted runner, GCC 13.3, Release, Mesa 25.2.8 lavapipe (LLVM 20.1.2). Built agc_driver_sampled_cache_budget_tests, agc_driver_storage_cache_budget_tests, and libs, with SPIR-V Tools enabled and ANYPS5_REQUIRE_VULKAN=1.

All six focused tests passed without skips, with fresh per-run cache directories (0.028–2.259 seconds per test):

  • agc_driver_resource_cache_storage_admission
  • agc_driver_resource_cache_oversized_storage_admission
  • agc_driver_resource_cache_storage_clear
  • agc_driver_storage_cache_budget
  • agc_driver_sampled_cache_budget
  • agc_driver_sampled_cache_budget_memory

For the baseline control, I replaced only production ShaderResources.cpp and ShaderResources.hpp with their exact Git blobs from main a11c8f7f70a0ed4e71504a89de69e8cdae687817, leaving the test fixture unchanged. All three regressions failed at their intended assertions:

Regression Main failure Time
Stale admission an uncached image was admitted to the resource cache 0.066 s
Oversized set an oversized storage descriptor set entered the resource cache 0.075 s
Explicit clear clearing storage images left their resources cached 0.067 s

After restoring the exact PR production files, rebuilding the tests and libs, all six passed again (0.055–2.238 seconds), with no skips. The harness verified both file hashes and a clean source worktree after restoration. The final private local-runner workflow completed successfully.

The focused CTest selection was:

ANYPS5_REQUIRE_VULKAN=1 ctest --test-dir build \
  -R '^agc_driver_(resource_cache_(storage_admission|oversized_storage_admission|storage_clear)|storage_cache_budget|sampled_cache_budget(_memory)?)$' \
  --parallel 3 --timeout 30 --no-tests=error --output-on-failure

Host-pointer import probes succeeded. The logs also report unavailable /dev/udmabuf and no LOD/mip streaming feedback.

Limitations: Linux software Vulkan only; no Windows run, hardware-GPU run, full CTest suite, or affected-title/OOM reproduction. This adds Linux regression evidence and lifetime coverage; it does not establish that every cause of #3256 is resolved. AI-assisted test implementation and review.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6109599765 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3473#issuecomment-6109599765). Originally posted by [jweidenh](https://github.com/jweidenh) on 2026-10-11T13:36:52Z. --- I checked the rebased `83c9eb7af102d6cb9265fe09ea70faf1acf63cb3` and prepared a small test-only follow-up. Production files are byte-for-byte unchanged from that PR head: - Commit: [1305a0652](https://github.com/jweidenh/AnyPS5/commit/1305a065214b84aa0e544739a135c8ca4418644f) - [Download patch](https://github.com/jweidenh/AnyPS5/commit/1305a065214b84aa0e544739a135c8ca4418644f.patch) The added assertions verify that rejected insertion/replacement produces no displaced entry, that an active sampled caller keeps the evicted image alive after its storage caller releases it, and that the image is freed when the last caller releases it. Oversized storage and sampled sets must also release the early evicted image before cache teardown. The fixture now asserts that these sets are eligible for caching and actually use storage-backed sampled views; mandatory Vulkan runs fail if host imports are unavailable. Validated on an Ubuntu 24.04 x86-64 self-hosted runner, GCC 13.3, Release, Mesa 25.2.8 lavapipe (LLVM 20.1.2). Built `agc_driver_sampled_cache_budget_tests`, `agc_driver_storage_cache_budget_tests`, and `libs`, with SPIR-V Tools enabled and `ANYPS5_REQUIRE_VULKAN=1`. All six focused tests passed without skips, with fresh per-run cache directories (0.028–2.259 seconds per test): - `agc_driver_resource_cache_storage_admission` - `agc_driver_resource_cache_oversized_storage_admission` - `agc_driver_resource_cache_storage_clear` - `agc_driver_storage_cache_budget` - `agc_driver_sampled_cache_budget` - `agc_driver_sampled_cache_budget_memory` For the baseline control, I replaced only production `ShaderResources.cpp` and `ShaderResources.hpp` with their exact Git blobs from main `a11c8f7f70a0ed4e71504a89de69e8cdae687817`, leaving the test fixture unchanged. All three regressions failed at their intended assertions: | Regression | Main failure | Time | | --- | --- | --- | | Stale admission | `an uncached image was admitted to the resource cache` | 0.066 s | | Oversized set | `an oversized storage descriptor set entered the resource cache` | 0.075 s | | Explicit clear | `clearing storage images left their resources cached` | 0.067 s | After restoring the exact PR production files, rebuilding the tests and `libs`, all six passed again (0.055–2.238 seconds), with no skips. The harness verified both file hashes and a clean source worktree after restoration. The final private local-runner workflow completed successfully. The focused CTest selection was: ```sh ANYPS5_REQUIRE_VULKAN=1 ctest --test-dir build \ -R '^agc_driver_(resource_cache_(storage_admission|oversized_storage_admission|storage_clear)|storage_cache_budget|sampled_cache_budget(_memory)?)$' \ --parallel 3 --timeout 30 --no-tests=error --output-on-failure ``` Host-pointer import probes succeeded. The logs also report unavailable `/dev/udmabuf` and no LOD/mip streaming feedback. Limitations: Linux software Vulkan only; no Windows run, hardware-GPU run, full CTest suite, or affected-title/OOM reproduction. This adds Linux regression evidence and lifetime coverage; it does not establish that every cause of #3256 is resolved. AI-assisted test implementation and review.
adriadam10 commented 2026-10-11 21:24:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T21:24:27Z.

Review: APPROVED


Checked on top of current main: the scoped libSceAgcDriver build and ctest pass, including the three new agc_driver_resource_cache_* tests. Without the change the admission and clear tests fail, so they pin the fix. The Insert guard and the ClearCachedTextures invalidation (reusing RemoveImage from #3474, storage mutex released first) look right, and @jweidenh's Linux run confirms it; merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5485023957 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3473#pullrequestreview-5485023957). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T21:24:27Z. **Review:** APPROVED --- Checked on top of current main: the scoped libSceAgcDriver build and ctest pass, including the three new `agc_driver_resource_cache_*` tests. Without the change the admission and clear tests fail, so they pin the fix. The `Insert` guard and the `ClearCachedTextures` invalidation (reusing `RemoveImage` from #3474, storage mutex released first) look right, and @jweidenh's Linux run confirms it; 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!3473
No description provided.