Repository navigation
Recompiler: early-exit-safe multi-wave s_barrier in direct DXIL - #3264
Conversation
7b568a1 to
44be66d
Compare
|
merge-check |
|
merge-check claim |
|
merge-check |
…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>
44be66d to
f8c0176
Compare
|
Thanks throny, the slot clash was real. Fixed in f8c0176 (rebased onto main 0fe06eb):
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.) |
|
Test report on NVIDIA: #3264 head Setup: RTX 3090 24 GB, driver 621.40, i5-13600K, Windows 11 26300, release builds named Result:
Not tested: AMD; visual correctness (frames are black in the world on this 3090 on every build, known); AI use: Claude Code (Claude Opus 5.5) built the trees, ran the runs and wrote this report. |
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>
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>
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_barrierfall 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'sPRELUDE_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 plainbar.syncwith 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) inVAR_BUDGET + 5, which on main islower_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 slotVAR_BUDGET + 7. A GPU test runs such a program (an LDS exchange across waves afters_denorm_mode 0/s_round_mode 0), andthe_translator_variables_have_slots_of_their_ownchecks the slots on any machine.What is in it
crates/xcl/src/gpu/dxil/lanes.rs:safe_barrier_init(reusesxcl_lds[8189..8190]when the program has LDS, else a 2-dwordxcl_bar),safe_barrier_sync,safe_barrier_exiton the exit tailcrates/xcl/src/gpu/dxil/lower.rs,kernel.rs:s_barriertakes it in groups of several hardware waves (XCL_SAFE_BARRIER=0keeps the plain barrier)crates/xcl/src/gpu/dxil/robustness_tests.rs:a_group_barrier_of_several_hardware_waves_uses_safe_barrier_directlyreplaces the test that asserted the HLSL fallback;gpu_a_multi_wave_barrier_after_the_f32_mode_is_set_to_zero_still_waitsandthe_translator_variables_have_slots_of_their_own(review fix)GROUP_SYNC(amd-dev'sbarrier_uav_fencecomes from a WIP commit main does not have)Tested
cargo test --workspace --no-fail-fast -- --test-threads=4on f8c0176 (rebased onto main 0fe06eb): 2739 passed, 0 failed, 49 ignored. SKIPPED GPU tests: 45 distinct notices, almost allno wave64.cargo test -p xcl --lib gpu::dxil: the newa_group_barrier_of_several_hardware_waves_uses_safe_barrier_directlypassesgpu_a_multi_wave_barrier_after_the_f32_mode_is_set_to_zero_still_waitsfails without the review fix above (wave64 split form: thread 0 read 0 instead of 320) and passes with it7b568a10) did not compile on main (lanes.rsused amd-dev'sbarrier_uav_fence, the test anMsInterface.paramsfield 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'sxcl_s_barrier(GroupMemoryBarrier).-StartupTimeoutSeconds 3600for the cold pipeline rebuild new DXIL needs.Regression run
main:
this PR:
Not tested
AI use
🤖 Generated with Claude Code