D3D12.X: per-queue worker dispatch and atomic 64-bit immediate writes (#1488) #1643

Open
github-bot wants to merge 1 commit from github-bot/gh-1643 into main AGit
Owner

@⁠slopgobblercobbler on GitHub · 2026-11-24 18:35 UTC · original
slopgobblercobbler:fix/cpu-writes-queue-independence → main · +188 −40 · 2 files · 1 commits · open

Summary

Implements dedicated per-queue worker dispatch and atomic 64-bit immediate writes in crates/xcl/src/hle/d3d12x/cpu_writes.rs and list_x.rs (Issue #1488, finding XCL-BT-003):

  1. Per-queue worker dispatch (HOL-blocking & deadlock prevention):
    • Previously, a single global xcl-cpu-writes worker thread handled writes across all command queues.
    • When independent command queues waited on cross-queue fences, a queue waiting on an unsignalled fence blocked the shared thread, starving unblocked queues (head-of-line blocking) and causing deadlocks.
    • Replaced the single global worker with dedicated per-queue worker threads and channels (spawn_queue_worker), ensuring independent command queues make forward progress without blocking each other while preserving strict in-queue FIFO ordering.
  2. Atomic 64-bit immediate writes:
    • Added Write::ImmediateU64(usize, u64) and updated write_now to commit 8-byte aligned word pairs as a single atomic u64 via AtomicU64::store(..., Ordering::Release).
    • In list_x.rs, records Write::ImmediateU64 directly for 64-bit bottom-of-pipe writes to title memory, preventing 64-bit tearing under concurrent title polling.
  3. Unit tests:
    • atomic_64bit_write_ordering: Validates atomic u64 store without tearing under high-frequency concurrent polling reader.
    • independent_queues_do_not_head_of_line_block: Validates that an unblocked command queue executes immediately (< 3s) without being head-of-line blocked behind a stalled command queue waiting on an unsignalled fence.

Changes

  • crates/xcl/src/hle/d3d12x/cpu_writes.rs: per-queue worker dispatch channels, atomic 64-bit stores, and regression tests.
  • crates/xcl/src/hle/d3d12x/list_x.rs: emit Write::ImmediateU64 for 64-bit immediate writes.

Tested

  • Windows 11 x64, Rust MSVC stable.
  • cargo test -p xcl -- cpu_writes: 5 passed, 0 failed.
  • cargo test -p xcl -- list_x: 27 passed, 0 failed.
  • Clean diff: zero trailing whitespace, clean rebase on latest upstream/main (c160d86), GPL-2.0-only compliant, zero retail game data or keys.

Not Tested

  • Extreme high-queue-count multi-GPU concurrent execution.

AI Use

Co-Authored-By: Claude Code (Claude Opus 5.5) / Gemini Antigravity

**@⁠slopgobblercobbler** on GitHub · 2026-11-24 18:35 UTC · [original](https://github.com/xcl-dev/xcl/pull/1643) `slopgobblercobbler:fix/cpu-writes-queue-independence` → `main` · +188 −40 · 2 files · 1 commits · open ## Summary Implements dedicated per-queue worker dispatch and atomic 64-bit immediate writes in `crates/xcl/src/hle/d3d12x/cpu_writes.rs` and `list_x.rs` (Issue #1488, finding `XCL-BT-003`): 1. **Per-queue worker dispatch (HOL-blocking & deadlock prevention)**: - Previously, a single global `xcl-cpu-writes` worker thread handled writes across all command queues. - When independent command queues waited on cross-queue fences, a queue waiting on an unsignalled fence blocked the shared thread, starving unblocked queues (head-of-line blocking) and causing deadlocks. - Replaced the single global worker with dedicated per-queue worker threads and channels (`spawn_queue_worker`), ensuring independent command queues make forward progress without blocking each other while preserving strict in-queue FIFO ordering. 2. **Atomic 64-bit immediate writes**: - Added `Write::ImmediateU64(usize, u64)` and updated `write_now` to commit 8-byte aligned word pairs as a single atomic `u64` via `AtomicU64::store(..., Ordering::Release)`. - In `list_x.rs`, records `Write::ImmediateU64` directly for 64-bit bottom-of-pipe writes to title memory, preventing 64-bit tearing under concurrent title polling. 3. **Unit tests**: - `atomic_64bit_write_ordering`: Validates atomic `u64` store without tearing under high-frequency concurrent polling reader. - `independent_queues_do_not_head_of_line_block`: Validates that an unblocked command queue executes immediately (< 3s) without being head-of-line blocked behind a stalled command queue waiting on an unsignalled fence. ## Changes - `crates/xcl/src/hle/d3d12x/cpu_writes.rs`: per-queue worker dispatch channels, atomic 64-bit stores, and regression tests. - `crates/xcl/src/hle/d3d12x/list_x.rs`: emit `Write::ImmediateU64` for 64-bit immediate writes. ## Tested - Windows 11 x64, Rust MSVC stable. - `cargo test -p xcl -- cpu_writes`: 5 passed, 0 failed. - `cargo test -p xcl -- list_x`: 27 passed, 0 failed. - Clean diff: zero trailing whitespace, clean rebase on latest `upstream/main` (`c160d86`), GPL-2.0-only compliant, zero retail game data or keys. ## Not Tested - Extreme high-queue-count multi-GPU concurrent execution. ## AI Use Co-Authored-By: Claude Code (Claude Opus 5.5) / Gemini Antigravity
- Replace the single global xcl-cpu-writes FIFO thread with dedicated
  per-queue worker threads and channels in cpu_writes.rs, preventing
  cross-queue head-of-line blocking and deadlocks when independent
  command queues await inter-queue fences (finding XCL-BT-003 from #1488).
- Ensure 64-bit immediate writes are stored atomically as a single u64
  via AtomicU64::store(..., Ordering::Release) on 8-byte aligned addresses
  (and via Write::ImmediateU64 in list_x.rs), preventing torn reads.
- Add unit test atomic_64bit_write_ordering verifying atomic 64-bit store
  without tearing under concurrent multi-threaded polling.
- Add unit test independent_queues_do_not_head_of_line_block verifying
  that an unblocked queue executes immediately even when another queue
  remains stalled on an unsignalled fence.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:00:21 +00:00
Author
Owner

@⁠Anon64 on GitHub · 2026-11-24 19:33 UTC · original

Regression run for this PR: head 7711f4c, based on main c160d86. RTX 3060 12 GB (581.80, wave32), Windows 11 26200, release, XCL_NETWORK=0, A pressed every 4 s from 20 s, scripts/smoke.ps1 on a retail title for 60 s, in one batch with the main run.

main c160d86:

xcl-smoke v1
commit: c160d86ef2efe3a07e4dfb473e4fa72eafb413c0
gpu: NVIDIA GeForce RTX 3060
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1531 (PresentX 1531)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 100443 MB

this PR:

xcl-smoke v1
commit: 7711f4c55672e0fe155943e39c529d8a822af937
gpu: NVIDIA GeForce RTX 3060
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1528 (PresentX 1528)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 99200 MB

No device removals or crashes; 99 % of main's frames, 98 % of its peak commit.

Peak commit on this machine is mostly the pipeline preload's DXC compiles (#1035) and varies from run to run, so it says little about this PR.

Not tested: the whole suite; whether the title reaches the changed code in these 60 s.

Written with Claude Code (Claude Opus 5.5) from runs on this machine.

**@⁠Anon64** on GitHub · 2026-11-24 19:33 UTC · [original](https://github.com/xcl-dev/xcl/pull/1643#issuecomment-7142267232) Regression run for this PR: head `7711f4c`, based on `main` `c160d86`. RTX 3060 12 GB (581.80, wave32), Windows 11 26200, release, `XCL_NETWORK=0`, A pressed every 4 s from 20 s, `scripts/smoke.ps1` on a retail title for 60 s, in one batch with the `main` run. main `c160d86`: ``` xcl-smoke v1 commit: c160d86ef2efe3a07e4dfb473e4fa72eafb413c0 gpu: NVIDIA GeForce RTX 3060 title: retail-title seconds: 60 exit: 0x0 frames shown: 1531 (PresentX 1531) presents per 2 s (last 3): 61 60 60 device removals: 0 crashes: 0 peak commit: 100443 MB ``` this PR: ``` xcl-smoke v1 commit: 7711f4c55672e0fe155943e39c529d8a822af937 gpu: NVIDIA GeForce RTX 3060 title: retail-title seconds: 60 exit: 0x0 frames shown: 1528 (PresentX 1528) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 99200 MB ``` No device removals or crashes; 99 % of main's frames, 98 % of its peak commit. Peak commit on this machine is mostly the pipeline preload's DXC compiles (#1035) and varies from run to run, so it says little about this PR. **Not tested:** the whole suite; whether the title reaches the changed code in these 60 s. Written with Claude Code (Claude Opus 5.5) from runs on this machine.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 21:06 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~22 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-24 21:06 UTC · [original](https://github.com/xcl-dev/xcl/pull/1643#issuecomment-7144493606) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~22 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified `main`.) Thanks!
Author
Owner

@⁠throny on GitHub · 2026-11-24 23:07 UTC · original

Two contributors checked independently and found that #562 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.

**@⁠throny** on GitHub · 2026-11-24 23:07 UTC · [original](https://github.com/xcl-dev/xcl/pull/1643#issuecomment-7147034536) <!-- xcl-1607-hint:D63 --> Two contributors checked independently and found that #562 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.
Author
Owner

@⁠throny on GitHub · 2026-11-25 17:00 UTC · original

Two contributors checked independently and found that #562 #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.

**@⁠throny** on GitHub · 2026-11-25 17:00 UTC · [original](https://github.com/xcl-dev/xcl/pull/1643#issuecomment-7168867848) <!-- xcl-1607-hint:D89 --> Two contributors checked independently and found that #562 #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.
@ -159,3 +178,3 @@
static FIRST: std::sync::Once = std::sync::Once::new();
FIRST.call_once(|| crate::xlog_info!("D3D12.X: bottom-of-pipe writes outside unified memory are done by the CPU after the GPU ({} in the first submission)", job.writes.len()));
let _ = worker().lock().unwrap().send(job);
let _ = tx.send(job);
Author
Owner

@⁠gut0to on GitHub · 2026-11-24 18:37 UTC · original

The fence value and Signal are serialized under QUEUES, but the job is sent after that lock is released. Two concurrent after() calls can therefore signal values 1 then 2 yet enqueue job 2 before job 1. Once the fence reaches 2, the worker can apply the newer payload and then overwrite it with the stale value-1 payload, violating the per-queue FIFO guarantee. Please keep enqueue order serialized with fence-value assignment (or use another ordering mechanism). AI-assisted review; I verified the race from this call sequence.

**@⁠gut0to** on GitHub · 2026-11-24 18:37 UTC · [original](https://github.com/xcl-dev/xcl/pull/1643#discussion_r4684780012) The fence value and `Signal` are serialized under `QUEUES`, but the job is sent after that lock is released. Two concurrent `after()` calls can therefore signal values 1 then 2 yet enqueue job 2 before job 1. Once the fence reaches 2, the worker can apply the newer payload and then overwrite it with the stale value-1 payload, violating the per-queue FIFO guarantee. Please keep enqueue order serialized with fence-value assignment (or use another ordering mechanism). AI-assisted review; I verified the race from this call sequence.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1643/head:github-bot/gh-1643'
git switch 'github-bot/gh-1643'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1643'
git switch 'github-bot/gh-1643'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1643'
git switch 'github-bot/gh-1643'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1643'
git switch 'main'
git merge --squash 'github-bot/gh-1643'
git switch 'main'
git merge --ff-only 'github-bot/gh-1643'
git switch 'main'
git merge 'github-bot/gh-1643'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.