D3D12.X: give each command queue its own cpu_writes worker #562
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!562
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-562"
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?
@gridoe on GitHub · 2026-11-24 01:50 UTC · original
gridoe:cpu-writes-per-queue→main· +130 −37 · 2 files · 1 commits · openGive each D3D12 command queue its own
cpu_writescompletion worker thread instead of multiplexing every queue through one global FIFO channel.Previously,
cpu_writes::aftersent every queue's bottom-of-pipe writes to a single sharedxcl-cpu-writesthread. If one queue waited on an unsignaled GPU fence (up toWAIT_MS = 10 s), bottom-of-pipe writes from other queues whose fences had already completed were head-of-line blocked behind it. Storing a dedicated channel perQueueFencelets independent queues drain concurrently, and removing the entry onCommandQueue::Release(forget_queue) lets its worker exit cleanly and close its Win32 event handle.What is in it
crates/xcl/src/hle/d3d12x/cpu_writes.rs: replace the single globalworker()channel with a per-queuempsc::Sender<Job>onQueueFence(preserving theLATEtimeout warning fromdbe9324), close the event handle when the worker exits, addforget_queue(queue), and add unit testblocked_queue_does_not_stall_another_queues_writes(isolated on a WARP device with aDropdrain guard so its intentional fence wait cannot interfere with sibling GPU tests sharing the default adapter).crates/xcl/src/hle/d3d12x/real.rs: callcpu_writes::forget_queuewhen aCommandQueuereaches refcount 0 inq_release.Tested
rustc 1.99.1 (58cf8f9c3 2026-10-13)(stable-x86_64-pc-windows-msvc), debug (tests) and release (smoke)..\scripts\test.ps1(cargo build --workspace+cargo test --workspace -- --test-threads=4): 717 passed, 0 failed, 41 ignored.SKIPPEDGPU tests on this adapter: 2 (no wave64—gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware).cargo test -p xcl --lib cpu_writes, default threads): 20/20 consecutive runs passed (4 passed each, 0 device removals, 0 flakes).Regression run
main:
PR:
Not tested
XCL_SAMPLE_*env vars.AI use
github-bot referenced this pull request2026-11-26 05:30:56 +00:00
@brothernog on GitHub · 2026-11-24 02:04 UTC · original · edited 2026-11-24 02:06 UTC
Tested
3dc82a8on an RTX 3050 (driver 610.88), Windows 11 Home 26300, Rust 1.100.0, debug. The new test makes its neighbours flaky here when they run in parallel:cargo test -p xcl --lib cpu_writes(4 tests, default threads): 5 of 20 runs failed, and 1 more of 6 in an earlier batch.title_textures::tests::gpu_mirror_upload_follows_cpu_writes_and_later_mapping_changespanics attitle_textures.rs:1192, whereCreateCommandQueuereturns0x887A0005(DXGI_ERROR_DEVICE_REMOVED).cpu_writes.rs:293, "q1 write landed before its fence was signaled" (left: 11). That is what a removed device looks like from there, since its fences read as complete.--skip blocked_queue: 0 of 20 failed.cpu_writes.rsandreal.rsfrommain508a0c7(the 3 old tests): 0 of 20 failed.--exact): 0 of 20 failed. The filter with--test-threads=1: 0 of 10 failed.So it only shows up when
blocked_queue_does_not_stall_another_queues_writesruns next to another GPU test. My guess, not confirmed:D3D12CreateDeviceon the default adapter hands back the same device the other tests use, so theq1.Wait(&blocker, 1)puts a GPU-side wait on the shared device. I didn't queryGetDeviceRemovedReason. Since the suite runs with--test-threads=4, it could make the suite flaky on other machines too.Also run:
cargo test -p xcl --lib cpu_writes -- --listshows the new test. I didn't run the full suite.This review was AI-assisted.
@WebIdentity1 on GitHub · 2026-11-24 02:17 UTC · original
Native Windows integration check of this PR (
3dc82a89896626374064563d436e3041261f9b74) with #317 (d87aa071287e4a8cd5f4a068d3b791e01c7052c7), both applied to main9ce2070eccf436d7bd38601c90407da447df34f3. This is a local conflict resolution, not a test of either unmodified PR head.The tested integration is available at commit
de9deed5for the original authors to inspect/reuse; no competing upstream PR. It keeps this PR's queue-local channels and release cleanup, calls #317'swrite_now(&Write)from the worker, and converts the new fixture toWrite::U32. Raw test queues are removed from the worker map after completion. The fixture unblocks/drains before its assertions so the negative control can fail without leaving a queued GPU wait or dangling write destination; its independence and ordering assertions remain.Tested
cargo test --locked -p xcl --lib -- cpu_writes::tests:: timestamps_outside_unified_memory_land_after_the_queue write64_os_timestamp_flags_route_to_qpc_instead_of_gpu_timestamps --nocapture --test-threads=1: 6 passed / 0 failed / 0 ignored, no skips. Covers independent queue completion, QPC/PAGE_GUARD, atomic64, retained ReadbackU64, GPU timestamp readback and flag routing.cargo test --locked -p xcl --lib blocked_queue_does_not_stall_another_queues_writes -- --nocapture --test-threads=1: 0 passed / 1 failed / 0 ignored on each GPU. In both: queue2 did not finish independently, queue1 remained unwritten before signaling, both drained after signaling,GetDeviceRemovedReason = Ok(()). With per-queue workers, independence passed and those ordering/drain/device checks also passed.cargo build --locked --workspaceruns passed. Matched serial workspace command in the interactive desktop session:cargo test --locked --workspace --no-fail-fast -- --test-threads=1 --show-output. Main: 683 passed / 1 failed / 41 ignored. Integration: 686 passed / 1 failed / 41 ignored. Sole failure on both:gpu_clamp_and_omod_per_instruction(#202). Four explicit skips on both, included in Rust's pass counts:gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware(no native wave64);test_title_draws_with_a_root_signature_under_the_debug_layer,uploads_start_from_each_subresources_state(debug-layer availability). Sample inputs unset; system XGameRuntime comparison unavailable. Test-only device-selection/control overlays were restored before these full runs; all changed-file hashes match the published commit.Not tested
Retail regression, release builds, or the full four-thread suite on this integration. The reported parallel-test interference is not fixed or disproved by these serial runs. Full-suite recompiler tests select NVIDIA; default-device fixtures may use AMD. Synthetic inputs only; no retail files used.
AI use
Codex (GPT-6) prepared the integration and test-only controls, ran the native Windows checks and wrote this report. Runtime changes originate in #317 and #562.
@MesshM on GitHub · 2026-11-24 03:04 UTC · original
Test run of
3dc82a89896626374064563d436e3041261f9b74on AMD RDNA4. I merged it onto currentmaindd2ae9alocally (clean merge) and tested that tree.Tested
stable-x86_64-pc-windows-msvc, debugcargo build --workspace+cargo test --workspace -- --test-threads=4on the merge: thexcllib test binary stopped with0xc0000005(STATUS_ACCESS_VIOLATION) after 636 tests had passed and before it printed a result line. The last lines printed werevfs::tests, but with 4 threads that does not tell which test was running when it crashed.cargo test -p xcl --lib -- --test-threads=4, 3 more runs on the same tree: 3 of 3 passed (651 passed, 0 failed, 21 ignored, ~20 s each),blocked_queue_does_not_stall_another_queues_writesamong them.maindd2ae9aright before and after (#564, #547, #532, #522, #537) all finished their lib runs without a crash, but that is one run each, not enough to callmainclean.I cannot say this PR causes the crash: I have one occurrence and no dump. It is a different symptom from @brothernog's (a removed device next to the new test, on an RTX 3050), but both point at flakiness when the lib tests run in parallel with this change, so it may be worth running
cargo test -p xcl --lib cpu_writesand the whole lib a few times on the final head.Review: per-queue workers remove the head-of-line blocking described: each
QueueFenceowns its channel, and its worker waits on its own fence. Two things to check: (1) a worker thread is spawned per queue and ends when its sender is dropped, so a title that creates and releases many queues relies onforget_queuerunning for each; a queue never released keeps its thread. (2) The new test leaves a queue blocked on an unsignalled fence while other tests in the same process use the device; that matches the removed-device failures @brothernog saw, and @WebIdentity1's integration commit drains the blocked queue before asserting, which may be the fix.Not tested: no retail title or regression run (I have no unpacked game), no
XCL_SAMPLE_*tests, release build; no crash dump was captured.Run and report by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.
@anes66 on GitHub · 2026-11-24 04:53 UTC · original
There is a separate completion race in the existing
writes_land_after_the_queuetest that this branch retains.write_nowrelease-stores the dwords one at a time. The test waits for the first dword to become 7, then reads both values. That does not establish that the second store has happened.29c254a is a small test-only fix on main
64b3f35: wait for the last dword, 9, with acquire ordering before checking the array. It preserves the two-dword coverage. #317 changes this test for its new 64-bit write path; this commit does not implement that feature or the per-queue worker change.Tested
left: [7, 0], right: [7, 9]. The observation used atomic loads during this control.#[cfg(test)]; runtime code is unchanged.cargo test --locked --workspace --no-fail-fast -j 4 -- --test-threads=4 --show-output: 701 passed, 0 failed, 41 ignored, exit 0, on that final patch (committed unchanged).Not tested
This is not a validation of #562's head, its queue cleanup, or the device-removal reports above. Those still need separate investigation. No retail title, release, AMD/Intel or native-wave64 run.
AI use
Codex (GPT-6; exact variant unavailable) investigated the test, wrote the minimal correction, ran the controlled comparison and suite, and drafted this report.
@iggyvilla on GitHub · 2026-11-24 05:31 UTC · original
Tested (PR head
3dc82a8, as fetched frompull/562/head, not merged onto currentmain; RDNA2/wave64, which the PR lists under Not tested)AMD Radeon RX 6650 XT 8 GB (RDNA2), driver 32.0.21045.29003; AMD Ryzen 7 5700X, 32 GB RAM;
Windows 11 Home build 26300.9974,
rustc 1.100.0 (0ef1bc386 2026-11-09) stable-x86_64-pc-windows-msvc.cargo build --release -p xcl— ok.cargo build --workspace— ok (debug test title built).cargo test --workspace --no-fail-fast -- --test-threads=4on the PR head, debug:678 passed, 3 failed, 41 ignored, 0 skipped.
xcllib: 638 passed, 3 failed, 21 ignoredconsole_dlls_e2e13;console_shaders3 passed, 4 ignored;disasm_e2e1;e2e3;gpu_compute_e2e2;gpu_pso_e2e7;heap_probe4 ignored;pls_quota1;predication_e2e1;rpf_e2e2;texture_states1;xg_oracle6 passed, 12 ignored.SKIPPEDlines.The three failures are the known failures of
mainon this card, not new ones:placed_title_textures_share_vram_and_preserve_pixels— also fails alone with the same message:assertion left == right failed: 3D 64x64x64 4 mips: subresource 2 mismatch(#470).transitions_apply_when_their_list_is_submittedandd32s8_targets_take_their_own_size_of_video_memory—PoisonErrorin the suite (the lock-poisoncascade #673 fixes); both pass when run alone.
Parallel-test flakiness (the removed-device failures and the one
STATUS_ACCESS_VIOLATIONcrashreported in the comments) did not reproduce here:
cargo test -p xcl --lib cpu_writesat default threads, 10 runs: 10/10 ok (4 passed each,~0.37 s per run), no removed device, no
q1 write landed before its fence was signaled.cargo test -p xcl --lib -- --test-threads=4, 3 runs: 3/3 finished without a crash, each withonly the three known failures above (638/3/21).
This is a small sample (10 filter runs, 3 whole-lib runs) and the reports above were on NVIDIA
adapters; it does not disprove the interference, only says it did not show on this card.
60 s smokes with
XCL_NETWORK=0,scripts/smoke.ps1 -Game D:\GTA6.Xbox.v1.0.2.1-CYBERLEEK,head first and its merge base
508a0c7immediately after:Head
3dc82a8:Base
508a0c7:Both smokes show a
0in the last-3 presents window (likely a load/menu pause in the sampledinterval); the frame counts of the two 60 s runs are reported as measured. One run each, so no A/B
claim is made. Both exit
0x0, 0 device removals, 0 crashes.Not tested
main; only the head as fetched was built and run.XCL_SAMPLE_*tests (none set).cpu_writesfilter runs, 3 whole-lib runs); theinterference reported on NVIDIA adapters was not ruled out, only not reproduced.
AI use
opencode with DeepSeek V4.1 Flash (
opencode-go/deepseek-v4.1-flash) ran the build, the tests, theflakiness repeats and the smoke runs and wrote this report.
@milas6669 on GitHub · 2026-11-24 06:01 UTC · original
Regression run of
3dc82a898966(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 (3dc82a8):
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
@gridoe on GitHub · 2026-11-24 08:22 UTC · original · edited 2026-11-24 15:51 UTC
Rebased onto
mainand updated to8ec2a46974d3(8ec2a46): isolatedblocked_queue_does_not_stall_another_queues_writesonto a WARP device with aDropdrain guard so its intentionalq1.Wait(&blocker, 1)cannot stall sibling GPU tests sharing the default hardware adapter (addressing the parallel test flake reported by @brothernog and @MesshM's drain note).Tested
rustc 1.99.1 (58cf8f9c3 2026-10-13)(stable-x86_64-pc-windows-msvc), debug (tests) and release (smoke)..\scripts\test.ps1(cargo build --workspace+cargo test --workspace -- --test-threads=4): 717 passed, 0 failed, 41 ignored (2SKIPPEDGPU tests:no wave64—gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware).cargo test -p xcl --lib cpu_writes, default threads): 20/20 consecutive runs passed (4 passed each, 0 device removals, 0 flakes).scripts/smoke.ps1, release) on8ec2a46vsmain09940bb:main:
PR:
Not tested
XCL_SAMPLE_*env vars.AI use
Dropdrain fix, ran the test suite, parallel flakiness repeats, andscripts/smoke.ps1regression run, and drafted this comment.@3L1A5-1 on GitHub · 2026-11-24 16:11 UTC · original
A retail run with this PR, in case it helps with what it covers and what it does not.
Setup: RTX 2060 SUPER 8 GB, GTA VI 1.0.2.1,
main930e8b4, release. Merged locally with8ec2a46(clean except forcpu_writes.rs, where I kept this PR's worker loop) and a diagnostic oncpu_writesand the counters the title waits on.What it fixes: without it, one queue's write waited behind another queue's in the shared FIFO. It was written after newer values from the other queue (
fence 17 / wanted 14), and the counter went down. With this PR, every write I logged landed on time (queue fence == wanted).What it does not fix: the title submits the same closed list again and again, 12 times in 300 s.
cpu_writes_afterre-applies that list's recorded values each time, so its old counter value still overwrites newer ones, now from the queue's own worker. Details and the trace: https://github.com/ivall/xcl/issues/505 (my two comments today).So on this title the per-queue worker is needed, but it is not enough by itself.
AI use: Claude Code (Claude Opus 5.5) ran this and wrote the note.
@throny on GitHub · 2026-11-24 22:59 UTC · original
Two contributors checked independently and found that #1643 solves the same problem in a different way: #1607, group D63. 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.
@gridoe on GitHub · 2026-11-25 11:19 UTC · original
Thanks for the triage pointer (@throny). Comparing
#562against#1643(group D63):xcl-cpu-writesworker with one worker thread perID3D12CommandQueueso a blocked queue cannot head-of-line stall another queue's bottom-of-pipe writes.#562differs (worker lifecycle & test isolation):#562hooksq_releaseincrates/xcl/src/hle/d3d12x/real.rs(cpu_writes::forget_queue) so destroying a queue drops its sender, exits its worker thread, closes its event handle, and prevents stale fence/value reuse if a new queue is allocated at the same address.#1643keeps queue entries and worker threads for the lifetime of the process.#562's regression test (blocked_queue_does_not_stall_another_queues_writes) isolates the intentionally blocked queue onto a dedicated WARP device with aDropdrain guard so it does not flake sibling GPU tests running in parallel on the default hardware adapter (reported earlier on RTX 3050 / RX 9060 XT);#1643's test blocks a queue on the default hardware adapter.#1643adds separate scope:#1643also adds atomic 64-bit stores for 8-byte aligned immediate writes (Write::ImmediateU64and 64-bit coalescing inwrite_now, which also addresses the torn-read concern noted above by @anes66).Those two pieces are orthogonal —
#562can land the per-queue worker +q_releasecleanup cleanly on its own, and#1643's atomic 64-bit immediate write change can stack on top (or be merged separately).AI use: Diff comparison and summary drafted with Antigravity with Gemini 4 Neon.
@DavidM1911 on GitHub · 2026-11-25 13:30 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!
@throny on GitHub · 2026-11-25 17:00 UTC · original
Two contributors checked independently and found that #1643 #1819 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.
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.