Shaders: track source lane in whole-wave Sym::Own to prevent miscompiled shuffles #1485
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1486"
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 AscilCH on 2026-11-24T18:22:19Z.
Bug
In
crates/victory-shader/src/emit/wave.rs, pre-section VGPR inputs were represented asSym::Own(Value)without recording which lane originally held the value.When a whole-wave section performed cross-lane operations on a pre-section VGPR:
v_readlane_b32(and subsequent broadcasts) copiedSym::Own(v)into scalar outputs;shapes()then matchedSym::Own(v)and returnedShape::Value(v)— silently lowering a broadcast of lanekas each lane's ownv[l]!row_mirror,quad_perm,row_ror,dpp8, etc.) andv_permlanex16_b32movedSym::Own(v)from lanesrcto lanedst;per_lane()then checkedlane.iter().all(|x| *x == Sym::Own(v))and collapsed the shuffled vector back toShape::Value(v)(identity)!v_cndmask_b32over a shuffled pre-section VGPR checked*a == Sym::Own(v)without checking the originating lane, silently collapsing toShape::Masked(v, mask, 0).Reproduction (Before Fix)
With a synthetic whole-wave section executing
v_readlane_b32 s5, v0, 7,v_mov_b32_dpp v2, v0 row_mirror,v_permlanex16_b32 v3, v0, 0, 0, andv_cndmask_b32over a shuffledv0:Fix
Sym::Own(Value, u8)(initialized withl as u8when reading an untracked VGPR in lanel).usize::from(from) == lwhen recognizing identity/masked outputs inv_cndmask_b32andper_lane().Sym::Own(..)toShape::Valuein scalarshapes()or inper_lane()'s uniform broadcast branch (since a broadcast of a single source lane's pre-section VGPR is not each lane's own value).emit::wave::tests::cross_lane_ops_on_pre_section_vgpr_do_not_collapse_to_identitycoveringv_readlane_b32,v_mov_b32_dpp(row_mirror),v_permlanex16_b32, andv_cndmask_b32over a shuffled VGPR, while asserting unshuffled identity/masked paths remain recognized.(Disjoint from #646, which addresses
constant()sign-extension andop: Noneinper_lane().)Verification
rustfmt --edition 2024 --check crates/victory-shader/src/emit/wave.rs: cleanVICTORY_WARP=1 cargo test -p victory-shader --locked -- --test-threads=1: 121 passed, 0 failedcargo xtask policy: 154 files okcargo clippy --workspace --all-targets --locked -- -D warnings: cleancargo clippy --workspace --all-targets --all-features --locked -- -D warnings: cleanImported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-24T18:28:06Z.
Review: APPROVED
Verified locally merged onto
origin/main(Windows 11 x64, Rust 1.98.1 MSVC):cargo test -p victory-shader --lib emit::wave::— 3 passed, 0 failed (includingcross_lane_ops_on_pre_section_vgpr_do_not_collapse_to_identity)cargo clippy -p victory-shader --all-targets— 0 warningscargo xtask policy— okClean fix tracking source lane identity in
Sym::Own(Value, u8)so cross-lane shuffles on pre-section VGPRs do not collapse to identity. Looks good.AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T18:42:09Z.
Review: APPROVED
Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (
ffe310e),cargo test -p victory-shader --locked→ 97 passed, 0 failed. Execution/valu tests are#[cfg(all(test, windows))]and were not run here; lowering/structure coverage only.Sym::Own(Value, u8)recording the source lane fixes cross-lane ops on pre-section VGPRs being collapsed to identity inwave.rs: theRedcase now requiresfrom == l, andper_laneonly folds toShape::Valuewhen every lane holds its ownx. The new simulate test (readlane broadcast, DPP row_mirror, cndmask, permlanex16 + positive controls for plain copy/unshuffled select/uniform readlane) runs on macOS — 97 passed (+1). Subtle miscompile fix, good coverage.Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-24T20:13:19Z.
Offline measurement on a retail dump, and the shader tests on Ada
Result: no count change against
main.Offline. I merged head
ecdb146ontomainffe310e(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 21,724 onmain, 21,724 with this PR.No program changes its failure reason either. That is the expected result for a fix whose instructions sit behind the earlier failures on
main. The count shows that the change rejects nothing. It does not show whether the output is right.Tests: with the same merge,
cargo test --locked -p victory-shader --libpassed 121, failed 0. The bitcode benchmark is ignored, as onmain, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, withVICTORY_WARPunset.No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:29:34Z.
Automated triage for the maintainers.
Needs rebase. This pull request conflicts with
main(conflicting:crates/victory-shader/src/emit/wave.rs). It will be reviewed once it is rebased onto the currentmain.Generated by Claude Code
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.