fix(agc): release sampled views after storage eviction #5997

Merged
Ondra97 merged 1 commit from upstream-pr/5997 into main 2026-10-16 23:56:35 +00:00
Ondra97 commented 2026-10-14 18:44:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Ondra97 on 2026-10-14T18:44:21Z.


What

Storage-only cache churn can retain full Vulkan images after storage-cache eviction: cached sampled views still own the evicted image until a later sampled lookup or TextureCacheUsage() drains the uncached-image queue. The existing lifetime test called that diagnostic before checking expiration, masking the retention.

Drain the existing sampled-view cleanup after storage eviction and resource-cache removal, outside the storage mutex. Descriptor resources transferred to the recorder and callers holding a view keep their ownership. The eviction vector also keeps images alive until sampled-cache cleanup has unlocked.

This addresses one concrete ownership problem relevant to the memory pressure reported in Wolverine PPSA03671 #5961, whose bring-up is #5516. It does not establish that the title's entire out-of-memory failure is fixed: its working-set size and other in-flight owners are separate factors.

Tested

I tested on Windows 11 Pro 10.0.26300, MinGW-w64 GCC 15.2.0 (WinLibs), Release/Ninja, bundled dependencies, BUILD_TESTING=ON, with Vulkan required.

  • Main ed835aa76: moving the existing expiry check before TextureCacheUsage() fails on the actual GPU with the sampled texture cache kept the view of an evicted storage image (2.12 s).
  • Regression coverage now checks exact view/image weak ownership before diagnostics, an externally held view surviving eviction, rejected descriptor-set ownership, and recorder ownership after resource-cache removal. A GPU transfer reads the original image's 0x5a5a5a5a pixel after eviction; objects expire after the scoped recorder completes.
  • Rebased onto main 587b63d2a: full default Windows build passed. All 12 targeted Vulkan tests passed (12.40 s): sampled and storage budgets, memory accounting, resource-cache admission/oversized admission/clear, image-table/cache/bounds/reuse, one-slice aliasing and write-back overhang. No GPU tests were skipped; the slowest took 2.73 s.
  • Before the rebase, the four central sampled-budget/resource-cache cases each passed three consecutive runs (12 executions, 10.45 s). Sampled-budget and resource-admission also passed with APS5_NO_TEXTURE_HASH=1 (2/2, 2.37 s).
  • Conventions and git diff --check passed. I checked the full inventory of 457 open PRs, compared the patches of all 37 that share these files, and ran the repository's overlap checker on this commit. No other open PR implements this cleanup.

