D3D12.X: triple-buffer Presenter to avoid per-frame fence stalls #674
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!674
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/674/head"
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:17 UTC · original
RandomGithub12309:d3d12x/triple-buffer-presenter→main· +335 −56 · 1 files · 2 commits · closed without mergingStacked on #711; only the top commit belongs here.
Triple-buffer
Presenterincrates/xcl/src/hle/d3d12x/present.rssoPresentXrotates across three(ID3D12CommandAllocator, ID3D12GraphicsCommandList, copy_source, dumps, fence_val)slots and a 3-buffer flip-discard swap chain instead of blocking on the previous frame's fence on every present.What is in it
f98dc20(from #711): drain present queue afterPresentbeforeResizeBuffersand queue switches.9699b96(this PR) incrates/xcl/src/hle/d3d12x/present.rs:PresenterwithPRESENT_SLOTS = 3PresentSlotentries and a 3-buffer swap chain, reclaiming completed slots non-blockingly and waiting only when rotating into an in-flight slot (never treatingu64::MAXdevice-removed sentinel as completed).p.disabled |= matches!(&e, FenceError::Removed(_))inensure_swapchainafter a faileddrain_queueso a failedSignalis not cleared.drain_and_reset_for_queueon a non-Removeddrain failure (e.g. timeout) so in-flight swap-chain and slot resources stay alive until the GPU finishes.triple_buffer_slot_completion_and_wait_logicandtriple_buffer_present_and_resize_drains_queue_cleanly(covering multi-resize presents and queue-move drain timeout retention).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 --nocapture: 8 passed, 0 failed, 0 ignored (0 skipped).cargo test --workspace -- --test-threads=4 --skip fuzz_validate_and_gpu:xcllib 939 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 at9699b96vsmain(8e87fc7).Regression run
Not tested
0x887A002D), AMD/Intel/wave64 GPUs, Wine/Linux, interaction with #450 (XCL_OVERLAY, not yet onmain), and gameplay beyond the 60 s smoke window.AI use
|=onp.disabled, queue-move drain timeout retention, stacking on #711), ran the tests andscripts/smoke.ps1on the hardware above, and updated this description.@RandomGithub12309 on GitHub · 2026-11-24 03:42 UTC · original
Thanks @thehollowedone for catching error 921! Updated PR #674 at
d2682eb(d3d12x/triple-buffer-presenter):present_frame_on(crates/xcl/src/hle/d3d12x/present.rs): Movedq.Signal(&p.fence, val)aftersc.Present(0, DXGI_PRESENT(0))so each slot's fence orders behind DXGI'sPresentqueue work instead of signaling beforePresent.drain_queuebefore resize & queue switches: Signals and waits onp.fenceviadrain_queue(p, ...)and clears allp.slotsbeforesc.ResizeBuffers(...)inensure_swapchain(and before moving to a new queue inpresent_now).triple_buffer_present_and_resize_drains_queue_cleanlyexercising640x360->768x432->512x288presents and resizes (plus checkingID3D12InfoQueuewhen the debug layer is enabled viaXCL_D3D12_DEBUG=1).Re-verified on RTX 5050 (
cargo test --workspace -- --test-threads=4:694 passed; 0 failed; 41 ignored,2skippedno wave64;cargo test -p xcl --lib hle::d3d12x::present -- --nocapture:8 passed; 0 failed; and 60 sscripts/smoke.ps1). Windows Graphics Tools /ID3D12Debugis not installed on this host (0x887A002D), so re-running under the D3D12 debug layer would confirm error 921 is resolved on your setup.@MesshM on GitHub · 2026-11-24 03:42 UTC · original
Test run of
93f147c09318d7f0e65e3d9a1add2fec84f36bd5on AMD RDNA4. I merged it onto currentmain91f9a5elocally (clean merge) and tested that tree.Tested
stable-x86_64-pc-windows-msvc, debugcargo build --workspace+cargo test --workspace -- --test-threads=4on the merge: 693 passed, 0 failed, 41 ignored, exit code 0;xcllib tests 653 passed, 0 failed, 21 ignoredSKIPPED;triple_buffer_slot_completion_and_wait_logicpasses.Review: Before
ResizeBuffersit waits for the latest fence value (p.value); all slots signal the same monotonic fence, so that covers the three slots, and each slot'scopy_sourceis dropped after. The device-removed value (u64::MAX) is not treated as completed. The frame-dump stop at the first resize mentioned above happens onmaintoo, so it is not from this change. I found nothing to change.Not tested: no retail title or regression run (I have no unpacked game), no
XCL_SAMPLE_*tests, release build; the PR's head on its old base was not run, only its merge ontomain.Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.
@MonkeyPython on GitHub · 2026-11-24 03:45 UTC · original
AMD / wave64 data point (the "Not tested" axis): the present-module tests pass on an AMD Raphael iGPU (RDNA2, native wave64) and on NVIDIA wave32 at this PR's head.
Setup: Windows 11 Pro 26300, Ryzen 7 7800X3D, 32 GB; AMD Radeon(TM) Graphics (Raphael iGPU, 485 MiB, wave64, no mesh shaders) and RTX 3080 Ti 12 GB (driver 621.01, wave32). PR head
d2682eb, release.Runs (
cargo test -p xcl --release --lib present::):XCL_ADAPTER=Radeon(iGPU; the selector errors on no match, so a pass means it ran there): 8 passed / 0 failed, 0.24 s.Not tested: the frame-dump resize regression reported elsewhere (D3D12 error 921 at 640×360 → 768×432) — these unit tests do not exercise resize; long sessions, other titles.
AI use: Gentle Shell (Pi coding agent), model qwen4-max: ran the tests and wrote this report from their logs; a human reviews it before posting. No code changes.
@thehollowedone on GitHub · 2026-11-24 03:26 UTC · original · edited 2026-11-24 03:47 UTC
Retest after the resize fix
I reran the same synthetic frame-dump fixture on
d2682eband with that revision integrated ontomainatf4ce27c. Both used the revised production presenter without the earlier scratch queue drain.Each run verified 28 presents, three resizes, and 14 BMP captures. All dimensions and 250,944 sampled pixels matched in each run. The D3D12 debug layer was active on the RTX 3080 Ti and reported no errors. The new stock
triple_buffer_present_and_resize_drains_queue_cleanlytest also passed on the exact head without a skip.Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti / 621.35, Rust 1.99.1 MSVC, debug. I used
XCL_FRAME_DUMP=2and the same scratch fixture command below. Queue changes, device removal, and retail performance remain untested. Codex with GPT-6.2 Sol ran the tests and drafted this update.Earlier reproduction and scratch control
Tested
A synthetic frame-dump test stopped at the first resize (640×360 → 768×432) on both
mainat91f9a5eand that revision with93f147capplied. Both hit D3D12 error 921. Repeating the integrated test with debug names identified the resource as a swap-chain back buffer.In a scratch control I drained the present queue immediately before
ResizeBuffers, after the previousPresent. The integrated fixture then passed 28 presents, 3 resizes, and 14 BMP captures with no debug-layer errors. The dimensions and all 250,944 sampled pixels matched. The existing copy fence is signaled beforePresent. Copy signal and PresentWindows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti / 621.35, Rust 1.99.1 MSVC, debug. I used
XCL_FRAME_DUMP=2and rancargo test --offline --locked -p xcl --lib hle::d3d12x::present::scratch_resize::check -- --exact --nocapture --test-threads=1.Not tested
Queue changes, device removal, and retail performance.
AI use
Codex with GPT-6.2 Sol wrote the scratch fixture, ran the tests, and drafted this report.
@JoaoPauluu on GitHub · 2026-11-24 03:59 UTC · original
Test report: #674 under Wine (Linux, NVIDIA): the swap chain is DXVK's DXGI on vkd3d-proton
The other reports are Windows runs. Under Wine the 3-buffer swap chain is DXVK's DXGI presenting vkd3d-proton queues, a different present path. GTA VI runs the same on the base and this PR, and the present module tests pass under Wine.
Setup
experimental-11.0-20261112(wine-11.0), vkd3d-proton v3.1 (4522cc1a) + the patch from #257, DXVK from Proton, DXC 1.9.2609,DXVK_CONFIG="dxgi.hideNvidiaGpu = False"x86_64-pc-windows-gnu(mingw-w64-gcc 16.2.0); release builds for the runs, debug for the testsd2682eband its basemainf4ce27cUnit tests (lib test binary under Wine,
--test-threads=1, filterpresent): 8 passed, 0 failed, 0 ignored, in 2 of 2 runs, includingtriple_buffer_slot_completion_and_wait_logicandtriple_buffer_present_and_resize_drains_queue_cleanly.GTA VI 1.0.2.1 (my own dump; 60 s runs with
scripts/linux/smoke.shfrom #257,XCL_NETWORK=0, alternating base / PR / PR / base)f4ce27cd2682ebNo swap-chain or
err:lines in Wine's stderr on any of the four runs. Both builds hold about 60 presents per 2 s in the steady parts, so I saw no frame-count difference either way.(The first pair.
peak commit: 0 MBis XCL reading 0 MB committed under Wine, see #257; the 125 % commit comparison says nothing here.)Not tested
XCL_FRAME_DUMP) in the title, the picture (not checked; black under Wine in my earlier runs, #175)AI use: Claude Code (Claude Opus 5.5) built both commits, ran everything above on the machine above and wrote this report. The blocks and counts are pasted from those runs. The account owner asked for test reports to be posted while they were away and has not reviewed this one.
@upipibi on GitHub · 2026-11-24 04:04 UTC · original
Merge note for this PR and #450 (
XCL_OVERLAY). Both are green and each merges cleanly ontomainf4ce27ceb6on its own, but together they conflict incrates/xcl/src/hle/d3d12x/present.rsin either order (headsd2682eb5c7andbac87c3db5).More than text is involved. #450 keeps one overlay upload buffer on
Presenter(overlay: Option<(ID3D12Resource, u32, u32)>), andoverlay_copyrewrites it every frame, reusing it while the panel size stays the same. Onmainthat's safe, becausepresent_nowwaits for the previous copy before reusing anything. With this PR's threePresentSlots in flight, one shared overlay buffer would be rewritten while an earlier slot's copy may still read it, so the panel could tear or show the next frame's stats.So whichever lands second should probably move the overlay into
PresentSlot, next to thecopy_sourceanddumpsthis PR already moved there, and not just resolve the text conflict.For the rest of the queue: of the 24 PRs that are green with full Tested counts, these two and the
netoff.rstrio on #570 are the only pairs that conflict with each other (276 pairs merged ontomain).Read-only, not built. AI-assisted (Claude Code).
@thehollowedone on GitHub · 2026-11-24 04:58 UTC · original
I reran the resize path on
d2682ebafter the fence-order fix. A scratch extension of the stock test ran 24 presents across 640×360 → 768×432 → 512×288, first with captures disabled and then withXCL_FRAME_DUMP=2. Both runs confirmed a three-buffer swap chain, drained successfully, and reported zero D3D12 errors, including zero 921 messages. The second run verified all 12 readback dimensions and the expected bright/dark content across 177,408 sampled pixels.Windows 11 build 26300, RTX 3080 Ti / 621.35, Rust 1.99.1 MSVC, debug. The fixture required an active D3D12 InfoQueue.
cargo test --offline --locked -p xcl --lib triple_buffer_present_and_resize_drains_queue_cleanly -- --nocapture --test-threads=1passed 1/1 in each fresh process, zero skips. This covers single-queue resize and readback. Retail frame pacing and the overlay combination were outside this test. AI-assisted. Codex (GPT-6, exact variant unavailable) extended and ran the fixture and drafted this reply.@milas6669 on GitHub · 2026-11-24 06:01 UTC · original
Regression run of
d2682eb5c72d(PR head, built as it is, not merged onto main) againstmaine50836b, on a retail title.Tested
scripts/smoke.ps1 -Seconds 60, the same title and time for both, one run each, main first:main (
e50836b):this PR (d2682eb):
What this does and does not say
Not tested
cargo teston this head (I did not run the test suite for this report)AI use
@iggyvilla on GitHub · 2026-11-24 07:34 UTC · original
Code read of
d2682eb; nothing built or run. The slot recycling, theSignalafterPresentand theUINT64_MAXhandling look right to me. Two things:present_nowdrops the old presenter even when the queue-move drain fails:let _ = drain_queue(old, 1000);then*guard = None;(present.rs:705-710). On a timeout that releases the swap chain with aPresentstill queued, plus three allocators/lists that may still run;Presenter::droponly closes the event. The PR body says a local follow-up (527aab2) "retains the current presenter on a queue-drain timeout"; that fix belongs in this PR, and the new test does not cover this path.ensure_swapchaindoesp.disabled = matches!(&e, FenceError::Removed(_))after a failed drain (:631).drain_queuesetsp.disabled = truewhenSignalfails (:610) and returns a non-Removederror, so this assignment clears it again.|=keeps it.AI use: Claude Code, Claude Sonnet 5.5, read the code at the head above and drafted this; a person checked it before posting.
@RandomGithub12309 on GitHub · 2026-11-25 00:57 UTC · original · edited 2026-11-25 01:03 UTC
Updated at
9699b96(rebased ontomain8e87fc7and stacked on #711):ensure_swapchainnow usesp.disabled |= matches!(&e, FenceError::Removed(_))so a failedSignalindrain_queueis preserved, and queue moves now retain the old presenter on non-Removeddrain timeouts viadrain_and_reset_for_queue(covered intriple_buffer_present_and_resize_drains_queue_cleanly).f98dc20) so only the triple-buffering commit belongs to this PR and the two no longer conflict.@JJAutoCompare on GitHub · 2026-11-25 01:49 UTC · original
PR #674 — D3D12.X triple-buffered Presenter verification
PR head
9699b9677ced62f2a03adde8c9e370e518b3d8f5was fetched fromorigin(xcl-dev/xcl). The detached checkout was clean before and after the run.origin/mainwas3da2abb81606df622610e009f0430de99aa9881c.git merge-tree --write-tree <main SHA> HEADexited 0 and produced95fceb50338b2b992229170821b681d2916d3e48.What is in it
crates/xcl/src/hle/d3d12x/present.rsadds three reusable presenter slots to reduce per-frame fence waits and adds tests for slot completion and swap-chain resizing.Tested
32.0.101.9175,DoublePrecisionFloatShaderOps=0, wave range8–32. AMD Ryzen 7 3800X, Windows 11 Enterprise Evaluation build26200.9974, DXC/DXIL1.9.2609.5, Rust1.100.0 (0ef1bc386 2026-11-09). The suite logged the Arc A770. Presenter resize uses automatic adapter selection.cargo build --workspaceandcargo test --workspace --no-runsucceeded outside the Arc lock. Both profiles were unoptimized, with debuginfo and incremental compilation disabled.cargo test -p xcl --lib triple_buffer_slot_completion_and_wait_logic -- --show-outputpassed outside the lock (1 passed, 0 failed, 0 ignored, 0 explicit skips).cargo test -p xcl --lib triple_buffer_present_and_resize_drains_queue_cleanly -- --show-outputran viaInvoke-ArcTest.ps1. Cargo recorded 1 passed, 0 failed, 0 ignored. The test reportedSKIPPED hle::d3d12x::present::frame_dump_tests::triple_buffer_present_and_resize_drains_queue_cleanly: no swap chainafterCreateSwapChainForHwndreturned0x887A0022, so the resize path was unverified.cargo test --workspace --no-fail-fast -- --test-threads=4 --show-outputran once viaInvoke-ArcTest.ps1and exited 101. All 19 test binaries and the doc-test harness reported results: 966 passed, 26 failed, 45 ignored, with 27 explicitSKIPPEDentries across 17 test names. Some entries cover individual test cases. The pass total is the raw harness count and includes tests that reported skips. Full output is inL:\XclTooling\neon-slot-2\tmp\pr674-suite.log.Failures
CreateComputePipelineStatewith0x80070057(invalid parameter). The four DXIL fuzz shards failed at seeds 2, 506, 1003 and 1501, respectively.gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_2gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_3gpu::dxil::ops_tests::doubles_match_cpugpu::dxil::ops_tests::groupshared_barrier_and_atomics_rungpu::dxil::round_tests::gpu_direct_f32_round_modes_dynamic_and_denormalsgpu::dxil::round_tests::gpu_direct_f32_round_preserved_denormal_times_inf_is_infgpu::dxil::round_tests::gpu_direct_f32_round_modes_staticgpu::recomp::lower_dxil::tests::f64_programs_on_the_gpugpu::recomp::tests::gpu_clamp_and_omod_per_instructiongpu::recomp::tests::gpu_f64_literal_high_wordgpu::recomp::tests::gpu_f64_compares_with_nangpu::recomp::tests::gpu_f64_class_comparegpu::recomp::tests::gpu_f64_rootsgpu::recomp::tests::gpu_f64_rounding_and_conversionsgpu::recomp::tests::gpu_f64_math_randomgpu::recomp::tests::gpu_frexp_f64_exp_and_mantgpu::recomp::tests::gpu_float_compares_randomgpu::recomp::tests::gpu_ldexp_f64gpu::recomp::tests::gpu_rndne_f64gpu::recomp::tests::gpu_nonfused_mad_and_mac_prevent_fma_contractionfailed the fusedv_fma_f32overflow control assertion.gpu::recomp::tests::gpu_ps_image_sample_offset_implicit_lod_between_mipsread 25.609375 at pixel (0,0), expected 26.gpu::recomp::tests::gpu_valu_16_and_64_bitfailed the lane-0v_add_f16high-half preservation assertion.gpu::recomp::tests::gpu_wave64_ps_whole_wave_reductionsread[2, 217, 2]at pixel 0, expected[2, 216, 2].test_title_runs_and_game_folder_is_untouchedfailed theRSSetDepthBiasX(-1000.5)check. The top-right pixel was blue where the depth test expected green.Workspace
SKIPPEDentriesNot tested
origin/mainto establish which failures reproduce on the baseline, AMD/NVIDIA adapters, and retail fixtures gated byXCL_SAMPLE_*. The sample variables were unset.AI use
gpt-6.2-sol) ran the build and tests, analyzed the logs, and drafted this report. Coordinator #2 (T3 Code / Antigravity,gemini-4-neon) verified the counts againstpr674-suite.logand published this report.@DavidM1911 on GitHub · 2026-11-25 12:10 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: 1038 passed, 1 failed in one parallel run; the failing test passes on a single-threaded rerun (1039/0). Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.Thanks!
@RandomGithub12309 on GitHub · 2026-11-25 22:08 UTC · original
Superseded as written by #1988, which pipelines PresentX on main. The post-Present fence fix remains in #711.
Pull request closed