Skip to content

[upstream #1819] D3D12.X: use per-queue cpu_writes workers and atomic 64-bit stores - #318

Open
ufoptg wants to merge 3 commits into
mainfrom
upstream-pr/1819
Open

ufoptg wants to merge 3 commits into
mainfrom
upstream-pr/1819

Conversation

@ufoptg

@ufoptg ufoptg commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Addresses xcl-dev#1488 (XCL-BT-003).

Previously, cpu_writes used a single global xcl-cpu-writes FIFO worker thread for all command queues and wrote Write::Immediate dwords with a loop of 32-bit AtomicU32 stores:

  1. A stalled or blocked queue waiting up to WAIT_MS (10,000 ms) head-of-line blocked or deadlocked independent queues' bottom-of-pipe writes.
  2. write_now tore 8-byte aligned 64-bit Write::Immediate stores into two separate 32-bit writes, allowing spinning CPU readers to observe a half-written u64.
  3. FENCES had no cleanup on queue release.

What is in it

  • crates/xcl/src/hle/d3d12x/cpu_writes.rs:
    • Replace the single global worker() with a dedicated FIFO worker thread per queue inside QueueFence (spawn_worker), checking CreateEventW for NULL, calling ResetEvent before SetEventOnCompletion to avoid stale timeout signals, and advancing entry.value only after q.Signal succeeds.
    • Add on_queue_release(queue) to remove released queues from FENCES and shut down their worker thread cleanly.
    • Share is_region_writable across write_now, write_u64_now, and writable, and store 8-byte aligned 64-bit Write::Immediate values atomically via write_u64_now.
    • Add independent_queues_do_not_hol_block_each_other and write_now_stores_64bit_immediates_atomically unit tests (with QueueCleanup guards).
  • crates/xcl/src/hle/d3d12x/real.rs: call super::cpu_writes::on_queue_release(this as usize) in q_release when refcount reaches 0.

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 ignored
  • cargo test --workspace -- --test-threads=4: 893 passed; 0 failed; 42 ignored
    • SKIPPED: 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 (4178e888c0b5be50a2887eda45cdb832763b68a4):

xcl-smoke v1
commit: 4178e888c0b5be50a2887eda45cdb832763b68a4
gpu: NVIDIA GeForce RTX 5060 Ti
title: FILES
seconds: 60
exit: 0x0
frames shown: 1538 (PresentX 1538)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14871 MB

PR (ef0b30b1535e20c66eef5cd1991e6a6c1635ff8a):

xcl-smoke v1
commit: ef0b30b1535e20c66eef5cd1991e6a6c1635ff8a
gpu: NVIDIA GeForce RTX 5060 Ti
title: FILES
seconds: 60
exit: 0x0
frames shown: 1471 (PresentX 1471)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17118 MB

Not tested

  • AMD GPU.
  • macOS / Linux (crate targets Windows only).

AI use

  • Antigravity (Claude Sonnet 5.5): implemented the cpu_writes.rs / real.rs changes and unit tests, ran the test suites and smoke.ps1, and verified the diff with an independent adversarial reviewer subagent.

Mirror of xcl-dev#1819 (auto-synced, do not edit).

raylitebull and others added 3 commits November 24, 2026 21:05
…-oom

dxil: eliminate giant-shader IR and CFG blowup in FormatLoad and multi-window memory
Replace the single global xcl-cpu-writes worker with a dedicated FIFO worker per queue (cleaned up on q_release) so one stalled queue cannot HOL-block or deadlock independent queues, reset the wait event before SetEventOnCompletion, and store 8-byte aligned 64-bit Write::Immediate values atomically.

Assisted-by: Antigravity (Claude Sonnet 5.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants