You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(agc): release evicted depth plane copies and scale their budget - #1248
Source commit: 198a1f6cc1dd0ae9e00549ea56b045dc491cc555. The import branch preserves this fetched upstream PR snapshot. The description and validation below are copied from upstream; no new code changes or test runs were made for this import. Original reviews, discussions, and attachments remain at the linked upstream PR.
What
Sampling layered depth surfaces through DepthPlaneCopy leaked gigabytes of VRAM into SharedResourceCache and 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). Because evictPlaneCopies used 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 its textures map without marking externally referenced Texture views as released (NoteReleasedTexture), so SharedResourceCache kept every evicted OwnedImage alive indefinitely. Over two minutes of gameplay on a 16 GiB RX 6900 XT, vkAllocateMemory depth plane copy leaked to 6.76 GiB, forced sampled textures down to their 2,048 MiB floor with heavy eviction churn, stalled for 10+ seconds, and crashed with radv/amdgpu: Not enough memory for command submission (VK_ERROR_DEVICE_LOST).
Changes:
Expose NoteReleasedTexture and ResourceCache::DropReleasedTextures in ShaderResources, and check textures[i]->Released() before the surface.depth shortcut in fastRevalidate and fastRevalidateEach.
In DepthPlaneCopy::release(), mark any externally referenced Texture (use_count() > 1) released via NoteReleasedTexture(texture, address) (guarded inside noexcept).
In DepthSurfaceTexture, unlock surfacesMutex() and sweep SharedResourceCache().DropReleasedTextures(&stale) whenever a copy was replaced or evicted (keeping displaced sets on any active recording Recorder), so copies evicted during a resource-cache hit (ReuseLookupHolds) are released without waiting for a subsequent Insert.
Scope evictPlaneCopies accounting and eviction to context.device, and add DepthPlaneCopyBudget (matching BufferPool::DeviceBudget): when APS5_DEPTH_PLANE_COPY_MIB is unset, scale the default budget to max(256 MiB, heapBudget / 16) on discrete GPUs or max(256 MiB, heapBudget / 64) on integrated/unified heaps, clamped by VK_EXT_memory_budget when reported. Explicit APS5_DEPTH_PLANE_COPY_MIB values (including 0, 1, and empty string) keep their existing behaviour.
Update docs/dev/ENVIRONMENT.md and record the unmeasured budget heuristic and release details in docs/dev/debt/changes/fix-agc-depth-plane-copy-release-budget.md.
Arch Linux (7.3.5-arch1-1), Intel Core i7-13700K, AMD Radeon RX 6900 XT (RADV NAVI21), Mesa 26.3.1-arch1.2, Release build (-DBUILD_TESTING=ON), base mainc880e0e50fe7.
New tests:
agc_driver_depth_plane_sampling_evicting (FrameCopiesCase, APS5_DEPTH_PLANE_COPY_MIB=1): verifies a sampled depth-plane copy is held by both planeCopies() and SharedResourceCache (use_count() >= 3), expires when evicted on a new copy insert, and also expires when evicted during a SharedResourceCache hit (Texture::TakeReuseLookupCounts()held == 1 && changed == 0, cache size drops without an Insert).
main (c880e0e50fe7): 34/34 passed, Insert instance layer "VK_LAYER_KHRONOS_validation" logged on every test, 0 was not found lines, 0 VUID- errors.
This branch (3057fe82db): 34/34 passed, Insert instance layer "VK_LAYER_KHRONOS_validation" logged on every test, 0 was not found lines, 0 VUID- errors.
tools/debt_fold.py --check and tools/check_conventions.py --base upstream/main: passed.
The default budget uses device-local heap size, optional reported budget, GPU type, and a 256 MiB minimum. Eviction applies to copies for the current device. Tests cover budget calculations, and the environment documentation describes the default and retention rule.
Copies track guest-plane addresses and notify the resource cache when externally retained textures are released. Resource revalidation rejects released textures before depth-surface checks. Replacement or eviction drops released cache entries and retains resulting resources in an active recording. Sampling tests check cache retention, reuse, and eviction.
Change: Bug fix
Merge Risk: Minimal · up to 198a1
This change scales the depth-plane copy budget with GPU memory and sweeps released copies from the resource cache sooner. No concrete merge-blocking problem was found, and new tests cover the budget and eviction paths. The default budget is still an unmeasured heuristic, which the PR documents.
Security architecture risk: Minimal · up to 198a1
AgcDriver now removes released depth-plane copies from reuse without relying on the shared cache to keep recorded GPU work alive. Eviction is limited to the current Vulkan device, and operators can still set a fixed cache budget. The reviewed paths did not establish a new security or failure-containment regression.
Security review details
Security Blast Radius
observed — A lookup can trigger eviction only within its device's plane-copy map. The follow-on sweep can remove entries anywhere in the process-wide shared resource cache, but only if they reference an already-released texture.
Resilience and Maintainability Implications
inferred — For the inspected paths, removal from the shared cache is not permission to destroy an in-flight image. Copy work either waits synchronously or retains the image and staging buffer in Recorder; recorded draws retain their shader resources, and submitted batches carry those references through completion.
Hardening Proposals
proposed — Make the existing shared-cache sweep retryable if collection fails partway through, so reclaiming released entries does not depend on a later release notification.
Rollout and rollback
observed — Operators who leave APS5_DEPTH_PLANE_COPY_MIB unset move from a fixed default to automatic sizing. Setting it to 256 before process startup restores the old numeric threshold, not the old cross-device policy or cleanup behavior. An explicit zero still disables budget eviction; it does not disable replacement cleanup.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Warning
Some tools did not complete. Review the errors below.
Cppcheck (2.22.0)
Cppcheck (2.22.0) exceeded its 180-second time budget. Findings from completed work are retained; remaining checks are incomplete.
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
Cppcheck interrupted; analysis of this file is incomplete
This review exceeded your plan’s limits and used usage-based reviews—free during trial, billed after paid activation unless disabled. Manage usage-based reviews.
Recent review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: defaults
Review profile: CHILL
Plan: Advanced
Run ID: 48290caf-e92e-4cf9-8c99-8030e16c8e4e
Commits
Reviewing files that changed from the base of the PR and between 4131f51 and 198a1f6.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 (c880e0e) — crashes at 125.9 s with VK_ERROR_DEVICE_LOST after 10 s stall
this 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