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

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

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

Bug

In crates/victory-shader/src/emit/wave.rs, pre-section VGPR inputs are represented as Sym::Own(Value) without recording which lane originally held the value.

When a whole-wave section executes cross-lane operations on a pre-section VGPR:

  • v_readlane_b32 (and subsequent broadcasts) copies Sym::Own(v) into scalar outputs; shapes() matches Sym::Own(v) and returns 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 move Sym::Own(v) from lane src to lane dst; per_lane() checks lanes.iter().all(|&s| s == first) and collapses the shuffled vector back to Shape::Value(v) (identity).
  • v_cndmask_b32 over a shuffled pre-section VGPR checks Some(Sym::Own(x)) without checking the originating lane, silently collapsing to Shape::Masked(v, mask, 0).

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 (a broadcast of one source lane's pre-section VGPR is not each lane's own value).
  • Add 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.

Verification

  • rustfmt --edition 2024 --check crates/victory-shader/src/emit/wave.rs (changed hunks): clean
  • cargo test -p victory-shader --locked wave -- --test-threads=1: 21 passed, 0 failed
  • cargo xtask policy: 169 files ok
  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings: clean
  • cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings: clean

(AI-assisted; synthetic unit test only, no game data.)

**@⁠AscilCH** on GitHub · 2026-11-24 22:34 UTC · [original](https://github.com/fxceless/victory-fork/pull/209) `AscilCH:fix/wave-own-tracks-source-lane` → `main` · +60 −6 · 1 files · 1 commits · open ## Bug In `crates/victory-shader/src/emit/wave.rs`, pre-section VGPR inputs are represented as `Sym::Own(Value)` without recording which lane originally held the value. When a whole-wave section executes cross-lane operations on a pre-section VGPR: - `v_readlane_b32` (and subsequent broadcasts) copies `Sym::Own(v)` into scalar outputs; `shapes()` matches `Sym::Own(v)` and returns `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` move `Sym::Own(v)` from lane `src` to lane `dst`; `per_lane()` checks `lanes.iter().all(|&s| s == first)` and collapses the shuffled vector back to `Shape::Value(v)` (identity). - `v_cndmask_b32` over a shuffled pre-section VGPR checks `Some(Sym::Own(x))` without checking the originating lane, silently collapsing to `Shape::Masked(v, mask, 0)`. ## 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 (a broadcast of one source lane's pre-section VGPR is not each lane's own value). - Add 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. ## Verification - `rustfmt --edition 2024 --check crates/victory-shader/src/emit/wave.rs` (changed hunks): clean - `cargo test -p victory-shader --locked wave -- --test-threads=1`: 21 passed, 0 failed - `cargo xtask policy`: 169 files ok - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings`: clean - `cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings`: clean *(AI-assisted; synthetic unit test only, no game data.)*
In `crates/victory-shader/src/emit/wave.rs`, pre-section VGPR inputs were
represented as `Sym::Own(Value)` without recording their originating lane.
When a whole-wave section applied `v_readlane_b32`, DPP shuffles
(`row_mirror`, `quad_perm`, `dpp8`, etc.), or `v_permlanex16_b32` to a
pre-section VGPR, `shapes()` and `per_lane()` collapsed the broadcast or
shuffled result back to `Shape::Value(v)` (identity), and `v_cndmask_b32`
over a shuffled VGPR collapsed to `Shape::Masked(v, mask, 0)`.

Store the originating lane in `Sym::Own(Value, u8)`, require
`usize::from(from) == l` in `v_cndmask_b32` and `per_lane()`, and never
treat `Sym::Own(..)` as a uniform broadcast in `shapes()` or `per_lane()`.
Add `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 03:38:23 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-209'
git switch 'github-bot/gh-209'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-209'
git switch 'github-bot/gh-209'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-209'
git switch 'main'
git merge --squash 'github-bot/gh-209'
git switch 'main'
git merge --ff-only 'github-bot/gh-209'
git switch 'main'
git merge 'github-bot/gh-209'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.