Skip to content

Direct DXIL: make multi-wave Compute and Mesh s_barrier early-exit-safe - #1793

Open
mastrr9 wants to merge 1 commit into
xcl-dev:mainfrom
mastrr9:fix/direct-dxil-split-wave64-barriers
Open

mastrr9 wants to merge 1 commit into
xcl-dev:mainfrom
mastrr9:fix/direct-dxil-split-wave64-barriers

Conversation

@mastrr9

@mastrr9 mastrr9 commented Nov 24, 2026

Copy link
Copy Markdown

Summary

Makes the multi-wave Compute and Mesh s_barrier in the Direct DXIL path safe against early-exiting waves on split-wave64 NVIDIA GPUs.

#1741 bounds the single-wave split exchanges. This change covers the remaining unguarded GROUP_SYNC in s_barrier (lower.rs), related to #1727. A wave that exits early no longer leaves the others waiting at a barrier it will never reach.

  • Ports the HLSL path's xcl_s_barrier live-wave bookkeeping (0c02b87) to Direct DXIL (group_barrier.rs).
  • Honors XCL_SAFE_BARRIER=0 to turn the guard off.
  • Keeps TGSM within 32 KiB.
  • Bumps TRANSLATOR_VERSION to 7.
  • Adds XCL_SAFE_BARRIER to the translation cache-bypass list.

#1741 applies cleanly on top of this branch.

Testing

Windows 11 x64, NVIDIA GeForce RTX 5080 16 GB, DXC 1.9.2602.17.

  • cargo test -p xcl --lib dxil::core_tests -- --test-threads=1: 17 passed, 0 failed, 1 ignored
  • XCL_DIRECT_DXIL=1 cargo test -p xcl --lib gpu_split_wave64 -- --test-threads=1: 5 passed, 0 failed
  • cargo test -p xcl --lib gpu::dxil -- --test-threads=1: 89 passed, 0 failed, 1 ignored
  • cargo test -p xcl --lib -- --test-threads=1: 849 passed, 0 failed, 22 ignored (no new warnings)

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
@upipibi

upipibi commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Two data points for the premise, RTX 3070 (Ampere), driver 616.56, Windows 11:

So the guard may not be what stops a hang on NVIDIA. It still covers Intel, where boykopovar/AnyPS5#26756 reports the ended-wave hang, and it covers waves that skip a barrier but stay alive. A test that hangs or fails without the guard on the RTX 5080 would show which case this PR fixes there. The update below runs this PR.

Update, this PR's direct path: I sent the same test's early-exit shader (128 threads, the upper console wave ends before two s_barriers) through direct_or locally. With XCL_DIRECT_DXIL=1 it then runs on this PR's direct translator. At 9648fe9, RTX 3070:

  • XCL_SAFE_BARRIER=1 (the new guard): passes.
  • XCL_SAFE_BARRIER=0 (SBarrier::Sync, a plain group sync): passes, 2 of 2.

So on Ampere the direct path doesn't hang without the guard either. That is consistent with the HLSL result above.

AI-assisted (Claude Code). Synthetic tests only.

Port the recompiler's early-exit-safe `xcl_s_barrier` (0c02b87) to the
direct DXIL translator. On RDNA2 `s_endpgm` removes the exiting wave from
the workgroup's barrier count; a D3D12 group sync (`bar.sync 0` on NVIDIA)
waits for every hardware wave, so one that ended (`s_endpgm`), ran out of
its loop budget or diverged after a split-wave64 desync hung the SM. The
direct path still lowered `s_barrier` to a bare GROUP_SYNC.

Same policy as the HLSL path (`gpu/dxil/group_barrier.rs`):
- Compute / Mesh groups of several hardware waves whose program has an
  `s_barrier`: a bounded arrival barrier on two group-shared words
  (`alive`: live hardware waves; `state`: generation:20 | arrived:12).
  Initialized in the entry block (whole group present), decremented once
  in the single exit block every way out of the program goes through
  (`s_endpgm`, end of code, exhausted loop budget). A wave that spins
  past 1 << 20 rounds leaves the count and only fences from then on.
  Opt-out: `XCL_SAFE_BARRIER=0`.
- One hardware wave: a group-shared fence (nothing to wait for).
- Kernel ABI: unchanged group sync.

With LDS the words sit at 8189..8190 of the 32 KB block (the split form's
exchange moves 2 words down; non-split LDS accesses clamp to 8188), so
TGSM never exceeds the D3D12 limit; without LDS they get their own
[2 x i32]. Programs without `s_barrier` are unchanged.

TRANSLATOR_VERSION 6 -> 7, and `XCL_SAFE_BARRIER` joins the shader cache
bypass list so toggling it never reuses a cached translation (HLSL too).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mastrr9
mastrr9 force-pushed the fix/direct-dxil-split-wave64-barriers branch from 9648fe9 to a6ace09 Compare November 24, 2026 22:35

@lewisnic94-max lewisnic94-max left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Guest LDS address aliasing

On a6ace09, the clamp at line 80 maps guest LDS words 8188 and 8191 to the same word. After storing 11 and 22, all 64 threads read [22,22] in three RTX 3080 runs. The merge base returned [11,22]. Exposing only word 8191 restored the expected result while the barrier counters at 8189/8190 remained active.

Please preserve distinct guest addresses and add this two-word GPU readback test.

AI-assisted validation by Codex (GPT-6).

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11): merge conflict with current main — needs a rebase before it can be tested.

