Repository navigation
D3D12.X: bridge Wait64BitValueX to GPU fences with exact cycle breaking - #795
Conversation
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.
|
Test run of Tested
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 Not tested: no retail title or regression run (I have no unpacked game), no Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code. |
|
Three points on 1. The watchdog can lose its wakeup (high confidence). The watchdog takes 2. The cycle check doesn't see XCL's own sparse-queue waits (medium).
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 AI-assisted (Claude Code), read-only review. |
|
A run where cross-queue Setup
What happened
Not tested
AI use
|
… 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.
|
Follow-up on upipibi's watchdog observation. I used PortBridge to compare queue synchronization work and isolated this case on XCL main 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 + 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. |
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 (ivall#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 ivall#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 ivall#505. Assisted-by: Claude Code (Claude Fable 5.2)
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>
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)
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)
Bridge monotonic
Wait64BitValueX/Wait32BitValueXandWrite64BitValueXoperations across queues using realID3D12Fencequeue.Wait/queue.Signalinstead 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 GPUID3D12Fencebridge for monotonicWait64/Wait32/Write64sequences, 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 explicitID3D12CommandQueue::Wait/Signalfence edges into the shared dependency graph for transitive cycle detection and watchdog diagnostics.crates/xcl/src/hle/d3d12x/real.rs: hookExecuteCommandListssubmission sequencing into the Wait64 GPU bridge.Tested
rustc 1.98.1(x86_64-pc-windows-msvccross-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).SKIPPEDGPU 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).Regression run
scripts/smoke.ps1runs on a retail title (Linux/Proton environment only).Not tested
scripts/smoke.ps1retail regression run.AI use