Skip to content

Recompiler: update per-lane DXIL block tail after split exchanges - #1928

Open
Decodere wants to merge 1 commit into
xcl-dev:mainfrom
Decodere:fix-1889-split-wave64-tails
Open

Decodere wants to merge 1 commit into
xcl-dev:mainfrom
Decodere:fix-1889-split-wave64-tails

Conversation

@Decodere

@Decodere Decodere commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Updates DxilIr's per-block tail pointer (self.tails[self.cur]) after split-wave64 ballot and read_lane exchanges so successor PHI predecessors match the actual post-exchange basic block. Fixes #1889. Part of #1269.

In split wave64 compute shaders with more than 64 threads per group (Partner::Spin), DxilIr::ballot and DxilIr::read_lane call Lw::ballot / Lw::read_lane_uniform, which lower through Lw::spin_exchange and create new DXIL basic blocks (advancing self.lw.cur() to the join block). Without syncing self.tails[self.cur] = self.lw.cur(), outgoing branches terminated the post-exchange join block while DxilIr::incoming wired successor PHIs to the stale pre-exchange block, failing DXIL validation (PHI node entries do not match predecessors!). Audited DxilIr::compute_ids (Lw::setup_lanes_compute) as well and confirmed it emits straight-line code with no basic-block splits.

What is in it

  • crates/xcl/src/gpu/recomp/lower_dxil.rs:
    • Sync self.tails[self.cur] = self.lw.cur() in DxilIr::ballot and DxilIr::read_lane when self.lw.split is set (matching DxilIr::foreign).
    • Add split_wave64_spin_exchange_updates_block_tails in #[cfg(test)] mod tests, compiling and validating [128, 1, 1] split-wave64 compute shaders through lower_dxil::compute_split for (1) whole-wave ballot (s_bcnt1_i32_b64) in a uniform branch feeding a join PHI, (2) cross-half v_readlane_b32 in a uniform branch feeding a join PHI, and (3) v_readfirstlane_b32 (ballot + read_lane) in a uniform loop feeding back-edge PHIs, then verifying GPU execution parity against run_compute_waves.

Tested

  • Hardware / toolchain: NVIDIA GeForce RTX 4060 (8 GB, 32-lane waves, driver 621.14), Intel Core i5-11400F, 32 GB RAM, Windows 11 Home build 26200, Rust 1.100.0 (0ef1bc386), DXC 1.9.2609.5 (01b62ad4), release build.
  • Pre-fix reproduction: confirmed split_wave64_spin_exchange_updates_block_tails fails DXIL validation (PHI node entries do not match predecessors!) independently on ballot diamond before fixing DxilIr::ballot and on readlane diamond before fixing DxilIr::read_lane.
  • cargo test --release -p xcl --lib gpu::recomp::lower_dxil -- --test-threads=4 --nocapture: 19 passed, 0 failed, 0 ignored (17 SKIPPED subcases: 14 no wave64 + 3 intentional #1426 f16 refusals).
  • cargo build --release --workspace + cargo test --release --workspace -- --test-threads=4: 1112 passed, 0 failed, 46 ignored across 20 test binaries.
  • SKIPPED GPU/runtime tests on this adapter (27 lines):
    • 20 no wave64 subcases across gpu::recomp::lower::tests (4), gpu::recomp::lower_dxil::tests (14), and gpu::recomp::tests (2)
    • 3 intentional per-lane #1426 refusals (V_MUL_F16, V_PK_MUL_F16, V_CVT_F16_F32) in gpu::recomp::lower_dxil::tests
    • shaders::tests::pso_measurement_compiles_an_exact_synthetic_record: cannot disable the driver cache (Windows Developer Mode is required)
    • heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows
    • 2 D3D12 debug-layer tests (test_title_draws_with_a_root_signature_under_the_debug_layer, uploads_start_from_each_subresources_state: no d3d12SDKLayers.dll / D3D12 debug layer)

Regression run
scripts/smoke.ps1 on origin/main (3da2abb81606df622610e009f0430de99aa9881c) and on this PR's head commit (3990660af24ecbd02d7ece38ee946a0626dee211):

xcl-smoke v1
commit: 3da2abb81606df622610e009f0430de99aa9881c
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1582 (PresentX 1582)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14666 MB
xcl-smoke v1
commit: 3990660af24ecbd02d7ece38ee946a0626dee211
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1526 (PresentX 1527)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14625 MB

Not tested

  • AMD and Intel GPUs, native wave64 hardware, and heap-window hardware paths (skipped above).
  • Live in-game retail smoke with XCL_DIRECT_DXIL=1 XCL_PER_LANE=1 enabled (the default smoke run above exercises the default HLSL runtime path; split-wave64 per-lane DXIL lowering was verified via DXIL validation and RTX 4060 GPU execution parity tests).
  • Debug-profile full workspace test run (the full suite ran in --release).

AI use

  • Google Antigravity (Gemini 4 Neon) — audited lower_dxil.rs and lanes.rs, implemented the fix, regression tests, and PR description; every line of the diff, test run, and smoke check was verified on local RTX 4060 hardware.

@WebIdentity1

Copy link
Copy Markdown

Independent Ampere check of exact head 79a7e326cc1b1419603f9a14e22dc7331f6287fd: the new regression passes on RTX 3090, driver 591.74, Ryzen 7 7800X3D, Windows 10 19045, Rust 1.98.1 MSVC, DXC 1.8.2502.11, debug.

cargo test --locked -p xcl --lib split_wave64_spin_exchange_updates_block_tails -- --test-threads=1 --show-output, with XCL_ADAPTER=3090:

  • Head with only the two production changes reverted (same test retained): 0 passed / 1 failed / 0 ignored. ballot diamond fails DXIL validation with PHI node entries do not match predecessors!, before GPU dispatch.
  • Unmodified head: 1 passed / 0 failed / 0 ignored, zero skips. All three cases execute: ballot diamond, cross-half readlane diamond, and readfirstlane loop. Their 256 output words per case match the existing CPU model.

Both builds recompiled XCL. All 310 source hashes matched before/after each run; the pair differs only in those block-tail updates. This adds an older Ampere/driver check to the author's Ada result.

Not tested: full workspace suite for this head, retail smoke/gameplay, native wave64, or performance. No implementation change is proposed.

AI use: Codex with GPT-6 Astra inspected the fix and test, ran the comparison, and drafted this report.

@upipibi

upipibi commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

NVIDIA run: RTX 3070 8 GB (32-lane waves, split wave64), driver 616.56, Windows 11, debug, 79a7e32 merged onto main 20cf130 (clean).

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

@upipibi

upipibi commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Re-checked 87adc4b on the RTX 3070 (driver 616.56, Windows 11, debug). split_wave64_spin_exchange_updates_block_tails passes, and the gpu_ tests with XCL_DIRECT_DXIL=1 give 111 passed, the same as main.

AI-assisted (Claude Code).

@raylitebull

Copy link
Copy Markdown
Member

Diff audit passed (lower_dxil.rs self.tails[self.cur] = self.lw.cur() after split-wave64 ballot and read_lane_uniform, plus the 3 regression cases), Build and test + PR description are green on 87adc4b, and NVIDIA (RTX 3090, RTX 3070) verified it.

Remaining before merge: one independent AMD GPU pass on 87adc4b.

In split wave64 compute shaders with more than 64 threads per group
(`Partner::Spin`), `DxilIr::ballot` and `DxilIr::read_lane` call
`Lw::ballot` and `Lw::read_lane_uniform`, which lower through
`Lw::spin_exchange` and create new DXIL basic blocks (advancing
`self.lw.cur()` to the post-exchange join block). Neither method updated
`self.tails[self.cur]`, so outgoing branches terminated the post-exchange
block while `DxilIr::incoming` wired successor PHIs to the stale
pre-exchange block, failing DXIL validation (`PHI node entries do not
match predecessors!`).

Sync `self.tails[self.cur] = self.lw.cur()` in both `DxilIr::ballot` and
`DxilIr::read_lane` when `self.lw.split` is set (matching
`DxilIr::foreign`), and add a `[128, 1, 1]` split-wave64 compute
regression test covering whole-wave ballot (`s_bcnt1_i32_b64`) and
`v_readlane_b32` in uniform branches feeding join PHIs plus
`v_readfirstlane_b32` in a uniform loop feeding back-edge PHIs.

Fixes xcl-dev#1889
Part of xcl-dev#1269

Assisted-by: Google Antigravity (Gemini 4 Neon)
@Decodere
Decodere force-pushed the fix-1889-split-wave64-tails branch from 87adc4b to 3990660 Compare November 25, 2026 02:03
@Decodere

Copy link
Copy Markdown
Contributor Author

Rebased cleanly onto main (3da2abb8) at 3990660a resolving only the crates/xcl/src/gpu/recomp/lower_dxil.rs end-of-file test conflict from #1865; the runtime fix in DxilIr::ballot / DxilIr::read_lane is unchanged.

Re-verified locally on RTX 4060 (release): gpu::recomp::lower_dxil (19 passed, 0 failed), full workspace (1,112 passed, 0 failed, 46 ignored), and paired 60 s scripts/smoke.ps1 (1,582 -> 1,526 frames, 0 crashes/removals). Ready for CI and the remaining independent AMD GPU check.

AI use: Google Antigravity (Gemini 4 Neon).

@gefydev gefydev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review of 87adc4b from the per-lane form's side (#1745). I read it against main 3da2abb; I did not run it.

The fix is right. Lw::ballot and Lw::read_lane_uniform go through spin_exchange when a group has more than one console wave (Partner::Spin), which ends the current block, and DxilIr was still wiring successor phis to the block before the exchange. foreign already resyncs tails[cur] after inst_guarded for the same reason; these two were missed when the split exchanges were routed through Lw.

I checked the other DxilIr paths that reach Lw in the split form: read_lane_half (wave_read_lane_at on l & 31), ballot_half (wave_ballot), the loads and stores, and compute_ids emit no blocks. So after this change, every place that can split a block resyncs its tail.

Two notes:

  1. Optional, more robust: br / br_if could set self.tails[self.cur] = self.lw.cur() before they terminate. The terminator is always in lw.cur(), so this one line would keep the tails right for any future Ir method that makes blocks, and it would replace the three separate syncs. Fine to leave as it is if you prefer the change minimal.
  2. The PR conflicts with main now, in lower_dxil.rs, probably the end of the test module after the recent per-lane merges (#2014, #1865). It needs a rebase.

Review written with Claude Code (Claude Opus 5.5); I checked each point against the code.

@Decodere

Copy link
Copy Markdown
Contributor Author

@gefydev Thank you for auditing every DxilIr path against the per-lane form (#1745)! Good news: head 3990660a is already rebased cleanly onto main (3da2abb8, resolving the lower_dxil.rs EOF test conflict from #1865), MERGEABLE, and green on CI. We'll keep the minimal explicit self.tails[self.cur] = self.lw.cur() syncs in ballot and read_lane (matching foreign) to keep the fix tight and focused.

@gefydev

gefydev commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

@Decodere thank you: noted that 3990660a is rebased onto main (3da2abb8), mergeable and green on CI, and that you keep the explicit tail syncs in ballot and read_lane, matching foreign. That is fine with us; the br / br_if resync was only an optional suggestion. The merge is for the maintainer.

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

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

@JJAutoCompare

Copy link
Copy Markdown

Tested

Independent Intel Arc A770 compatibility check for XCL PR #1928 at 3990660af24ecbd02d7ece38ee946a0626dee211. The PR was open at this commit before and after the run. The detached checkout was clean both times.

  • DXIL validation: 3/3 passed. The checked-in debug test validates each shader with DXC before the GPU capability check. The run loaded DXC and DXIL 1.9.2609.5 from the explicit toolchain directory and reported zero validation skips.
  • GPU parity: 3/3 passed on the A770 using split wave64 on hardware wave32. The whole-wave ballot diamond, cross-half lane-37 readlane diamond, and readfirstlane loop each dispatched two 128-thread groups and matched the CPU reference on all 256 output words per case. The test also checked three CPU reference spot values per case.
  • Libtest: 1 passed, 0 failed, 0 ignored, 0 skipped, 1,088 filtered out. Libtest finished in 0.34 s. The wrapper acquired and released the shared A770 lock and exited 0. PowerShell formatted the DXC version line from stderr as NativeCommandError in the captured log.

Windows 11 Enterprise Evaluation 26200.9974, AMD Ryzen 7 3800X, Intel Arc A770 driver 32.0.101.9175, Rust 1.100.0 (0ef1bc386, x86_64-pc-windows-msvc), Cargo 1.100.0, DXC/DXIL 1.9.2609.5 (01b62ad4), unoptimized test profile with debug assertions on and debuginfo off.

Process environment for the build and run

XCL_ADAPTER=A770
XCL_DXC_DIR=%LOCALAPPDATA%/XclTooling/dxc-1.9.2609/bin/x64
CARGO_BUILD_JOBS=2
CARGO_INCREMENTAL=0
CARGO_PROFILE_DEV_DEBUG=0
CARGO_PROFILE_TEST_DEBUG=0
CARGO_TARGET_DIR=L:/XclTooling/pr1947-1831ec4-t3-97236edf/target
TEMP=L:/XclTooling/pr1928
TMP=L:/XclTooling/pr1928

Prebuild outside the Arc lock and graphics execution inside it

& "$env:USERPROFILE/.cargo/bin/cargo.exe" test --locked -p xcl --lib --no-run -j 2 --message-format=json-render-diagnostics > L:/XclTooling/pr1928/build-3990660.log

$pr1928Command = @'
& 'L:/XclTooling/Invoke-ArcTest.ps1' -Test {
    $pr1928Exe = Join-Path $env:CARGO_TARGET_DIR 'debug/build/xcl/97fdf2b9ff8e1482/out/xcl-97fdf2b9ff8e1482.exe'
    if ((Get-FileHash -LiteralPath $pr1928Exe).Hash -ne 'E321749EF65B804C74EE37850BB786D14E1B169E5D431EC6CAD74F4D3945BB6C') { throw 'Test binary changed since the prebuild' }
    & $pr1928Exe 'gpu::recomp::lower_dxil::tests::split_wave64_spin_exchange_updates_block_tails' --exact --test-threads=1 --nocapture
}
'@
& powershell.exe -NoLogo -NoProfile -NonInteractive -ExecutionPolicy RemoteSigned -Command $pr1928Command 2>&1 | Tee-Object -FilePath L:/XclTooling/pr1928/gpu-3990660.log

The temporary RemoteSigned policy applied only to the child PowerShell process running the local lock wrapper.

Not tested

Full workspace suite, comparison against main or the pre-fix revision, retail-title smoke or gameplay, native wave64, other adapters, release profile, and performance.

AI use

T3 Code / Codex (gpt-6.2-sol) verified the exact PR head, ran the checked-in test, and prepared this report.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Per-lane: DxilIr::ballot and DxilIr::read_lane do not update self.tails after spin_exchange, emitting invalid DXIL PHI predecessors

7 participants