Repository navigation
Recompiler: bounded split-wave64 spin default and early-exit-safe s_barrier - #798
Conversation
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()`.
|
Test run of Tested
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 Not tested: no retail title or regression run (I have no unpacked game), no Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code. |
|
On When AI-assisted (Claude Code), read-only review. |
|
Hardware check of Tested
Regression run PR ( Not tested
AI use
|
|
Independent native Windows NVIDIA RTX 5080 (wave32) + D3D12 debug layer build/test run and code review at head Code Review
Tested
Not tested
AI use: Antigravity (Gemini 4 Neon reviewed the diff; Gemini 4 Hydrogen ran the RTX 5080 workspace tests) drafted this report. |
PR xcl-dev#798 (066ae5b, "Recompiler: default split-wave64 exchange to bounded spin") made the counter variant the default for every group and made XCL_WAVE64_SPIN=0 the way back to group barriers. The note still described the state before it, in three places and in the opposite direction: - the "one console wave per group" bullet presented GroupMemoryBarrierWithGroupSync as what those groups use; - the counter bullet said "XCL_WAVE64_SPIN=1 forces this variant everywhere", so a reader takes the bounded wait to be opt-in; - hazard 5 said "only the multi-wave variant spins". `emit.rs`, `x64_spin`, reads the variable as `map_or(true, |v| v.trim() != "0")`: unset means spin. Its own doc comment says so, and `tests.rs` reads it the same way. This matters beyond tidiness. As written, the note tells a reader on a wave32 GPU that the bounded wait (2^20 polls, then `xcl_x_dead` and half-local values) is off for their one-wave groups, when it is on for every group. That is the first thing one would want to rule out when reading a load-sensitive failure in this family, such as xcl-dev#847. The old sentence "the test suite passes with it too" is dropped rather than carried over to the other direction: on an RTX 5070 Ti, `cargo test -p xcl --lib gpu::recomp -- --test-threads=4` is not stable in either mode (four runs each: 0, 6, 5, 0 failures with the default and 1, 7, 1, 7 with XCL_WAVE64_SPIN=0). The failures are the family of xcl-dev#343 plus DXGI_ERROR_DEVICE_REMOVED collateral, and they do not separate by the variable, so the note should not claim an outcome either way. Documentation only; the emitter is unchanged. Assisted-by: Claude Code (Claude Opus 5) Co-Authored-By: Claude Opus 5 <[email protected]>
…v#798) The Synchronisation section still named the group barrier as the form for a group of one console wave and XCL_WAVE64_SPIN=1 as the switch to the counters. Since xcl-dev#798 the HLSL translation uses the counters in every group and XCL_WAVE64_SPIN=0 brings the barrier back; the direct DXIL backend still uses the barrier there (Partner::Present) and does not read the variable. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…arrier In the HLSL split-wave64 form a group of one console wave (64 threads or fewer) is just the two 32-lane halves, and they take the same branches (on exchanged, wave-uniform state), so both reach every exchange. Since xcl-dev#798 they met through the bounded counter spin there too, which costs about 2.3x the group barrier per exchange on Ampere (xcl-dev#1244: 13.2 ms vs 5.7 ms on an RTX 3080 in bench_split_wave64, 64-thread groups, one exchange per iteration; 3.6x vs 1.55x wave32 on an RTX 3070). x64_spin_for picks the form: groups of more than one console wave keep the counters (a barrier would wait for other console waves); one-wave groups now get the barrier, as the direct DXIL translator does (Partner::Present, xcl-dev#1426). XCL_WAVE64_SPIN=1 forces the counters everywhere, for debugging a desynchronised pair (wrong output instead of a hang); =0 keeps the barrier, as before. Assisted-by: Claude Code (Claude Opus 5.5)
…(XCL_WAVE64_BARRIER=1) In the HLSL split-wave64 form a group of one console wave (64 threads or fewer) is just the two 32-lane halves, and they take the same branches (on exchanged, wave-uniform state), so both reach every exchange. The counter spin they use by default (xcl-dev#798) costs about 2.3x the group barrier per exchange on Ampere (xcl-dev#1244), but the barrier is unbounded: a pair that desynchronises (a plain scalar load that sees two values) hangs the dispatch, where the counters give up after a bounded wait. So the counters stay the default and the barrier is opt-in: XCL_WAVE64_BARRIER=1 (or XCL_WAVE64_SPIN=0, as before) selects it for groups of 64 threads or fewer; XCL_WAVE64_SPIN set to any other value still forces the counters and wins. Groups of several console waves always use the counters. x64_spin_for holds the rule and is unit tested; XCL_WAVE64_BARRIER bypasses the shader cache like XCL_WAVE64_SPIN. A GPU test covers one-wave groups that end early under the barrier.
…arrier In the HLSL split-wave64 form a group of one console wave (64 threads or fewer) is just the two 32-lane halves, and they take the same branches (on exchanged, wave-uniform state), so both reach every exchange. Since xcl-dev#798 they met through the bounded counter spin there too, which costs about 2.3x the group barrier per exchange on Ampere (xcl-dev#1244: 13.2 ms vs 5.7 ms on an RTX 3080 in bench_split_wave64, 64-thread groups, one exchange per iteration; 3.6x vs 1.55x wave32 on an RTX 3070). x64_spin_for picks the form: groups of more than one console wave keep the counters (a barrier would wait for other console waves); one-wave groups now get the barrier, as the direct DXIL translator does (Partner::Present, xcl-dev#1426). XCL_WAVE64_SPIN=1 forces the counters everywhere, for debugging a desynchronised pair (wrong output instead of a hang); =0 keeps the barrier, as before. Assisted-by: Claude Code (Claude Opus 5.5)
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-warps_barrier.On RDNA2,
s_endpgmdecrements the active workgroup wave count so surviving waves reachings_barrierdo not wait for already-exited waves. On PC D3D12/NVIDIA,GroupMemoryBarrierWithGroupSync()compiles tobar.sync 0, which hangs the SM permanently if any hardware warp exits early (s_endpgm), exhaustsxcl_budget(LOOP_GUARD), or diverges in split-wave64 mode.What is in it
crates/xcl/src/gpu/recomp/emit.rs,tests.rs): defaultx64_spin()totrue(XCL_X_SPIN 1, opt-out viaXCL_WAVE64_SPIN=0) and updategpu_split_wave64_waves_diverge.crates/xcl/src/gpu/recomp/emit.rs,tests.rs): pre-scan fors_barrierin multi-warp Compute/Mesh shaders (compute_or_mesh_hw_waves() > 1) and emitxcl_s_barrier_init/xcl_s_barrier/xcl_s_barrier_exitbacked byXCL_BAR_ALIVE+ packed(gen: 20, arrived: 12)XCL_BAR_STATEbounded at1 << 20iterations (opt-out viaXCL_SAFE_BARRIER=0); emitGroupMemoryBarrier()for single-warp Compute/Meshs_barrier; addgpu_safe_s_barrier_multi_warp_and_early_endpgmtesting 4-warp 2-gen LDS exchange (wave64 and wave32) and upper-wave earlys_endpgmbefore twos_barriers.Tested
rustc 1.98.1(x86_64-pc-windows-msvccross-compile), debug.cargo test --workspace --no-fail-fast --target x86_64-pc-windows-msvc -- --test-threads=4 --skip a_freed_block_is_decommitted_before_its_address_is_reused: 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).SKIPPEDGPU tests:gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask(no wave64),gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware(no wave64).gpu_split_wave64_waves_diverge,gpu_safe_s_barrier_multi_warp_and_early_endpgm.Regression run
scripts/smoke.ps1runs on a retail title (Linux/Proton environment only).Not tested
xcl_s_barrierdispatch on hardware (Compute path tested),scripts/smoke.ps1retail regression run.AI use