D3D12.X: drain present queue after Present before ResizeBuffers #711
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!711
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-711"
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?
@RandomGithub12309 on GitHub · 2026-11-24 03:59 UTC · original
RandomGithub12309:d3d12x/drain-present-before-resize→main· +305 −35 · 1 files · 1 commits · openFix a pre-existing swap-chain synchronization bug on
main(surfaced during review of #674; isolated here from #674's triple-buffering change) whereq.Signal(&p.fence, p.value)ran beforesc.Present(0, DXGI_PRESENT(0))andensure_swapchaincalledsc.ResizeBufferswithout draining the present queue first.Because DXGI's
Presentsubmits internal GPU queue work on the swap-chain back buffer afterp.fencewas signaled, waiting onp.valuedid not wait forPresentto retire. WhenResizeBuffersran (or whenpresent_nowmoved to another queue), old back-buffer allocations could be freed while still referenced by DXGI's in-flightPresentwork (D3D12 error921/OBJECT_DELETED_WHILE_STILL_IN_USE).What is in it
crates/xcl/src/hle/d3d12x/present.rs:present_frame_onfrompresent_nowand movep.value += 1; q.Signal(&p.fence, p.value)aftersc.Present(0, DXGI_PRESENT(0))sop.fenceorders behind DXGI'sPresentqueue work (while still signaling whenPresentreturns an error so the submitted copy command list remains fenced).drain_queue(p, timeout_ms)to signal a newp.fencevalue onp.queue, wait viafence::wait, and clearp.copy_sourceandp.dumps; extractdrain_and_reset_for_queue(slot, queue, timeout_ms)for cross-queue switch draining, retaining the old presenter when a drain fails with a non-Removederror (e.g. timeout) so in-flight swap-chain,copy_source, and dump resources stay alive until the GPU finishes.drain_queue(p, 2000)beforesc.ResizeBuffers(2, ...)inensure_swapchain(preservingp.disabled |= ...on device removal) anddrain_and_reset_for_queuebefore droppingoldon queue switches inpresent_now.FRAME_DUMP_TEST_LOCKand unit/GPU regression tests covering multi-resize + frame dumps (present_and_resize_with_frame_dumps_drains_queue_cleanly), cross-queue switch draining (queue_switch_drains_old_presenter_before_recreating_swapchain), and drain/queue-move timeout retention andResizeBufferserror recovery (drain_queue_and_resize_error_paths_preserve_in_flight_state).Tested
rustc 1.100.0 (0ef1bc386 2026-11-09)stable-x86_64-pc-windows-msvc(debug for unit tests, release forsmoke.ps1).cargo test -p xcl --lib hle::d3d12x::present -- --test-threads=1 --nocaptureatf98dc20: 9 passed, 0 failed, 0 ignored (0 skipped).cargo test --workspace -- --test-threads=4 --skip fuzz_validate_and_gpuatf98dc20:xcllib 940 passed, 0 failed, 25 ignored (SKIPPEDon this adapter: wave64-only GPU tests andpso_measurement_compiles_an_exact_synthetic_recordbecause Windows Developer Mode is off;gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_{0..3}excluded due to pre-existing0x8007000ECreateComputePipelineStateOOM on this adapter).scripts/smoke.ps1release build atf98dc20vsmain(8e87fc7).Regression run
Not tested
d3d12SDKLayers.dll/ Graphics Tools not installed;0x887A002D), AMD/Intel/wave64 GPUs, Wine/Linux, and gameplay beyond the 60 s smoke window.AI use
main, ran the tests andscripts/smoke.ps1on the hardware above, and updated this description.@thehollowedone on GitHub · 2026-11-24 04:07 UTC · original
Tested
I reran the synthetic frame-capture fixture from #674 on the standalone fix
091a941, with the D3D12 debug layer active.ResizeBufferscalls, with zero D3D12 validation errors.In each run, all 14 BMP captures matched their expected dimensions and all 250,944 sampled pixels matched. Both scratch tests passed 1/1 with no skips. Runtime code was stock.
Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti / 621.35, Rust 1.99.1 MSVC, debug.
cargo test --offline --locked -p xcl --lib hle::d3d12x::present::scratch_resize::check -- --exact --nocapture --test-threads=1withXCL_FRAME_DUMP=2.Not tested
Queue-drain timeout, device removal, and retail performance.
AI use
Codex with GPT-6.2 Sol adapted the scratch fixture, ran the tests, and drafted this report.
@iggyvilla on GitHub · 2026-11-24 07:53 UTC · original
Read of
e21f158(nothing built or run by me).Overlap with #674. This is the drain / signal-after-
Presentpart of #674 (present_frame_on,drain_queue, the drain beforeResizeBuffers), on the two-buffer presenter. A tree merge of the two heads conflicts inpresent.rs, so they cannot both land as they stand. If #674 goes first, what #711 has that #674 does not is the|=onp.disabledafter a failed drain (present.rs:605,:619; #674 assigns with=at:631, which can clear thedisabledthat a failedSignaljust set) and the test helpers. If #711 goes first, #674 has to drop its copies of the drain hunks.Queue move.
drain_and_reset_for_queueignores the result ofdrain_queue(old, 1000)and then sets*slot = None(:657-667). On a timeout that releases the swap chain with aPresentstill queued, which is the error 921 case this PR exists to remove. Returningfalsewithout droppingoldwhen the drain fails with anything butRemoved(thep.queue != queueguard then skips that frame) would close it; the same point is on #674.Tests.
assert_no_debug_errorsdoes nothing without the D3D12 debug layer (the PR says0x887A002Don the author's machine), so a green run shows the fence/drain order but not the 921 itself; a run on a machine with Graphics Tools installed, named in the report, would show it.AI use: Claude Code, Claude Sonnet 5.5, read the code at the head above; the points are mine.
@iggyvilla on GitHub · 2026-11-24 09:31 UTC · original
Read of
e21f158(nothing built or run by me).Overlap with #674. This is the drain / signal-after-
Presentpart of #674 (present_frame_on,drain_queue, the drain beforeResizeBuffers), on the two-buffer presenter. A tree merge of the two heads conflicts inpresent.rs, so they cannot both land as they stand. If #674 goes first, what #711 has that #674 does not is the|=onp.disabledafter a failed drain (present.rs:605,:619; #674 assigns with=at:631, which can clear thedisabledthat a failedSignaljust set) and the test helpers. If #711 goes first, #674 has to drop its copies of the drain hunks.Queue move.
drain_and_reset_for_queueignores the result ofdrain_queue(old, 1000)and then sets*slot = None(:657-667). On a timeout that releases the swap chain with aPresentstill queued, which is the error 921 case this PR exists to remove. Returningfalsewithout droppingoldwhen the drain fails with anything butRemoved(thep.queue != queueguard then skips that frame) would close it; the same point is on #674.Tests.
assert_no_debug_errorsdoes nothing without the D3D12 debug layer (the PR says0x887A002Don the author's machine), so a green run shows the fence/drain order but not the 921 itself; a run on a machine with Graphics Tools installed, named in the report, would show it.AI use: Claude Code, Claude Sonnet 5.5, read the code at the head above; the points are mine.
@RandomGithub12309 on GitHub · 2026-11-25 00:57 UTC · original · edited 2026-11-25 01:03 UTC
Updated at
f98dc20(rebased ontomain8e87fc7):drain_and_reset_for_queue: on a non-Removeddrain failure (e.g. timeout), the old presenter and its swap-chain /copy_source/ dump resources are now retained andfalseis returned instead of dropping*slot.drain_queue_and_resize_error_paths_preserve_in_flight_state.present.rs.@JJAutoCompare on GitHub · 2026-11-25 06:18 UTC · original
Empirical test report (
f98dc204)Hardware / environment
f98dc204d358723e497259e6fd3c8203f4aa146c, detached and clean. Windows 11 Enterprise Evaluation x64, build 26200, non-interactive Session 0, AMD Ryzen 7 3800X.XCL_ADAPTER=A770.Commands and results
cargo test --workspace --no-runexited 0 outside the Arc lock. This compiled the test binaries without running tests.xcl-77aca8ccb20e299f.exe --exact <test> --test-threads=1 --format terseonce per test. Each name below starts withhle::d3d12x::present::frame_dump_tests::.XCL_ADAPTER=NONE_CPU_ONLY:reports_without_frame_dumps_remain_readableexited 0. 1 passed, 0 failed, 0 ignored, 0 skipped.Invoke-ArcTest.ps1 -Test,XCL_ADAPTER=A770andRUST_TEST_NOCAPTURE=1:mapped_frame_dump_distinguishes_dark_bright_and_undecoded_contentexited 0. 1 passed, 0 failed, 0 ignored, 0 skipped.present_and_resize_with_frame_dumps_drains_queue_cleanly,queue_switch_drains_old_presenter_before_recreating_swapchain, anddrain_queue_and_resize_error_paths_preserve_in_flight_stateeach exited 0. The wrapper exited 0.SKIPPEDline, leaving 2 tests that ran without skipping.Observed behavior
All three HWND tests skipped at
CreateSwapChainForHwndwith0x887A0022. The resize, queue-switch, and error-path assertions were not reached.Not tested
Full GPU workspace suite, interactive desktop presentation, and game smoke runs.
AI use: Verified with T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high). Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against pr711-focused.log and published.
@DavidM1911 on GitHub · 2026-11-25 11:54 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)Thanks!
@gut0to on GitHub · 2026-11-24 17:13 UTC · original
On
crates/xcl/src/hle/d3d12x/present.rsline 662 (outdated):Could we keep the old presenter until this drain succeeds? If the wait times out, the queue may still be executing the copy or present, but this code drops the presenter immediately, including
copy_sourceand pending dump resources. Those D3D12 resources must stay alive until the GPU finishes using them. Please retain the presenter after a timeout and reset the slot only after a successful drain. AI-assisted review: I checked this path againstdrain_queueand the presenter-owned resource lifetimes.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.