Skip to content

Recompiler: signal Partner::Spin exit bit (0x4000_0000) in @xcl.spin.wait - #3652

Merged
throny merged 1 commit into
xcl-dev:mainfrom
Kalmarv:fix/spin-exchange-exit-cap
Dec 2, 2026
Merged

throny merged 1 commit into
xcl-dev:mainfrom
Kalmarv:fix/spin-exchange-exit-cap

Conversation

@Kalmarv

@Kalmarv Kalmarv commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Prevent GPU stalls in direct-DXIL split-wave64 compute/mesh shaders when one hardware half exits early while its partner enters a Partner::Spin exchange.

When one half exits early, its partner previously polled @xcl.spin.wait for the full 1 << 20 (1,048,576) live-partner cap before timing out. This PR signals bit 30 (0x4000_0000, EXITED) on the departing half's counter so the partner bails out immediately on the first poll after exit, while keeping main's 1 << 20 live-partner poll cap and leaving barrier_arrive / safe_barrier_sync untouched.

What is in it

  • crates/xcl/src/gpu/dxil/module.rs (Module::spin_wait): in @xcl.spin.wait, check (c & 0x3FFF_FFFF) >= need before inspecting bit 30 (0x4000_0000) so a convergent partner exiting immediately after its final exchange never corrupts a valid rendezvous; bail immediately to the fail-marking cmpxchg when bit 30 is observed with (c & 0x3FFF_FFFF) < need; reject bits 30..31 in the entry bounds check. The live-partner poll cap stays 1 << 20 (1048576), and barrier_arrive is unchanged.
  • crates/xcl/src/gpu/dxil/lanes.rs, lower.rs, kernel.rs: add Lw::spin_exchange_exit() (called at program tail right after safe_barrier_exit()), reusing has_spin_exchange and spin_bases from #3655. Guarded by compute_gate's entry predicate (spin_entered) so out-of-limit lanes cannot signal exit while active lanes in the same hardware wave are still running under Independent Thread Scheduling. Updates lanes.rs comments to note this is direct DXIL only (the HLSL recomp::emit xcl_x_meet path is separate).
  • crates/xcl/src/gpu/dxil/module/split.rs: allow RmwOp::Or on xcl_xc alongside RmwOp::Add so split-wave64 compute shaders with spin_exchange_exit() keep dispatch-chain splitting.
  • crates/xcl/src/gpu/dxil/lanes.rs, core_tests.rs: add GPU test gpu_spin_exchange_early_exit_bails_immediately covering (1) divergent early-exit bailout (0.0038 ms median across 256 groups vs 31.1890 ms when spin_exchange_exit is removed — verified to fail without the exit bit — plus IR checks for COUNT_MASK, EXITED, and the 1 << 20 cap), (2) convergent translate_compute V_READLANE_B32 + immediate exit, and (3) the spin_entered ITS guard under partial IO_THREAD_LIMIT = 112 (16 active + 16 out-of-limit lanes in wave 3, 64-iteration scalar delay loop, 8 iterations). Update core_tests.rs split_lds_reads_meet_after_writes for the single atomicrmw or.

Tested

  • hardware (GPU + driver, CPU), Rust version, debug / release: NVIDIA GeForce RTX 5070 Ti (driver 610.74), AMD Ryzen 9 9950X, Windows 11 Pro 26200, rustc 1.99.0 (b940084d7 2026-09-28), DXC 1.9.2609.5, debug tests + release build (cargo build --release -p xcl: 39 warnings, 0 new vs main baseline of 39).
  • scripts/test.ps1 (workspace build, cargo bench -p xcl --bench '*' -- --test, cargo test --workspace -- --test-threads=4): 2975 passed, 0 failed, 52 ignored across 43 targets; 24 SKIPPED GPU tests (22 no wave64, 2 no heap windows).
  • cargo test -p xcl --lib gpu_spin_exchange_early_exit_bails_immediately -- --nocapture: passed (SPIN_EARLY_EXIT 256 groups median 0.0038 ms; temporarily removing lw.spin_exchange_exit() in Case 1 failed at 31.1890 ms > 2.0 ms).

Regression run

main:

xcl-smoke v1
commit: 5eaadb54c14e0fc29597b2a1689d7dbd83491303
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 60
exit: 0x0
frames shown: 1698 (PresentX 1698)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 15798 MB

PR:

xcl-smoke v1
commit: 4b77d6a701e41eb56aaf9391a49755c6c21e4ffb
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 60
exit: 0x0
frames shown: 1672 (PresentX 1672)
presents per 2 s (last 3): 62 60 60
device removals: 0
crashes: 0
peak commit: 16344 MB

(Note: the first smoke run after changing crates/xcl/src/gpu/dxil/* hit a cold shader cache due to XCL_DIRECT_DXIL_SOURCE_ID — 1316 frames, 0 removals, 0 crashes; the PR block above is the second warm run matching the warm main baseline.)

Not tested

  • AMD / Intel GPUs, native wave64 GPU tests (22 SKIPPED), heap-window GPU tests (2 SKIPPED), HLSL recomp::emit (xcl_x_meet) path (left untouched and out of scope for this direct-DXIL PR), in-world title gameplay beyond the 60 s smoke, Wine/Linux, and game-data sample tests (XCL_SAMPLE_* unset).

AI use

  • Antigravity (Gemini 4 Neon) rebased this PR onto origin/main (5eaadb54c, including #3655), ported only the bit-30 EXITED signal into @xcl.spin.wait while restoring the 1 << 20 live-partner cap and dropping the barrier cap change, allowed RmwOp::Or on xcl_xc in module/split.rs, strengthened gpu_spin_exchange_early_exit_bails_immediately (including the spin_entered test and without-exit-bit failure verification), ran the build/test/smoke suite, and updated this PR description.

@github-actions github-actions Bot added area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 area:tests Unit, integration, e2e tests, or testtitle gpu:nvidia Code is specific to NVIDIA / wave32 GPUs (scope tag; see needs:nvidia-test) labels Dec 2, 2026
@Kalmarv Kalmarv closed this Dec 2, 2026
@Kalmarv Kalmarv reopened this Dec 2, 2026

@SavageCore SavageCore left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment (not blocking, needs CI confirm): spin-exchange EXIT bit (0x40000000) + timeout caps address GPU hangs in the right place, and arrived-before-EXITED ordering looks right. Concerns before merge: (1) caps 1<<20->1<<12 (spin) / ->1<<16 (barrier) are aggressive - premature timeout on loaded slow-partner rendezvous vs TDR tradeoff not quantified. (2) Exit signal only wired at normal tail - S_BARRIER-leave / loop-budget early-outs bypass it, leaving spin-to-timeout. spin_entered==None fallback is unguarded. (3) CI shows one success (04:05:59) and one prior failure (03:50:00) on Build and test - confirm failure was prior push/flake; get_status is pending.

@Kalmarv

Kalmarv commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review @SavageCore! Addressing each point directly against the current code:

  1. Timeout caps (1 << 12 spin / 1 << 16 safe-barrier):

    • With bit-30 EXITED signaling, divergent early exits no longer hit the timeout path at all (they bail on the first poll after exit; 0.0017 ms median for 256 groups in gpu_spin_exchange_early_exit_bails_immediately).
    • Both halves of a split console wave belong to the same threadgroup (co-resident on the same SM sharing LDS), so 4096 serialized LDS atomicrmw iterations for a cross-half exchange (spin_exchange) and 65536 iterations for a multi-wave workgroup barrier (safe_barrier_sync) are sized to leave room for a live co-scheduled partner while cutting worst-case runaway stall duration by 256x / 16x vs 1 << 20 (which can trip the 2 s Windows TDR across dense dispatches).
    • That said, we do not currently have a GPU-to-CPU telemetry counter quantifying slow-partner timeout rate under heavy SM load, so if you prefer a more conservative fallback cap (e.g. 1 << 14 = 16384 for spin_exchange now that bit 30 handles early exits immediately), I am happy to adjust and re-verify.
  2. Exit paths and spin_entered == None:

    • Every early-out path in translate_on_this_thread routes to the single exit -> tail block (kernel.rs:596-600, right after safe_barrier_exit()):
      • Term::End (S_ENDPGM): branches to end == exit (kernel.rs:517, 569).
      • Per-loop pass cap (VAR_LOOP_PASSES): branches to end == exit (kernel.rs:528-530).
      • Per-lane loop budget (VAR_BUDGET): branches to end == exit (kernel.rs:540-543).
      • Compact mode (compact::emit / emit_with_nest): both S_ENDPGM and VAR_BUDGET branch to exit (compact.rs:976, 992).
      • compute_gate (S_BARRIER / leave): kernel.rs:483-486 sets lw.spin_entered = Some(runs) and branches to exit. When S_BARRIER is present (leave == false), compute_gate returns group-uniform st.runs (kernel.rs:1233-1234), so either the entire group skips together (runs == false, nobody waits) or all lanes enter together (runs == true) and signal EXITED at tail. When leave == true, out-of-limit lanes have runs == false and are already excluded from the partner's xn via st.partner_lanes, so guarding spin_exchange_exit on spin_entered prevents them from setting bit 30 early under ITS while active lanes in the same warp are still executing.
    • spin_entered == None only occurs when group_runs is None — for Partner::Spin, that is strictly Entry::Mesh, which has no compute_gate (every lane in the mesh threadgroup enters h0 together).
  3. CI status:

    • Confirmed: the earlier 03:49:53Z Build and test (Windows, no GPU) failure (job 143202141589) on the same commit 032557e79 was an unrelated runner flake (xcl.exe hit 0xc0000005 inside D3D12Core.dll during gpu::dxil::compact_tests::gpu_compact_form_runs_as_the_plain_form right after eh::tests::the_process_ends_while_another_thread_holds_the_heap, before core_tests or lanes tests started).
    • Retriggering on the exact same commit 032557e79 via close/reopen passed cleanly (job 143205667464), and all 5 latest check-runs (Build and test (Windows, no GPU), PR description, triage, mirror, publish) are completed / success. (The legacy commit /status endpoint reports pending with statuses: [] because this repo uses Actions check-runs.)

@vasanex

vasanex commented Dec 2, 2026 •

Copy link
Copy Markdown

merge-check
base: 1c8b551
head: 032557e
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2910 passed, 0 failed, 51 ignored; SKIPPED: 25 (22 no wave64, 2 no heap windows, 1 cannot disable the driver cache), the same tests as on the base (2909 passed there); failing: none. gpu_spin_exchange_early_exit_bails_immediately ran and passed on this wave32 adapter.
review: whole diff read. One point that blocks for me. (1) The exit bit is sound as far as I can see: the count is compared under COUNT_MASK before bit 30 is looked at, and a half's own counter cannot carry the bit before its own exit. (2) Separately from the exit bit, the wait for a partner that has NOT exited drops from 1 << 20 to 1 << 12 polls (and safe_barrier_sync from 1 << 20 to 1 << 16). A timed-out half marks the partner's counter, and from then on both halves stop consuming exchanged values for the rest of the dispatch (they read zeros). So a partner half that is alive but late (scheduled later, or in a long stretch before its next exchange) now fails the exchange 256 times sooner, and that shows as wrong output, not as a hang. The new test covers a partner that exited and a pair that meets at once; nothing covers a live partner that arrives late, and the 60 s smoke does not reach a title's world, where split wave64 programs with long bodies run (on this card several of them take 10 to 20 ms a dispatch). The exit bit alone already removes the long spin in the case the PR describes.
performance: no cost by default in the 60 s smoke: base 1608 frames, peak commit 19911 MB; merged tree 1696 frames, 18123 MB (91 %), presents 60 60 61, 0 device removals, 0 crashes. Not measured: a title's world (the change retranslates every split program, which is a cold shader cache of well over 25 minutes here; I did not run it).
verdict: not yet: the lower poll caps for a live partner are an unmeasured correctness risk; either keep 1 << 20 for a partner that has not exited (the exit bit gives the early bail-out), or show with a late-partner test or an in-world comparison that 4096 polls are enough.
hardware / tool and model: NVIDIA GeForce RTX 3080 10 GB (driver 621.40), AMD Ryzen 9 7950X, Windows 11 Pro 26200, rustc 1.100.0 / Claude Code with Claude Fable 5.2. Run and posted without a human check of each point.

@github-actions github-actions Bot added needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU and removed needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU labels Dec 2, 2026
@Foniass

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Review (head 032557e, diff read, not a merge-check):

  • The 2^12 poll cap also applies to a partner that is alive but late. crates/xcl/src/gpu/dxil/lanes.rs ~547 drops the wait from 2^20 to 4096 polls for every exchange, including ones where the partner has not exited. When the cap runs out, the half marks the partner's counter FAIL. Both halves then set VAR_XDEAD and read 0 for every exchange until the dispatch ends, so the result is wrong output, not a hang. The exit bit already handles the case the description gives (a departed half), and nothing measures a slow live partner: the new test only covers a partner that exited and a pair that meets at once. Keeping 2^20 when the EXITED bit is clear would fix the early-exit case without this risk.
  • The barrier cap has nothing to do with early exits. On main, safe_barrier_exit already decrements XCL_BAR_ALIVE when a wave leaves, so a departed wave never holds safe_barrier_sync. The 2^16 cap at lanes.rs ~741 therefore only cuts the wait for waves that are still running. A wave that times out goes past the barrier and sets VAR_BAR_ALIVE to 0, so it skips every later barrier and its LDS accesses are no longer synchronised. The description does not justify this cap and nothing measures it.
  • The HLSL translator is left out. crates/xcl/src/gpu/recomp/emit.rs ~6671 (xcl_x_meet) and ~6772 (PRELUDE_SAFE_BARRIER) still poll 2^20 times and have no exit bit, yet the comments at lanes.rs ~439 and ~679 still say the DXIL code matches them. A split program that goes through the HLSL path keeps the stall this PR fixes, and the same program now times out differently depending on which translator built it.
  • The test does not show that the exit bit works. With only the new 2^12 cap and no exit bit, case 1's upper half would give up after 4096 polls (about 0.1 to 0.3 ms by Recompiler: bound spin waits of programs without a loop at 2^12 polls #3668's numbers) and still store 0xBEEF. So the marker check and the med_ms < 2.0 check (lanes.rs ~1484) would both pass. Only the atomicrmw or string check notices if the exit bit is missing. The spin_entered guard is untested too, since case 2 runs every lane. A fixed 2 ms wall-clock limit also depends on the GPU.
  • Overlaps. Recompiler: bound spin waits of programs without a loop at 2^12 polls #3668 changes the same two lines (lanes.rs ~547, ~741) with the opposite policy: it keeps 2^20 in programs that have a loop because there a wave can rightly wait for another wave's loop, and it covers the HLSL preludes as well. At most one of the two policies can land. Recompiler: eliminate redundant split-wave64 compute barriers and share exchange helpers #3655 replaces both loops with module::spin_wait / barrier_arrive helpers (module.rs ~540, still 2^20) and has its own has_spin_exchange, so the exit bit would have to be rewritten inside that helper. D3D12.X: cap a small compute dispatch's loop entries at 4096 passes #3667 changes the dispatch loop budget, a different layer, and does not conflict.

Fine: the exit bit itself looks sound by reading. Arrival is compared under COUNT_MASK before bit 30 is checked, so a partner that exits right after its last exchange does not break the meet. A half's own counter cannot carry bit 30 before that half exits. Every exit (S_ENDPGM, the loop-pass and budget caps, the compact form, the compute gate) goes through tail, where the gate's runs dominates. The entry bounds check now refuses bits 30 and 31.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

@Foniass

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

merge-check
base: 1c8b551
head: 032557e
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2910 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: read by one reviewer at this same head; the review is at #3652 (comment) and its findings stand. Most serious: the 2^12 spin and 2^16 barrier caps also cut partners that are still running, giving silently wrong output.
performance: 60 s smoke of a retail title, main 1c8b551 vs this merge (032557e): 1652 -> 1586 frames shown (96 %; last presents per 2 s: 60 60 60), peak commit 18228 -> 15729 MB, 0 device removals, 0 crashes.
verdict: not yet: the 2^12 spin and 2^16 barrier caps also cut partners that are still running, giving silently wrong output (see the review)
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

AI-written and posted by Foniass without a human check of each point.

…wait

When one hardware half of a split-wave64 compute or mesh shader exits
early while its partner enters a Partner::Spin exchange, the partner
previously polled the full 1 << 20 live-partner cap before timing out.

Port only the bit-30 EXITED signal (0x4000_0000) into @xcl.spin.wait
while keeping main's 1 << 20 live-partner poll cap and leaving
barrier_arrive / safe_barrier_sync untouched:
- Emit Lw::spin_exchange_exit() at program tail (after
  safe_barrier_exit), guarded by compute_gate's entry predicate
  (spin_entered) so out-of-limit lanes cannot signal exit while active
  lanes in the same wave are still running under ITS.
- In Module::spin_wait (@xcl.spin.wait), check (c & 0x3FFF_FFFF) >= need
  before inspecting bit 30 so a convergent partner exiting right after
  its final exchange never corrupts a valid rendezvous, and reject bits
  30..31 in the entry bounds check.
- Allow RmwOp::Or on xcl_xc in module/split.rs so split-wave64 compute
  shaders using spin_exchange_exit keep dispatch-chain splitting.
- Add GPU test gpu_spin_exchange_early_exit_bails_immediately covering
  divergent early-exit bailout (0.0038 ms vs 31.1890 ms without the exit
  bit across 256 groups on RTX 5070 Ti), convergent exchange + exit, and
  the spin_entered guard under partial IO_THREAD_LIMIT.

Co-Authored-By: Antigravity (Gemini 4 Neon) <noreply@google.com>
@Kalmarv
Kalmarv force-pushed the fix/spin-exchange-exit-cap branch from 032557e to 4b77d6a Compare December 2, 2026 14:55
@Kalmarv Kalmarv changed the title Recompiler: signal Partner::Spin exit bit (0x4000_0000) and cap spin/barrier timeouts Recompiler: signal Partner::Spin exit bit (0x4000_0000) in @xcl.spin.wait Dec 2, 2026
@Kalmarv

Kalmarv commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @vasanex, @Foniass, and @SavageCore for the thorough reviews and merge-checks! Rebased onto origin/main (5eaadb54c, which includes merged #3655) and updated to 4b77d6a70 addressing every point:

  1. Restored 1 << 20 live-partner poll cap and dropped barrier cap change (@vasanex, @Foniass, @SavageCore):

    • Ported only the bit-30 EXITED signal (0x4000_0000) into #3655's shared @xcl.spin.wait helper (crates/xcl/src/gpu/dxil/module.rs), keeping limit = 1 << 20 unchanged for partners that have not exited.
    • Dropped the safe_barrier_sync / barrier_arrive 2^16 cap change completely (barrier_arrive and safe_barrier_sync are untouched).
    • Also allowed RmwOp::Or on xcl_xc in crates/xcl/src/gpu/dxil/module/split.rs so split-wave64 compute shaders using spin_exchange_exit() keep dispatch-chain splitting.
  2. Honest lanes.rs comments on HLSL scope (@Foniass):

    • Updated the exchange_spin / spin_exchange_exit doc comments in lanes.rs to state clearly that bit-30 exit signaling is direct DXIL only and that the HLSL recomp::emit xcl_x_meet path is separate (not claiming parity with HLSL).
  3. Strengthened GPU test + without-exit-bit failure check + spin_entered coverage (@Foniass, @SavageCore):

    • With 1 << 20 restored, verified Case 1 genuinely fails without spin_exchange_exit(): temporarily disabling lw.spin_exchange_exit() in Case 1 made the 256-group divergent dispatch stall to 31.1890 ms median (failing the < 2.0 ms assertion by >15x), vs 0.0038 ms median with bit-30 exit signaling (~8,200x faster).
    • Added IR assertions checking COUNT_MASK (0x3FFF_FFFF), EXITED (0x4000_0000), and the 1 << 20 live-partner cap (1048576) inside @xcl.spin.wait.
    • Added Case 3 exercising the spin_entered ITS guard under partial IO_THREAD_LIMIT[0] = 112 on a 128-thread group (wave 3 has 16 active + 16 out-of-limit lanes, 64-iteration scalar delay loop before V_READLANE_B32 lane 32, 8 iterations verifying 0..63 -> 0x1020, 64..111 -> 0x1060, 112..127 -> 0).
  4. Verification on 4b77d6a70 (RTX 5070 Ti, driver 610.74, rustc 1.99.0, DXC 1.9.2609.5):

    • cargo build --release -p xcl: 39 warnings (0 new vs main 5eaadb54c).
    • scripts/test.ps1: 2975 passed, 0 failed, 52 ignored across 43 targets; 24 SKIPPED (22 no wave64, 2 no heap windows).
    • Warm 60 s smoke (title: ea3b5e4d): 5eaadb54c 1698 frames (60 61 60, 15798 MB) vs 4b77d6a70 1672 frames (62 60 60, 16344 MB), 0 device removals, 0 crashes, exit: 0x0.
    • python scripts/pr_check.py --local: description ok.

Ready for re-review! (Updated and verified with Antigravity, Gemini 4 Neon.)

@github-actions github-actions Bot added the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Dec 2, 2026
@vasanex

vasanex commented Dec 2, 2026 •

Copy link
Copy Markdown

merge-check
base: 5eaadb5
head: 4b77d6a
merge: clean (git diff --check clean)
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2975 passed, 0 failed, 52 ignored; SKIPPED: 25 (22 no wave64, 2 no heap windows, 1 cannot disable the driver cache), the same tests as on the base (2974 passed there); failing: none. The new GPU test gpu_spin_exchange_early_exit_bails_immediately ran on this card (wave32) and passed, and so did the edited split_lds_reads_meet_after_writes.
review: whole diff read (6 files, +182/-14). The blocker of my check of 032557e is gone: @xcl.spin.wait keeps 1 << 20 polls for a partner that has not exited, and the barrier waits are untouched. No finding in the new head. Checked by reading: the wait tests the arrived count under the 30-bit mask before it looks at the exit bit, so a partner that leaves right after its last exchange still gives a valid meeting; on a seen exit bit the half goes through the same compare-exchange as a timeout and polls again when the partner's counter moved meanwhile; the own-counter guard now refuses bits 30 and 31, which only stops a half that has itself left; the exit bit is set once per half (first lane) and only by lanes that passed the launch gate (spin_entered), which the test's third case covers; split.rs lets the or on xcl_xc through so such programs still split. The comments now say that the HLSL path does not signal the exit. Not covered by anything here: wave64 hardware, and a program in a title that reaches a divergent exit.
performance: one atomic or per half at program exit, and a faster bail-out where a partner has left. 60 s smoke, release, same title and settings: base 1697 frames, peak commit 17749 MB; merged tree 1685 frames, 17859 MB (101 %), presents 60 60 60, 0 device removals, 0 crashes. The smoke's title did not visibly depend on the path either way.
verdict: safe to merge
hardware / tool and model: NVIDIA GeForce RTX 3080 10 GB (driver 621.40), AMD Ryzen 9 7950X, Windows 11 Pro 26200, rustc 1.100.0 / Claude Code with Claude Fable 5.2. Run and posted without a human check of each point.

@Foniass

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

merge-check
base: 5eaadb5
head: 4b77d6a
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2975 passed, 0 failed, 52 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: follow-up on 4b77d6a (reworked and rebased from 032557e, my last review's head). Rebased onto main 5eaadb5 (which has #3655): the exit bit moved into Module::spin_wait and the live-partner cap is back to 1 << 20 (module.rs ~566-630); the barrier cap is gone and barrier_arrive is untouched; spin_exchange_exit runs at the program tail right after safe_barrier_exit (kernel.rs ~642, lanes.rs ~663), guarded by the new spin_entered (compute_gate's runs, kernel.rs ~527); module/split.rs ~194 now accepts RmwOp::Or on xcl_xc; the test has three cases (lanes.rs ~1438-1547). Earlier findings: (1) the 2^12 cap cutting a live but late partner: fixed; the cap is 1 << 20 again and a partner is cut short only when bit 30 is set. (2) the unrelated barrier cap: fixed (dropped). (3) the HLSL translator: partly fixed; the comments now say the exit bit is direct DXIL only, but emit.rs xcl_x_meet has no exit bit, so a split program built through the HLSL path still waits the full 2^20 polls when one half exits early. (4) the test not proving the exit bit: mostly fixed; with the 2^20 cap, case 1 stalls without the exit bit (31.19 ms against 0.0038 ms) and case 2 checks a convergent exchange followed by an immediate exit; the 2 ms wall-clock limit (~1488) depends on the GPU, with a large margin. (5) overlaps: #3655 is merged and the exit bit sits in its helper; open #3668 targets the same limit in @xcl.spin.wait, so whichever lands second needs a rebase there, but the policies no longer contradict. New: the one-line split.rs ~194 change is untested; every translated split-wave64 compute program with a spin exchange now carries the new atomicrmw or, and without that line split_compute would silently stop building dispatch chains for them, but no test translates such a program and checks a chain is still built. Case 3 (the spin_entered guard with IO_THREAD_LIMIT = 112) isn't shown to fail without the guard. Fine: the arrival count is compared under COUNT_MASK before bit 30 is read; a peer setting bit 30 between a timeout poll and the cmpxchg goes through raced and fails correctly; the fallback own-counter pointer matches exchange_bases(self.half); runs dominates the tail; a half entirely past the thread limit gives its partner xn from partner_lanes, so it doesn't wait; geometry phases end with a partner other than Spin, so they don't signal. One logical change of about 180 lines, most of them test.
performance: 60 s smoke of a retail title, main 5eaadb5 vs this merge (4b77d6a): 1422 -> 1440 frames shown (101 %; last presents per 2 s: 61 60 60), peak commit 17184 -> 16116 MB, 0 device removals, 0 crashes. This run is lower than most today: the PC was in use at the time (a browser and Discord running), and main's own runs on this machine today ranged from 1370 to 1652 frames, so the difference isn't clearly from this PR.
verdict: safe to merge: no blocking finding in the review (the points there are minor), the suite passes and the smoke run is clean
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

AI-written and posted by Foniass without a human check of each point.

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of 4b77d6a7: 2 finding(s) (2 medium), most severe first.

  1. Medium crates/xcl/src/gpu/dxil/lanes.rs:684: Not certain about this one, because it depends on ITS scheduling: the spin_entered guard excludes only compute_gate's out-of-limit lanes, and the exit signal still comes from wave_is_first_lane() among whichever entered lanes reach `.... (inline)
  2. Medium crates/xcl/src/gpu/dxil/module.rs:597: The entry bounds check now rejects bit 30 as well as bit 31 in old | after | need, which halves the counter's headroom: an exchange fails once epoch*partners or the own count reaches 2^30 instead of 2^31. (inline)

These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.

Ok(())
})
};
if let Some(entered) = self.spin_entered {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium: Not certain about this one, because it depends on ITS scheduling: the spin_entered guard excludes only compute_gate's out-of-limit lanes, and the exit signal still comes from wave_is_first_lane() among whichever entered lanes reach tail first. So a hardware wave whose entered lanes haven't reconverged at tail can publish EXITED while other lanes of that half are still running. On NVIDIA ITS, the non-leader lanes of @xcl.spin.wait branch straight to exit and can run ahead, as can lanes split by per-lane guarded regions. If they OR 0x4000_0000 into this half's counter while the half still has exchanges to do, the partner's next exchange fails at once, VAR_XDEAD latches, and every later exchange returns 0 instead of the real value. Signalling only when all entered lanes are present (wave_all_bit_count against the entered-lane count taken at entry) would remove the dependence.

let bounds = emit(word, Op::Bin(BinOp::Or, old, after, 0));
let bounds = emit(word, Op::Bin(BinOp::Or, bounds, need, 0));
let bad = emit(bit, Op::Cmp(Pred::SLt, bounds, zero));
let bounds_high = emit(word, Op::Bin(BinOp::And, bounds, hi2, 0));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium: The entry bounds check now rejects bit 30 as well as bit 31 in old | after | need, which halves the counter's headroom: an exchange fails once epoch*partners or the own count reaches 2^30 instead of 2^31. A 32-lane half in a loop with many exchanges per iteration (VAR_XK counts every exchange the program runs) gets bit 30 set in need after about 2^25 exchanges, takes bad with no peer exit or timeout, latches VAR_XDEAD and returns 0 from every later exchange. Before this PR the limit was twice as high. Masking bit 30 out of the bounds check (it's checked separately as EXITED) would keep the old headroom.

@bmjask

bmjask commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.

@Kalmarv

Kalmarv commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for checking 4b77d6a7 @bmjask! Checked both automated findings against the implementation — both are non-issues, so 4b77d6a7 does not need changes:

  1. lanes.rs:684 (spin_entered / ITS scheduling):

    • Inside @xcl.spin.wait (module.rs:590, 633-636), non-leader lanes branch to the helper's internal exit merge block (not program tail), where dx.op.waveReadLaneFirst immediately broadcasts the leader's result (SHFL.SYNC on NVIDIA) before the trailing TGSM_FENCE; non-leader lanes cannot run ahead of the leader out of @xcl.spin.wait to program tail.
    • Inside the shader body, RDNA2 control flow (S_CBRANCH_*), VAR_LOOP_PASSES, and VAR_BUDGET are wave-uniform across the entered lanes of a 32-lane half, and per-lane guarded(...) regions reconverge locally without branching to program tail. Only compute_gate branches per-lane to program exit -> tail, which spin_entered guards (matching safe_barrier_exit() right above at lanes.rs:721).
    • Also note: checking wave_all_bit_count == entered_count at tail would drop the exit signal entirely if lanes ever arrived unsynchronized (neither subset would equal entered_count).
  2. module.rs:597 (rejecting bit 30 in old | after | need):

    • Rejecting bit 30 (0xC000_0000) is required for soundness because bit 30 is EXITED (0x4000_0000): masking bit 30 out would let own carry into bit 30 while alive (spontaneously setting EXITED and wrapping c & 0x3FFF_FFFF to 0) and let need >= 0x4000_0000 become unsatisfiable against the 30-bit arrived = c & 0x3FFF_FFFF.
    • The 30-bit counter gives 2^25 (~33.5M) exchanges for a 32-lane half, which is far beyond LOOP_BUDGET (1 << 16 = 65,536 iterations in lower.rs:45).

(Checked and drafted with Antigravity, Gemini 4 Neon; no code changed on 4b77d6a70, so both verdict: safe to merge checks from @vasanex and @Foniass remain current for @Prime1997.)

@github-actions github-actions Bot added needs:title-run Runtime change: needs a merge-check with a real title run into the world (#3041) and removed needs-pr-check Failing the PR description check (CONTRIBUTING.md) labels Dec 2, 2026
@tiagonleal

Copy link
Copy Markdown
Contributor

merge-check
base: 5ad98ad
head: 4b77d6a
merge: clean (merge commit 7762c81f9c2e80495e706eda18a23f600dd152e8; git diff --check clean)
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 3006 passed, 0 failed, 52 ignored; SKIPPED: 24 (22 no wave64, 2 no heap windows); failing: none
title run: Newer Retail Game, release build of this merge, Series S settings (XCL_DEVICE_TYPE=lockhart, XCL_COHERENT_MB=512, XCL_UMA_WINDOWS=16, XCL_SPARSE_LAZY=1), scripted A presses, 240 s planned: into the world at 92 s, 147 s there with no frame presented (as in main's first run), no crash, no device removal; ran to the 240 s limit.
review: none found that blocks. Nit: the GPU test asserts a median under 2.0 ms of wall-clock time, which could flake on a loaded GPU.
performance: one extra groupshared atomic per spin kernel; the wait loop can now leave early when the partner has exited. World frame rate not compared: on this 32 GB PC the runs of main and of the PRs end 30 to 150 s into the world (RAM guard or time limit).
verdict: safe to merge
hardware / tool and model: RTX 5070 Ti 16 GB (driver 617.42), Ryzen 7 9800X3D, 32 GB, Windows 11 Pro 26300 / Claude Code with Claude Opus 5.5

Same settings on main 5ad98ad, two runs: into the world at 94 s with 145 s there and no frame presented (ran to the 240 s limit); into the world at 80 s with 59 s there and 90 frames, then stopped by our RAM guard (free RAM under 1 GB). "In the world" here means the first 2 s window of the activity log with 5,000+ draws and dispatches.

AI use: Claude Code (Claude Opus 5.5) ran the build, tests and title runs and wrote this; a Claude Sonnet subagent read the diff and I checked its points.
~Tiago

@github-actions github-actions Bot added ready-to-merge Has 2 independent safe merge-checks on current head (#3041) and removed needs:title-run Runtime change: needs a merge-check with a real title run into the world (#3041) labels Dec 2, 2026
@throny
throny merged commit 12ece31 into xcl-dev:main Dec 2, 2026
5 of 7 checks passed
Jockerino pushed a commit to Jockerino/xcl-fork that referenced this pull request Dec 3, 2026
…barrier timeouts (port of xcl-dev/xcl#3652)

Prevent TDRs when one half of a split-wave64 compute/mesh wave exits early while its partner enters a Partner::Spin exchange or safe_barrier_sync:

- Signal bit 30 (0x4000_0000) on this half's spin counter in spin_exchange_exit() at program exit (guarded by compute_gate's per-lane entry predicate so out-of-limit lanes cannot race under Independent Thread Scheduling).
- Check (c & 0x3FFF_FFFF) >= need before inspecting bit 30 in spin_exchange so a convergent partner that exits right after its final exchange never corrupts a successful rendezvous, and bail immediately to timeout/FAIL when bit 30 is observed before need is met.
- Cap spin_exchange polling at 4096 (1 << 12) iterations and safe_barrier_sync polling at 65536 (1 << 16) iterations instead of 1 << 20.
- Add GPU test gpu_spin_exchange_early_exit_bails_immediately covering both divergent early-exit bailout and convergent exchange + immediate exit.

Co-Authored-By: Antigravity (Gemini 4 Neon) <noreply@google.com>

(cherry picked from commit 032557e79bcc68a45846b55c8dac91f216dff8f6)
Jockerino pushed a commit to Jockerino/xcl-fork that referenced this pull request Dec 3, 2026
…7d6a70

Upstream rewrote #3652 on top of #3655 (head 4b77d6a70, "signal Partner::Spin exit bit
(0x4000_0000) in @xcl.spin.wait"): a half leaving the program sets bit 30 on its arrival
counter (`Lw::spin_exchange_exit`, guarded by `compute_gate`'s `spin_entered`), and the
shared wait helper `@xcl.spin.wait` checks the arrived count first, then bit 30, so a
partner that left is seen at once while a live partner keeps the `1 << 20` poll cap; the
barrier's poll cap is no longer changed; the split splitter allows the `atomicrmw or` on
`xcl_xc` (module/split.rs). The Lw-level `has_spin_exchange` goes (the module's, from
#3655, is the one), and the exit takes its counter from `spin_bases` (or the half's
counter, `cbase + half`) and does nothing without a partner half (`xn` 0).

Port note (by hand): stage c had already moved the old #3652's exit bit into #3655's
`@xcl.spin.wait` and allowed the `or` in split.rs, so the bit exists once in the build,
where the new head has it. This commit aligns the helper with the new head (names,
order of its constants, comments), replaces `spin_exchange_exit` and the exchange's
doc with the new head's, and drops the Lw flag. Ours stays: `XCL_SPIN_POLLS` and
`XCL_BARRIER_POLLS` set the polls, and their defaults are now the new head's `1 << 20`
both (unset: no cache tag; another count still tags the identity). Upstream's GPU test
gpu_spin_exchange_early_exit_bails_immediately (its new case 3, the `spin_entered` guard
under a partial thread limit) runs in #3655's outlined form and in our default, the
helpers inline; split_lds_reads_meet_after_writes counts as the new head does (the exit
`or` left out of the per-exchange count) in both forms.

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

area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 area:tests Unit, integration, e2e tests, or testtitle gpu:nvidia Code is specific to NVIDIA / wave32 GPUs (scope tag; see needs:nvidia-test) ready-to-merge Has 2 independent safe merge-checks on current head (#3041)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants