fix(agc): keep uncached storage images out of the resource cache #3473
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3473"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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.ClearCachedTexturesalso leaves resource-cache entries holding the images it clears. Invalidate those entries using the existingResourceCache::RemoveImagefrom #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
RemoveStorageImageand 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 productionShaderResources.cppandShaderResources.hppexactly 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, andagc_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
07297a54ain 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) withANYPS5_REQUIRE_VULKAN=1,--parallel 3,--timeout 30, and--no-tests=error. The test source exactly matches the contributor's commit; the production Git blobs match83c9eb7af.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
libsbuilt. All six focused tests passed without skips withANYPS5_REQUIRE_VULKAN=1. Replacing only the two production files with exact maina11c8f7fblobs 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 --checkpassed. 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
main(a11c8f7f); no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)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, soRemoveStorageImageduplicates it.Please rebase on main and drop the duplicate removal. What I'd keep, if it is still needed on top of #3474:
HasCachedStorageImages) that rejects sets binding an already-uncached storage image, including the early image evicted while building an oversized set;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.
Imported from boykopovar/AnyPS5. Originally posted by superhe11 on 2026-10-11T13:14:16Z.
@adriadam10 Updated in
83c9eb7af. Rebased onto maina11c8f7f(including #3474) and removed the duplicateRemoveStorageImageimplementation and eviction notification. The ordinary eviction path is now unchanged from main;ClearCachedTexturesuses the existingRemoveImage, 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:
an uncached image was admitted to the resource cache;an oversized storage descriptor set entered the resource cache;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.
Imported from boykopovar/AnyPS5. Originally posted by jweidenh on 2026-10-11T13:36:52Z.
I checked the rebased
83c9eb7af102d6cb9265fe09ea70faf1acf63cb3and 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, andlibs, with SPIR-V Tools enabled andANYPS5_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_admissionagc_driver_resource_cache_oversized_storage_admissionagc_driver_resource_cache_storage_clearagc_driver_storage_cache_budgetagc_driver_sampled_cache_budgetagc_driver_sampled_cache_budget_memoryFor the baseline control, I replaced only production
ShaderResources.cppandShaderResources.hppwith their exact Git blobs from maina11c8f7f70a0ed4e71504a89de69e8cdae687817, leaving the test fixture unchanged. All three regressions failed at their intended assertions:an uncached image was admitted to the resource cachean oversized storage descriptor set entered the resource cacheclearing storage images left their resources cachedAfter 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:
Host-pointer import probes succeeded. The logs also report unavailable
/dev/udmabufand 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.
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. TheInsertguard and theClearCachedTexturesinvalidation (reusingRemoveImagefrom #3474, storage mutex released first) look right, and @jweidenh's Linux run confirms it; merging.