Shaders: fix whole-wave EXEC inline constant sign-extension and prefix lane validation #646
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/646"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by nathanbzrr on 2026-11-24T06:06:19Z.
Summary
Fixes two silent miscompilation bugs in whole-wave symbolic simulation (
crates/victory-shader/src/emit/wave.rs):constant()collapsed all negative inline integer constants-2..=-16(and negative 32-bit inline floats like-1.0f) tou64::MAX(-1), turning maskeds_mov_b32 exec_lo, -2/s_mov_b64 exec, -2steps intoexec == all, silently clobbering lane 0 and bypassingif exec != allguards. In addition,EXEC/EXEC + 1updates insimulate()were not masked by& all, causing 64-bitexecwrites in wave32 sections to missexec == all.per_lane(),op: Nonelanes withfound == Nonehit(None, None) => continuebefore checking(src, mask, ident, inclusive), allowing mismatched lane 0 / lane 1 values in prefix scans to be silently accepted as validShape::Prefix.Changes (
crates/victory-shader/src/emit/wave.rs)constant(inst)to distinguish 64-bits_mov_b64from 32-bit moves: decodeNULL(125) as0, sign-extend 64-bit inline integers (128..=208) viai64::from(x as i32) as u64, keep 32-bit inline constants zero-extended, and returnNonefor non-integer inline constants ons_mov_b64.EXECandEXEC + 1updates insimulate()by& all.meta: Option<(Value, Value, u32, bool)>independently fromop_foundinper_lane()so everySym::Redlane (including single-laneop: Nonelanes 0 and 1) validates(src, mask, ident, inclusive),op.identity(ident), andlanes[0]inclusive/exclusive invariants.constant_decodes_width_and_inline_kinds,exec_minus_two_masks_lane_zero_and_enforces_dpp_guard,wave32_mov_b64_all_lanes_keeps_exec_masked_for_dpp,per_lane_prefix_soundness).Verification
Isolated verification on branch
shader/wave-exec-const-and-prefix-validation(12eba49):rustfmt --edition 2024 --config skip_children=true --check crates/victory-shader/src/emit/wave.rs(passed)cargo test -p victory-shader -- --test-threads=1(73 passed, 0 failed, 0 ignored)cargo clippy -p victory-shader --all-targets(0 warnings)cargo xtask policy(151 files ok)No game files. AI-assisted; reviewed and verified with the tests above.
Imported from Marvisak/VIctory. Originally posted by LAKSHYA-cmd-tech on 2026-11-24T06:14:57Z.
Review: APPROVED
Tested on Windows 11 with Rust 1.98.1 (x86_64-pc-windows-msvc).
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T10:18:21Z.
Review: APPROVED
Merges cleanly; merged into current main
ffe310e(post-#566), macOS arm64, rustc 1.98.1,cargo test -p victory-shader --locked→ 100 passed / 0 failed / 1 ignored.Three fixes, each with targeted tests:
simulatenow clamps EXEC to the wave width (& all) afters_mov_b64/exec_hiwrites, so a 64-bit mask can't leak bits past lane 31/63 into the DPP guard logic.constant()handles the NULL operand (→ 0) and sign-extends inline constants correctly fors_mov_b64(wide) vss_mov_b32— the old code sign-extended everything to u64::MAX, which was wrong for b32 consumers reading the low dword only.per_laneprefix validation is rewritten to track lane metadata and op separately, requiring a consistent op across lanes, a single-bit set for lanes without an op, and the identity check viaop.identity(ident); lane 0 must be the identity for exclusive prefixes and a reduction for inclusive ones.The four new tests (
constant_decodes_width_and_inline_kinds,exec_minus_two_masks_lane_zero_and_enforces_dpp_guard,wave32_mov_b64_all_lanes_keeps_exec_masked_for_dpp,per_lane_prefix_soundness) exercise exactly the changed paths with real encodings. These are wave32/64 shape-analysis fixes that run on macOS (no GPU needed forstructure/wave).Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T11:03:27Z.
Review: APPROVED
Tested
12eba49on Windows 11, RTX 5070, MSVC:cargo test -p victory-shader -- --test-threads=173 passed, including the four newwave.rstests.cargo clippy -p victory-shader --all-targetsis clean.victory translate --validate --pipelineson the local title executable gives the same result at the merge base (d2a4bae) and at this head: 12 of 12 emitted, validated and built into pipelines.constant(): sign-extending inline integers 128..=208 only fors_mov_b64and zero-extending them for 32-bit moves matches how SOP1 widens inline constants. ReturningNonefor float inline constants ons_mov_b64is the conservative choice (they would be f64 bit patterns).& allfixes the wave32s_mov_b64 exec, -1case, where theexec == allcomparison never matched.per_lane: validating(src, mask, ident, inclusive)for every lane, not only lanes that name an op, closes the gap where a single-laneop: Nonelane skipped the check. Requiringop.identity(ident)and the lane-0 shape matches the prefix invariant.AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-24T10:47:20Z.
Independent verification & code review on Windows 11 Pro (build 26100) + AMD Radeon RX 9060 XT (RDNA4, driver
32.0.32029.2010, Rust1.98.1), cleanly merged ontomain(ffe310e):cargo xtask policy: PASS (154 files ok)cargo clippy -p victory-shader --all-targets --locked -- -D warnings: PASScargo clippy -p victory-shader --all-targets --features diagnostics --locked -- -D warnings: PASScargo test -p victory-shader --locked: 124 passed, 0 failed, 1 ignored (including all newemit::wave::tests::*cases)VICTORY_D3D12_DEBUG=1 cargo test -p victory-shader --locked -- valu_tests: 13/13 PASS on RX 9060 XT and 13/13 PASS on WARP (VICTORY_WARP=1)Diff review of
crates/victory-shader/src/emit/wave.rslooks solid:128..=208) fors_mov_b64fixes the-2..-16 -> u64::MAXbug while keeping float inline constants rejected on 64-bitB64moves and zero-extending 32-bit literals per RDNA2B64rules.execwithallon bothEXECandEXEC+1updates prevents high-half leakage in wave32.metaandop_foundinper_lanecloses the single-laneop: Nonebypass and properly validateslanes[0]andop.identity(ident).AI-assisted; synthetic tests only, no game files.
Imported from Marvisak/VIctory. Originally posted by molodayamama on 2026-11-24T14:06:00Z.
Independent Windows check of
12eba495039d8018eb6959be95fcc10e387b7e33(Windows 10 22H2 19045, Rust 1.98.1, MSVC x64).cargo test -p victory-shader --locked --lib emit::wave::tests -- --test-threads=1 --nocapture: 6 passed.The whole-wave fixtures covered inline constant kinds, signed
EXEC = -2, DPP guarding with lane zero masked, and the wave32/wave64 prefix checks. This is a CPU-side analysis run.Only source-built synthetic fixtures were used. AI-assisted verification.