Repository navigation
D3D12.X: drain present queue after Present before ResizeBuffers - #711
RandomGithub12309 wants to merge 1 commit into
Conversation
|
Tested I reran the synthetic frame-capture fixture from #674 on the standalone fix
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. 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. |
091a941 to
e21f158
Compare
|
Read of Overlap with #674. This is the drain / signal-after- Queue move. Tests. AI use: Claude Code, Claude Sonnet 5.5, read the code at the head above; the points are mine. |
1 similar comment
|
Read of Overlap with #674. This is the drain / signal-after- Queue move. Tests. AI use: Claude Code, Claude Sonnet 5.5, read the code at the head above; the points are mine. |
gut0to
left a comment
There was a problem hiding this comment.
AI-assisted review (GPT-6): I verified this finding against the queue wait and presenter-owned resource lifetimes in the current diff.
| return false; | ||
| } | ||
| if let Some(old) = slot.as_mut() { | ||
| let _ = drain_queue(old, 1000); |
There was a problem hiding this comment.
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_source and 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 against drain_queue and the presenter-owned resource lifetimes.
Previously present_now signaled p.fence before sc.Present(0, DXGI_PRESENT(0)), leaving DXGI's internal Present queue work unordered behind p.fence. When ensure_swapchain called sc.ResizeBuffers or present_now moved queues, old swap-chain back buffers could be freed while still in use (D3D12 error 921). Extract present_frame_on so q.Signal runs after sc.Present (while still fencing submitted copy command lists on Present failure), extract drain_and_reset_for_queue, add drain_queue to wait for all in-flight copy and Present work before ResizeBuffers and queue switches, handle ResizeBuffers device removal via fence::api_error, and add regression tests for dimension/format resizes, queue switches, timeouts, and ResizeBuffers error recovery. Assisted-by: Antigravity (Gemini 4 Neon)
Rotate three command allocators, command lists, and swap-chain buffers in Presenter so PresentX no longer blocks on the previous frame's fence every frame. Stacked on xcl-dev#711.
e21f158 to
f98dc20
Compare
|
Updated at
|
Fix 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.