Skip to content

Recompiler: early-exit-safe multi-wave s_barrier in direct DXIL - #3264

Merged
raylitebull merged 1 commit into
xcl-dev:mainfrom
Foniass:dxil-multiwave-barrier
Nov 29, 2026
Merged

raylitebull merged 1 commit into
xcl-dev:mainfrom
Foniass:dxil-multiwave-barrier

Conversation

@Foniass

@Foniass Foniass commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

Overlaps #1793 (mastrr9, same goal, currently conflicting with main): this is amd-dev's implementation (965cc655, raylitebull). Maintainers, keep one of the two.

Multi-wave compute and mesh programs containing s_barrier fall back to HLSL + DXC today (on this card's retail run: 84 CS + 2 MS; amd-dev's commit counts 192/192 MS and 21 CS on a world load). This lowers the barrier in the direct DXIL translator with the same bounded, early-exit-safe groupshared arrival barrier as the HLSL path's PRELUDE_SAFE_BARRIER (XCL_BAR_ALIVE / XCL_BAR_STATE), so a wave that left (s_endpgm, loop budget) does not hang the others. On NVIDIA a plain bar.sync with a missing wave hangs the GPU, so this is the PR that most needs an NVIDIA run.

Review fix (throny): amd-dev put the wave's alive flag (VAR_BAR_ALIVE) in VAR_BUDGET + 5, which on main is lower_round::VAR_F32_MODE. A program that directs f32 rounding and sets its MODE bits to 0 then counted itself out and passed its barriers early. The flag now has the free slot VAR_BUDGET + 7. A GPU test runs such a program (an LDS exchange across waves after s_denorm_mode 0 / s_round_mode 0), and the_translator_variables_have_slots_of_their_own checks the slots on any machine.

What is in it

  • crates/xcl/src/gpu/dxil/lanes.rs: safe_barrier_init (reuses xcl_lds[8189..8190] when the program has LDS, else a 2-dword xcl_bar), safe_barrier_sync, safe_barrier_exit on the exit tail
  • crates/xcl/src/gpu/dxil/lower.rs, kernel.rs: s_barrier takes it in groups of several hardware waves (XCL_SAFE_BARRIER=0 keeps the plain barrier)
  • crates/xcl/src/gpu/dxil/robustness_tests.rs: a_group_barrier_of_several_hardware_waves_uses_safe_barrier_directly replaces the test that asserted the HLSL fallback; gpu_a_multi_wave_barrier_after_the_f32_mode_is_set_to_zero_still_waits and the_translator_variables_have_slots_of_their_own (review fix)
  • port note: the non-safe branch keeps main's plain GROUP_SYNC (amd-dev's barrier_uav_fence comes from a WIP commit main does not have)

Tested

  • RTX 5070 Ti (driver 32.0.16.2114), AMD Ryzen 7 7800X3D, Windows 11 build 26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), debug tests, release smoke
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on f8c0176 (rebased onto main 0fe06eb): 2739 passed, 0 failed, 49 ignored. SKIPPED GPU tests: 45 distinct notices, almost all no wave64.
  • cargo test -p xcl --lib gpu::dxil: the new a_group_barrier_of_several_hardware_waves_uses_safe_barrier_directly passes
  • gpu_a_multi_wave_barrier_after_the_f32_mode_is_set_to_zero_still_waits fails without the review fix above (wave64 split form: thread 0 read 0 instead of 320) and passes with it
  • Correction: the first push (7b568a10) did not compile on main (lanes.rs used amd-dev's barrier_uav_fence, the test an MsInterface.params field main lacks). Kalmarv caught it; my earlier compile check was broken (the wrapper hid cargo's exit code). Fixed: the safe barrier fences groupshared memory only, as the HLSL path's xcl_s_barrier (GroupMemoryBarrier).
  • Retail title (it has multi-wave barrier programs, which took the HLSL path before): 60 s smoke run below, no hang, no device removal, no crash. The PR's run used -StartupTimeoutSeconds 3600 for the cold pipeline rebuild new DXIL needs.

Regression run

main:

xcl-smoke v1
commit: 3b6a91ed096d6d6e0fee52cfb86dc0a7d7c8c1b0
gpu: NVIDIA GeForce RTX 5070 Ti
title: 3cb1d8e0
seconds: 60
exit: 0x0
frames shown: 1193 (PresentX 1193)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15684 MB

this PR:

xcl-smoke v1
commit: f8c01769a40b88f2ea2b7e1288ff91f39659a90b
gpu: NVIDIA GeForce RTX 5070 Ti
title: 3cb1d8e0
seconds: 60
exit: 0x0
frames shown: 1573 (PresentX 1573)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15353 MB

Not tested

  • AMD GPUs; whether the image looks the same; titles other than this one
  • how many of this title's barrier programs took the new path in the run (not counted)
  • a hang check: a title with multi-wave barrier programs (mesh passes) on NVIDIA

AI use

  • Claude Code with Claude Opus 5.5: ported the commit to main, resolved conflicts (noted in the commit message), made the review fix and its tests, ran the tests and the smoke run above and wrote this description.

🤖 Generated with Claude Code

@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:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Nov 29, 2026
@Foniass
Foniass force-pushed the dxil-multiwave-barrier branch from 7b568a1 to 44be66d Compare November 29, 2026 02:37
@github-actions github-actions Bot added the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Nov 29, 2026
@Foniass
Foniass marked this pull request as ready for review November 29, 2026 02:55
@github-actions github-actions Bot added needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU and removed needs-pr-check Failing the PR description check (CONTRIBUTING.md) needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU labels Nov 29, 2026
@Kalmarv

Kalmarv commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

merge-check
base: fa20459
head: 44be66d
merge: clean onto main and with the 7-PR stack.
build: cargo build --workspace -> ok; cargo build --release -p xcl -> ok.
tests: Standalone on RTX 5070 Ti: cargo test -p xcl --lib gpu::dxil:: -> 231 passed, 0 failed, 3 ignored (all 4 fuzz_validate_and_gpu_0..3 passed); standalone 150 s NVIDIA hang-test smoke (ea3b5e4d, XCL_PREPARE=0) -> exit: 0x0, 2076 frames shown, 0 device removals, 0 crashes, 0 nvlddmkm/display System events, 32971 MB peak commit, 0 s_barrier direct-DXIL fallbacks. tested in the clean 7-PR stack (#3250+#3261+#3263+#3264+#3265+#3266+#3268) on main fa204595: cargo test --workspace --no-fail-fast -- --test-threads=4 (DXC 1.9.2609.5; -p xcl --lib rerun skipping the 2 known main #3187 uma_driver mixed-window tests a_refused_gpu_upload_segment_becomes_custom and mixed_window_keeps_its_bytes_and_the_gpu_sees_every_segment) -> 2620 passed, 0 failed, 49 ignored (2481 lib + 139 integration, 25 SKIPPED notices; all 4 fuzz_validate_and_gpu_0..3 passed); failing: none. 150 s xcl-smoke (ea3b5e4d, XCL_PREPARE=0, RTX 5070 Ti) on the combined 8-PR stack: exit: 0x0, 2096 frames shown, 0 device removals, 0 crashes, 0 display System events, 32049 MB peak commit.
review: none (whole diff read: branchless safe_barrier_init, bounded CAS generation/arrival loop in safe_barrier_sync with TGSM fence matching HLSL xcl_s_barrier, and unified exit-tail safe_barrier_exit; reuses xcl_lds[8189..8190] to stay within 32 KiB D3D12 groupshared limit).
performance: positive: eliminates multi-wave s_barrier HLSL fallbacks without hanging or regressing RTX 5070 Ti (2076 frames standalone, 2096 frames in 8-PR stack).
verdict: safe to merge
hardware / tool and model: NVIDIA GeForce RTX 5070 Ti 16 GB (wave32 only), Windows 11, DXC 1.9.2609.5 via XCL_DXC_DIR; Antigravity (Gemini 3.5 Pro) ran the merges, builds, workspace test suites, 150 s title smokes, diff reviews, and drafted this check.

@throny

throny commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator

merge-check claim
head: 44be66d

@throny

throny commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator

merge-check
base: d8bd9a3
head: 44be66d
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2618 passed, 0 failed, 49 ignored (27 SKIPPED lines). Base alone at d8bd9a3: 2618 passed, 0 failed, 49 ignored.
review: one blocking finding. The new VAR_BAR_ALIVE is VAR_BUDGET + 5 in lower.rs, and main already uses that slot: lower_round::VAR_F32_MODE is VAR_BUDGET + 5 (lower_round.rs line 25 at d8bd9a3). So the alive count and the f32 rounding mode share one variable. From reading the init code, the existing check for VAR_F32_MODE comes first, so the new "start at 1" branch is not reached; a program that sets its f32 mode bits to 0 would mark its wave as having left, skip the barriers after that and never count itself out, and a barrier timeout would write 0 into the rounding mode. The suite does not catch it because the new test only checks disassembly strings. Apart from that the port matches the HLSL barrier from reading: every exit goes through the tail where the wave counts itself out, and waiting waves re-read the alive count on every spin, so a wave that leaves early releases them. Also: this is the same work as the older open #1793 (listed on #1607); one of the two should be closed.
performance: not measured.
verdict: not yet: give VAR_BAR_ALIVE a free slot (no constant on main is VAR_BUDGET + 7) and add a test that runs a program which changes the f32 mode and uses the barrier.
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).

@github-actions github-actions Bot added checks-disagree Merge-checks disagree (safe vs not yet); needs maintainer/3rd look and removed needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) labels Nov 29, 2026
…DXIL

Multi-wave compute and mesh shaders containing s_barrier previously fell
back to the HLSL + DXC path (213/213 fallbacks on a retail world load:
192/192 MS and 21 CS). Implement the same bounded, early-exit-safe
groupshared arrival barrier (XCL_BAR_ALIVE + XCL_BAR_STATE) directly in
the Direct DXIL translator (lanes.rs, lower.rs, kernel.rs):

- Branchless initialization in Block(0) via safe_barrier_init(), reusing
  xcl_lds[8189..8190] when LDS is used so total groupshared stays within
  D3D12's 32 KiB limit (or a 2-dword xcl_bar otherwise).
- safe_barrier_sync() lowers s_barrier with the exact generation +
  arrival-counter CAS loop and UAV/TGSM memory fence semantics of
  recomp::emit::PRELUDE_SAFE_BARRIER.
- safe_barrier_exit() decrements XCL_BAR_ALIVE once on the unified exit
  tail block before ret, covering s_endpgm, loop-budget exits, and
  compact mode.

(cherry picked from commit 965cc65)

Ported to main: the non-safe branch keeps main's plain GROUP_SYNC barrier (amd-dev's barrier_uav_fence comes from its WIP commit 6fa964d, which main does not have); robustness_tests.rs keeps main's split-LDS tests next to the new barrier test.

