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!

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.

5 participants