Recompiler: bounded split-wave64 spin default and early-exit-safe s_barrier #798

Manually merged
github merged 2 commits from gh-pr/798/head into gh-pr/798/base 2026-11-26 04:33:00 +00:00
Owner

@⁠gsucristo on GitHub · 2026-11-24 05:33 UTC · original
gsucristo:recomp/safe-s-barrier-and-x64-spin → main · +244 −17 · 2 files · 2 commits · merged 2026-11-24 05:57 UTC

Prevent GPU SM deadlocks in translated Compute and Mesh shaders on 32-lane GPUs (and under early wave exits) by defaulting split-wave64 exchanges to bounded arrival counters (XCL_X_SPIN 1) and emitting an early-exit-safe, bounded LDS arrival barrier (xcl_s_barrier) for multi-warp s_barrier.

On RDNA2, s_endpgm decrements the active workgroup wave count so surviving waves reaching s_barrier do not wait for already-exited waves. On PC D3D12/NVIDIA, GroupMemoryBarrierWithGroupSync() compiles to bar.sync 0, which hangs the SM permanently if any hardware warp exits early (s_endpgm), exhausts xcl_budget (LOOP_GUARD), or diverges in split-wave64 mode.

What is in it

  • Commit 1 (crates/xcl/src/gpu/recomp/emit.rs, tests.rs): default x64_spin() to true (XCL_X_SPIN 1, opt-out via XCL_WAVE64_SPIN=0) and update gpu_split_wave64_waves_diverge.
  • Commit 2 (crates/xcl/src/gpu/recomp/emit.rs, tests.rs): pre-scan for s_barrier in multi-warp Compute/Mesh shaders (compute_or_mesh_hw_waves() > 1) and emit xcl_s_barrier_init / xcl_s_barrier / xcl_s_barrier_exit backed by XCL_BAR_ALIVE + packed (gen: 20, arrived: 12) XCL_BAR_STATE bounded at 1 << 20 iterations (opt-out via XCL_SAFE_BARRIER=0); emit GroupMemoryBarrier() for single-warp Compute/Mesh s_barrier; add gpu_safe_s_barrier_multi_warp_and_early_endpgm testing 4-warp 2-gen LDS exchange (wave64 and wave32) and upper-wave early s_endpgm before two s_barriers.

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: 700 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).
  • New/updated GPU tests passed on RTX 4090: gpu_split_wave64_waves_diverge, gpu_safe_s_barrier_multi_warp_and_early_endpgm.

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 (native wave64 hardware), Mesh shader xcl_s_barrier dispatch on hardware (Compute path tested), 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.
**@⁠gsucristo** on GitHub · 2026-11-24 05:33 UTC · [original](https://github.com/xcl-dev/xcl/pull/798) `gsucristo:recomp/safe-s-barrier-and-x64-spin` → `main` · +244 −17 · 2 files · 2 commits · merged 2026-11-24 05:57 UTC Prevent GPU SM deadlocks in translated Compute and Mesh shaders on 32-lane GPUs (and under early wave exits) by defaulting split-wave64 exchanges to bounded arrival counters (`XCL_X_SPIN 1`) and emitting an early-exit-safe, bounded LDS arrival barrier (`xcl_s_barrier`) for multi-warp `s_barrier`. On RDNA2, `s_endpgm` decrements the active workgroup wave count so surviving waves reaching `s_barrier` do not wait for already-exited waves. On PC D3D12/NVIDIA, `GroupMemoryBarrierWithGroupSync()` compiles to `bar.sync 0`, which hangs the SM permanently if any hardware warp exits early (`s_endpgm`), exhausts `xcl_budget` (`LOOP_GUARD`), or diverges in split-wave64 mode. **What is in it** - Commit 1 (`crates/xcl/src/gpu/recomp/emit.rs`, `tests.rs`): default `x64_spin()` to `true` (`XCL_X_SPIN 1`, opt-out via `XCL_WAVE64_SPIN=0`) and update `gpu_split_wave64_waves_diverge`. - Commit 2 (`crates/xcl/src/gpu/recomp/emit.rs`, `tests.rs`): pre-scan for `s_barrier` in multi-warp Compute/Mesh shaders (`compute_or_mesh_hw_waves() > 1`) and emit `xcl_s_barrier_init` / `xcl_s_barrier` / `xcl_s_barrier_exit` backed by `XCL_BAR_ALIVE` + packed `(gen: 20, arrived: 12)` `XCL_BAR_STATE` bounded at `1 << 20` iterations (opt-out via `XCL_SAFE_BARRIER=0`); emit `GroupMemoryBarrier()` for single-warp Compute/Mesh `s_barrier`; add `gpu_safe_s_barrier_multi_warp_and_early_endpgm` testing 4-warp 2-gen LDS exchange (wave64 and wave32) and upper-wave early `s_endpgm` before two `s_barrier`s. **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`: 700 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`). - New/updated GPU tests passed on RTX 4090: `gpu_split_wave64_waves_diverge`, `gpu_safe_s_barrier_multi_warp_and_early_endpgm`. **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 (native wave64 hardware), Mesh shader `xcl_s_barrier` dispatch on hardware (Compute path tested), `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.
In split-wave64 mode (two hardware wave32s per console wave64), 1-wave64
threadgroups previously defaulted to `XCL_X_SPIN 0` (`GroupMemoryBarrierWithGroupSync()`),
which can permanently hang a GPU SM if the two hardware wave32 halves ever
diverge. Default `x64_spin()` to `true` (bounded arrival-counter exchange)
and allow opting back to group barriers with `XCL_WAVE64_SPIN=0`.
On RDNA2, `s_endpgm` removes the exiting wave from the workgroup's active
barrier count so surviving waves executing `s_barrier` do not wait for it.
On PC D3D12/NVIDIA, `GroupMemoryBarrierWithGroupSync()` compiles to
`bar.sync 0`, which hangs the SM if any hardware warp exits early via
`s_endpgm`, exhausts `xcl_budget`, or diverges after a split-wave64 desync.

For multi-warp Compute and Mesh shaders containing `s_barrier`, emit an
early-exit-safe, bounded LDS arrival barrier (`xcl_s_barrier`) tracking live
warps in `XCL_BAR_ALIVE` and `(generation, arrived)` in `XCL_BAR_STATE`,
initialized at shader entry and decremented on exit (opt-out via
`XCL_SAFE_BARRIER=0`). Single-warp Compute/Mesh `s_barrier` emits
`GroupMemoryBarrier()`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:32:58 +00:00
github manually merged commit 0c02b87b26 into gh-pr/798/base 2026-11-26 04:33:00 +00:00
Author
Owner

@⁠MesshM on GitHub · 2026-11-24 05:46 UTC · original

Test run of 0c02b87b267142801e6843563988bf7ac5f6a2e7 on AMD RDNA4. I merged it onto current main e50836b locally (clean merge) and tested that tree.

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, Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug
  • cargo build --workspace + cargo test --workspace -- --test-threads=4 on the merge: 705 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 664 passed, 0 failed, 21 ignored
  • 0 SKIPPED; gpu_safe_s_barrier_multi_warp_and_early_endpgm passes, natively in wave64 on this adapter.

Review: A question about the bounded barrier: it lets waves go on after a bounded wait instead of hanging the SM when a wave has exited early. If the bound can also be reached by a wave that is merely slow (a long divergent path before its s_barrier), the others would continue unsynchronised and read LDS that is not written yet, giving wrong results rather than a hang. Is the bound tied only to waves that have executed s_endpgm (counted), or is it a spin count? If it is a spin count, a log or counter when it expires would make such a case visible. The change also alters how multi-wave s_barrier is emitted on 64-lane GPUs like this one; the suite passes here.

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.

**@⁠MesshM** on GitHub · 2026-11-24 05:46 UTC · [original](https://github.com/xcl-dev/xcl/pull/798#issuecomment-7123256517) Test run of `0c02b87b267142801e6843563988bf7ac5f6a2e7` on AMD RDNA4. I merged it onto current `main` `e50836b` locally (clean merge) and tested that tree. **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, Rust 1.100.0 `stable-x86_64-pc-windows-msvc`, debug - `cargo build --workspace` + `cargo test --workspace -- --test-threads=4` on the merge: **705 passed, 0 failed, 41 ignored**, exit code 0; `xcl` lib tests 664 passed, 0 failed, 21 ignored - **0 `SKIPPED`**; `gpu_safe_s_barrier_multi_warp_and_early_endpgm` passes, natively in wave64 on this adapter. **Review:** A question about the bounded barrier: it lets waves go on after a bounded wait instead of hanging the SM when a wave has exited early. If the bound can also be reached by a wave that is merely slow (a long divergent path before its `s_barrier`), the others would continue unsynchronised and read LDS that is not written yet, giving wrong results rather than a hang. Is the bound tied only to waves that have executed `s_endpgm` (counted), or is it a spin count? If it is a spin count, a log or counter when it expires would make such a case visible. The change also alters how multi-wave `s_barrier` is emitted on 64-lane GPUs like this one; the suite passes here. **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.
Author
Owner

@⁠upipibi on GitHub · 2026-11-24 05:52 UTC · original

On 0c02b87, from reading the code (not run):

When xcl_s_barrier hits the 1 << 20 poll bound (emit.rs:5410-5416), the waiting wave decrements XCL_BAR_ALIVE for
itself while it keeps running, advances the generation (which releases every wave waiting at this barrier before the slow
wave has arrived), and turns its own later barriers off. The slow wave's eventual arrival is counted in the next
generation, so every later barrier in the group releases one arrival early. The result is silently wrong LDS data with no
host-side signal, where main would wait or hang visibly. A wave stuck in a long but legitimate loop (LOOP_GUARD allows
65 536 iterations) can plausibly exceed 2^20 LDS-atomic polls. Could the timeout raise a sticky flag the runtime logs,
and keep the waiter counted? The same applies to the now default-on XCL_X_SPIN path (xcl_x_dead).

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

**@⁠upipibi** on GitHub · 2026-11-24 05:52 UTC · [original](https://github.com/xcl-dev/xcl/pull/798#issuecomment-7123351083) On `0c02b87`, from reading the code (not run): When `xcl_s_barrier` hits the `1 << 20` poll bound (emit.rs:5410-5416), the waiting wave decrements `XCL_BAR_ALIVE` for itself while it keeps running, advances the generation (which releases every wave waiting at this barrier before the slow wave has arrived), and turns its own later barriers off. The slow wave's eventual arrival is counted in the next generation, so every later barrier in the group releases one arrival early. The result is silently wrong LDS data with no host-side signal, where main would wait or hang visibly. A wave stuck in a long but legitimate loop (`LOOP_GUARD` allows 65 536 iterations) can plausibly exceed 2^20 LDS-atomic polls. Could the timeout raise a sticky flag the runtime logs, and keep the waiter counted? The same applies to the now default-on `XCL_X_SPIN` path (`xcl_x_dead`). AI-assisted (Claude Code), read-only review.
Author
Owner

@⁠eizispark on GitHub · 2026-11-24 05:53 UTC · original

Hardware check of 0c02b87b267142801e6843563988bf7ac5f6a2e7 (verified clean merge with main e50836b): pass.

Tested

  • Hardware: AMD Radeon RX 9070 XT (RDNA4, driver 32.0.32015.16001), AMD Ryzen 7 9800X3D, 32 GB RAM, Windows 11, rustc 1.100.0 (0ef1bc386 2026-11-09), release + test profile
  • cargo test --workspace -- --test-threads=4: 702 passed, 3 failed, 41 ignored (GPU tests skipped on this adapter: none; unfiltered native Windows run — the 3 hle::d3d12x failures were shared-VRAM contention in placed_title_textures_share_vram_and_preserve_pixels plus 2 downstream mutex PoisonErrors; cargo test -p xcl --lib hle::d3d12x:: -- --test-threads=1: 105 passed, 0 failed, 1 ignored)
  • gpu::recomp::tests (gpu_split_wave64_waves_diverge, gpu_safe_s_barrier_multi_warp_and_early_endpgm): 2 passed, 0 failed on native RDNA4 wave64

Regression run
main (f4ce27c):

xcl-smoke v1
commit: f4ce27ceb6d1b0576d0c659b713b674778bf1968
gpu: AMD Radeon RX 9070 XT
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1667 (PresentX 1667)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14847 MB

PR (0c02b87):

xcl-smoke v1
commit: 0c02b87b267142801e6843563988bf7ac5f6a2e7
gpu: AMD Radeon RX 9070 XT
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1653 (PresentX 1653)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14863 MB

Not tested

  • wave32-only GPUs (NVIDIA / Intel); mesh-shader xcl_s_barrier hardware dispatch; gameplay past the menus

AI use

  • Antigravity (Gemini 4 Carbon) ran the build, test suite, and scripts/smoke.ps1 harness on this machine and formatted this report.
**@⁠eizispark** on GitHub · 2026-11-24 05:53 UTC · [original](https://github.com/xcl-dev/xcl/pull/798#issuecomment-7123369586) Hardware check of `0c02b87b267142801e6843563988bf7ac5f6a2e7` (verified clean merge with `main` `e50836b`): **pass**. **Tested** - Hardware: AMD Radeon RX 9070 XT (RDNA4, driver 32.0.32015.16001), AMD Ryzen 7 9800X3D, 32 GB RAM, Windows 11, `rustc 1.100.0 (0ef1bc386 2026-11-09)`, release + test profile - `cargo test --workspace -- --test-threads=4`: `702 passed, 3 failed, 41 ignored` (GPU tests skipped on this adapter: `none`; unfiltered native Windows run — the 3 `hle::d3d12x` failures were shared-VRAM contention in `placed_title_textures_share_vram_and_preserve_pixels` plus 2 downstream mutex `PoisonError`s; `cargo test -p xcl --lib hle::d3d12x:: -- --test-threads=1`: `105 passed, 0 failed, 1 ignored`) - `gpu::recomp::tests` (`gpu_split_wave64_waves_diverge`, `gpu_safe_s_barrier_multi_warp_and_early_endpgm`): `2 passed, 0 failed` on native RDNA4 wave64 **Regression run** `main` (`f4ce27c`): ``` xcl-smoke v1 commit: f4ce27ceb6d1b0576d0c659b713b674778bf1968 gpu: AMD Radeon RX 9070 XT title: GTA6.Xbox.v1.0.2.1 seconds: 60 exit: 0x0 frames shown: 1667 (PresentX 1667) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14847 MB ``` PR (`0c02b87`): ``` xcl-smoke v1 commit: 0c02b87b267142801e6843563988bf7ac5f6a2e7 gpu: AMD Radeon RX 9070 XT title: GTA6.Xbox.v1.0.2.1 seconds: 60 exit: 0x0 frames shown: 1653 (PresentX 1653) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14863 MB ``` **Not tested** - wave32-only GPUs (NVIDIA / Intel); mesh-shader `xcl_s_barrier` hardware dispatch; gameplay past the menus **AI use** - Antigravity (Gemini 4 Carbon) ran the build, test suite, and `scripts/smoke.ps1` harness on this machine and formatted this report.
Author
Owner

@⁠mastrr9 on GitHub · 2026-11-24 05:57 UTC · original

Independent native Windows NVIDIA RTX 5080 (wave32) + D3D12 debug layer build/test run and code review at head 0c02b87b267142801e6843563988bf7ac5f6a2e7.

Code Review

  • Checked the LDS layout math in x64_lds + safe_barrier_prelude: XCL_XS + XCL_XC end at 8189, XCL_BAR_ALIVE = 8189, XCL_BAR_STATE = 8190, XCL_XW = 8191 (no slot overlap), and in the non-x64 LDS case XCL_LDS_TOP = 8188u keeps title LDS accesses below 8189..8190.
  • Checked Flow::End lowering in recomp/mod.rs: sets pc = 0xFFFFFFFFu; rather than return;, so early s_endpgm falls cleanly into xcl_s_barrier_exit() at the end of main().
  • Both gpu_safe_s_barrier_multi_warp_and_early_endpgm and gpu_split_wave64_waves_diverge passed cleanly on wave32 NVIDIA hardware (where split_wave64 + XCL_X_SPIN 1 + xcl_s_barrier() actually exercise the multi-warp wave32 path).

Tested

  • Environment: NVIDIA GeForce RTX 5080 (16 GB, wave32, driver 617.42 / 32.0.16.1742), Windows 11 Pro 25H2 (26200.9974), D3D12 debug layer installed (d3d12SDKLayers.dll), rustc 1.100.0 (0ef1bc386 2026-11-09) MSVC, DXC from Windows SDK 10.0.26100.0, debug build.
  • Command: cargo build --workspace && cargo test --workspace -- --test-threads=4
  • Result: 705 passed, 0 failed, 41 ignored (0 new warnings).
  • PR-specific tests (2/2 ok, executed on RTX 5080, not skipped):
    • gpu::recomp::tests::gpu_safe_s_barrier_multi_warp_and_early_endpgm
    • gpu::recomp::tests::gpu_split_wave64_waves_diverge
  • SKIPPED (2):
    • gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask (no wave64)
    • gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware (no wave64)

Not tested

  • AMD/wave64 hardware (already covered above), release build, and retail titles.

AI use: Antigravity (Gemini 4 Neon reviewed the diff; Gemini 4 Hydrogen ran the RTX 5080 workspace tests) drafted this report.

**@⁠mastrr9** on GitHub · 2026-11-24 05:57 UTC · [original](https://github.com/xcl-dev/xcl/pull/798#issuecomment-7123437268) Independent native Windows **NVIDIA RTX 5080 (wave32)** + **D3D12 debug layer** build/test run and code review at head `0c02b87b267142801e6843563988bf7ac5f6a2e7`. ### Code Review - Checked the LDS layout math in `x64_lds` + `safe_barrier_prelude`: `XCL_XS` + `XCL_XC` end at `8189`, `XCL_BAR_ALIVE` = `8189`, `XCL_BAR_STATE` = `8190`, `XCL_XW` = `8191` (no slot overlap), and in the non-`x64` LDS case `XCL_LDS_TOP = 8188u` keeps title LDS accesses below `8189..8190`. - Checked `Flow::End` lowering in `recomp/mod.rs`: sets `pc = 0xFFFFFFFFu;` rather than `return;`, so early `s_endpgm` falls cleanly into `xcl_s_barrier_exit()` at the end of `main()`. - Both `gpu_safe_s_barrier_multi_warp_and_early_endpgm` and `gpu_split_wave64_waves_diverge` passed cleanly on wave32 NVIDIA hardware (where `split_wave64` + `XCL_X_SPIN 1` + `xcl_s_barrier()` actually exercise the multi-warp wave32 path). ### Tested - **Environment:** NVIDIA GeForce RTX 5080 (16 GB, wave32, driver `617.42` / `32.0.16.1742`), Windows 11 Pro 25H2 (`26200.9974`), D3D12 debug layer installed (`d3d12SDKLayers.dll`), `rustc 1.100.0 (0ef1bc386 2026-11-09)` MSVC, DXC from Windows SDK `10.0.26100.0`, debug build. - **Command:** `cargo build --workspace && cargo test --workspace -- --test-threads=4` - **Result:** **705 passed, 0 failed, 41 ignored** (0 new warnings). - **PR-specific tests (2/2 `ok`, executed on RTX 5080, not skipped):** - `gpu::recomp::tests::gpu_safe_s_barrier_multi_warp_and_early_endpgm` - `gpu::recomp::tests::gpu_split_wave64_waves_diverge` - **SKIPPED (2):** - `gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask` (`no wave64`) - `gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware` (`no wave64`) ### Not tested - AMD/wave64 hardware (already covered above), release build, and retail titles. **AI use:** Antigravity (Gemini 4 Neon reviewed the diff; Gemini 4 Hydrogen ran the RTX 5080 workspace tests) drafted this report.
This discussion has been locked. Commenting is limited to contributors.
No description provided.