Skip to content

Recompiler: guard NULL (125) dests and bridged lane_mask inputs in per-lane lowering - #2117

Open
Decodere wants to merge 1 commit into
xcl-dev:mainfrom
Decodere:fix-1269-perlane-null-and-bridge
Open

Decodere wants to merge 1 commit into
xcl-dev:mainfrom
Decodere:fix-1269-perlane-null-and-bridge

Conversation

@Decodere

Copy link
Copy Markdown
Contributor

What is in it

Fixes two correctness bugs in the per-lane lowering (crates/xcl/src/gpu/recomp/lower.rs) and lane-mask analysis (crates/xcl/src/gpu/recomp/lane_masks.rs):

  1. NULL (125) destination & source handling (recomp/lower.rs, recomp/lane_masks.rs):
    • Lower::write_num and Lower::write_bit lacked an early return on r == 125. In wave64, mask writes to null (such as S_AND_B64 null, exec, vcc, S_WQM_B64 null, exec, S_CSELECT_B64 null, ..., and VOP3 V_CMP_* null, ...) wrote num_marker/bit_marker to r + 1 = 126 (destroying EXEC), and 64-bit scalar / multi-dword SMEM writes (S_GETPC_B64, S_MOV_B64, S_CSELECT_B64, S_LOAD_DWORD*) wrote sd + 1 = 126. Added if r == 125 { return; } to write_num and write_bit, guarded the 64-bit scalar and SMEM write sites with != 125, and excluded 125 in reads_mask and cmp64.
    • In lane_masks.rs, mapped 125 (null) to Some(FALSE) in mask_src, avoided pushing 125 into set (st.regs[125]) on V_CMP_*, saveexec/wrexec, and SALU mask ops while preserving SCC tracking (scc = Some((v, SccKind::Any))) for non-MOV/CSELECT mask ops to null, and excluded 125 when detecting tracked mask sources.
  2. Bridged lane_mask input clobbering (recomp/lower.rs::bridge):
    • bridge() pushed (Var::S(m), ...) and (Var::S(m + 1), ...) unconditionally after the whole SGPR loop, overwriting live scalar operands already placed in inputs (for example, wave32 V_ADD_CO_CI_U32 v2, vcc_lo, s1, v1, s0 clobbered s1 with 0; SRC0 == SRC2 clobbered the scalar addend with 1 << lane; and m == 127 pushed out-of-range Var::S(128)).
    • Guarded lane_mask pushes so (Var::S(r), val) is only pushed when r < 128 and Var::S(r) is not already in inputs (in wave32 dxil::Lw::lane_of ignores hi, and a scalar register already present as a number in inputs already holds its true mask bit for every lane).
  3. Tests (lane_masks.rs, lower.rs):
    • lane_masks::tests::null_dest_and_source_in_lane_masks: verifies S_AND_SAVEEXEC_B64 null, vcc + S_OR_B64 s[0:1], null, vcc reads FALSE for null (keeping MOV2 guarded) and S_AND_B64 null, exec, vcc / null still tracks mask SCC.
    • lower::tests::null_dest_preserves_exec_and_scc: CPU Interp test covering wave64 S_AND_B64, VOP3 V_CMP_EQ_U32, S_MOV_B64, S_CSELECT_B64, and S_GETPC_B64 to null (125), verifying EXEC and SCC.
    • lower::tests::bridged_wave32_carry_preserves_scalar_operands_in_dxil: CPU + dxil.dll validation test checking lower_dxil::kernel preserves s1=42 (SRC0 adjacent to SRC2=s0) and s4=5 (SRC0 == SRC2) in the generated DXIL.
    • lower::tests::gpu_null_dest_and_bridged_carry_agree_with_hlsl: CI-WARP-safe (gpu_waves() + dxc::location()) GPU parity test verifying wave32 bridged V_ADD_CO_CI_U32 (lower_dxil::kernel) and wave64 split NULL dests (lower_dxil::kernel_split) match HLSL on the GPU.

Part of #1269

