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

Merged
gsucristo merged 2 commits from upstream-pr/798 into main 2026-11-24 05:57:43 +00:00
gsucristo commented 2026-11-24 05:33:19 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by gsucristo on 2026-11-24T05:33:19Z.


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.
<!-- greyfinch-sync:ivall/xcl:issue:6575370376 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/798). Originally posted by [gsucristo](https://github.com/gsucristo) on 2026-11-24T05:33:19Z. --- 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.
upstream-sync closed this pull request 2026-11-24 06:59:59 +00:00
MesshM commented 2026-11-24 07:06:38 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by MesshM on 2026-11-24T05:46:11Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7123256517 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/798#issuecomment-7123256517). Originally posted by [MesshM](https://github.com/MesshM) on 2026-11-24T05:46:11Z. --- 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.
upipibi commented 2026-11-24 07:06:40 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by upipibi on 2026-11-24T05:52:10Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7123351083 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/798#issuecomment-7123351083). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-24T05:52:10Z. --- 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.
eizispark commented 2026-11-24 07:06:40 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by eizispark on 2026-11-24T05:53:21Z.


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.
<!-- greyfinch-sync:ivall/xcl:comment:7123369586 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/798#issuecomment-7123369586). Originally posted by [eizispark](https://github.com/eizispark) on 2026-11-24T05:53:21Z. --- 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.
ethandepstein-del commented 2026-11-24 07:06:41 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by ethandepstein-del on 2026-11-24T05:57:36Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7123437268 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/798#issuecomment-7123437268). Originally posted by [ethandepstein-del](https://github.com/ethandepstein-del) on 2026-11-24T05:57:36Z. --- 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.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!792
No description provided.