Shaders: track source lane in whole-wave Sym::Own to prevent miscompiled shuffles #1486

Open
github-bot wants to merge 1 commit from github-bot/gh-1486 into main AGit
Owner

@⁠AscilCH on GitHub · 2026-11-24 18:22 UTC · original
AscilCH:fix/wave-own-tracks-source-lane → main · +106 −6 · 1 files · 1 commits · open

Bug

In crates/victory-shader/src/emit/wave.rs, pre-section VGPR inputs were represented as Sym::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) copied Sym::Own(v) into scalar outputs; shapes() then matched Sym::Own(v) and returned Shape::Value(v) — silently lowering a broadcast of lane k as each lane's own v[l]!
  • DPP shuffles (row_mirror, quad_perm, row_ror, dpp8, etc.) and v_permlanex16_b32 moved Sym::Own(v) from lane src to lane dst; per_lane() then checked lane.iter().all(|x| *x == Sym::Own(v)) and collapsed the shuffled vector back to Shape::Value(v) (identity)!
  • v_cndmask_b32 over a shuffled pre-section VGPR checked *a == Sym::Own(v) without checking the originating lane, silently collapsing to Shape::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, and v_cndmask_b32 over a shuffled v0:

v_readlane_b32 of pre-section VGPR must not collapse to Shape::Value: left: Some(Value(Value(2))), right: None

Fix

  • Carry the originating lane index in Sym::Own(Value, u8) (initialized with l as u8 when reading an untracked VGPR in lane l).
  • Require usize::from(from) == l when recognizing identity/masked outputs in v_cndmask_b32 and per_lane().
  • Never map Sym::Own(..) to Shape::Value in scalar shapes() or in per_lane()'s uniform broadcast branch (since a broadcast of a single source lane's pre-section VGPR is not each lane's own value).
  • Added unit test emit::wave::tests::cross_lane_ops_on_pre_section_vgpr_do_not_collapse_to_identity covering v_readlane_b32, v_mov_b32_dpp (row_mirror), v_permlanex16_b32, and v_cndmask_b32 over a shuffled VGPR, while asserting unshuffled identity/masked paths remain recognized.

(Disjoint from #646, which addresses constant() sign-extension and op: None in per_lane().)

Verification

  • rustfmt --edition 2024 --check crates/victory-shader/src/emit/wave.rs: clean
  • VICTORY_WARP=1 cargo test -p victory-shader --locked -- --test-threads=1: 121 passed, 0 failed
  • cargo xtask policy: 154 files ok
  • cargo clippy --workspace --all-targets --locked -- -D warnings: clean
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean
**@⁠AscilCH** on GitHub · 2026-11-24 18:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/1486) `AscilCH:fix/wave-own-tracks-source-lane` → `main` · +106 −6 · 1 files · 1 commits · open ## Bug In `crates/victory-shader/src/emit/wave.rs`, pre-section VGPR inputs were represented as `Sym::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) copied `Sym::Own(v)` into scalar outputs; `shapes()` then matched `Sym::Own(v)` and returned `Shape::Value(v)` — silently lowering a broadcast of lane `k` as each lane's own `v[l]`! - DPP shuffles (`row_mirror`, `quad_perm`, `row_ror`, `dpp8`, etc.) and `v_permlanex16_b32` moved `Sym::Own(v)` from lane `src` to lane `dst`; `per_lane()` then checked `lane.iter().all(|x| *x == Sym::Own(v))` and collapsed the shuffled vector back to `Shape::Value(v)` (identity)! - `v_cndmask_b32` over a shuffled pre-section VGPR checked `*a == Sym::Own(v)` without checking the originating lane, silently collapsing to `Shape::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`, and `v_cndmask_b32` over a shuffled `v0`: ```text v_readlane_b32 of pre-section VGPR must not collapse to Shape::Value: left: Some(Value(Value(2))), right: None ``` ## Fix - Carry the originating lane index in `Sym::Own(Value, u8)` (initialized with `l as u8` when reading an untracked VGPR in lane `l`). - Require `usize::from(from) == l` when recognizing identity/masked outputs in `v_cndmask_b32` and `per_lane()`. - Never map `Sym::Own(..)` to `Shape::Value` in scalar `shapes()` or in `per_lane()`'s uniform broadcast branch (since a broadcast of a single source lane's pre-section VGPR is not each lane's own value). - Added unit test `emit::wave::tests::cross_lane_ops_on_pre_section_vgpr_do_not_collapse_to_identity` covering `v_readlane_b32`, `v_mov_b32_dpp` (`row_mirror`), `v_permlanex16_b32`, and `v_cndmask_b32` over a shuffled VGPR, while asserting unshuffled identity/masked paths remain recognized. *(Disjoint from #646, which addresses `constant()` sign-extension and `op: None` in `per_lane()`.)* ## Verification - `rustfmt --edition 2024 --check crates/victory-shader/src/emit/wave.rs`: clean - `VICTORY_WARP=1 cargo test -p victory-shader --locked -- --test-threads=1`: 121 passed, 0 failed - `cargo xtask policy`: 154 files ok - `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: clean
In crates/victory-shader/src/emit/wave.rs, every per-lane VGPR entering a
whole-wave section was represented as Sym::Own(Value) without recording
which lane it belonged to. Because all lanes shared the same symbol:
- v_readlane_b32 of a pre-section VGPR (and any broadcast of that scalar)
  collapsed via shapes()/per_lane() to Shape::Value(v), giving each lane
  its own v[lane] instead of the selected lane's value.
- Cross-lane DPP permutations (e.g. row_mirror, quad_perm, row_ror, dpp8)
  and v_permlanex16_b32 on a pre-section VGPR produced [Sym::Own(v); wave]
  and silently collapsed to Shape::Value(v), turning shuffles into no-ops.
- v_cndmask_b32 over a shuffled pre-section VGPR matched Sym::Own(v) and
  produced a wrong Shape::Masked / reduction over unshuffled lanes.

Fix:
- Carry the originating lane in Sym::Own(Value, u8).
- Require usize::from(from) == l in v_cndmask_b32 and in per_lane()'s
  identity check; never map Sym::Own(..) to Shape::Value in shapes()
  (scalar outputs) or in per_lane()'s uniform branch.
- Add unit test emit:👋:tests::cross_lane_ops_on_pre_section_vgpr_do_not_collapse_to_identity.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:33:40 +00:00
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-24 20:13 UTC · original

Offline measurement on a retail dump, and the shader tests on Ada

Result: no count change against main.

Offline. I merged head ecdb146 onto main ffe310e (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 21,724 on main, 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 --lib passed 121, failed 0. The bitcode benchmark is ignored, as on main, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with VICTORY_WARP unset.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

**@⁠sinan-cmyk** on GitHub · 2026-11-24 20:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/1486#issuecomment-7143210508) ### Offline measurement on a retail dump, and the shader tests on Ada **Result: no count change against `main`.** **Offline.** I merged head ecdb146 onto `main` ffe310e (clean merge) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 21,724 on `main`, 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 --lib` passed 121, failed 0. The bitcode benchmark is ignored, as on `main`, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with `VICTORY_WARP` unset. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:29 UTC · original

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 current main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/1486#issuecomment-7149607322) <!-- victory-triage v1 head=ecdb14633b45dc729112facb35ddfbc248795b55 verdict=needs-rebase at=2026-11-25T01:29:33Z --> 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 current `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/wave.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1486/head:github-bot/gh-1486'
git switch 'github-bot/gh-1486'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1486'
git switch 'github-bot/gh-1486'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1486'
git switch 'github-bot/gh-1486'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1486'
git switch 'main'
git merge --squash 'github-bot/gh-1486'
git switch 'main'
git merge --ff-only 'github-bot/gh-1486'
git switch 'main'
git merge 'github-bot/gh-1486'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1486
No description provided.