Tested

  • Hardware / toolchain: Windows 11 (26200), Intel Core i5-11400F, 32 GB RAM, NVIDIA GeForce RTX 4060 8 GB (32-lane waves, driver 621.14), rustc 1.100.0, DXC 1.9.2609.5, release build.
  • Failing-first check (before the fixes on 6987e496):
    • CPU tests: 0 passed, 3 failed:
      • null_dest_and_source_in_lane_masks failed (left: [], right: [16] — null read stale st.regs[125]).
      • null_dest_preserves_exec_and_scc failed (s126: a mask read as a number — write_bit(125) clobbered EXEC).
      • bridged_wave32_carry_preserves_scalar_operands_in_dxil failed (adjacent scalar operand s1=42 must not be clobbered by lane_mask).
    • GPU test on RTX 4060: gpu_null_dest_and_bridged_carry_agree_with_hlsl failed (lane 0: v2 (s1 + v0 + cin): left: 0, right: 43).
  • After the fix (targeted, RTX 4060 + WARP):
    • RTX 4060 (null_dest_and_source_in_lane_masks, null_dest_preserves_exec_and_scc, bridged_wave32_carry_preserves_scalar_operands_in_dxil, gpu_null_dest_and_bridged_carry_agree_with_hlsl): 4 passed, 0 failed, 0 ignored, 0 skipped.
    • WARP (XCL_ADAPTER="Microsoft Basic Render Driver" and XCL_ADAPTER=warp): 4 passed, 0 failed (all 3 CPU tests pass; GPU test skips cleanly with no GPU with 32-lane waves).
  • Release workspace build & full test suite:
    • cargo build --release --workspace: exit 0.
    • cargo test --release --workspace -- --test-threads=4: 1158 passed, 0 failed, 46 ignored across 21 test binaries, with 25 SKIPPED stderr lines:
      • 20 no wave64 (32-lane RTX 4060 hardware)
      • 3 per-lane form: refused (#1426 unsupported f16/f32 semantics in per-lane wave32 tests)
      • 1 cannot disable the driver cache (Windows Developer Mode is required) (pso_measurement_compiles_an_exact_synthetic_record)
      • 1 no heap windows (heap_window_out_of_memory_falls_back_to_the_switch_form)

Regression run

Paired 60s scripts/smoke.ps1 runs on the same retail title (title: 29640639) and GPU (NVIDIA GeForce RTX 4060):

Base (origin/main, 6987e496):

xcl-smoke v1
commit: 6987e496c35653f9ccc9dbdc1f1d342734306811
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1590 (PresentX 1590)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14516 MB

This PR (d758ce8b):

xcl-smoke v1
commit: d758ce8b2cf1a2f1f961c316b8a76a7d1206572a
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1602 (PresentX 1602)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 14471 MB

No regressions (1602 vs 1590 frames, 14471 MB vs 14516 MB peak commit, 60 61 60 presents per 2 s, 0 device removals, 0 crashes).

Not tested

  • Native 64-lane hardware waves (AMD / Intel GPUs); wave64 GPU parity was verified on RTX 4060 via lower_dxil::kernel_split, and wave64 per-lane semantics were verified on the CPU via Interp.

AI use

  • Google Antigravity (Gemini 4 Neon) investigated the NULL (125) destination/source and bridged lane_mask input-clobbering bugs in recomp/lower.rs and recomp/lane_masks.rs, authored the fixes and CPU/GPU regression tests, and ran all build, unit, GPU, WARP, workspace, and paired smoke checks.

…r-lane lowering

Fix two correctness bugs in the per-lane lowering and lane-mask analysis:

1. `NULL` (`125`) destination/source handling (`recomp/lower.rs`,
   `recomp/lane_masks.rs`):
   - `Lower::write_num` and `Lower::write_bit` lacked an `r == 125` early
     return, so wave64 mask writes to `null` (such as `S_AND_B64 null,
     exec, vcc`, `S_WQM_B64 null, exec`, `S_CSELECT_B64 null, ...`, and
     VOP3 `V_CMP_* null, ...`) wrote markers to `r + 1 = 126`, clobbering
     `EXEC`, and 64-bit scalar writes (`S_GETPC_B64`, `S_MOV_B64`,
     `S_CSELECT_B64`, multi-dword `S_LOAD_DWORD*`) wrote `sd + 1 = 126`.
     Guard `write_num`, `write_bit`, the 64-bit/SMEM write sites, and
     exclude `125` in `reads_mask` and `cmp64`.
   - In `lane_masks.rs`, map `125` (`null`) to `Some(FALSE)` in
     `mask_src`, avoid writing `st.regs[125]` on `V_CMP_*`,
     `saveexec`/`wrexec`, and SALU mask ops while still updating `SCC` on
     non-`MOV`/`CSELECT` mask ops to `null`, and exclude `125` when
     detecting tracked mask sources.

2. Bridged `lane_mask` input clobbering (`recomp/lower.rs::bridge`):
   - Pushing `(Var::S(m), ...)` and `(Var::S(m + 1), ...)` unconditionally
     after the `whole` SGPR loop overwrote live scalar operands in
     `inputs` (e.g. wave32 `V_ADD_CO_CI_U32 v2, vcc_lo, s1, v1, s0`
     clobbered `s1` with `0`, `SRC0 == SRC2` clobbered the scalar addend
     with `1 << lane`, and `m == 127` pushed out-of-range `Var::S(128)`).
   - Only push `(Var::S(r), val)` when `r < 128` and `Var::S(r)` is not
     already present in `inputs`.

Add CPU, DXIL-validation, and CI-WARP-safe GPU parity tests covering
both bugs (wave32 bridged `V_ADD_CO_CI_U32` and wave64 `NULL` dests).

Part of xcl-dev#1269

Assisted-by: Google Antigravity (Gemini 4 Neon)
@futurepro62

futurepro62 commented Nov 25, 2026 •

Copy link
Copy Markdown

Full-suite run, since this PR has no test report yet. Tested exact head d758ce8 (on its base 6987e49).

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::recomp::lower_dxil::tests::const_and_null_mask_operands_agree_with_hlsl_on_the_gpu --skip gpu::recomp::lower_dxil::tests::mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu --skip gpu::dxil::fuzz_tests: 1146 passed, 0 failed, 44 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: null_dest_and_source_in_lane_masks, bridged_wave32_carry_preserves_scalar_operands_in_dxil, null_dest_preserves_exec_and_scc, gpu_null_dest_and_bridged_carry_agree_with_hlsl.
  • 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: 1157 passed, 0 failed, 46 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 6020a33 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), the four gpu::recomp::lower_dxil::tests::*_programs_on_the_gpu tests, const_and_null_mask_operands_agree_with_hlsl_on_the_gpu and mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu (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.

@DarkPanda69

Copy link
Copy Markdown

Tested: gpu_null_dest_and_bridged_carry_agree_with_hlsl passes on an AMD D3D12 driver and on an RTX 3060.

Head d758ce8 applied on main 6020a33, cargo test -p xcl --lib -- gpu:: --test-threads=4 with XCL_ADAPTER set to each card.
The new test runs its wave32 case and the split form of its wave64 case (kernel_split, split_wave64: true), so even on the 9070 XT it does not run the NULL-dest case in native 64-lane waves. This is an AMD driver result, not the native wave64 check the PR lists as untested.
Not tested: native wave64 per-lane, retail runs.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

IvyNotFound added a commit to IvyNotFound/xcl that referenced this pull request Nov 25, 2026
@JoaoPauluu

Copy link
Copy Markdown

A run with vkd3d-proton as the host D3D12. The DXIL goes through dxil-spirv and then the NVIDIA Vulkan driver, not the native-Windows path: this PR's 4 new tests pass, none skipped.

Tested

  • RTX 3060 12 GB (NVIDIA 620.70.06, 32-lane waves), i5-10400F, 16 GB, CachyOS (kernel 7.3.3), Proton Experimental 11.0-20261112 with the patched vkd3d-proton 3.1 from Linux: docs/linux.md, scripts/linux and Wine start-up checks for vkd3d-proton and DXVK (#154, #241) #257, DXC 1.9.2609.5. Release, cross-built for x86_64-pc-windows-gnu. d758ce8 as it is (merge base with main 6987e49), no uncommitted changes. The lib test binary runs under Wine, one test per process.
    • null_dest_and_source_in_lane_masks: ok
    • bridged_wave32_carry_preserves_scalar_operands_in_dxil: ok
    • gpu_null_dest_and_bridged_carry_agree_with_hlsl: ok
    • null_dest_preserves_exec_and_scc: ok

Not tested

  • the whole suite on this head, a retail title, native Windows, AMD.

AI use

  • Claude Code (Claude Opus 5.5) built the commit, ran the tests and wrote this report. The account owner asked for test reports to be posted and has not reviewed this one.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

@throny

throny commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

merge-check claim
head: d758ce8

@throny

throny commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

merge-check
base: 309c3ec
head: d758ce8
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2145 passed, 1 failed, 48 ignored (26 SKIPPED lines). Base alone at 309c3ec: 2142 passed, 0 failed, 48 ignored. The failure is one of this PR's own new tests, gpu::recomp::lower::tests::bridged_wave32_carry_preserves_scalar_operands_in_dxil ("adjacent scalar operand s1=42 must not be clobbered by lane_mask"). Rerun alone: it fails twice on the merge result and passes on this PR's head d758ce8 without main (merge base 6987e49). It is a CPU-only test of the generated DXIL text, so this is not about the GPU here.
review: the code reads as correct and the merge itself is clean (main renamed a helper next to one of the PR's lines; the three-way merge keeps main's name). The real fix, writers of a 64-bit value with the null register as destination no longer touching the register after it, is not on main yet; parts of the rest are (main already reads register 125 as false and skips it in two paths). The blocking point is only the test above: on current main either the test's expectation or the code path it checks no longer fits what main generates, and that needs the author's look after a rebase. Minor: a few guards are now redundant with the new early return.
performance: no runtime cost. It changes per-lane translator sources only: testers who use the per-lane path re-translate those entries once.
verdict: not yet: rebase onto main and make the PR's own test bridged_wave32_carry_preserves_scalar_operands_in_dxil pass there; I will re-check the new head.
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).

@jsalzy

jsalzy commented Nov 30, 2026

Copy link
Copy Markdown

merge-check claim
head: d758ce8

@github-actions github-actions Bot added area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test) labels Nov 30, 2026
@jsalzy

jsalzy commented Nov 30, 2026

Copy link
Copy Markdown

merge-check
base: 9335bc0
head: d758ce8
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2804 passed, 2 failed, 50 ignored; SKIPPED: 28 (22 no wave64 on this GPU; 3 per-lane form refused (#1426 semantics); 2 no heap windows (opt-in XCL_HEAP_WINDOWS=1); 1 driver cache cannot be disabled without Windows Developer Mode); failing: (1) this PR's own new test gpu::recomp::lower::tests::bridged_wave32_carry_preserves_scalar_operands_in_dxil (lower.rs:4791, "adjacent scalar operand s1=42 must not be clobbered by lane_mask"), not on main; (2) hle::d3d12x::standin::tests::concurrent_shell_miss_reuses_winner_and_releases_loser_pipeline, fails on base too. Main alone at 9335bc0: 2800 passed, 2 failed, 50 ignored (the same standin test, and two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs in its warm child run, which passed on the merge result). The PR's other three new tests pass, including gpu_null_dest_and_bridged_carry_agree_with_hlsl on the GPU (wave32 and split wave64).
review: the failing test is stale, not the fix. It looks for "zext i32 42 to i64" in the DXIL, but since aa63928 ("keep VALU carry arithmetic in i32", adapted from #2565, on main through #2959) the carry is lowered as two i32 operations and an unsigned compare: the DXIL in the failure message has "add i32 42, %30" and "add i32 5, %30", so both operands reach the add unclobbered. The GPU test of the same program agrees: every lane gives 42 + lane + carry-in and 5 + lane + carry-in, matching HLSL. That explains the first check's finding (passes on the PR's own base, fails merged). The fix itself reads right: write_num / write_bit drop writes to register 125, and the 64-bit pair writers (S_GETPC_B64, S_MOV_B64, S_CSELECT_B64, SMEM loads) skip both halves, which is what keeps EXEC_LO (126) intact, so those guards are not redundant with the early return; lane_masks reads null as FALSE and never records it as a destination; the lane-mask inputs no longer overwrite an SGPR the instruction also reads whole. Overlaps without duplicating: #1864 (on main) handles null as a source in the same lowering; #2136 handles the null destination in upper_lanes.rs; #2833 touches the same files for SRC_SCC.
performance: none at run time; per-lane translations of programs with these instructions change once.
verdict: not yet: update bridged_wave32_carry_preserves_scalar_operands_in_dxil to main's i32 carry lowering (e.g. look for "add i32 42," and "add i32 5,"); the fix itself has no finding.
hardware / tool and model: RTX 4070 SUPER 12 GB (621.24 / 32.0.16.2124), Ryzen 7 7800X3D, 32 GB, Windows 11 Pro 25H2 26200.9974, Rust 1.100.0, debug / Claude app (Claude Opus 5.5): merge, build and suite run on this PC with git and cargo only; diff review by Claude Opus 5.5.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head d758ce8

Part of this is on main now: 15fff3b (#1864) reads NULL as a FALSE mask in lower.rs, skips NULL in the lane-mask inputs and the saveexec destination, and 574bda4 passes the real SGPRs for a wave32 bridged carry. Still missing on main: lane_masks.rs:mask_src treats 125 as a register, and S_MOV_B64 / S_CSELECT_B64 / S_GETPC_B64 with SDST = NULL still write sd + 1 = s126 (EXEC_LO).
The PR conflicts and needs a rebase down to those parts. #2136 fixes the same class of NULL-destination bug in upper_lanes.rs, a different module.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

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 gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants