Skip to content

Recompiler: a bridged mask write in the split form meets no barrier - #2074

Merged
raylitebull merged 1 commit into
xcl-dev:mainfrom
gefydev:per-lane-bridge-local-masks
Nov 25, 2026
Merged

raylitebull merged 1 commit into
xcl-dev:mainfrom
gefydev:per-lane-bridge-local-masks

Conversation

@gefydev

@gefydev gefydev commented Nov 25, 2026

Copy link
Copy Markdown
Member

In the split wave64 form, the per-lane form (XCL_PER_LANE=1, #1745) could put a group barrier in a block that only one 32-lane half reaches. Point 5 of Pipodi's review of #1745. Part of #1269.

An instruction the per-lane form lowers through #1426's semantics (the bridge: float compares, carry-outs, v_cmpx) writes its mask with Lw::write_mask. When that mask is whole-live, as with a nested if whose float condition goes to s_and_saveexec, #1426 builds both words through an exchange between the halves, and with one console wave per group that exchange is a group barrier. In a block only the lower half reaches, the upper half never gets there. The bridge only reads back each lane's own bit of the result, so this half's ballot is enough: the bridge now asks Lw for the half-local mask, and the exchange is gone. Only XCL_PER_LANE=1 reaches this code.

What is in it

  • crates/xcl/src/gpu/dxil/lower.rs, kernel.rs: Lw::local_masks. When set in the split form, write_mask builds the mask from this half's ballot, as it already does for a mask that is never read whole.
  • crates/xcl/src/gpu/recomp/lower_dxil.rs: DxilIr::foreign sets it around inst_guarded. New test a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier: a nested if in a block only lanes 0–31 reach, with v_cmp_lt_f32 → s_and_saveexec. It counts the group barriers in the DXIL and checks the result on the GPU. Without the fix the program has 3 barriers (two from the exchange inside the half's block); with it, only the one at the start where the halves take their console lanes.

Tested

  • NVIDIA GTX 1650 (32-lane waves only), driver 621.24, Windows 11 Pro 26300, Rust 1.100.0, debug.
  • The new test fails without the fix (left: 3, right: 1) and passes with it, including the GPU check: v7 = 5 in lanes 1–31 and 0 elsewhere, in both groups.
  • cargo test --workspace -- --test-threads=4 on 254a058 (on main 3da2abb): 1112 passed, 0 failed, 46 ignored; 24 SKIPPED (20 "no wave64" on this GPU, 1 "no heap windows", 3 per-lane halves refused on purpose for gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426's f16 rounding).

Regression run
main:

xcl-smoke v1
commit: 3da2abb81606df622610e009f0430de99aa9881c
gpu: NVIDIA GeForce GTX 1650
title: 5d6132ca
seconds: 60
exit: 0x0
frames shown: 934 (PresentX 934)
presents per 2 s (last 3): 17 10 2
device removals: 0
crashes: 0
peak commit: 11918 MB

This PR's head:

xcl-smoke v1
commit: 254a058c400ea86645810f0660d70be23f146fbb
gpu: NVIDIA GeForce GTX 1650
title: 5d6132ca
seconds: 60
exit: 0x0
frames shown: 829 (PresentX 829)
presents per 2 s (last 3): 7 2 0
device removals: 0
crashes: 0
peak commit: 14598 MB

Both with XCL_PER_LANE off (the default), which this change does not reach.

Not tested

  • Native wave64 GPUs (AMD): the split form is not used there.
  • A title run with XCL_PER_LANE=1; the regression runs are with it off, the default.
  • The hang itself: I checked the barrier count only, and did not run the old code on the GPU.

AI use

  • Claude Code (Claude Opus 5.5): wrote the fix, the test and this description, ran the checks.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Pu3TMXtx8TYFxrYEFhfdEp

In the split wave64 form, an instruction the per-lane form lowers
through xcl-dev#1426's semantics (a float compare, a carry-out, v_cmpx) builds
its mask with Lw::write_mask. When the mask is whole-live, as with a
nested if whose float condition goes to s_and_saveexec, xcl-dev#1426 exchanges
the words between the halves, and with one console wave per group that
exchange is a group barrier. In a block only one half reaches, the
other half never gets there (point 5 of Pipodi's review of xcl-dev#1745).

The bridge reads back only each lane's own bit of the result, so this
half's ballot is enough. DxilIr::foreign now sets Lw::local_masks
around inst_guarded, and write_mask then builds the mask from this
half's ballot, as it does for a mask that is never read whole.

The new test's program had 3 group barriers before (two from the
exchange inside the half's block) and has 1 now, the one at the start
where the halves take their console lanes. Only XCL_PER_LANE=1 reaches
this code.
@Pipodi

Pipodi commented Nov 25, 2026

Copy link
Copy Markdown

Test report for 254a058 (this PR's head, on main 3da2abb).

Tested

  • RTX 4090 (driver 617.42), i9-13900K, 32 GB, Windows 11 Pro 26300, rustc 1.100.0, debug.
  • cargo build --workspace && cargo test --workspace -- --test-threads=4: 1112 passed, 0 failed, 46 ignored, in 20 result blocks.
    • a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier passes, including its GPU dispatch: this adapter runs the split wave64 form.
  • SKIPPED: 23 GPU cases, all "no wave64" or a per-lane refusal that also happens on main; heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows); pso_measurement_compiles_an_exact_synthetic_record (cannot disable the driver cache: Developer Mode is required).
  • Fails without the change: I removed the two self.lw.local_masks = … lines in DxilIr::foreign and ran the new test alone. It failed on its barrier count, left: 3, right: 1, as the commit message says.

Not tested

  • A title run with XCL_PER_LANE=1: the default path does not reach this code.
  • Native wave64 hardware (AMD).

I read the diff. It matches point 5: the bridge reads back only each lane's own bit, so this half's ballot is enough.

AI use: Claude Code with Claude Opus 5.5 ran the tests and wrote this report.

@gefydev

gefydev commented Nov 25, 2026

Copy link
Copy Markdown
Member Author

@Pipodi thank you for the test report on 254a058: 1112 passed, 0 failed, 46 ignored on the RTX 4090, with the new test passing including its GPU dispatch, and failing without the change (barrier count left: 3, right: 1). Noted that a title run with XCL_PER_LANE=1 and native wave64 hardware were not covered.

AI use: Claude Code (Claude Opus 5.5) wrote this comment for @gefydev.

@JJAutoCompare

Copy link
Copy Markdown

PR #2074 split-wave64 mask-write verification

Tested

  • Commit 254a058c400ea86645810f0660d70be23f146fbb. The assigned checkout was clean and matched the open PR before and after testing.
  • Windows 11 Enterprise Evaluation 26200.9974, AMD Ryzen 7 3800X, Intel Arc A770 with driver 32.0.101.9175, Rust and Cargo 1.100.0 (x86_64-pc-windows-msvc), DXC and DXIL DLLs 1.9.2609.5.
  • Prebuild outside the GPU mutex with cargo test -p xcl --lib --no-run -j 2. Test profile unoptimized with debug info disabled. Prebuild completed in 1m 01s.
  • The successful run used the prebuilt executable from Cargo’s output. The child script was loaded with powershell.exe -NoProfile -ExecutionPolicy RemoteSigned -EncodedCommand $encoded (UTF-16LE base64 of arc-command.txt), and called the lock wrapper below. The policy override was scoped to that child process.
$exe = 'L:/XclTooling/pr2014-1c971de6/target/debug/build/xcl/97fdf2b9ff8e1482/out/xcl-97fdf2b9ff8e1482.exe'
$fixture = 'gpu::recomp::lower_dxil::tests::a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier'
& 'L:/XclTooling/Invoke-ArcTest.ps1' -Test { & $exe $fixture --exact --nocapture }
  • Environment for the build and run used CARGO_TARGET_DIR=L:/XclTooling/pr2014-1c971de6/target, CARGO_BUILD_JOBS=2, CARGO_INCREMENTAL=0, CARGO_PROFILE_DEV_DEBUG=0, CARGO_PROFILE_TEST_DEBUG=0, XCL_ADAPTER=A770, and XCL_DXC_DIR=%LOCALAPPDATA%/XclTooling/dxc-1.9.2609/bin/x64. Both TEMP and TMP pointed to this report’s directory.
Run Passed Failed Ignored Skipped Filtered out Fixture time
Mutex run with separate stdout and stderr 1 0 0 0 1088 0.16s

The checked-in fixture’s DXIL disassembly assertion found exactly one group barrier, at entry. Its direct-DXIL dispatch checked 128 readback values across two groups. In each group, v7 was 5 in lanes 1–31 and 0 in lane 0 and lanes 32–63.

The first two launches ended before the test ran. The default process policy blocked the wrapper and the first child invocation lost quoting. A subsequent exact run passed in 0.66s, but PowerShell reported a stderr parsing error. The table records the repeat with separate stdout and stderr so the skip count could be verified.

Not tested

The run covers the synthetic split-wave64 fixture on one Intel Arc A770. Native wave64, other adapters, the parent commit, stress/hang cases, the workspace suite, and retail title smoke are outside this run.

Evidence

Raw evidence in this directory includes environment.log, build.log, pr-before.log, pr-after.log, arc-command.txt, arc-verified.stdout.log, arc-verified.stderr.log, and arc-verified-exit.txt. The public PR discussion exposed 2 comment or review anchors at the final check.

AI use

T3 Code / Codex (gpt-6.2-sol) ran the checked-in fixture and wrote this empirical report.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

@gefydev

gefydev commented Nov 25, 2026

Copy link
Copy Markdown
Member Author

@DavidM1911 thank you for the verification of #2074 on the RTX 3060 Ti (cargo test -p xcl --lib: all passed, 0 failed, about 26 ignored; the intermittent parallel-scheduling abort tracked in #1978 was clean on a single-threaded rerun). Noted.

AI use: Claude Code (Claude Opus 5.5) wrote this comment for @gefydev.

@LANgmas

LANgmas commented Nov 25, 2026

Copy link
Copy Markdown

Independent hardware validation — RTX 3050 (Ampere): PASS

I independently reproduced the author's GTX 1650 result on an NVIDIA GeForce RTX 3050 Laptop GPU (Ampere, wave32-only).

  • Focused test a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier, run twice with XCL_ADAPTER=nvidia XCL_PER_LANE=1: 2/2 PASS.
  • DXIL assertion confirmed exactly 1 barrier.
  • Actual GPU dispatch assertions passed: v7 == 5 in lanes 1–31 and 0 elsewhere, across both groups. The focused test was not skipped.
  • Narrow lower_dxil suite: 19 passed, 0 failed, 17 skipped. Skips were 14 wave64 capability skips and 3 intentional gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantic refusals.

Hardware: RTX 3050 Laptop GPU, driver 617.14, D3D12 FL 12_2 / Shader Model 6.8, DXC 1.9.2602.17, Windows build 26300.

This independently reproduces the reported barrier count and GPU output on a second NVIDIA architecture (Ampere vs. the author's Turing GTX 1650).

Scope: supplemental GPU validation only. No retail-game smoke test was performed, so this does not replace the required runtime/integration validation.

@jennydeth

Copy link
Copy Markdown

Test report for #2074 on a 32-lane NVIDIA card (split wave64 form).

Setup: RTX 3060 12 GB (32-lane waves, driver 32.0.16.2101), Ryzen 5 5600X, 32 GB RAM, Windows 11 build 26300, Rust 1.100.0, DXC 1.9.2609.5, debug build. Head 254a058.

Result: cargo test --workspace -- --test-threads=4: 1112 passed, 0 failed, 46 ignored.

a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier: ok
SKIPPED: 23 GPU tests for no wave64 (expected on this card), the per-lane f16 arithmetic / f16 packed / f32 conversions cases (per-lane form: refused), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows), pso_measurement_compiles_an_exact_synthetic_record (cannot disable the driver cache).
Not tested: a title run (no smoke run from me), native wave64 GPUs.

AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report.

@gefydev

gefydev commented Nov 25, 2026

Copy link
Copy Markdown
Member Author

@JJAutoCompare, @LANgmas and @jennydeth thank you for the reports on 254a058; noted, each as you gave it:

  • @JJAutoCompare: Intel Arc A770 (driver 32.0.101.9175), the new test run on its own, 1 passed, 0 failed, 1088 filtered out.
  • @LANgmas: RTX 3050 Laptop (Ampere, driver 617.14), the focused test twice with XCL_PER_LANE=1, 2/2 pass, exactly 1 barrier in the DXIL and v7 == 5 in lanes 1–31 and 0 elsewhere in both groups; lower_dxil 19 passed, 0 failed, 17 skipped. No title run.
  • @jennydeth: RTX 3060 12 GB (driver 32.0.16.2101), cargo test --workspace -- --test-threads=4: 1112 passed, 0 failed, 46 ignored, the new test ok; the SKIPPED ones as you list them. No title run, no native wave64.

With these and the earlier ones on the RTX 4090 and RTX 3060 Ti, the test has passed on four NVIDIA cards and one Intel card; native wave64 hardware and a title run with XCL_PER_LANE=1 are still not covered.

AI use: Claude Code (Claude Sonnet 5.5) wrote this comment for @gefydev.

@throny throny added the goal:world-load Bears on the retail title getting past world loading label Nov 25, 2026
@raylitebull
raylitebull merged commit 50a9fde into xcl-dev:main Nov 25, 2026
3 checks passed
@DarkPanda69

Copy link
Copy Markdown

Heads-up: since this merge, main 50a9fde fails this PR's own test a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier on every GPU here; at the PR head 254a058 it passes. So it looks like an interaction with something that reached main after this branch's base, not a driver difference.

cargo test -p xcl --lib -- a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier --test-threads=1, debug, Windows 11 Pro 26200:

RX 9070 XT (32.0.32029.2010) RTX 3060 (32.0.16.1088)
PR head 254a058 ok ok
merged main 50a9fde failed failed

On main it panics at lower_dxil.rs:1155 (assertion left == right failed: group barriers in the program: followed by the disassembly, a NumThreads=(64,1,1), WaveSize=32 compute shader), in 0.02 s, so it is the static barrier count, not a GPU run. Merges between this branch's base and 50a9fde that touch the recompiler or the direct DXIL path include #2076 (compact form), #2346, #2126, #2107 and #2080 (direct dispatch split); I have not bisected which one.

AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this comment.

@Gevroska

Copy link
Copy Markdown

I followed up on the reported barrier-count failure by checking where the extra barriers occur in the generated DXIL. On merged 50a9fdef, all three group barriers are in the entry block, before the first conditional branch. Two surround the shared-memory ballot exchange that computes the whole-wave EXEC condition for that branch. The guarded float compare still uses a half-local ballot and contains zero group barriers.

The test body is identical on both revisions. With DXC/DXIL 1.9.2609.5 on Windows, the static assertion passed on PR head 254a058c with one barrier and failed on 50a9fdef with three. The GPU stage was explicitly skipped on the PR head, and the assertion stopped the merged run before GPU execution.

I’d keep the regression test focused on the guarded mask write. Checking the relevant block for a group barrier would catch one moving back into the divergent path. Changing the expected whole-program count to three would still let that regression pass if a barrier moved and the total stayed the same.

I used Codex GPT-6.2 Sol for the comparison and a separate GPT-6.2 Sol agent to verify the revisions, test output, and barrier positions in the disassembly.

I reviewed and approved this comment before posting.

@gefydev

gefydev commented Nov 25, 2026

Copy link
Copy Markdown
Member Author

@DarkPanda69 @Gevroska thank you, both of you were right, and I reproduced it: on a clean main 68a284a the test fails with left: 3, right: 1 in 0.02 s, a static count (GTX 1650, DXC 1.9.2602.17).

@Gevroska's reading of the disassembly holds on my side too: the three barriers are in the entry block, before the first conditional branch, two of them around the exchange of the whole-wave EXEC condition of s_cbranch_execz; the guarded float compare has none. So the property of #2074 holds and the test's count of the whole program was too coarse. The fix is #2379, test only: at least one barrier in the entry block and none past the first conditional branch, as you suggested. With #2074's fix switched off the new check fails on the barrier in the guarded block, so it still catches the deadlock. I did not bisect which merged change added the entry-block exchange.

AI use: Claude Code (Claude Sonnet 5.5) wrote this comment for @gefydev.

@SashaTun

SashaTun commented Nov 25, 2026 •

Copy link
Copy Markdown

The test this PR added fails on main, and main's CI has been red since it landed

main is 3ceb5507 and its CI run fails on the test this PR added:

gpu::recomp::lower_dxil::tests::a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier
  assertion `left == right` failed: group barriers in the program
  left: 3
 right: 1

The CI runner has no GPU, so this is not card-specific. I can reproduce it on main 68a284a on an NVIDIA RTX 5060 as well:

cargo test --release -p xcl --lib a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier -- --nocapture

The program has 3 group barriers, the test expects 1. It fails the same way with and without XCL_PER_LANE=1 (I ran both).

The PR's commit message ties the 3 → 1 change to the per-lane path: "The new test's program had 3 group barriers before (two from the exchange inside the half's block) and has 1 now … Only XCL_PER_LANE=1 reaches this code." The fix sets Lw::local_masks in crates/xcl/src/gpu/recomp/lower_dxil.rs (foreign(), the per-instruction path), and local_masks = true appears nowhere else in the tree. The test lowers its program through compute_split → DxilIr::split, so I could not see how that path reaches the code the fix changes - with and without the variable the program still has 3 barriers.

I do not know which side is wrong (the test may lower the program through a path the fix does not cover, or the fix may need to reach that path), so I am not proposing a change - this is not my PR. What is clear is that main stays red until it is settled, and every PR merged in the meantime carries the failure with it.

I hit this while testing #2352 and #2344 on an NVIDIA card; my reports there name the failure and point here.

AI use: MiniMax Code (MiniMax-M3.1-Flash) ran the test, read the CI log and traced the code path.

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.