Shaders: DPP and ds_swizzle_b32 read nothing from source lanes outside EXEC (port of upstream b51011a) #232

Open
murillojndem wants to merge 1 commit from upstream-pr/232 into main
murillojndem commented 2026-11-29 21:55:37 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by murillojndem on 2026-11-29T21:55:37Z.


On RDNA2 a cross-lane read from a source lane outside EXEC is invalid unless FI (fetch inactive) is set. DPP16 then gives 0 with bound_ctrl and otherwise leaves the destination lane unwritten. DPP8 gives 0, and so does ds_swizzle_b32. The lowering here read the source lane's register whatever its EXEC bit: dpp() ignored FI, and both read with WaveReadLaneAt, whose result for a lane the host does not run there is undefined in DXIL. On an RX 7900 XT, an active lane reading an inactive neighbour got the neighbour's old value.

This ports upstream Marvisak/VIctory b51011a (#1582, Capt-Speed). Its tests reproduce the bug here. On main, on the RX 7900 XT, 12 of 18 DPP16 cases fail: for example row_shr:1 with bound_ctrl under a 0x55555555 guard, where lane 2 got 0x10010004 and RDNA2 gives 0x00010002. The DPP8/DPP8FI and ds_swizzle_b32 tests fail too. With this change all pass.

Change (emit/lower.rs):

  • src_lane_active says whether a source lane runs the instruction under the console's EXEC.
    • Outside pixel shaders it is a ballot of the guard (EXEC narrowed without a branch), read at the source lane by the new lane_bit_of. Lanes a branch took elsewhere are not in a host ballot either.
    • In pixel shaders it is the guard read from the source lane with the same quad read as the value. Without a guard there is no check, so helper lanes stay active (a ballot leaves them out).
    • In mesh shaders the ballot is read at the host lane in the same quad position.
  • dpp(): a source outside the row, or inactive without FI, is invalid. DPP8 then gives 0 (it gave the value). DPP16 gives 0 with bound_ctrl and otherwise does not write, as it already did for a source outside the row. An invalid source is not read with WaveReadLaneAt; the lane reads its own register instead, and the result is not used.
  • ds_swizzle_b32: an inactive source gives 0, and is likewise not read.
  • This repository's lowering differs from upstream's in three places, adapted here: quad_pick takes the quad pattern, and the guard is read with the same pattern; use_quad includes mesh shaders, whose lane_index is the console's lane; and lane_bit only gives a lane's own bit, so lane_bit_of is new.

Tests:

  • emit::crosslane_tests is upstream's file. It holds DPP16 in 18 cases (straight-line guards, branches, and both nested), DPP8 and DPP8FI, ds_swizzle_b32, pixel quad forms validated and made into pipelines, and a CPU model of the RDNA2 rules. Only the harness's Parts and HostShader fields are adapted to this repository, and lib.rs lists the file among the sources outside the translation. The GPU cases run on the hardware adapter (they declare WaveSize(32)).
  • With this change all 5 tests pass on the RX 7900 XT.
  • victory-shader --lib on the RX 7900 XT and WARP with one test thread: 242 passed, 2 failed, 4 ignored (main: 237, 2, 4). The 2 failures (emit::rect::tests::rectangles_are_drawn_whole and the_rectangle_stage_is_a_geometry_shader) fail on main too.
  • Clippy with -D warnings, with and without --all-features, and cargo xtask policy pass. rustfmt reports 269 differences in victory-shader on main and 272 here.

Cost: outside pixel shaders, each DPP or ds_swizzle_b32 now makes a ballot even under a full EXEC: one waveActiveBallot, one more waveGetLaneIndex in mesh shaders, and about 8 ALU operations. DPP16 without bound_ctrl is now always a guarded write. Pixel shaders without a guard are lowered as before.

Limits:

  • In a pixel shader, a DPP or swizzle inside a DXIL branch (no guard) still reads quad lanes the branch took elsewhere, as upstream does.
  • With FI, a read inside a branch still names lanes the host does not run there, as before.
  • No test runs a mesh shader through the new path.
  • An older defect in dpp() is left for a change of its own. When console wave64 code runs on 32-lane host waves, the DPP16 row mask is indexed by the host lane, so console rows 2 and 3 test mask bits 0 and 1. An independent review found it. It needs hosts whose waves have at most 32 lanes, which the RX 7900 XT's do not.

Generated with Claude Code

<!-- greyfinch-sync:DexNom/VIctory:issue:5555546494 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/232). Originally posted by [murillojndem](https://github.com/murillojndem) on 2026-11-29T21:55:37Z. --- On RDNA2 a cross-lane read from a source lane outside EXEC is invalid unless FI (fetch inactive) is set. DPP16 then gives 0 with bound_ctrl and otherwise leaves the destination lane unwritten. DPP8 gives 0, and so does `ds_swizzle_b32`. The lowering here read the source lane's register whatever its EXEC bit: `dpp()` ignored FI, and both read with `WaveReadLaneAt`, whose result for a lane the host does not run there is undefined in DXIL. On an RX 7900 XT, an active lane reading an inactive neighbour got the neighbour's old value. This ports upstream Marvisak/VIctory b51011a (#1582, Capt-Speed). Its tests reproduce the bug here. On main, on the RX 7900 XT, 12 of 18 DPP16 cases fail: for example `row_shr:1` with bound_ctrl under a 0x55555555 guard, where lane 2 got 0x10010004 and RDNA2 gives 0x00010002. The DPP8/DPP8FI and `ds_swizzle_b32` tests fail too. With this change all pass. Change (`emit/lower.rs`): - `src_lane_active` says whether a source lane runs the instruction under the console's EXEC. - Outside pixel shaders it is a ballot of the guard (EXEC narrowed without a branch), read at the source lane by the new `lane_bit_of`. Lanes a branch took elsewhere are not in a host ballot either. - In pixel shaders it is the guard read from the source lane with the same quad read as the value. Without a guard there is no check, so helper lanes stay active (a ballot leaves them out). - In mesh shaders the ballot is read at the host lane in the same quad position. - `dpp()`: a source outside the row, or inactive without FI, is invalid. DPP8 then gives 0 (it gave the value). DPP16 gives 0 with bound_ctrl and otherwise does not write, as it already did for a source outside the row. An invalid source is not read with `WaveReadLaneAt`; the lane reads its own register instead, and the result is not used. - `ds_swizzle_b32`: an inactive source gives 0, and is likewise not read. - This repository's lowering differs from upstream's in three places, adapted here: `quad_pick` takes the quad pattern, and the guard is read with the same pattern; `use_quad` includes mesh shaders, whose `lane_index` is the console's lane; and `lane_bit` only gives a lane's own bit, so `lane_bit_of` is new. Tests: - `emit::crosslane_tests` is upstream's file. It holds DPP16 in 18 cases (straight-line guards, branches, and both nested), DPP8 and DPP8FI, `ds_swizzle_b32`, pixel quad forms validated and made into pipelines, and a CPU model of the RDNA2 rules. Only the harness's `Parts` and `HostShader` fields are adapted to this repository, and `lib.rs` lists the file among the sources outside the translation. The GPU cases run on the hardware adapter (they declare `WaveSize(32)`). - With this change all 5 tests pass on the RX 7900 XT. - `victory-shader --lib` on the RX 7900 XT and WARP with one test thread: 242 passed, 2 failed, 4 ignored (main: 237, 2, 4). The 2 failures (`emit::rect::tests::rectangles_are_drawn_whole` and `the_rectangle_stage_is_a_geometry_shader`) fail on main too. - Clippy with `-D warnings`, with and without `--all-features`, and `cargo xtask policy` pass. rustfmt reports 269 differences in victory-shader on main and 272 here. Cost: outside pixel shaders, each DPP or `ds_swizzle_b32` now makes a ballot even under a full EXEC: one `waveActiveBallot`, one more `waveGetLaneIndex` in mesh shaders, and about 8 ALU operations. DPP16 without bound_ctrl is now always a guarded write. Pixel shaders without a guard are lowered as before. Limits: - In a pixel shader, a DPP or swizzle inside a DXIL branch (no guard) still reads quad lanes the branch took elsewhere, as upstream does. - With FI, a read inside a branch still names lanes the host does not run there, as before. - No test runs a mesh shader through the new path. - An older defect in `dpp()` is left for a change of its own. When console wave64 code runs on 32-lane host waves, the DPP16 row mask is indexed by the host lane, so console rows 2 and 3 test mask bits 0 and 1. An independent review found it. It needs hosts whose waves have at most 32 lanes, which the RX 7900 XT's do not. Generated with [Claude Code](https://claude.com/claude-code)
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/232:upstream-pr/232'
git switch 'upstream-pr/232'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/232'
git switch 'upstream-pr/232'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/232'
git switch 'upstream-pr/232'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/232'
git switch 'main'
git merge --squash 'upstream-pr/232'
git switch 'main'
git merge --ff-only 'upstream-pr/232'
git switch 'main'
git merge 'upstream-pr/232'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
DexNom/VIctory!232
No description provided.