The wave's alive flag (VAR_BAR_ALIVE) takes the free translator slot
VAR_BUDGET + 7: amd-dev's VAR_BUDGET + 5 is main's VAR_F32_MODE, so a
program that directs f32 rounding and sets its MODE bits to 0 counted
itself out and passed its barriers early (review on xcl-dev#3264). Tests: a GPU
run of that program (it read LDS before the other wave wrote it without
the change) and a check that the translator's variables have slots of
their own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Foniass
Foniass force-pushed the dxil-multiwave-barrier branch from 44be66d to f8c0176 Compare November 29, 2026 17:15
@github-actions github-actions Bot removed checks-disagree Merge-checks disagree (safe vs not yet); needs maintainer/3rd look needs:amd-test Needs a test report or merge-check on an AMD GPU labels Nov 29, 2026
@Foniass

Foniass commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks throny, the slot clash was real. Fixed in f8c0176 (rebased onto main 0fe06eb):

  • VAR_BAR_ALIVE is now VAR_BUDGET + 7, the free slot.
  • gpu_a_multi_wave_barrier_after_the_f32_mode_is_set_to_zero_still_waits runs the program you described (directed f32 rounding, MODE set to 0, then an LDS exchange across waves through s_barrier). Without the fix it fails here: the wave64 split form read 0 instead of 320. With the fix it passes.
  • the_translator_variables_have_slots_of_their_own checks the slots on any machine, CI included.

Full suite on f8c0176: 2739 passed, 0 failed, 49 ignored. The new smoke run is in the description. I'm leaving the overlap with #1793 for the maintainers to settle.

(Written with Claude Code, Claude Opus 5.5.)

@afpruivo

Copy link
Copy Markdown

Test report on NVIDIA: #3264 head f8c01769 against main 0fe06eb0 (its base), retail title, 4 alternating runs after a warm-up per build.

Setup: RTX 3090 24 GB, driver 621.40, i5-13600K, Windows 11 26300, release builds named xcl.exe (NVIDIA profile applies), no local changes. XCL_DIRECT_DXIL=1 XCL_NETWORK=0 XCL_UMA_DRIVER=mixed:1536:1792 XCL_TEXTURE_LEVEL_PAGES=1, scripted presses, XCL_GPU_TIMES=16,750 (16 frames in the world after 750 s).

Result:

run build wall ms/frame GPU span ms
m1 main 214.1 213.3
p1 #3264 218.5 216.9
m2 main 248.0 244.1
p2 #3264 216.8 216.0
  • All four runs reached the world; no device removal, no crash.
  • The PR does what it says: on main the log has 1,271 direct DXIL fallback … s_barrier in a group of several hardware waves – HLSL path lines; on the PR there are none.
  • Frame time is the same within run-to-run noise (the m2 outlier included). On this title the barrier programs that moved off HLSL are not where the GPU time goes on the 3090.

Not tested: AMD; visual correctness (frames are black in the world on this 3090 on every build, known); cargo test on the PR head.

AI use: Claude Code (Claude Opus 5.5) built the trees, ran the runs and wrote this report.

Prime1997 pushed a commit to Prime1997/xcl that referenced this pull request Nov 30, 2026
With LDS and a safe multi-wave barrier, the barrier keeps its counts in
xcl_lds[8189..8190] and lds_top is 8188 (xcl-dev#3264), but only the split form
clamped the program's LDS indices to lds_top. A native wave64 or wave32
program could write the top of LDS over the barrier's counts. The HLSL
path clamps every LDS access to XCL_LDS_TOP (8188) in this case; direct
DXIL now does the same whenever lds_top is below 8191 (DS loads and
stores, and the mesh epilogue's reads).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Foniass added a commit to Foniass/xcl that referenced this pull request Nov 30, 2026
The direct DXIL translator gave every compute program that uses LDS the
whole 8,192-dword groupshared block D3D12 allows. A one-wave group then
holds 32 KB, which caps how many groups a GPU keeps resident when its LDS
is shared by them (an RDNA WGP's 128 KB: four groups, one wave a SIMD).

The block is now the LDS COMPUTE_PGM_RSRC2 declares (CsInterface::lds_dwords,
LDS_SIZE in 128-dword granules) followed by the translator's own words: a
native 2-D / 3-D group's arrival counter, a multi-wave safe barrier's two
words (xcl-dev#3264; right after the program's LDS in a native group, below the
arrival word in the split form, as at the top of the 8,192-dword block),
and the split form's exchange slots and counters. A header with no size,
or one too large to leave room for those words, keeps the 8,192-dword
layout. Program LDS indices are clamped below the translator's words
(lds_index's `split || lds_top < 8191`, the parent commit), so an access
past the declared size stays at the last declared dword. Mesh and geometry
programs keep the 8,192-dword block. The HLSL path is unchanged.

On by default; XCL_DECLARED_LDS=0 restores the 8,192-dword layout. The
direct translator's disk-cache identities and ComputePolicyKey (the
driver pipeline cache's key) key the switch apart.

From Kalmarv's xcl-dev#2937 ("XCL_DECLARED_LDS=1 sizes direct compute
LDS from the header", opt-in there; written with Claude Code (Claude Opus
5.5), ComputePolicyKey part with Antigravity (Gemini 4 Neon)):
CsInterface::lds_dwords, the declared layout, the ComputePolicyKey field
and its build-key test, the `lds_top < 8191` clamp. From raylitebull's
amd-dev 5e48878 (xcl-dev#2937 adapted to the safe-barrier words, default on):
the safe barrier's placement, the test switch, the declared-size test and
the GPU test, extended here to native wave64 and the split form. New here:
a disassembly test of the clamp and of the translator's words.

Measured by xcl-dev#2937 (RTX 5070 Ti, the title, per-program GPU timestamps over
187-229 s): the late frame's compute from about 89 to about 78 ms per
present. Measured by 5e48878 offline (Radeon GPU Analyzer, gfx1201): the
title's top open-world program from 32,768 to 5,008 bytes of LDS.

Co-authored-by: Kalmarv <59708937+Kalmarv@users.noreply.github.com>
Co-authored-by: raylitebull <287713799+raylitebull@users.noreply.github.com>
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:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants