Skip to content

D3D12.X: bridge Wait64BitValueX to GPU fences with exact cycle breaking - #795

Merged
theaustinayers merged 1 commit into
xcl-dev:mainfrom
gsucristo:d3d12x/wait64-gpu-bridge-and-cycles
Nov 24, 2026
Merged

theaustinayers merged 1 commit into
xcl-dev:mainfrom
gsucristo:d3d12x/wait64-gpu-bridge-and-cycles

Conversation

@gsucristo

Copy link
Copy Markdown
Contributor

Bridge monotonic Wait64BitValueX / Wait32BitValueX and Write64BitValueX operations across queues using real ID3D12Fence queue.Wait / queue.Signal instead of stalling the CPU submission thread until timeout, with an exact (queue, seq) dependency graph that detects and breaks genuine cross-queue cycles at Signal time without false positives on pipelined frames. Related to #505 (note: overlaps in goal with draft #769 and open #708; this PR specifically contributes the exact (queue, seq) transitive cycle graph including same-cell edges and GPU watchdog diagnostics, with mid-list splitting separated into a stacked follow-up PR).

Size note: The diff is +1,717 / -21 lines total (~1,005 runtime lines, ~712 lines of unit and GPU tests across 6 new tests). Mid-list command-list splitting has already been split out into a stacked follow-up PR; the remaining bridge state machine, (queue, seq) cycle graph, same-queue FIFO bypass, and GPU watchdog share the same per-cell fence table and are kept together so every submission path stays deadlock-free.

What is in it

  • crates/xcl/src/hle/d3d12x/list_x.rs: per-cell GPU ID3D12Fence bridge for monotonic Wait64/Wait32/Write64 sequences, same-queue FIFO bypass, exact (queue, seq) transitive dependency graph (including same-cell edges) with deterministic Signal-time cycle breaking, GPU completion watchdog, and 6 new GPU/unit regression tests (write_buffer_immediate_on_open_existing_heap_visible_to_cpu, cross_queue_wait64_before_signal_does_not_deadlock_submit_thread, cross_queue_cycle_and_same_queue_fifo_do_not_deadlock, pipelined_next_frame_write_is_not_false_cycle, rotating_queue_self_deadlock_and_non_monotonic_rescue_do_not_hang, cpu_watchdog_signal_with_inflight_gpu_signal_completes_cleanly).
  • crates/xcl/src/hle/d3d12x/fence_x.rs: record explicit ID3D12CommandQueue::Wait / Signal fence edges into the shared dependency graph for transitive cycle detection and watchdog diagnostics.
  • crates/xcl/src/hle/d3d12x/real.rs: hook ExecuteCommandLists submission sequencing into the Wait64 GPU bridge.

Tested

  • NVIDIA GeForce RTX 4090 (driver 610.57.04), AMD Ryzen 9 7950X3D, Linux + Proton Experimental / vkd3d-proton (relaxed vtable check), rustc 1.98.1 (x86_64-pc-windows-msvc cross-compile), debug.
  • cargo test --workspace --no-fail-fast --target x86_64-pc-windows-msvc -- --test-threads=4 --skip a_freed_block_is_decommitted_before_its_address_is_reused: 705 passed, 4 failed (pre-existing Wine-only failures: hle::xaudio2::tests::xma2_source_voice_decodes_and_manages_lifetime, test_title_runs_and_game_folder_is_untouched, disk_free_space_ex_reports_pls_quota, set_predication_buffer_state_and_kickoff), 41 ignored, 1 filtered (a_freed_block_is_decommitted_before_its_address_is_reused).
  • SKIPPED GPU tests: gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask (no wave64), gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware (no wave64).
  • All 6 new Wait64 GPU/unit tests passed on RTX 4090.

Regression run

  • Pending native Windows scripts/smoke.ps1 runs on a retail title (Linux/Proton environment only).

Not tested

  • Native Windows 10/11, AMD RDNA, Intel GPUs, scripts/smoke.ps1 retail regression run.

AI use

  • Antigravity (Google DeepMind; exact model version not exposed to the agent) — assisted with code, tests, and PR description; reviewed, built, and run on hardware by the author.

Bridge monotonic `Wait64BitValueX` / `Wait32BitValueX` and `Write64BitValueX`
sequences across queues via real `ID3D12Fence` `queue.Wait` / `queue.Signal`
instead of blocking the CPU submission thread until timeout (related to xcl-dev#505).

Track submitted and pending wait/signal dependencies as an exact `(queue, seq)`
directed graph (including same-cell write/wait edges and same-queue FIFO
ordering) so genuine cross-queue cycles are detected and broken deterministically
at Signal time without false positives on pipelined frames, backed by a GPU
completion watchdog and unit/GPU regression tests.
@MesshM

MesshM commented Nov 24, 2026

Copy link
Copy Markdown

Test run of 8a5643f4eaf1d6ffa343cd636ab50c54ef57d049 on AMD RDNA4. I merged it onto current main e50836b locally (clean merge).

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200 (native Windows, not Wine), Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug
  • cargo build --workspace + cargo test --workspace -- --test-threads=4 on the merge: 710 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 669 passed, 0 failed, 21 ignored
  • 0 SKIPPED; the fence_x / list_x tests pass, the_cell_follows_the_fence included.

Review: At 1717 lines I reviewed the structure, not every line. Overlap: the description itself names #708 (open) and #769 (draft) as having the same goal; the maintainer will want one approach for cross-queue Wait64BitValueX, so it may help to say in one place how this one differs from #708's list splitting.

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 onto main.

Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.

@upipibi

upipibi commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Three points on 8a5643f, from reading the code (not run):

1. The watchdog can lose its wakeup (high confidence). The watchdog takes lock, sees ARMED_GPU_WAITS == 0 and calls cv.wait(guard) with no timeout (list_x.rs:1335-1336), but wake_sync_watchdog calls notify_one() (:1427) without taking lock. A wait armed and notified between the check and the cv.wait is missed, and the watchdog then sleeps until the next wait is armed. If that missed wait is the one a frame hangs on, nothing releases it. Taking lock around the counter update and notify_one, or using wait_timeout in the idle branch too, closes it.

2. The cycle check doesn't see XCL's own sparse-queue waits (medium). would_signal_close_cycle (:1120) is exact only for the edges in SYNC_GRAPH. Two waits XCL inserts aren't in it: after a list that writes sparse memory the sparse queue waits on the title queue's rb_fence (sparse.rs:1193-1194), and every title queue waits on the sparse queue's s.fence (sparse.rs:1429). With a bridged Wait64 they close a cycle:

  1. L1 is submitted on Q1 with Wait64(A >= n); its writer L2 is recorded but not yet submitted; L1 writes sparse memory. That gives Q1.Wait(A), Q1.Signal(rb), sparseQ.Wait(rb).
  2. The CPU dirties pages and L2 is submitted on Q2: its uploads queue on sparseQ behind that wait, and Q2 waits on s.fence.
  3. Q2.Signal(A) passes the check (no edge from Q2 to Q1), and now Q1 waits on Q2, Q2 on sparseQ, sparseQ on Q1. Only the 5 s watchdog breaks it, by releasing A on the CPU before L2 has written it, which is an ordering violation as well as a hitch. With point 1 it can be permanent.

Recording the rb / sparse-fence edges in the graph, or not taking the readback wait on a queue that has an armed bridged wait, would cover it.

3. Overlap with #708. #708 (open, retail-tested) converts the same waits, and #769 was closed today in its favour. This PR conflicts with #708 in list_x.rs and real.rs. Is the plan to rebase onto #708 and add the cycle graph and watchdog on top?

AI-assisted (Claude Code), read-only review.

@theaustinayers
theaustinayers merged commit 78cc0f6 into xcl-dev:main Nov 24, 2026
1 check failed
@woreksami

Copy link
Copy Markdown

A run where cross-queue Wait64 cycles were not caught at Signal time and ended in the 5 s watchdog, then no frames until the title's stall watchdog (#232). It may be the case upipibi's second point describes, though here no sparse-queue edge was needed: the cycles are direct, title queue to title queue.

Setup

What happened

  • With D3D12.X: an allocator Reset keeps the recordings the title still submits #897 in there was no device removal this time (… allocator resets so far with recordings still held or on the GPU – another PC allocator took its place (64 made …)).
  • Presents fell from 30 fps (≤ 45 s) to 2 per 2 s around 90 s, and to 0 from 94.1 s on: no presents, submits, draws or dispatches in any 2 s activity line from 94.1 s until the title's watchdog at 122.2 s (+0x23cf683, write at 0, as in Retail title: null write at +0x2215c35 (#159) still hits on NVIDIA RTX 4070 Ti, with and without XCL_NETWORK=0 #232).
  • 41 GPU queue.Wait … did not complete within 5000 ms … – released on CPU to prevent GPU hang lines, all within 96.2–96.8 s and all for the same value 0x5fa, with submitted=0x5fa, completed=0x5f9 on the producer. Grouped by waiter ← producer:
    q0 <- q2   7      q2 <- q0   7
    q1 <- q2   4      q2 <- q1   4
    q3 <- q2   4      q2 <- q3   4
    q4 <- q2   5      q2 <- q4   5
    q0 <- q4   1
    
    So q2 waits on each of q0, q1, q3, q4 at 0x5fa while each of them waits on q2 at 0x5fa: four two-queue cycles at one value. The last would close a GPU cycle – signalled on CPU line was at 91.8 s, so these were not broken at Signal time.
  • Example: 96.246 GPU queue.Wait at 0x70416ab68 >= 0x5fa did not complete within 5000 ms (waiter=q0/ty2, prod=qSome(2)/tySome(0), recorded=0x5fa, submitted=0x5fa, completed=0x5f9) and 96.800 … at 0x70416aaf0 >= 0x5fa (waiter=q2/ty0, prod=qSome(0)/tySome(2), …). Next to it: pending title ID3D12Fences during GPU wait timeout: 0x…(done=0x14/sig=0x19/wait=0x0,cell=true), …(done=0xc14/sig=0xc26, …).
  • After the 41 releases on the CPU the title still made no progress for 25 s. At the end, the thread dump had none of the title's threads inside XCL except the main one (in the watchdog's report): they were waiting on their own events.
  • Video memory was oversubscribed (10.8 GB local on this 8 GB card, RAM down to ~0.6 GB free), so a slow GPU may play a part; completed stayed one below submitted on every producer for the whole 5 s, though.

Not tested

AI use

  • Claude Code with Claude Opus 5.5: built and ran the tree, read the log and thread dump and wrote this comment from that run.

wondercrash pushed a commit to wondercrash/xcl that referenced this pull request Nov 24, 2026
… split

xcl-dev#708 predates xcl-dev#795 (GPU-fence bridge) and xcl-dev#797 (mid-list split) and was
not rebased. Resolution keeps main's split machinery (xcl-dev#797 + xcl-dev#851) and
cpu_writes from xcl-dev#850 (the xcl-dev#708 per-queue workers with xcl-dev#873's
diagnostics), and ports xcl-dev#708's core change onto it:

- wait_gate.rs (from xcl-dev#708): a queue-side gate the CPU opens once it
  sees the progress value.
- PendingWait::gate: a Wait64 GE, full mask, on a non-sparse value the
  CPU can read, in a direct/compute title list, that starts its PC
  segment (split by xcl-dev#797/xcl-dev#851, or nothing recorded before it).
- execute_with_waits_on / KickoffX: gated waits arm a wait_gate instead
  of the xcl-dev#795 GPU-fence bridge; with sparse writes at or after the list
  in the batch they take the bounded CPU wait (xcl-dev#708's rule). Other waits
  keep the xcl-dev#795 bridge. Arming failure stops the title (xcl-dev#708).
- Dropped from xcl-dev#708: its own title_list piece/split machinery,
  split_recording, restore_after_reopen, open-query / split-barrier
  tracking and the Result-returning execute_with_waits.
- wait_tests.rs (from xcl-dev#708) adapted to push_segments /
  execute_with_waits_on.
@akimfomin

Copy link
Copy Markdown

Follow-up on upipibi's watchdog observation. I used PortBridge to compare queue synchronization work and isolated this case on XCL main 930e8b49.

On Windows, a synthetic CPU check missed the notification in 3/3 trials when it arrived just before the worker waited. The positive control with the worker already waiting passed 3/3. Holding the existing wake mutex while notifying made both cases pass 3/3. The producer releases the synchronization-graph lock before reaching this code. The XCL library passed cargo check.

+    let _guard = pair.0.lock().unwrap();
     pair.1.notify_one();

GPU and runtime integration still need the project's normal test path. Worker source · Rust Condvar. AI-assisted with Codex.

mastrr9 pushed a commit to mastrr9/xcl that referenced this pull request Nov 24, 2026
When a bridged Wait64 expires, the watchdog's lines give each cell's
recorded / submitted / completed values. They read the same for a cycle
of queues and for a chain of waits behind one queue that is busy, or
held by a wait outside the sync graph, because the 5 s start when the
CPU issues the Wait and not when the queue reaches it (xcl-dev#505).

Once per burst (at most one line per timeout, 64 lines in all) the
watchdog now follows the tracked waits from the queue of an expired
wait. A queue is held at its earliest tracked call in flight; when that
is a wait, the chain goes on at the queue of the Signal that satisfies
it. The line names the waits passed and where they end:

- end=cycle: a queue already on the chain,
- end=signal: a queue with no tracked wait in front of it, so it is
  executing or behind one of XCL's own tile-mapping waits, which are
  not in the graph (review of xcl-dev#795, point 2),
- end=unsubmitted: a wait that no submitted Signal satisfies,
- end=signal-gone: a wait on a cell that counts the value as submitted
  while the graph tracks no Signal for it and the fence is below it
  (the graph lost track; printed with the cell's submitted and
  CPU-signalled values).

With it: how many of the cells released in that tick end at the same
place, the watchdog's releases before this tick, the count of Write64
cycle breaks so far (their own line stops after 32), and the
tile-mapping queue's fence and readback fence as completed / asked for.

Limit: a CPU release (the watchdog's, a cycle break's) drops the cell's
tracked Signals up to its value although they may still be queued.
After the first one a queue can look held at a wait that really sits
behind such a Signal, and a chain can end in a cycle that is none. The
line is exact only while earlier_releases and write64_cycle_breaks are
0; mixed title-fence breaks are not counted.

No change to what is released or signalled. The calls in flight are
read under the graph lock before the releases, without pruning, and the
line is written after them. The watchdog now reads the clock once per
tick for the chain check and the expiry test, so both see the same
waits as expired. While no wait expires the cost is one pass over the
armed waits on the watchdog's 50 ms tick, skipped for one timeout after
a line. sparse.rs keeps a second reference to its two fences and the
value wait_for sleeps on, so that they can be read while a submit holds
the state.

Part of xcl-dev#505.

Assisted-by: Claude Code (Claude Fable 5.2)
Geckomacabre added a commit to Geckomacabre/gexcl that referenced this pull request Nov 24, 2026
The watchdog checks ARMED_GPU_WAITS holding its mutex and then waits on the
condvar; wake_sync_watchdog notified without the mutex, so a wake between
the check and the wait was lost and the watchdog slept with GPU waits armed
(reported on xcl-dev#795 and reproduced there with a synthetic test). The
notify now takes the lock first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
wondercrash pushed a commit to wondercrash/xcl that referenced this pull request Nov 24, 2026
The producer label introduced by gsucristo in xcl-dev#795 can name an old
recording-list queue even when the graph has no signal covering the
requested value. Report the covering graph-assigned signal queue and
recording-list history independently, and clear unknown hints when a
newer recording advances the tracked value.

Graph assignment precedes the host Signal call: the label does not
claim host acceptance or GPU completion. Signal/Wait behavior and
production locking are unchanged.

Verified with pure before/after controls: old selection/hint semantics
fail 3 of 4 assertions; the candidate passes all 6 focused assertions.
The existing native fixture has an added graph-attribution assertion;
its GPU execution and the broader suite remain for independent checks.

Assisted-by: Codex (GPT-6; exact deployment identifier not provided)
not-rex added a commit to not-rex/xcl that referenced this pull request Nov 25, 2026
When a bridged Wait64 expires, the watchdog's lines give each cell's
recorded / submitted / completed values. They read the same for a cycle
of queues and for a chain of waits behind one queue that is busy, or
held by a wait outside the sync graph, because the 5 s start when the
CPU issues the Wait and not when the queue reaches it (xcl-dev#505).

Once per burst (at most one line per timeout, 64 lines in all) the
watchdog now follows the tracked waits from the queue of an expired
wait. A queue is held at its earliest tracked call in flight; when that
is a wait, the chain goes on at the queue of the Signal that satisfies
it. The line names the waits passed and where they end:

- end=cycle: a queue already on the chain,
- end=signal: a queue with no tracked wait in front of it, so it is
  executing or behind one of XCL's own tile-mapping waits, which are
  not in the graph (review of xcl-dev#795, point 2),
- end=unsubmitted: a wait that no submitted Signal satisfies,
- end=signal-gone: a wait on a cell that counts the value as submitted
  while the graph tracks no Signal for it and the fence is below it
  (the graph lost track; printed with the cell's submitted and
  CPU-signalled values).

With it: how many of the cells released in that tick end at the same
place, the watchdog's releases before this tick, the count of Write64
cycle breaks so far (their own line stops after 32), and the
tile-mapping queue's fence and readback fence as completed / asked for.

Limit: a CPU release (the watchdog's, a cycle break's) drops the cell's
tracked Signals up to its value although they may still be queued.
After the first one a queue can look held at a wait that really sits
behind such a Signal, and a chain can end in a cycle that is none. The
line is exact only while earlier_releases and write64_cycle_breaks are
0; mixed title-fence breaks are not counted.

No change to what is released or signalled. The calls in flight are
read under the graph lock before the releases, without pruning, and the
line is written after them. The watchdog now reads the clock once per
tick for the chain check and the expiry test, so both see the same
waits as expired. While no wait expires the cost is one pass over the
armed waits on the watchdog's 50 ms tick, skipped for one timeout after
a line. sparse.rs keeps a second reference to its two fences and the
value wait_for sleeps on, so that they can be read while a submit holds
the state.

Part of xcl-dev#505.

Assisted-by: Claude Code (Claude Fable 5.2)
not-rex added a commit to not-rex/xcl that referenced this pull request Nov 25, 2026
When a bridged Wait64 expires, the watchdog's lines give each cell's
recorded / submitted / completed values. They read the same for a cycle
of queues and for a chain of waits behind one queue that is busy, or
held by a wait outside the sync graph, because the 5 s start when the
CPU issues the Wait and not when the queue reaches it (xcl-dev#505).

Once per burst (at most one line per timeout, 64 lines in all) the
watchdog now follows the tracked waits from the queue of an expired
wait. A queue is held at its earliest tracked call in flight; when that
is a wait, the chain goes on at the queue of the Signal that satisfies
it. The line names the waits passed and where they end:

- end=cycle: a queue already on the chain,
- end=signal: a queue with no tracked wait in front of it, so it is
  executing or behind one of XCL's own tile-mapping waits, which are
  not in the graph (review of xcl-dev#795, point 2),
- end=unsubmitted: a wait that no submitted Signal satisfies,
- end=signal-gone: a wait on a cell that counts the value as submitted
  while the graph tracks no Signal for it and the fence is below it
  (the graph lost track; printed with the cell's submitted and
  CPU-signalled values).

With it: how many of the cells released in that tick end at the same
place, the watchdog's releases before this tick, the count of Write64
cycle breaks so far (their own line stops after 32), and the
tile-mapping queue's fence and readback fence as completed / asked for.

Limit: a CPU release (the watchdog's, a cycle break's) drops the cell's
tracked Signals up to its value although they may still be queued.
After the first one a queue can look held at a wait that really sits
behind such a Signal, and a chain can end in a cycle that is none. The
line is exact only while earlier_releases and write64_cycle_breaks are
0; mixed title-fence breaks are not counted.

No change to what is released or signalled. The calls in flight are
read under the graph lock before the releases, without pruning, and the
line is written after them. The watchdog now reads the clock once per
tick for the chain check and the expiry test, so both see the same
waits as expired. While no wait expires the cost is one pass over the
armed waits on the watchdog's 50 ms tick, skipped for one timeout after
a line. sparse.rs keeps a second reference to its two fences and the
value wait_for sleeps on, so that they can be read while a submit holds
the state.

Part of xcl-dev#505.

Assisted-by: Claude Code (Claude Fable 5.2)
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.

6 participants