graphics: release retired resources only after the command buffer their handles reach #2355
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!2355
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2355"
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?
@Nawid3333 on GitHub · 2026-11-17 17:13 UTC · original
Nawid3333:fix/release-after-commit→main· +72 −16 · 11 files · 1 commits · openProblem
A draw can record a buffer after that buffer has already been destroyed.
Code Violet (PPSA26528, #938) loses the device on an RX 9060 XT; with the device-loss diagnostics build, the last command the GPU started is a draw-indirect. A run with
--vulkan-validationdoes not lose the device; its first and only validation error is:Cause
All line numbers are at
15c8c6182.ExecutePreparedDrawtakes the draw's buffer handles first:PrepareGraphicsBindings, thenAcquireVertexBuffersand the index buffer (renderDraw.cpp:1107-1113).CreateBufferthen joins them, andJoinOverlapdeletes the old buffer (bufferCache.cpp:382-390, 408).DeleteBufferdefers the erase withDeferOperation(bufferCache.cpp:148), which stamps it withCurrentTick()(commandScheduler.cpp:207). Call that tick T.Wait(CurrentTick())does this for a stream-buffer wrap (commandScheduler.cpp:159-172). NeitherWaitnorFlushpops.PopPendingOperations()(renderDraw.cpp:1272/1363). T is complete by then, becauseWaitwaited for it. So the erase runs, and~Bufferdestroys theVkBufferat once (streamBuffer.cpp:110), while T+1 is still recording with it.Our closed #2224 moved the descriptor handles after these joins so that shader writes do not land in the retired buffer. That is about stale data; this change is about the retired buffer's lifetime, which matters for every handle taken before a join (vertex and index buffers too).
CheckSchedulerTimelineexpects exactly this order: a deferred operation is not released byWait(T), but is released at the next pop. That holds only if nothing taken before the restart is recorded after it.The same applies to every caller that defers the release of something a draw or dispatch may already hold:
DeleteImage)Change
DeferReleaseholds a release without a tick.StartOperation()stamps the held releases with the tick being recorded (the last submitted tick when nothing is recording), then pops as before. It replacesPopPendingOperations()at the start ofDrawIndex,DrawAuto,DispatchDirect,DispatchIndirectandProcessPssr.FinishandShutdownstamp held releases before their final submit, so they still drain everything.DeferRelease:DeleteBufferDropDeferOperationkeeps its exact tick. faultManager.cpp:122 consumes GPU results, and its area reuse waits on that tick, then pops (faultManager.cpp:69-71).Tests
CheckSchedulerTimeline(shader_recompiler_compute_tests --scheduler-only) gets a release that is deferred at T, followed byWait(T)andStartOperation(). It must not run while T+1 records, and must run exactly once after T+1 completes.DeferReleasestamping at once, asDeferOperationdoes on main, it fails:SchedulerTimeline failed at release across a restart: a release ran while the command buffer restarted after it still recordedshader_recompiler_compute_testssuite (keep-going, on15c8c6182) gives the same result with and without the change on an RX 9070 XT (Windows 11, clang-cl, with the harness change of #2038): 192 checks ok, and the same 4 failed checks, which are known failures of this machine's harness.Costs
A release becomes due when the tick stamped at the next draw, dispatch or PSSR start (or by
FinishorShutdown) has completed, and runs at the next pop after that. Before, it became due with the tick that was current when it was deferred. There are no extra waits or submits.In a game
pedrohenriquebragap ran a test build with this change on Code Violet (#938 comment): the
VkBuffer ... was destroyedvalidation error and the device loss both still occur. So this change does not fix that game's stop; it fixes the release ordering that theSchedulerTimelinetest shows. A trace build to find the code that destroys that buffer is with the reporter.Refs #938
Written with Claude Code (AI): Claude Code found the cause from the reporter's validation log, wrote the change and the test, and ran them; Codex and Claude Opus reviewed the design and the change.
🤖 Generated with Claude Code
@coderabbitai[bot] on GitHub · 2026-11-17 17:23 UTC · original · edited 2026-11-22 15:23 UTC
No actionable comments were generated in the recent review.
Walkthrough
CommandScheduler now buffers deferred releases and seals them into pending operations at operation boundaries and during shutdown. Renderer cleanup call sites use DeferRelease, and rendering entry points use StartOperation. The scheduler timeline test adds checks for when a deferred release callback runs.
Suggested reviewers:
nmzikChange: Bug fix
Merge Risk:
Minimal · up to
3865fDeferred resources are now released only after the command buffer that last recorded them has completed. This fixes the use-after-release when a command buffer restarts mid-draw. No concrete merge-blocking issue was found. In-game confirmation from the issue reporter is still pending.
Pre-merge checks:
4
#2224. It is closed and marked as historical context only. No active directly linked target remains, so no linked-issue coding requirements apply. The PR objectives state the …Full details: Title check
Explanation
The title names the main change: retired resources are released only after the command buffer that holds their handles has been recorded. The changeset adds DeferRelease and StartOperation, and switches release sites to them, which matches the title's intent. The title does not name the new API, but it is specific and accurate.
Full details: Description check
Explanation
The description explains the problem (a draw records a buffer after it was destroyed), the cause, the change (DeferRelease, StartOperation, and the nine release sites), the test (CheckSchedulerTimeline), and the costs. It is directly related to the changeset.
Full details: Linked Issues check
Explanation
The only linked issue is
#2224. It is closed and marked as historical context only. No active directly linked target remains, so no linked-issue coding requirements apply. The PR objectives state the same. This PR fixes a different defect: release lifetime of retired buffers, not the binding order of draw shader buffers. The acceptance criteria of#2224are therefore not evaluated here.Full details: Out of Scope Changes check
Explanation
Each changed file supports the stated objective of releasing retired resources only after the command buffer that holds their handles completes. commandScheduler.h and commandScheduler.cpp add DeferRelease, StartOperation, the held-release staging and sealing, and the Finish and Shutdown seal logic. bufferCache.cpp, textureCache.cpp, tiler.cpp, imageHeap.cpp, rayTracing.cpp, and renderPssr.cpp move the nine named release sites from DeferOperation to DeferRelease. renderDraw.cpp, renderCompute.cpp, and renderPssr.cpp replace PopPendingOperations with StartOperation at the draw, dispatch, and PSSR entry points. ShaderRecompilerComputeTests.cpp adds the CheckSchedulerTimeline case for the new behavior. No unrelated file or change appears in the summary. The PR description states that DeferOperation, faultManager, and priority operations are unchanged, and the summary does not contradict this. This assessment rests on the whole-PR summary and the PR description. Hunk-level diffs were not inspected in this pass. Changes since the previous reviewed head (
4ec06201) were not separately isolated, so the whole-PR file list was used.Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Share
3c2ea0a6-8be4-4292-868f-24bcec7d7890Reviewing files that changed from the base of the PR and between
4ec06201f6and3865f62334.src/graphics/host_gpu/renderer/commandScheduler.cpptests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
@Nawid3333 on GitHub · 2026-11-24 07:24 UTC · original
Game result: pedrohenriquebragap ran a test build with this change on Code Violet (#938 comment): the
VkBuffer ... was destroyedvalidation error and the device loss both still occur. So this does not fix that game's stop; it fixes the release ordering that itsSchedulerTimelinetest shows. A trace build to find the code that destroys that buffer is with the reporter (#938).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.