mastrr9 added a commit to mastrr9/xcl that referenced this pull request Nov 24, 2026
The direct translator dropped the clamp operand of sample, sample_b and
sample_c (the implicit-LOD forms in a pixel shader) when the T# is a
cube, so image_sample_cl / _b_cl / _c_cl on a cube sampled below the
clamp. The HLSL path passes the clamp for cubes as for every other
dimension (TextureCubeArray Sample / SampleBias / SampleCmp with a
clamp, no offset), and the hardware applies the minimum LOD whatever
the dimension. No validator rule is known to forbid a clamp on a cube.

TRANSLATOR_VERSION 7 -> 8: the emitted containers change for these
programs. Open PR xcl-dev#1793 also bumps TRANSLATOR_VERSION. Identical
edits merge silently in git, so check the bump by hand at merge time:
the later change takes the next free number, or the pipeline cache
could serve containers of another translator under the same version.
The test draws a pixel shader sampling a mipped cube at zero
derivatives with clamp 2.0 through both backends, and builds the
_b_cl and _c_cl cube forms on both backends (not drawn).
mastrr9 added a commit to mastrr9/xcl that referenced this pull request Nov 24, 2026
The HLSL path's image_sample_o in a pixel shader with an implicit LOD and
a linear mip filter samples the two blended mips with SampleLevel, each
moved by the offset in its own texels, and blends them by the LOD's
fraction (20271d4). The direct translator still moved the coordinates
once, by the offset over the size of the rounded LOD's mip, so the
second mip read a texel off when the offset was half its texel or less.

Port that form: LOD = the clamped implicit LOD (raised by the _cl clamp,
capped at the view's last mip), mips floor(LOD) and the next one (capped
too), each with its own texel offset, lerp by the fraction. It is taken
under the same conditions read from the S#: MIP_FILTER linear, not
anisotropic, and LOD >= 1 or min = mag filter; otherwise the single
Sample as before. The texel-offset computation moves into a helper
shared with the existing path.

TRANSLATOR_VERSION 7 -> 8: the emitted containers change for these
programs. Open PR xcl-dev#1793 also bumps TRANSLATOR_VERSION. Identical
edits merge silently in git, so check the bump by hand at merge time:
the later change takes the next free number, or the pipeline cache
could serve containers of another translator under the same version.

The existing test gpu_ps_image_sample_offset_implicit_lod_between_mips
now also draws its pixel shader through the direct translator and
expects the same result.
@futurepro62

futurepro62 commented Nov 24, 2026 •

Copy link
Copy Markdown

Full-suite run, since this PR has no test report yet. Tested exact head a6ace09 (on its base 689f2db).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu --skip gpu::dxil::fuzz_tests: 972 passed, 0 failed, 43 ignored. SKIPPED (no wave64): a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu, a_per_lane_2d_or_3d_group_runs_on_the_gpu, coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu, cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu, gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware, the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu.
  • The new tests ran and passed: s_barrier_policy_matches_the_recompiler, programs_without_s_barrier_have_no_safe_barrier, multi_wave_s_barrier_is_early_exit_safe, safe_barrier_decrements_on_every_exit, single_wave_s_barrier_is_a_fence, kernel_s_barrier_stays_a_group_sync, safe_barrier_words_live_in_the_lds_block.
  • Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4 --skip gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1: 981 passed, 0 failed, 45 ignored. SKIPPED: f16_programs_on_the_gpu (f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 arithmetic, wave64, per-lane form: refused (unsupported V_MUL_F16 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave64, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave64, per-lane form: refused (unsupported V_CVT_F16_F32 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • --skip leaves out tests that fail on main 62265d3 too, not because of this PR. On NVIDIA: heap_window_out_of_memory_falls_back_to_the_switch_form (Tests: heap_window_out_of_memory_falls_back_to_the_switch_form fails under XCL_REQUIRE_GPU=mesh (opt-in skip counted as missing coverage) #1651) and the four gpu::recomp::lower_dxil::tests::*_programs_on_the_gpu tests (follow-up on #1651) fail because runner::skip_test turns their skips into failures under XCL_REQUIRE_GPU=mesh, and gpu::dxil::fuzz_tests seeds 70, 545, 1019 and 1507 fail CreateComputePipelineState with E_OUTOFMEMORY on this card (drivers 616.64 and 621.40). On AMD: fuzz_validate_and_gpu_1 fails on seed 540 (res[833] 0x7 vs CPU 0x6). The AMD run does not set XCL_REQUIRE_GPU.

Not tested

  • a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.

@Anon64

Anon64 commented Nov 25, 2026

Copy link
Copy Markdown

Regression run for this PR: head a6ace09, based on main 689f2db. RTX 3060 12 GB (581.80, wave32), Windows 11 26200, release, XCL_NETWORK=0, A pressed every 4 s from 20 s, scripts/smoke.ps1 on a retail title for 60 s, in one batch with the main run.

main 689f2db:

xcl-smoke v1
commit: 689f2db477c3c062cf162649781640ef8a977c18
gpu: NVIDIA GeForce RTX 3060
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1590 (PresentX 1591)
presents per 2 s (last 3): 44 53 35
device removals: 0
crashes: 0
peak commit: 25217 MB

this PR:

xcl-smoke v1
commit: a6ace09a58cb9de261e0ad7e995a246a6196a334
gpu: NVIDIA GeForce RTX 3060
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1602 (PresentX 1603)
presents per 2 s (last 3): 59 44 37
device removals: 0
crashes: 0
peak commit: 24507 MB

No device removals or crashes; 100 % of main's frames, 97 % of its peak commit.

Not tested: the whole suite; the direct DXIL path this PR changes (these runs use the default HLSL path, XCL_DIRECT_DXIL unset).

Written with Claude Code (Claude Opus 5.5) from runs on this machine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants