Skip to content

Direct DXIL: bound single-wave split exchanges - #1741

Closed
hajduzsolt wants to merge 1 commit into
xcl-dev:mainfrom
hajduzsolt:fix/direct-dxil-single-wave-spin
Closed

hajduzsolt wants to merge 1 commit into
xcl-dev:mainfrom
hajduzsolt:fix/direct-dxil-single-wave-spin

Conversation

@hajduzsolt

@hajduzsolt hajduzsolt commented Nov 24, 2026 •

Copy link
Copy Markdown

Runtime fix verified with unit tests and RX 9070 XT smoke run.

What is in it

Tested

  • Windows 11 x64, AMD Ryzen 7 9800X3D, AMD Radeon RX 9070 XT 16 GB: cargo test -p xcl --lib split_single_wave_uses_bounded_exchange -- --test-threads=2 passed.
  • XCL_DIRECT_DXIL=1 cargo test -p xcl --lib gpu_split_wave64 -- --test-threads=1 --nocapture passed (5 passed, no reported skips).
  • cargo test --workspace -- --test-threads=2 passed; library tests: 827 passed, 22 ignored. Other test binaries also passed. Runtime GPU skips were not individually assessed in this run.

Regression run

main:

xcl-smoke v1
commit: b9b6ea62080cc62fc19e212033372d01c6214e5c
gpu: AMD Radeon RX 9070 XT
title: A newer retail game
seconds: 60
exit: 0x0
frames shown: 1678 (PresentX 1678)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14840 MB

PR:

xcl-smoke v1
commit: 254f51a7e6faa1d757016b39979ced29ab05b24b
gpu: AMD Radeon RX 9070 XT
title: A newer retail game
seconds: 60
exit: 0x0
frames shown: 1679 (PresentX 1679)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14845 MB

Not tested

AI use

  • Codex (GPT 6.1 Terra Medium) wrote the implementation and synthetic unit tests; human review and smoke verification are pending.

@hajduzsolt
hajduzsolt marked this pull request as ready for review November 24, 2026 20:09
anoyarou pushed a commit to anoyarou/xcl that referenced this pull request Nov 24, 2026
@fromthemoonx

Copy link
Copy Markdown

On an NVIDIA wave32 card the #1727 hang still happens with this PR, as often as on main. The build, the tests and the new test's check are fine.

Tested

  • NVIDIA GeForce RTX 3060 12 GB (32-lane waves, so wave64 runs split), driver 32.0.16.1088; AMD Ryzen 7 5700X; native Windows 11 Pro 26H2 (build 26300.9974); rustc 1.100.0 stable-x86_64-pc-windows-msvc; DXC 1.9.2602.17; debug

  • Direct DXIL: split wave64 uses a group barrier for 1-wave groups – GPU hangs in parallel test runs on NVIDIA (RTX 5070) #1727's reproduction, XCL_DIRECT_DXIL=1 cargo test -p xcl --lib -- --test-threads=4, alternating main b9b6ea6 and this head 254f51a, 12 runs each:

    runs hung (0x887a0006)
    main 12 6
    this PR 12 6
    main, default HLSL path (no XCL_DIRECT_DXIL) 6 0

    The System log has 44 nvlddmkm event 153 entries during these runs. The hung runs fail the same wave64 tests on both trees (gpu_split_wave64_waves_diverge, gpu_wave64_ps_spill_slots, gpu_wave64_vs_spill_slots_and_identity, …), plus gpu_sparse_vram_descriptors_buffers_and_xmem and the tests that share the removed device. So the 33–64-thread group barrier does not look like the cause on this card, or not the only one.

  • Exact head 254f51a7e6faa1d757016b39979ced29ab05b24b (base 85e3826): cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4: 876 passed, 0 failed, 42 ignored

  • Merged onto current main b9b6ea6 (no conflict): 890 passed, 0 failed, 42 ignored

  • split_single_wave_uses_bounded_exchange fails with 33..=64 => Partner::Present put back (33 threads must use bounded counter exchange). 10 runs with the change: 10 of 10 passed.

  • Your command, XCL_DIRECT_DXIL=1 cargo test -p xcl --lib gpu_split_wave64 -- --test-threads=1: 3 of 3 passed (5 tests each). One thread does not hang on either tree.

  • SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware; heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows

Not tested

  • Release build; a retail title with XCL_DIRECT_DXIL=1; DRED.

AI use

  • Claude Code (Claude Opus 5.5) ran the builds, tests and hang counts on the machine above and wrote this report from the output.

@IgorAntunes66

Copy link
Copy Markdown

Test report from split-wave64 hardware (the case listed under "Not tested"), plus a correction on the motivation.

RTX 5070 12 GB (wave32 only), driver 621.24, Windows 11 26H2, rustc 1.100.0, DXC 1.9.2602.17, PR head 254f51a (base 85e3826).

Correctness: cargo test -p xcl --lib -- --test-threads=1: 827 passed, 0 failed, 22 ignored, both without and with
XCL_DIRECT_DXIL=1 (skips: 2 × no wave64, 1 × Developer Mode). split_single_wave_uses_bounded_exchange + gpu_split_wave64*
with XCL_DIRECT_DXIL=1: 6 passed.

#1727 hang: this does not fix it. I wrote #1727's barrier hypothesis and later bisected it to the sparse VRAM test, which
#614 fixes (correction in #1727). XCL_DIRECT_DXIL=1 cargo test -p xcl --lib -- gpu::recomp::tests::gpu_ --test-threads=4,
runs interleaved with base 85e3826:

runs hung (0x887a0006 + nvlddmkm 153)
85e3826 12 2
this PR 12 9
this PR + #614 12 0

An equivalent local patch earlier gave 9/15 vs 9/15 on c160d86, so I would not read the 9 vs 2 as this PR making it worse;
with #614 applied it is clean. So this can stand as hardening, but not as the fix for #1727.

Review notes (from reading the code, not tested):

  • TRANSLATOR_VERSION (kernel.rs:36-39) is not bumped. Its comment says it must change with any change to the emitted
    containers because gpu/dxil is not in build.rs's source hash, so existing direct-DXIL disk caches would keep serving the
    barrier form.
  • The HLSL path lets XCL_WAVE64_SPIN=0 go back to group barriers for 1-wave groups; there is no counterpart here.

AI use: Claude Code (claude-opus-5-5) ran the tests and measurements and drafted this comment; I reviewed it.

mastrr9 added a commit to mastrr9/xcl that referenced this pull request Nov 24, 2026
Brings xcl-dev#1747, xcl-dev#1791, xcl-dev#605, xcl-dev#1679, xcl-dev#1806, xcl-dev#1745, xcl-dev#1307, xcl-dev#1321 among others.

Resolutions:
- dxil/kernel.rs: upstream's Lw::new / Lw::finish; the safe s_barrier state
  and policy and xcl-dev#1741's single-wave bounded exchange move into Lw::new, with
  a safe_barrier flag (false for the per-lane lowering).
- dxil/lower.rs: VAR_BAR_DEAD moves to VAR_BUDGET + 6 (+5 is VAR_F32_MODE).
- TRANSLATOR_VERSION 9.
- d3d12x/bind.rs: the bounded ExecuteIndirect call runs inside
  fresh_indirect_arguments.
- d3d12x/list_x.rs: tracked_list_type, and transition (pub(super)) over the
  batched transitions.
- recomp/mod.rs: compact backend and per-lane modules both kept; the
  oversized-structured-code fallback applies to translate after prepare.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11): merge conflict with current main — needs a rebase before it can be tested.

@Raul-Paiva

Copy link
Copy Markdown

A test of this PR on split-wave64 NVIDIA hardware, the case under Not tested. Counts only.

Setup:

Warm caches hide this PR. src/gpu/dxil/ is not in TRANSLATOR_SOURCES (build.rs), so with a warm translated cache the new DXIL is never built (#1947 fixes that). I changed the cache identity locally for the runs below.

Result on a retail title:

  • Without this PR (2 runs), the device was removed (0x887a0006) 3.5 s after a burst of compute dispatches. Nsight Aftermath showed the GPU hung in a 64-thread compute program (one console wave per group).
  • With this PR (6 runs), that program grows from 8.5 KB to 10.7 KB of DXIL, and Aftermath no longer finds the hang there.
  • The device removal is still there in 5 of the 6 runs, 4 – 85 s after the burst. DRED names the same partly executed list as before. Aftermath shows the hang in another 64-thread program, the one with the most cross-half exchanges (136).
  • It does not change when the spin gives up after 1 024 polls instead of 2^20 (local switch, 4 runs). So the remaining hang does not look like this PR's exchange.

A cost: the bounded exchange grows the largest compute program from 4.0 MB to 6.2 MB of DXIL. The NVIDIA driver took 92 s to build it once, and with 32 GB of RAM (47 GB commit limit) four runs and two precompile attempts ran out of memory while it was building. For the other runs I kept the group barrier locally for that one program.

Not tested: the whole suite on this tree; AMD; the HLSL path; the title without the other PRs listed above.

AI use: Claude Code (Claude Opus 5.5) applied the PR locally, ran the builds, tests and runs, read the logs and dumps, and wrote this comment.

@throny throny added the goal:world-load Bears on the retail title getting past world loading label Nov 25, 2026
theaustinayers added a commit to theaustinayers/xcl that referenced this pull request Nov 25, 2026
…ges by counters

A wave64 program on 32-lane hardware runs as two hardware halves that
exchange ballot words and lane values. Groups of more than one console wave
do that through bounded group-shared counters; a group of exactly one
(33 to 64 threads) met at a group barrier at every exchange. Those barriers
hung NVIDIA GPUs when several such programs ran at once (xcl-dev#1727: device hung
and driver event 153 in 11 of 25 parallel runs of the lib tests on an
RTX 5070, none on the HLSL path, whose exchange spins by default). A retail
title's world runs such programs on several queues at once and ended in a
driver time-out with no shader exception.

A compute or mesh group of one console wave now takes the counter exchange
too (its slots and counters are made for it when the program has no LDS).
Geometry programs, which set their partner by phase, and the tests' kernel
form keep the barrier. The change is that of xcl-dev#1741 (hajduzsolt), which is
open and written against an older main; applied here by hand.

Not run on a GPU. The test checks the translated program: one group barrier
(the start's) and the counters' atomics for 33, 64 and 128 threads.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@hajduzsolt

Copy link
Copy Markdown
Author

Thank you for the detailed reports and the correction to the original motivation. The results do not establish this as a fix for #1727; the change should be evaluated as separate split-wave hardening. The direct-DXIL source-hash cache fix in #1947 has since merged upstream.

I tested a local rebase with a single-wave barrier fallback, but have not pushed it: the updated tree introduced three failing dispatch-splitting tests, including invalid PHI nodes. Its workspace run had 1,193 passed, 5 failed and 26 ignored in the xcl unit suite. A separate run on upstream 06c9f55 had 1,194 passed, 2 failed and 26 ignored; those two failures were also present in the rebased run. The additional three failures need investigation before the rebase is ready. No new smoke result is claimed.

@hajduzsolt
hajduzsolt marked this pull request as draft November 25, 2026 15:40
@hajduzsolt
hajduzsolt marked this pull request as ready for review November 25, 2026 15:40
@hajduzsolt

Copy link
Copy Markdown
Author

Thank you for the testing and review. I am closing this change: the bounded spin exchange uses group-shared counters and atomics, while the current dispatch splitter cannot safely carry that state across dispatch boundaries. Supporting it requires a broader splitter redesign. The barrier fallback passes the split-dispatch fixtures, but its synchronization behavior does not establish an equivalent fix for the originally proposed spin path.

@hajduzsolt hajduzsolt closed this Nov 25, 2026
@hajduzsolt
hajduzsolt deleted the fix/direct-dxil-single-wave-spin branch November 25, 2026 15:43
theaustinayers added a commit to theaustinayers/xcl that referenced this pull request Nov 25, 2026
…ing them

After the merge of upstream's dispatch chains, a single split wave64 of a
compute group (64 threads, two hardware wave32 halves) meets its other half
through group-shared counters its entry zeroes (Partner::Spin, xcl-dev#1741), and the
exchange's running number (VAR_XK) counts from the program's start. A later
piece of a chain is a new dispatch: its prefix zeroes the counters again, so
its first exchange waits for a count they never reach, stalls for 2^20 polls
and then reads 0 for the other half. split_compute refused every such program
only by accident (the xcl_xc global, the atomics and the TGSM fences), and
upstream's wave64 chain tests still expected a chain: on a GPU with wave32
they panic at chain.expect(...).

- kernel.rs finish_dispatch: a program with a split thread id and the spin
  exchange is not given to split_compute at all; it is built whole as before
  (optimize + finish_optimized, the same output as try_finish), with a log
  line when it is above XCL_DIRECT_SPLIT_INSTRUCTIONS saying why.
- split.rs tests: compare() and dispatch_chain_divergent_forward_edges_3d now
  build and check the program on the CPU before the wave32 skip. At 64 threads
  they assert that split_compute keeps the program whole and run only the
  whole program on the GPU; at 32 threads they still require a chain of at
  least 3 pieces and compare it with the whole one. On the merged tree the
  64-thread case fails on the software adapter this way (chain None where the
  test expected a chain). compare()'s loop blocks register their edges with
  the translator's SSA (lw.block / lw.br / lw.cond_br): the spin exchange
  reads VAR_XK / VAR_XDEAD through it, and with raw blocks the 64-thread whole
  program failed validation (a PHI with no entries).
- kernel.rs test a_split_wave64_compute_program_stays_whole: a 64-thread
  split program with exchanges before and after 40 cuttable blocks goes
  through finish_dispatch with a piece limit and comes out whole and valid.

Tested (agentcargo wrapper, software adapter, release):
  test --release -p xcl --lib -- --test-threads=4 gpu::dxil::
  169 passed, 0 failed, 3 ignored. The CPU halves of the chain tests ran;
  their GPU halves printed SKIPPED (no wave32 GPU): dispatch_chain_wave32_live_loops,
  dispatch_chain_wave64_live_loops_and_exchange, dispatch_chain_oversized_loop_matches_whole,
  dispatch_chain_divergent_forward_edges_3d, dispatch_chain_payload_*.
Not run: the 54 tests that open the hardware GPU themselves (the wrapper skips
them); no GPU run of the whole 64-thread fixtures.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants