fix(agc): release evicted depth plane copies and scale their budget #25534
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/25534"
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 Mouhand-Kaddo on 2026-11-22T07:50:14Z.
What
Sampling layered depth surfaces through
DepthPlaneCopyleaked gigabytes of VRAM intoSharedResourceCacheand thrashed on >4 GiB GPUs.In Demon's Souls (
PPSA01342,OUTPOST PASSAGE), the title samples 21 active 16 MiB depth plane copies (336 MiB of images plus 336 MiB of staging = 672 MiB). BecauseevictPlaneCopiesused a hardcoded 256 MiB budget (512 MiB active-frame ceiling), copies evicted continuously within a single frame. On each eviction or replacement,DepthPlaneCopy::release()cleared itstexturesmap without marking externally referencedTextureviews as released (NoteReleasedTexture), soSharedResourceCachekept every evictedOwnedImagealive indefinitely. Over two minutes of gameplay on a 16 GiB RX 6900 XT,vkAllocateMemory depth plane copyleaked to 6.76 GiB, forced sampled textures down to their 2,048 MiB floor with heavy eviction churn, stalled for 10+ seconds, and crashed withradv/amdgpu: Not enough memory for command submission(VK_ERROR_DEVICE_LOST).Changes:
NoteReleasedTextureandResourceCache::DropReleasedTexturesinShaderResources, and checktextures[i]->Released()before thesurface.depthshortcut infastRevalidateandfastRevalidateEach.DepthPlaneCopy::release(), mark any externally referencedTexture(use_count() > 1) released viaNoteReleasedTexture(texture, address)(guarded insidenoexcept).DepthSurfaceTexture, unlocksurfacesMutex()and sweepSharedResourceCache().DropReleasedTextures(&stale)whenever a copy was replaced or evicted (keeping displaced sets on any active recordingRecorder), so copies evicted during a resource-cache hit (ReuseLookupHolds) are released without waiting for a subsequentInsert.evictPlaneCopiesaccounting and eviction tocontext.device, and addDepthPlaneCopyBudget(matchingBufferPool::DeviceBudget): whenAPS5_DEPTH_PLANE_COPY_MIBis unset, scale the default budget tomax(256 MiB, heapBudget / 16)on discrete GPUs ormax(256 MiB, heapBudget / 64)on integrated/unified heaps, clamped byVK_EXT_memory_budgetwhen reported. ExplicitAPS5_DEPTH_PLANE_COPY_MIBvalues (including0,1, and empty string) keep their existing behaviour.docs/dev/ENVIRONMENT.mdand record the unmeasured budget heuristic and release details indocs/dev/debt/changes/fix-agc-depth-plane-copy-release-budget.md.ViewedArrayWindow) touch theDepthPlaneCopyconstruction line atDepthSurface.cpp:4782; they address orthogonal issues and compose cleanly with this fix.Tested
Arch Linux (
7.3.5-arch1-1), Intel Core i7-13700K, AMD Radeon RX 6900 XT (RADV NAVI21), Mesa26.3.1-arch1.2, Release build (-DBUILD_TESTING=ON), basemainc880e0e50fe7.agc_driver_depth_plane_sampling_evicting(FrameCopiesCase,APS5_DEPTH_PLANE_COPY_MIB=1): verifies a sampled depth-plane copy is held by bothplaneCopies()andSharedResourceCache(use_count() >= 3), expires when evicted on a new copy insert, and also expires when evicted during aSharedResourceCachehit (Texture::TakeReuseLookupCounts()held == 1 && changed == 0, cache size drops without anInsert).agc_driver_graphics_tests(depthPlaneCopyBudgetTests): covers discrete heap sizes, 256 MiB floor, host-only heap, unified/system memory heap, integrated GPU flag, andVkPhysicalDeviceMemoryBudgetPropertiesEXTclamping.ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationlayer1.4.363,VK_LOADER_DEBUG=layer,ctest --test-dir build -R "^(agc_driver_depth_plane_|agc_driver_graphics_tests$|agc_driver_sampled_cache_budget_|agc_driver_resource_cache_)" -V):main(c880e0e50fe7): 34/34 passed,Insert instance layer "VK_LAYER_KHRONOS_validation"logged on every test, 0was not foundlines, 0VUID-errors.3057fe82db): 34/34 passed,Insert instance layer "VK_LAYER_KHRONOS_validation"logged on every test, 0was not foundlines, 0VUID-errors.tools/debt_fold.py --checkandtools/check_conventions.py --base upstream/main: passed.PPSA0134201.004.000,OUTPOST PASSAGE,APS5_OUTPUT_RESOLUTION=1920x1080,ANYPS5_PRESENT_MODE=immediate, warmed shader cache, unprofiled) —tools/trace_digest.py:main (
c880e0e50f) — crashes at 125.9 s with VK_ERROR_DEVICE_LOST after 10 s stallthis change — runs full 213 s cleanly; steady-state p50 413–436 ms (-34% to -43%), GPU busy 178–195 ms (-42% to -46%)
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)Created with gemini-4-neon in T3 Code.
Summary by CodeRabbit
New Features
Bug Fixes
Documentation
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T08:01:44Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: make the initial eviction check per-device so the current device’s copies are always budgeted.
What I ran
3057fe82db1fd9912615b612b5ba588a88791f8ausing the prepared diff and pinned repository reader.Results
Findings
Blocking
core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp:2876:evictPlaneCopiesreturns early when the globalcopiesmap has at most one entry. The subsequent accounting and eviction are per device, so if device A has one copy and device B has one or more, device A's copy is never checked against its budget. This bypasses the newly introduced per-device budget and can retain over-budget images for that device. Base the early return on the count of copies belonging tocontext.device, or remove the early return and let the per-device total determine whether eviction is needed.Non-blocking
None.
Not verified
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppandcore/libs/prx/libSceAgcDriver/tests/Graphics.cppwas excluded from the review bundle; only targeted ranges at the pinned head were read through the reader. Other changed files were read from the bundle or targeted reader ranges.To get this to a good state
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T08:54:08Z.
Review: APPROVED
Reviewed — looks good
Nothing in the inspected changes blocks merging; the changed source regions support the cache release and per-device budget behavior, and the description reports successful checks that I did not run.
What I ran
Reviewed head
084d326bdd2246463e0b0d45081f66ee1e4c4574usingrepo_read.pyto inspect the prepared diff and targeted source ranges. No build or tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The full contents of
ShaderResources.cppandtests/Graphics.cppwere excluded from the review bundle; only changed regions and relevant helpers were read. No tests were run here. Other changed files were read in the prepared bundle. The author-reported Vulkan tests, performance traces, and convention checks were not independently verified.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-29T11:54:18Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the inspected code supports merging, while reported tests and performance measurements were not run by me.
What I ran
Reviewed head
198a1f6cc1dd0ae9e00549ea56b045dc491cc555using the prepared diff andrepo_read.pyreader. I did not run commands or tests.Results
Findings
Blocking
None.
Non-blocking
(dirty), and both traces note a metadata change at interval 3. Provide matched baseline and change captures with consistent scene and environment metadata to support the reported performance improvement.Not verified
DepthSurface.cpp,ShaderResources.cpp,Graphics.cpp, andDepthPlaneSampling.cpp. I did not read every line of those files.ShaderResources.cpp,Graphics.cpp, andDepthPlaneSampling.cppwas excluded from the prepared files because each was too large; I used the pinned reader for relevant ranges. The manifest marks all other changed files as included, but their full texts were not available through the review-folder listing.To get this to a good state
Nothing is required. Optional: provide matched baseline and change trace captures so the performance claim can be checked.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-03T11:50:39Z.
Review: COMMENTED
Reviewed — comments
The change has no verified blocking defects; the performance captures and traces were not available for independent review.
What I ran
Reviewed head
6710f2593f2a5c8beb7a58030944cf82e1bfa39eusing the prepared diff and files, plusrepo_read.pyat the pinned head for excluded source ranges. I ran no tests or builds.Results
files.jsonwere reviewedNegative control
Not run; no tests were run.
Findings
Blocking
None.
Non-blocking
None.
Sources
Reviewed the changed code and documentation at the pinned head, including
DepthSurface.cpp,ShaderResources.cpp,Graphics.cpp, andDepthPlaneSampling.cpp.Not verified
I did not independently verify the author-reported test results or performance measurements. The prepared review folder excluded no files by rule; full text was included for six changed files, and the two oversized files (
ShaderResources.cppandGraphics.cpp) were read throughrepo_read.pyfor relevant ranges.To get this to a good state
Nothing is required. Optional: provide the performance captures and traces referenced by the report so those measurements can be independently checked.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-03T12:13:10Z.
Review: COMMENTED
Reviewed — no blocking findings
The code inspection found no verified blocking defect; the supplied performance summaries do not clearly identify a run of the reviewed head.
What I ran
Reviewed head:
7a9c6c34ee9964ee724960652e8fed663cdf55f7; base:main. I inspected the prepared review artifacts and changed source hunks usingrepo_read.py. No build or tests were run; no merged preview was checked. The supplied test and performance results are author-reported.Results
Negative control
Not run; no test was executed or modified.
Findings
Blocking
None.
Non-blocking
c880e0e50fe7 (dirty), rather than the reviewed head, and reports 3840×2160 while the description lists 1920×1080. A matching performance report would make the evidence for this budget change clearer. Changed line:core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp:5351(source at reviewed head).Sources
The budget calculation is at DepthSurface.cpp, line 5351. Cache release and sweeping changes are in the reviewed diff at
core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cppandcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp.Not verified
No tests, builds, GPU runs, or console behavior were independently verified. All eight changed files listed as reviewed were inspected; two files whose full text was not staged in
files/were inspected throughrepo_read.py.files.jsonlists no excluded files.To get this to a good state
Nothing is required. Optionally, provide a performance digest tied to the reviewed head and reconcile its resolution metadata with the stated test configuration.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-03T12:18:28Z.
Review: COMMENTED
Actionable comments
APS5_DEPTH_PLANE_COPY_MIBis set.cb7f4f0c-6b3b-4e76-a97e-4e4569d2cc32Reviewing files that changed from the base of the PR and between
198a1f6cc1and7a9c6c34ee.core/libs/prx/libSceAgcDriver/Graphics/include/DepthSurface.hppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/execution/DepthPlaneSampling.cppdocs/dev/ENVIRONMENT.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-03T12:34:14Z.
Review: COMMENTED
Actionable comments
f44f4502-9663-4b87-b669-31bd9389bea4Reviewing files that changed from the base of the PR and between
7a9c6c34eeandbb819e686d.core/libs/prx/libSceAgcDriver/tests/Graphics.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-03T12:35:26Z.
Review: APPROVED
Reviewed — looks good
The reviewed changes have no verified blocking defects, and the inspected evidence supports merging.
What I ran
Reviewed head
bb819e686d75baa1aa6760994ef68c5cd4a132b0. Inspected the prepared diff, manifest, changed-file excerpts, and relevant pinned source context withrepo_read.py. No tests or builds were run.Results
Findings
Blocking
None.
Non-blocking
None.
Sources
Not verified
No tests, build, or console run was performed. The author-reported test and performance results were not independently confirmed. All eight changed files listed as reviewed in
files.jsonwere inspected through the prepared diff; the full text ofShaderResources.cppandtests/Graphics.cppwas not present in the review folder, so their changed hunks were reviewed from the diff.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T13:13:58Z.
Review: COMMENTED
The same scalar-buffer-base and depth-plane sampling CTest cases passed on main and the preceding PR head on Linux Mesa lavapipe with Khronos validation 1.4.369. Both logs show the loader inserting validation and contain no missing-layer diagnostic or VUID. The current head changes one separate Graphics fixture assertion path. The implementation and the two tested cases are identical between the heads.
AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.