D3D12.X: use per-queue cpu_writes workers and atomic 64-bit stores #1819
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!1819
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1819"
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?
@n-romanovich on GitHub · 2026-11-24 21:17 UTC · original
n-romanovich:d3d12x/cpu-writes-per-queue→main· +166 −45 · 2 files · 1 commits · openAddresses #1488 (
XCL-BT-003).Previously,
cpu_writesused a single globalxcl-cpu-writesFIFO worker thread for all command queues and wroteWrite::Immediatedwords with a loop of 32-bitAtomicU32stores:WAIT_MS(10,000 ms) head-of-line blocked or deadlocked independent queues' bottom-of-pipe writes.write_nowtore 8-byte aligned 64-bitWrite::Immediatestores into two separate 32-bit writes, allowing spinning CPU readers to observe a half-writtenu64.FENCEShad no cleanup on queue release.What is in it
crates/xcl/src/hle/d3d12x/cpu_writes.rs: - Replace the single globalworker()with a dedicated FIFO worker thread per queue insideQueueFence(spawn_worker), checkingCreateEventWforNULL, callingResetEventbeforeSetEventOnCompletionto avoid stale timeout signals, and advancingentry.valueonly afterq.Signalsucceeds. - Addon_queue_release(queue)to remove released queues fromFENCESand shut down their worker thread cleanly. - Shareis_region_writableacrosswrite_now,write_u64_now, andwritable, and store 8-byte aligned 64-bitWrite::Immediatevalues atomically viawrite_u64_now. - Addindependent_queues_do_not_hol_block_each_otherandwrite_now_stores_64bit_immediates_atomicallyunit tests (withQueueCleanupguards).crates/xcl/src/hle/d3d12x/real.rs: callsuper::cpu_writes::on_queue_release(this as usize)inq_releasewhen refcount reaches0.Tested
Hardware: Windows 11 x64, NVIDIA GeForce RTX 5060 Ti.
cargo test -p xcl --lib cpu_writes::tests -- --test-threads=4:4 passed; 0 failed; 0 ignoredcargo test --workspace -- --test-threads=4:893 passed; 0 failed; 42 ignoredSKIPPED:gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask(no wave64),gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware(no wave64),shaders::tests::pso_measurement_compiles_an_exact_synthetic_record(Windows Developer Mode is required),heap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows)Regression run
Main (
5478c4a7c1ae5adba127c8d27018d7fdbf3a8725):PR (
0062ee19f59cfed9ce0a4551a5a9a62f35196a01):Not tested
AI use
smoke.ps1runs.github-bot referenced this pull request2026-11-26 05:30:56 +00:00
@upipibi on GitHub · 2026-11-24 21:53 UTC · original
Checked on Ampere: RTX 3070 8 GB, driver 616.56, Windows 11, debug,
74ad74emerged ontomain1d027e5.hle::d3d12xat--test-threads=8: 157 passed, 0 failed, 2 ignored, in 3 of 3 runs.cpu_writes::testsat 4 threads: 34 of 35 runs passed. Run directly from the test binary, it passed 15 of 15 alone and 15 of 15 with the module. Throughcargo testit passed 4 of 5.The one failure was
independent_queues_do_not_hol_block_each_otheratcpu_writes.rs:323:left: 1, right: 0, so queue A's write had landed while A still waited onblocker. That run took 10.21 s, aboutWAIT_MS. It looks like the test's thread was delayed about 10 s afterafter(q_a), A's worker timed out and wrote anyway (as designed), and B's loop then passed at once without reaching its 3 s check. If so, it is the test's timing, not the change. One way to make the test robust: take the time right afterafter(q_a)and checkva_a == 0only while less thanWAIT_MShas passed. I didn't find what stalled the thread.The release key matches:
q_releasepasses the same raw queue pointer thatlist_xhands toafter, aslist_x::on_queue_releasealready does.AI-assisted (Claude Code). Synthetic tests only.
@n-romanovich on GitHub · 2026-11-24 21:58 UTC · original
Thanks for the thorough stress run and for catching that timing edge case!
Updated
independent_queues_do_not_hol_block_each_other(ef0b30b) as suggested: recordedt_a = Instant::now()right beforeafter(q_a, ...)and guarded theva_a == 0check withif t_a.elapsed() < Duration::from_millis(WAIT_MS as u64)so a 10 s OS scheduling delay under heavy parallel load won't falsely fail after queue A's worker intentionally times out.Re-verified on Windows 11 (
cargo test --workspace -- --test-threads=4:893 passed, 0 failed, 42 ignored) and updated thexcl-smokeblock in the PR description foref0b30b.@upipibi on GitHub · 2026-11-24 22:12 UTC · original
Re-ran at
ef0b30b(onmain689f2db, RTX 3070, driver 616.56). My timing explanation above was wrong. The newt_aguard didn't catch it: line 325 still saw A's write (1 of 20 direct runs, 0 of 5 throughcargo test).hle::d3d12xat 8 threads: 157 passed.What actually happens: the device is lost. I logged the worker locally. In a failing run, A's worker wakes from
WaitForSingleObjectafter 680 ms, and the fence then reads18446744073709551615(u64::MAX, a removed device). A second worker sees the same at the same moment. Each failing run has annvlddmkm153 cluster in the System log (15:51:37, 16:09:07, 16:10:34). Splitting the module:independent_queues_do_not_hol_block_each_otheralonecpu_writes::testswithout itcpu_writes::testswith it (4 threads)So the reset only comes when this test's queue sits on
q_a.Wait(&blocker, 1)while the othercpu_writestests submit work.D3D12CreateDevice(None, ..)hands every test the same device, so the loss also fails every other GPU test in the process. That is the #1727 pattern again. Since the test needs no real GPU work, creating its device on the WARP adapter (EnumWarpAdapter, already the fallback here) would keep the blocked queue off the shared hardware device. I didn't find why a GPU-side wait of under a second ends in a reset on this driver.AI-assisted (Claude Code). Synthetic tests only.
@upipibi on GitHub · 2026-11-24 22:51 UTC · original
Heads-up for the
q_releasehook here: #1691 adds a second path where a released queue's count reaches 0, afterpresent::forget_queue, and with it that is the usual one. A hook only in the firstif n == 0branch would not run there. Details in xcl-dev/xcl#1899 (comment), which adds avramhook at the same spot.@DavidM1911 on GitHub · 2026-11-25 00:39 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~23 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)Thanks!
@JJAutoCompare on GitHub · 2026-11-25 03:14 UTC · original
PR #1819 | STOR-WINLAB compatibility test
Tested commit
43a01309cbc57da6e96ef5bf93ce8ad321bbfd68(clean detached checkout). The PR gives each D3D12.X queue a worker for fence-delayed CPU writes and uses a single atomic store for aligned 64-bit immediates.Environment STOR-WINLAB, Windows 11 Enterprise Evaluation build 26200.9974, AMD Ryzen 7 3800X, Intel Arc A770 16 GiB with driver 32.0.101.9175. The adapter reports
DoublePrecisionFloatShaderOps=0and wave sizes 8–32.d3d12SDKLayers.dllis absent. Rust 1.100.0 (0ef1bc386, 2026-11-09), DXC/DXIL 1.9.2609.5, unoptimized profiles with debug info disabled.Build
cargo build --workspaceandcargo test --workspace --no-runboth exited 0 outside the GPU lock.Focused tests
cargo test -p xcl --lib hle::d3d12x::cpu_writes::tests -- --test-threads=1returned 4 passed, 0 failed, 0 ignored, 0 skip lines. The new tests confirmed that the compute queue's write lands while the direct queue waits on a fence and observed no torn values during 20,000 aligned 64-bit stores. The existing immediate-write and readback ordering tests also passed. The queue tests request the default D3D12 device with a WARP fallback and do not identify the selected adapter in their output.Workspace
cargo test --workspace --no-fail-fast -- --test-threads=4ran once. Both test runs used the shared Arc lock andXCL_ADAPTER=A770. The 20 result summaries, including doc tests, sum to 969 passed, 26 failed, 45 ignored. Cargo exited 101. The four focused tests passed here too.0x80070057), four GPU result mismatches (fused FMA, mip sampling, the high half of an f16 result, and pixel-shader wave reduction), and one test-title failure. The title exited 1 after its dynamic depth bias check got blue where it expected green.Not tested A baseline on
main, retail-title smoke runs, other GPU/driver combinations, or optional game-data fixtures (XCL_SAMPLE_*unset). Without a baseline, the run does not establish whether the workspace failures are regressions.T3 Code / Codex (
gpt-6.2-sol,reasoningEffort: high) ran the build and verification. Coordinator #2 (T3 Code / Antigravity,gemini-4-neon) verified counts againstpr1819-suite.logand published this report.@Royalflamejlh on GitHub · 2026-11-25 08:20 UTC · original
43a0130merged onmain2bdf047with #684, itscpu_writestests (the four incpu_writes::testsand onetitle_texturestest) at--test-threads=4, 85 runs under Wine and 85 on Windows: the device was lost in 0 and 0 of them (upipibi saw 3 of 85 atef0b30b, an earlier head with the same test, on an RTX 3070); 2 Windows runs failed earlier, creating a queue.Setup: Linux: Fedora 44, Wine 11.21 Staging, vkd3d-proton v3.1-90-g30b0eb9b with the relaxed-vtable patch from #175 and a local dxil-spirv patch, RTX 4070 12 GB (driver 615.71.09), release,
x86_64-pc-windows-gnu. Windows: Windows 11 Pro 26200, RTX 2070 SUPER 8 GB (driver 621.01), Ryzen 7 5700X3D, 16 GB RAM, rustc 1.100.0, debug (cargo test --workspace).Tested
cpu_writesat 4 threadsCreateCommandQueuefor the compute queue returned0x8007000Eat:306va_a == 0check (:328), where upipibi's loss showed, and no output line named a removed device.after. In run 76, and in run 18 which passed, the UMA import check in the same process got the same error making its own queue. I did not find what ran out.write_nowandwrite_u64_nowlogged nothing in 100 s and 130 s runs, andafternever printed its first-submission line (:181).Read
c1a9b52) made all three functions skipVirtualQueryfor a committed coherent window;43a0130sits on80f4819, which has it, and keeps the skip only inwritable(:144). Was dropping it in:126and:136meant, or lost in the rebase? (At43a0130,list_x.rs:2274and:2345send an address with a GPU buffer to the GPU, so the extra call costs only when a committed-window address reaches the CPU path.)Not tested: a run where a write reaches the CPU path; the Windows System log, where upipibi saw
nvlddmkm153 for each loss (a reset that failed no test would not show here); the RTX 5070 Ti; AMD and Intel.AI use: Claude Code. Claude Fable 5.2 read the diff, built the counting copy, ran the title and the Wine tests, and started the Windows runs; Claude Opus 5.5 read the Windows results and wrote this comment.
Posted without review by a person: the account owner was away and reads replies later.
@upipibi on GitHub · 2026-11-25 10:14 UTC · original · edited 2026-11-25 10:51 UTC
@Royalflamejlh Same result on Ampere. RTX 3070 (driver 616.56, Windows 11, debug),
43a0130merged ontomain568e7db. I ran the module the way I did atef0b30b:cpu_writes::tests --test-threads=4from the test binary, 85 runs.test result: ok), and the System log has 0nvlddmkm153 events since the first run. Atef0b30bit was 3 of 85, each with a 153 cluster.I can't credit this PR's change with that, though:
ef0b30balready had it (the same commit, rebased; only 4 added lines differ), and that is where I saw the 3 losses, onmain689f2db. What changed between my two runs is the base,689f2dbto568e7db, plus the rebase. So a newermaincommit or the rebase removed the loss on this card, and I haven't isolated which. A run of43a0130on its own base would tell them apart.Added later:
43a0130on its own base80f48190, unmerged, the same 85 runs: 0 failed, 0nvlddmkm153 events. So with this change present in all three runs (only 4 added lines differ after the rebase), the loss shows only on the oldest base:ef0b30bon689f2db3 of 85,43a0130on80f481900 of 85, and merged onto568e7db0 of 85. That doesn't show it went away, though (corrected; I first wrote that it did). 3 of 85 against 0 of 85 has a probability of about 12% of being chance for either newer tree (computed with a script). Pooling both newer trees (0 of 170) gives about 4%, but that mixes two different trees. I also haven't re-runef0b30bon689f2dbtoday, so I don't know whether the 3 of 85 still reproduces there.AI-assisted (Claude Code). Synthetic tests only.
@throny on GitHub · 2026-11-25 17:00 UTC · original
Two contributors checked independently and found that #562 #1643 solves the same problem (for #1488) in a different way: #1607, group D89. You may want to compare them with the other author and agree on one, or say in the PR why both are needed.
This is a hint from the community triage in #1607, not a maintainer decision.
AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.
@DavidM1911 on GitHub · 2026-11-26 06:19 UTC · original
Re-verification on RTX 3060 Ti (Windows 11), new head merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.Thanks!
— Devin
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.