I have not replayed Wolverine or tested an 8 GB GPU, Linux or AMD/Intel drivers. No cache budget or shader instruction semantics are changed.

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 technical debt
  • 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
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 4070 Ti SUPER, driver 32.0.16.1714, Windows 11 Pro 10.0.26300
  • AI-assisted: yes — Codex
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4862781000 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5997). Originally posted by [Ondra97](https://github.com/Ondra97) on 2026-10-14T18:44:21Z. --- ### What Storage-only cache churn can retain full Vulkan images after storage-cache eviction: cached sampled views still own the evicted image until a later sampled lookup or `TextureCacheUsage()` drains the uncached-image queue. The existing lifetime test called that diagnostic before checking expiration, masking the retention. Drain the existing sampled-view cleanup after storage eviction and resource-cache removal, outside the storage mutex. Descriptor resources transferred to the recorder and callers holding a view keep their ownership. The eviction vector also keeps images alive until sampled-cache cleanup has unlocked. This addresses one concrete ownership problem relevant to the memory pressure reported in [Wolverine PPSA03671 #5961](https://github.com/boykopovar/AnyPS5/issues/5961), whose bring-up is [#5516](https://github.com/boykopovar/AnyPS5/discussions/5516). It does not establish that the title's entire out-of-memory failure is fixed: its working-set size and other in-flight owners are separate factors. ### Tested I tested on Windows 11 Pro 10.0.26300, MinGW-w64 GCC 15.2.0 (WinLibs), Release/Ninja, bundled dependencies, `BUILD_TESTING=ON`, with Vulkan required. - Main `ed835aa76`: moving the existing expiry check before `TextureCacheUsage()` fails on the actual GPU with `the sampled texture cache kept the view of an evicted storage image` (2.12 s). - Regression coverage now checks exact view/image weak ownership before diagnostics, an externally held view surviving eviction, rejected descriptor-set ownership, and recorder ownership after resource-cache removal. A GPU transfer reads the original image's `0x5a5a5a5a` pixel after eviction; objects expire after the scoped recorder completes. - Rebased onto main `587b63d2a`: full default Windows build passed. All 12 targeted Vulkan tests passed (12.40 s): sampled and storage budgets, memory accounting, resource-cache admission/oversized admission/clear, image-table/cache/bounds/reuse, one-slice aliasing and write-back overhang. No GPU tests were skipped; the slowest took 2.73 s. - Before the rebase, the four central sampled-budget/resource-cache cases each passed three consecutive runs (12 executions, 10.45 s). Sampled-budget and resource-admission also passed with `APS5_NO_TEXTURE_HASH=1` (2/2, 2.37 s). - Conventions and `git diff --check` passed. I checked the full inventory of 457 open PRs, compared the patches of all 37 that share these files, and ran the repository's overlap checker on this commit. No other open PR implements this cleanup. I have not replayed Wolverine or tested an 8 GB GPU, Linux or AMD/Intel drivers. No cache budget or shader instruction semantics are changed. ### 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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in technical debt - [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] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 4070 Ti SUPER, driver 32.0.16.1714, Windows 11 Pro 10.0.26300 - [x] AI-assisted: yes — Codex
Ondra97 commented 2026-10-14 19:45:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Ondra97 on 2026-10-14T19:45:10Z.


Could a maintainer review the lock ordering and resource lifetime changes, particularly preservation of images still referenced by recorded GPU work?

My local Windows build and all 12 targeted Vulkan tests passed, but I have not tested Wolverine. Its latest measurements in #5961 point to other owners as the main source of retained images, so the impact of this cleanup on that title remains unverified.

Could you also trigger the full CI build? A Wolverine test on an 8 GB GPU would help establish its practical impact.

AI-assisted: yes — Codex

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6176885584 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5997#issuecomment-6176885584). Originally posted by [Ondra97](https://github.com/Ondra97) on 2026-10-14T19:45:10Z. --- Could a maintainer review the lock ordering and resource lifetime changes, particularly preservation of images still referenced by recorded GPU work? My local Windows build and all 12 targeted Vulkan tests passed, but I have not tested Wolverine. Its latest measurements in #5961 point to other owners as the main source of retained images, so the impact of this cleanup on that title remains unverified. Could you also trigger the full CI build? A Wolverine test on an 8 GB GPU would help establish its practical impact. AI-assisted: yes — Codex
tv7 commented 2026-10-14 20:39:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by tv7 on 2026-10-14T20:39:19Z.


@Ondra97 I read the change with your two questions in mind, on head fd9525a2e.

Lock ordering: I don't see a problem. The new drain takes Textures().mutex only after the storage cache's mutex is released, so the two are never nested on this path. The sampled lookup (cachedTexture) reaches the storage cache through sampledStorageSource before it takes the sampled mutex. The other places that take the sampled mutex do so briefly (findSampledEntry, TextureCacheUsage, ClearCachedTextures) and don't call into the storage cache while holding it. CachedTableTextures holds the sampled mutex and then asks the storage cache. That order is sampled before storage, and the new code never holds storage while taking sampled, so it can't invert.

Ownership of recorded work: RemoveImage hands the removed ShaderResources to the recorder before the drain runs. The drain only erases sampled-cache entries, so a descriptor resource or a view that recorded work or a caller holds keeps its own reference. The evicted vector also keeps each image alive until the drain has looked it up, which dropUncachedViews relies on to lock the weak_ptr.

Wolverine: I ran #5998 alone and #5998 with this PR, 900 s each (numbers in #5998). There's no regression, and no measurable difference in this title: the most evicted-but-alive images at one report were 664 vs 652, and the peak live allocations were 13.9 vs 14.2 GiB. That matches the earlier count in #5961, where almost no survivor was held by a sampled view. So the fix looks correct to me, but Wolverine doesn't show a gain from it.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6177950632 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5997#issuecomment-6177950632). Originally posted by [tv7](https://github.com/tv7) on 2026-10-14T20:39:19Z. --- @Ondra97 I read the change with your two questions in mind, on head fd9525a2e. **Lock ordering:** I don't see a problem. The new drain takes `Textures().mutex` only after the storage cache's mutex is released, so the two are never nested on this path. The sampled lookup (`cachedTexture`) reaches the storage cache through `sampledStorageSource` before it takes the sampled mutex. The other places that take the sampled mutex do so briefly (`findSampledEntry`, `TextureCacheUsage`, `ClearCachedTextures`) and don't call into the storage cache while holding it. `CachedTableTextures` holds the sampled mutex and then asks the storage cache. That order is sampled before storage, and the new code never holds storage while taking sampled, so it can't invert. **Ownership of recorded work:** `RemoveImage` hands the removed `ShaderResources` to the recorder before the drain runs. The drain only erases sampled-cache entries, so a descriptor resource or a view that recorded work or a caller holds keeps its own reference. The `evicted` vector also keeps each image alive until the drain has looked it up, which `dropUncachedViews` relies on to lock the `weak_ptr`. **Wolverine:** I ran #5998 alone and #5998 with this PR, 900 s each (numbers in #5998). There's no regression, and no measurable difference in this title: the most evicted-but-alive images at one report were 664 vs 652, and the peak live allocations were 13.9 vs 14.2 GiB. That matches the earlier count in #5961, where almost no survivor was held by a sampled view. So the fix looks correct to me, but Wolverine doesn't show a gain from it. AI-assisted: yes
Ondra97 commented 2026-10-14 20:45:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Ondra97 on 2026-10-14T20:45:58Z.


@tv7 Thanks for reviewing the lock ordering and recorded-resource lifetime, and for both 900-second comparisons. I’ll keep #5997 scoped to the independently reproduced sampled-view retention issue; your results show no measurable Wolverine benefit or regression. Full CI for #5997 is still outstanding.

AI-assisted: yes — Codex

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6178074283 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5997#issuecomment-6178074283). Originally posted by [Ondra97](https://github.com/Ondra97) on 2026-10-14T20:45:58Z. --- @tv7 Thanks for reviewing the lock ordering and recorded-resource lifetime, and for both 900-second comparisons. I’ll keep #5997 scoped to the independently reproduced sampled-view retention issue; your results show no measurable Wolverine benefit or regression. Full CI for #5997 is still outstanding. AI-assisted: yes — Codex
github-actions[bot] commented 2026-10-15 12:13:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:13:00Z.


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
PR 6937 core/libs/prx/libSceAgcDriver/tests/execution/SampledCacheBudget.cpp L238

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 1896 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 5021 core/libs/prx/libSceAgcDriver/tests/execution/SampledCacheBudget.cpp
PR 6177 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 6188 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 6222 core/libs/prx/libSceAgcDriver/tests/execution/SampledCacheBudget.cpp
PR 6373 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 6412 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 6718 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6191764212 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5997#issuecomment-6191764212). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-15T12:13:00Z. --- <!-- 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 | |---|---|---|---| | [PR 6937](https://www.github.com/boykopovar/AnyPS5/pull/6937) | `core/libs/prx/libSceAgcDriver/tests/execution/SampledCacheBudget.cpp` [L238](https://github.com/boykopovar/AnyPS5/blob/af0fff7627135cd6e3d6f1b4b25b49f198b9bf14/core/libs/prx/libSceAgcDriver/tests/execution/SampledCacheBudget.cpp#L238) | | | Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 1896](https://www.github.com/boykopovar/AnyPS5/pull/1896) | `core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libSceAgcDriver/tests/execution/SampledCacheBudget.cpp` | | [PR 6177](https://www.github.com/boykopovar/AnyPS5/pull/6177) | `core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp` | | [PR 6188](https://www.github.com/boykopovar/AnyPS5/pull/6188) | `core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp` | | [PR 6222](https://www.github.com/boykopovar/AnyPS5/pull/6222) | `core/libs/prx/libSceAgcDriver/tests/execution/SampledCacheBudget.cpp` | | [PR 6373](https://www.github.com/boykopovar/AnyPS5/pull/6373) | `core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp` | | [PR 6412](https://www.github.com/boykopovar/AnyPS5/pull/6412) | `core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp` | | [PR 6718](https://www.github.com/boykopovar/AnyPS5/pull/6718) | `core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp` |
coltken95 commented 2026-10-15 17:57:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by coltken95 on 2026-10-15T17:57:22Z.


Tested on Linux x86-64 (Release build, lavapipe / llvmpipe LLVM 20.1.2), with fd9525a2e merged into main 8cd937e29:

  • With the PR: all 5 tests built from SampledCacheBudget.cpp pass.
  • With main's Graphics/src/ShaderResources.cpp:
    • agc_driver_sampled_cache_budget fails with AGC graphics: the sampled texture cache kept the view of an evicted storage image.
    • agc_driver_resource_cache_storage_admission fails with AGC graphics: the rejected descriptor sets retained an evicted storage image.
    • The other 3 pass.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6198739449 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5997#issuecomment-6198739449). Originally posted by [coltken95](https://github.com/coltken95) on 2026-10-15T17:57:22Z. --- Tested on Linux x86-64 (Release build, lavapipe / llvmpipe LLVM 20.1.2), with fd9525a2e merged into main 8cd937e29: - With the PR: all 5 tests built from `SampledCacheBudget.cpp` pass. - With main's `Graphics/src/ShaderResources.cpp`: - `agc_driver_sampled_cache_budget` fails with `AGC graphics: the sampled texture cache kept the view of an evicted storage image`. - `agc_driver_resource_cache_storage_admission` fails with `AGC graphics: the rejected descriptor sets retained an evicted storage image`. - The other 3 pass. AI-assisted: yes (Claude Code)
MarcZX10 commented 2026-10-16 16:33:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T16:33:16Z.

Review: COMMENTED


Reviewed #5997 at fd9525a2e and compared it with #5998. I do not see a lock-order cycle or a resource-lifetime regression in the cleanup path:

  • cachedStorageTexture releases the storage-cache mutex before removing shared resources and taking the sampled-texture mutex. cachedTexture obtains its storage source before taking the sampled-texture mutex, and TextureCacheUsage releases that mutex before reading storage-cache accounting.
  • The evicted vector keeps each image alive while RemoveImage and dropUncachedViews run. Resources returned by RemoveImage are retained by the active recorder before the sampled-cache views are erased; descriptor resources and caller-held views therefore keep their images alive for recorded work.
  • #5997 and #5998 have a clean merge preview. In the combined path, #5998 can conservatively charge an evicted image while the sampled cache still holds a view, before #5997 drains that view; I see this as temporary over-accounting, not a lifetime or correctness issue.

The current checks show conventions, eligibility and report passing; platform build jobs are skipped by the current path-filtered workflow. I have not run a full build or a title test, so this is a source review rather than a full-CI result. I see no blocker in the reviewed cleanup change.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5550756005 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5997#pullrequestreview-5550756005). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-16T16:33:16Z. **Review:** COMMENTED --- Reviewed #5997 at `fd9525a2e` and compared it with #5998. I do not see a lock-order cycle or a resource-lifetime regression in the cleanup path: - `cachedStorageTexture` releases the storage-cache mutex before removing shared resources and taking the sampled-texture mutex. `cachedTexture` obtains its storage source before taking the sampled-texture mutex, and `TextureCacheUsage` releases that mutex before reading storage-cache accounting. - The `evicted` vector keeps each image alive while `RemoveImage` and `dropUncachedViews` run. Resources returned by `RemoveImage` are retained by the active recorder before the sampled-cache views are erased; descriptor resources and caller-held views therefore keep their images alive for recorded work. - #5997 and #5998 have a clean merge preview. In the combined path, #5998 can conservatively charge an evicted image while the sampled cache still holds a view, before #5997 drains that view; I see this as temporary over-accounting, not a lifetime or correctness issue. The current checks show conventions, eligibility and report passing; platform build jobs are skipped by the current path-filtered workflow. I have not run a full build or a title test, so this is a source review rather than a full-CI result. I see no blocker in the reviewed cleanup change.
adriadam10 commented 2026-10-16 20:29:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T20:29:59Z.


Checked the diff, the lock order (the new drain takes the sampled mutex after the storage mutex is released, never nested), and ran the area's tests on Linux (RADV): agc_driver_sampled_cache_budget and agc_driver_resource_cache_storage_admission pass with the change and fail with ShaderResources.cpp reverted, matching @coltken95's lavapipe run. The only failure in the scope, agc_driver_tessellation, segfaults inside the RADV pipeline-library link and is unrelated to this change. Merging once the full Build is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6224117173 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5997#issuecomment-6224117173). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-16T20:29:59Z. --- Checked the diff, the lock order (the new drain takes the sampled mutex after the storage mutex is released, never nested), and ran the area's tests on Linux (RADV): `agc_driver_sampled_cache_budget` and `agc_driver_resource_cache_storage_admission` pass with the change and fail with `ShaderResources.cpp` reverted, matching @coltken95's lavapipe run. The only failure in the scope, `agc_driver_tessellation`, segfaults inside the RADV pipeline-library link and is unrelated to this change. Merging once the full Build is green.
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!5997
No description provided.