fix(agc): reclaim idle images safely during cache creation #7800
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7800"
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 santhoshkumar-dev on 2026-10-19T08:05:55Z.
What
Image creation can fail while its cache still holds idle images: ordinary recovery cannot reuse the cache lock held by the creation call. Permit same-cache recovery only inside a new image's allocation, after lookup iterators are no longer used. Buffer uploads, hit refreshes and write-back allocations keep conservative permissions.
Thread that permission through
OwnedImage::Allocate,AllocateImageMemory,TakeImageMemoryandAllocateMemory, preserving main's image pooling, allocated-memory-type feedback and host-memory fallback. Cover initial sRGB expansion and repacked copies as well as sampled, block/depth-copy and storage-image allocations.Recovery tries other cache/resource/device locks without waiting, preserves caller-held sampled images, pending storage results and recorded references, and counts allocations released by the caches before trimming the pool and retrying. The reclaim reserve saturates at the
VkDeviceSizelimit.This incorporates Queuse's reviewed current-main composition and its copy-recovery regressions, with original authorship retained. The six commits are now rebased onto main
093149c5bd; range-diff against the previousd669999c01head reports all six unchanged, with authorship preserved. This addresses the requested allocator rebase, committed conflict markers, unrelated debt paragraph and inaccurate validation note.Tested
Windows 11 Pro 10.0.26200, WinLibs MinGW-w64 GCC 15.2.0 r7 UCRT, Ninja Release, bundled dependencies,
BUILD_TESTING=ON,ANYPS5_ENABLE_SPIRV_TOOLS=OFF. GPU: AMD Radeon RX 6700 XT, AMD Vulkan 26.8.1 / Windows driver 32.0.21045.5002. Khronos validation layer 1.4.363.0 loaded from the signed LunarG SDK.093149c5bd: built the four focused executables; 14/14 existing checks passed, no skips, 18.06 s.a2ec2a3818: full default Windows build passed, including dependent AGC execution tests. 18/18 focused checks passed, no skips, 18.94 s.ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, loader layer logging andctest -V. Both logs confirm the validation DLL loaded; neither contains a missing-requested-layer warning or anyVUID-validation error.d669999c01: removing only the initial sRGB/repacked allocation permissions made both copy regressions fail withan image allocation did not identify itself to the recovery callback. That control was restored before publication and was not repeated for this source-identical rebase.Earlier AMD/NVIDIA/RADV and title runs remain historical evidence in the review comments. No fresh title, Linux/macOS runtime, full CTest-suite or performance claim is made for this head.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-19T08:59:57Z.
Rebase handoff — rebased onto current
main(authorship unchanged). The nine conflicts resolved:main'sAllocateMemorysignature extended with your trailingnewImageflag and forwarded through theAllocateImageMemoryhelper (the four construction sites markedtrue; the depth/resources sites keepmain's unflagged form, which your diff left unmarked too); both test-mode flags kept inSampledCacheBudget; and the PR branch's own badly-resolved debt merge deduplicated.Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV): builds; conventions pass; full suite green apart from the four knownmainregressions (#5444 Mesa, #7584 BDA, #7766, #7784), none from this PR.To pick it up:
Head is
0c04dcf46.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T17:32:29Z.
Review: CHANGES_REQUESTED
Thanks for the extension of #6174. Blockers before this can go on:
docs/dev/debt/libSceAgcDriver.md:49-53has committed conflict markers (<<<<<<< HEAD/=======/>>>>>>> c12897b53). It also adds an unrelated "Untracked surfaces in the fast revalidate" entry next to the allocation-recovery one; keep only the line for this change. The recovery line says the paths "have not been compiled or run", which contradicts the Tested section: update it to what was actually run.maininCMakeLists.txt,BufferPool.hpp/.cpp,DepthSurface.cpp,MultisampleTarget.cpp,Resources.cpp,Texture.cppandtests/execution/SampledCacheBudget.cpp.mainnow routes image allocations throughAllocateImageMemory(context, allocation, mask, operation)andAllocateMemorytakeshostType/allocatedType, so thenewImageflag and the depth/stencil/MSAA/render-target sites need to be redone on top of that rather than mechanically rebased. @blawesom pushed such a rebase (blawesom/AnyPS5branchrebase/7800,0c04dcf46, full suite green on RADV apart from the knownmainfailures); you can fast-forward to it or redo it, then re-run the ten listed tests on the result.After that, the review of the lock changes (
TryRemoveImage, the*CacheReclaimableholds) will be against the rebased head.Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-19T19:06:33Z.
Rebase handoff, with one bug in the branch itself — rebased onto current
main(585075cb7, authorship unchanged). This was a real semantic merge; here's what it took and what I found.The conflict:
main'sad11cb1b3and this PR evolvedBufferPool::AllocateMemoryin opposite directions —mainadded the host-memory fallback (hostType/allocatedTypeparameters and theAllocateImageMemorywrapper), this PR addednewImage(reclaim may only reuse a held cache lock at new-image construction). Resolution: the union signature carries all three parameters;AllocateImageMemorygainedbool newImage = falsethreaded to its pool call; your four new-image sites (texture, block copy, depth copy, storage texture) passtruethrough the wrapper; the rest (depth target, stencil copy, depth plane copy, multisampled target, render target, attachment proxy) keepmain's wrapper with the default. Sincemain's wrapper already routes throughBufferPool::AllocateMemory, your recovery applies at every one of those sites — the two designs compose rather than compete.The branch bug: your committed tree carries conflict markers in
docs/dev/debt/libSceAgcDriver.md(lines 49–53, wrapping an empty HEAD side — looks like an earlier self-rebase againstc12897b53left them behind). The rebase drops them and keeps your two entries.Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV): builds; the merged recovery path works end-to-end —agc_driver_recover_sampled_allocationlogsvkAllocateMemory texture recovered: allocation=262144 reclaimed=2621440 released=262144 initialResult=-2 attempts=3and both recovery tests pass, along with the other foursampled_cache_budgetmodes; full suite green apart from the four knownmainregressions (#5444 Mesa, #7584 BDA, #7766, #7784), none from this PR; conventions pass.That run is also the first time the integrated result has been compiled and run anywhere, I believe — your debt entry for the recovery says "not been compiled or run on hardware in this local integration", which you may want to refresh now that it has been (RADV here; other stacks still unverified).
To pick it up:
Head is
8a29005f5.Imported from boykopovar/AnyPS5. Originally posted by santhoshkumar-dev on 2026-10-20T03:11:40Z.
Addressed the review changes in 828d2ad6f.
mainatc942b37c0.AllocateMemoryretainshostType/allocatedType, andAllocateImageMemoryforwardsnewImagefrom the four image-construction sites. Other allocation sites keep the conservative default.Validation on Debian 13, GCC 14, Release, Mesa 25.0.7 lavapipe (LLVM 19.1.7), with Khronos validation enabled:
main; all 12 passed on this commit, including both sampled/storage allocation-recovery tests. No skips.ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1, andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation. Neither log contained missing-layer warnings orVUID-errors.This run used lavapipe; the AMD hardware results referenced in the debt note are the earlier reported runs.
Imported from boykopovar/AnyPS5. Originally posted by Queuse on 2026-10-21T23:36:32Z.
Current-main composition,
36ffc6819d, maina6dcea9279; original authorship, image pooling and memory-type feedback preserved. Adds recovery for initial sRGB/repacked copies.Baseline: 14 matching existing cases pass. Candidate: 18/18 pass on Windows 11, RTX 3050 Laptop/617.42, GCC 15.2.0-r7; no skips, missing validation layer or VUIDs. All 4 recovery fixtures release exactly 262144 bytes after 2 injected failures, retaining held images and pending storage results.
Copy fixtures check ownership before lookup can promote snapshots to storage views; a pre-pressure control confirms this transition with zero recovery requests. Removing only copy allocation permissions fails both cases; restoring passes 18/18. No title/Linux/full-suite/performance claim. AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by santhoshkumar-dev on 2026-10-22T08:11:02Z.
Addressed the requested allocator rebase in
d669999c01, based on current maind6eafa54d0.36ffc6819dcomposition and copy-recovery regressions with original authorship; all six commits have equal range-diffs after rebasing.newImagethroughOwnedImage::Allocate,AllocateImageMemory,TakeImageMemoryandAllocateMemory. Initial sRGB/repacked copies now have the same scoped permission as the other new-image paths.Local Windows 11 / RX 6700 XT / AMD Vulkan 26.8.1 validation: 14/14 baseline tests, 18/18 candidate tests, and 18/18 after restoring the negative control. All runs use required Vulkan, disabled shader cache and the actual Khronos validation layer; no skips, missing-layer warnings or VUIDs. Removing only the sRGB/repacked permissions makes both corresponding tests fail as expected.
The full default Windows build passed. Conventions, whitespace and registration audit passed (1,173 test executables, none built and unregistered). No fresh title/Linux/full-suite/performance result is claimed.
The updated head is ready for the lock/recovery review requested above.