Skip to content

Recompiler: fix per-lane whole-wave predicate and SRC_SCC checks - #2014

Merged
raylitebull merged 1 commit into
xcl-dev:mainfrom
AlpPesen:fix/per-lane-whole-wave-predicates
Nov 25, 2026
Merged

raylitebull merged 1 commit into
xcl-dev:mainfrom
AlpPesen:fix/per-lane-whole-wave-predicates

Conversation

@AlpPesen

@AlpPesen AlpPesen commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1888.

Fixes three soundness gaps in the per-lane (XCL_PER_LANE=1) whole-wave mask predicate analysis and lowering (crates/xcl/src/gpu/recomp/lane_masks.rs, crates/xcl/src/gpu/recomp/lower.rs):

What is in it

  • Track wave-wide SCC reduction semantics in lane_masks via SccKind (Uniform, Any, All, Unknown) so uniform_over accounts for inactive lanes (EXEC == 0) when wave_branches == false:
    • Any (mask != 0, e.g. S_*_SAVEEXEC, S_NOT, mask bitwise ops, S_CMP_LG_U32/U64): per-lane bit matches hardware only when c == FALSE wave-wide or re != FALSE && re => c.
    • All (a == b, S_CMP_EQ_U32/U64): per-lane bit matches hardware only when c == TRUE wave-wide or re != FALSE && re => !c.
    • Preserve SccKind across CFG joins without folding non-uniform mask SCCs via fact alone, and check uniform_over on the unnegated branch predicate before applying SCC0/VCCZ/EXECZ negation.
  • Stop ANDing VCC with EXEC in S_CBRANCH_VCCZ / S_CBRANCH_VCCNZ (lane_masks::cond and lower::cond when !self.wave_branches), matching RDNA2 hardware which tests all bits of VCC independent of EXEC.
  • Validate all non-branch SCC reads via reads_scc: both implicit OPR_SSRC_SPECIAL_SCC inputs and explicit SRC_SCC (encoding 253) in SSRC0, SSRC1, SRC0, SRC1, SRC2, SOFFSET.
  • Add 3 unit tests in lane_masks::tests covering inactive-lane S_CMP_EQ/S_CMP_LG/S_NOT SCC checks, S_CBRANCH_VCCZ/VCCNZ with bits outside EXEC, and explicit SRC_SCC (253) SALU/VALU reads.

Tested

  • Hardware: Intel Core i9-9900K, 32 GB RAM, AMD Radeon RX 6800 (16337 MiB VRAM, RDNA2, driver 32.0.21045.29003), Windows 11 Pro build 26300, rustc 1.100.0, DXC 1.9.2602.17.
  • cargo test -p xcl --lib gpu::recomp::lane_masks: 13 passed, 0 failed, 0 ignored, 0 skipped.
  • cargo test -p xcl --lib gpu::recomp::lower -- --test-threads=4: 51 passed, 0 failed, 0 ignored, 6 sub-case skips (V_MUL_F16/V_PK_MUL_F16/V_CVT_F16_F32 unsupported in per-lane form).
  • cargo test --workspace -- --test-threads=4 (xcl lib, prior to #1910 rebase): 945 passed, 4 failed (pre-existing on RX 6800: fuzz_validate_and_gpu_1 DXIL GPU fuzz tests reproducibly fail with E_OUTOFMEMORY on RTX 5060 #1905 and placed_title_textures_share_vram_and_preserve_pixels + 2 VRAM_TEST_LOCK PoisonError cascades D3D12.X: map a one-slice title texture's packed mips where D3D12 addresses them #470), 25 ignored, 1 skipped (pso_measurement_compiles_an_exact_synthetic_record: Windows Developer Mode not enabled).
  • cargo test -p xcl --test '*' -- --test-threads=4: 49 passed, 0 failed, 20 ignored, 1 skipped (heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows).

Not tested

  • NVIDIA or Intel GPUs, wave32-only adapters, or Linux/Wine.
  • XCL_PER_LANE=1 full retail title playthrough past 60 s.

Regression run

xcl-smoke v1
commit: 6567c5ffa38fbc7039b2d6bf520154689cc1f482
gpu: AMD Radeon RX 6800
title: 6ca5cab7
seconds: 60
exit: 0x0
frames shown: 1532 (PresentX 1532)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15167 MB
xcl-smoke v1
commit: 1c971de6463a26fae5b438f3eada5eaf58c66050
gpu: AMD Radeon RX 6800
title: 6ca5cab7
seconds: 60
exit: 0x0
frames shown: 1524 (PresentX 1524)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15159 MB

AI use

Fixes xcl-dev#1888.

- Distinguish wave-wide any-lane-nonzero (SccKind::Any) from
  all-lanes-equal (SccKind::All) in lane_masks::uniform_over so
  inactive lanes (EXEC == 0) are accounted for on S_CMP_EQ, S_CMP_LG,
  S_NOT, and mask-op SCC joins/branches.
- Stop ANDing VCC with EXEC in S_CBRANCH_VCCZ / S_CBRANCH_VCCNZ in both
  lane_masks::cond and lower::cond; hardware tests all bits of VCC
  regardless of EXEC.
- Validate explicit SRC_SCC (encoding 253) source operands and implicit
  OPR_SSRC_SPECIAL_SCC inputs against uniform_over in lane_masks.

Assisted-by: Antigravity (Gemini 4 Neon)
@AlpPesen
AlpPesen force-pushed the fix/per-lane-whole-wave-predicates branch from dae6a97 to 1c971de Compare November 25, 2026 00:49
@JJAutoCompare

Copy link
Copy Markdown

Tested

  • Exact PR head 1c971de6463a26fae5b438f3eada5eaf58c66050. The clean checkout matched the open PR before and after testing.
  • Windows 11 Enterprise Evaluation build 26200 (x64 VM), AMD Ryzen 7 3800X (6 cores / 12 logical processors exposed), Intel Arc A770 with driver 32.0.101.9175. Rust/Cargo 1.100.0, x86_64-pc-windows-msvc, debug test profile. CARGO_BUILD_JOBS=2, CARGO_INCREMENTAL=0, isolated Cargo target and TEMP/TMP on L:/XclTooling.
  • DXC 1.9.2609.5 from %LOCALAPPDATA%/XclTooling/dxc-1.9.2609/bin/x64. The GPU case compiled the HLSL reference with -E main -T cs_6_6 -HV 2021 and used XCL_ADAPTER=A770.
Command Passed Failed Ignored Skipped
cargo test -p xcl --lib gpu::recomp::lane_masks -- --nocapture 13 0 0 0
cargo test -p xcl --lib gpu::recomp::lower::tests::a_whole_wave_decision_on_a_mask_some_lanes_lack_is_refused -- --exact --nocapture 1 0 0 0
& 'L:/XclTooling/Invoke-ArcTest.ps1' -Test { cargo test -p xcl --lib gpu::recomp::lower_dxil::tests::a_branch_on_a_mixed_mask_matches_the_hlsl_path_on_the_gpu -- --exact --nocapture } 1 0 0 0

The CPU checks include inactive-lane SCC decisions, VCC bits outside EXEC, and explicit SRC_SCC reads. The wave32 Arc case dispatched the HLSL reference and checked the per-lane lowering for a mixed-mask S_CBRANCH_SCC0 (expected refusal or matching DXIL output).

Not tested

Full workspace suite, retail-title smoke, native wave64, or other GPU/driver combinations in this run. Explicit SRC_SCC and VCC bits outside EXEC were covered by CPU tests here.

AI use

Codex (gpt-6.2-sol) selected and ran the focused tests and wrote this report.

@raylitebull

Copy link
Copy Markdown
Member

Diff audit passed on 1c971de (SccKind::{Uniform,Any,All,Unknown} tracking in lane_masks.rs, preserving all-lane VCC semantics in S_CBRANCH_VCCZ/VCCNZ, and reads_scc checking explicit SRC_SCC = 253 across SALU/VALU), and CI (Build and test + PR description) is green.

Remaining before merge: independent AMD and NVIDIA GPU test runs on 1c971de.

@DarkPanda69

Copy link
Copy Markdown

NVIDIA and native-wave64 AMD runs, which this PR lists as not tested (the report above is on an Arc A770).

Tested: pass, head 1c971de applied on main 0be6ce8, debug, Rust 1.100.0, Windows 11 Pro 26200, Ryzen 7 5800X, DXC 1.9.2602.17.
cargo test -p xcl --lib -- gpu:: --test-threads=4:

  • NVIDIA RTX 3060, driver 32.0.16.1088, waves 32 only: 542 passed, 0 failed, 22 ignored. whole_wave_scc_accounts_for_inactive_lanes, vccz_branch_checks_bits_outside_exec, explicit_src_scc_reads_are_validated and a_branch_on_a_mixed_mask_matches_the_hlsl_path_on_the_gpu ok. The SKIPPED lines are the same as on main.
  • AMD RX 9070 XT (RDNA4), driver 32.0.32029.2010, native wave64: 540 passed, 2 failed, 22 ignored. Same tests ok. The 2 failures are gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 and _3, which fail the same way on main 0be6ce8 without this PR on this card.

Not tested: XCL_PER_LANE=1 title runs; Linux / Wine; the whole workspace suite.

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

@fromthemoonx

Copy link
Copy Markdown

Passes on NVIDIA (RTX 3060, wave32 only) in the whole workspace suite and with XCL_PER_LANE=1. One gap: the lower.rs half of the VCCZ change has no test that fails without it.

This adds to the RTX 3060 gpu:: run above: the whole suite, the merged tree, XCL_PER_LANE=1 and two mutation checks.

  • Exact head 1c971de: cargo build --workspace + cargo test --workspace --no-fail-fast -- --test-threads=4: 1000 passed, 0 failed, 45 ignored. Merged onto main 5796cc4 (no conflicts): 1060 passed, 0 failed, 45 ignored. 23 SKIPPED on both, the same as on main: 19 for no wave64, 3 per-lane refusals (V_MUL_F16, V_PK_MUL_F16, V_CVT_F16_F32) and heap_window_out_of_memory_falls_back_to_the_switch_form.
  • XCL_PER_LANE=1 cargo test -p xcl --lib gpu:: -- --test-threads=1 --skip gpu_sparse_vram: merged tree 525 passed / 0 failed / 21 ignored, main 5796cc4 522 / 0 / 21 (the difference is the 3 new tests).
  • gpu::recomp::lane_masks 10 runs: 10 of 10 passed (13 tests each).
  • Mutation, lane_masks.rs: with S_CBRANCH_VCCZ/NZ ANDing VCC with EXEC again (line 680), vccz_branch_checks_bits_outside_exec fails, and it is the only gpu::recomp test that fails.
  • Mutation, lower.rs: with the old VCC & EXEC put back only in Lower::cond (line 1012), every test still passes: cargo test -p xcl --lib gpu::recomp (323 passed), and XCL_PER_LANE=1 … gpu::recomp::lower (51 passed). So that half of the fix has no test that fails without it. A GPU case through lower_dxil that compares the HLSL path for a VCCNZ branch whose VCC has bits only outside EXEC would cover it, if lane_masks accepts such a program.

Hardware: RTX 3060 12 GB, driver 610.88, Windows 11 Pro 26300, Rust 1.100.0 MSVC, DXC 1.9.2602.17, debug.

Not tested: native wave64, a release build, scripts/smoke.ps1 (no title on this machine).

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

@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.

Per-lane: unsound whole-wave predicate checks (uniform_over ignores inactive lanes, S_CBRANCH_VCCZ/NZ ANDs with EXEC, SRC_SCC 253 unchecked)

6 participants