Shaders: lower v_permlane16_b32 and v_permlanex16_b32 outside full-wave sections #3663

Open
Luislariosss wants to merge 1 commit from upstream-pr/3663 into main
Luislariosss commented 2026-11-28 04:15:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Luislariosss on 2026-11-28T04:15:23Z.


v_permlane16_b32 and v_permlanex16_b32 were previously only simulated inside full-wave sections with constant selectors, causing compute shaders that invoke them outside full-wave sections (e.g. a929109552ce1e84) to fail translation.

Changes

  • Lower v_permlane16_b32 and v_permlanex16_b32 in valu_op (crates/victory-shader/src/emit/lower.rs), supporting both constant and uniform SGPR nibble selectors, fi (fetch-invalid), and bc (bound-control) across wave32 and wave64 halves.
  • Add v_permlane* to the console_lanes detection list so compute shaders preserve console lane numbering.
  • Add synthetic GPU/WARP tests in crates/victory-shader/src/emit/synthetic_tests.rs covering all opsel (fi/bc) combinations, constant/SGPR/mixed selectors, partial exec masks, full-wave rows, and wave64 32-lane half isolation.

Verification

  • cargo xtask policy (191 files ok)
  • cargo clippy -p victory-shader --all-targets -- -D warnings
  • cargo test -p victory-shader --lib (305 passed, 0 failed, 3 ignored)
<!-- greyfinch-sync:Marvisak/VIctory:issue:5536567110 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3663). Originally posted by [Luislariosss](https://github.com/Luislariosss) on 2026-11-28T04:15:23Z. --- `v_permlane16_b32` and `v_permlanex16_b32` were previously only simulated inside full-wave sections with constant selectors, causing compute shaders that invoke them outside full-wave sections (e.g. `a929109552ce1e84`) to fail translation. ### Changes - Lower `v_permlane16_b32` and `v_permlanex16_b32` in `valu_op` (`crates/victory-shader/src/emit/lower.rs`), supporting both constant and uniform SGPR nibble selectors, `fi` (fetch-invalid), and `bc` (bound-control) across wave32 and wave64 halves. - Add `v_permlane*` to the `console_lanes` detection list so compute shaders preserve console lane numbering. - Add synthetic GPU/WARP tests in `crates/victory-shader/src/emit/synthetic_tests.rs` covering all `opsel` (`fi`/`bc`) combinations, constant/SGPR/mixed selectors, partial exec masks, full-wave rows, and wave64 32-lane half isolation. ### Verification - `cargo xtask policy` (191 files ok) - `cargo clippy -p victory-shader --all-targets -- -D warnings` - `cargo test -p victory-shader --lib` (305 passed, 0 failed, 3 ignored)
andrewpozdnakov7-jpg commented 2026-11-28 04:48:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T04:48:05Z.


Independent WARP comparison on exact 498d63b and main 63bcca43. I used the same three generated PR fixtures in both builds.

  • Main refuses v_permlanex16_b32 at lowering in all three fixtures.
  • This PR lowers the shaders and dispatches them. On app-local WARP 1.0.22 with Agility 1.620.2, all three fail the lane readback assertion. The all-active cross-row fixture disagrees in 16/32 Wave32 lanes and 32/64 Wave64 lanes. Forcing WARP also sends the helper's row labelled hardware to WARP.
  • A separate DXC-compiled HLSL control produced the same 32 and 64 output words as the translated shaders. In the native control, selecting the read by four-lane group brought both counts to zero.

For a full-active wave, the HLSL used lane = WaveGetLaneIndex() and the same source as the PR fixture:

uint i = lane & 15u;
uint sel = i < 8u ? 0x3C5A1E07u : 0x87654321u;
uint src = (lane & ~31u) | ((lane & 16u) ^ 16u)
         | ((sel >> ((i & 7u) * 4u)) & 15u);
uint direct = WaveReadLaneAt(0x4000u + lane, src);

The grouped version holds base at 0, 4, 8, etc. in each read of base | (src & 3u), then selects the result for src & ~3u. I ran both versions with matching WaveSize and thread-group widths of 32 and 64. This isolates the failure to the direct wave read on this runtime and matches the failure class in #2949. #2997 has the grouped path for ds_bpermute. Applying it here still needs coverage for the new opcodes' fetch-inactive and bound-control cases.

If reusing the test, please retain the Git author on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding it into another commit.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7234267506 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3663#issuecomment-7234267506). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T04:48:05Z. --- Independent WARP comparison on exact `498d63b` and `main` `63bcca43`. I used the same three generated PR fixtures in both builds. - Main refuses `v_permlanex16_b32` at lowering in all three fixtures. - This PR lowers the shaders and dispatches them. On app-local WARP 1.0.22 with Agility 1.620.2, all three fail the lane readback assertion. The all-active cross-row fixture disagrees in **16/32** Wave32 lanes and **32/64** Wave64 lanes. Forcing WARP also sends the helper's row labelled `hardware` to WARP. - A separate DXC-compiled HLSL control produced the **same 32 and 64 output words** as the translated shaders. In the native control, selecting the read by four-lane group brought both counts to zero. For a full-active wave, the HLSL used `lane = WaveGetLaneIndex()` and the same source as the PR fixture: ```hlsl uint i = lane & 15u; uint sel = i < 8u ? 0x3C5A1E07u : 0x87654321u; uint src = (lane & ~31u) | ((lane & 16u) ^ 16u) | ((sel >> ((i & 7u) * 4u)) & 15u); uint direct = WaveReadLaneAt(0x4000u + lane, src); ``` The grouped version holds `base` at 0, 4, 8, etc. in each read of `base | (src & 3u)`, then selects the result for `src & ~3u`. I ran both versions with matching `WaveSize` and thread-group widths of 32 and 64. This isolates the failure to the direct wave read on this runtime and matches the failure class in #2949. #2997 has the grouped path for `ds_bpermute`. Applying it here still needs coverage for the new opcodes' fetch-inactive and bound-control cases. If reusing the test, please retain the Git author on cherry-pick or rebase, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding it into another commit. AI-assisted with OpenAI Codex.
upipibi commented 2026-11-28 04:55:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-28T04:55:48Z.


Two things for this PR: it's the third open one for the same instructions, and here is the NVIDIA row for all three. RTX 3070 8 GB, driver 616.56, Windows 11, hardware adapter, each PR's own new tests, 3 runs each with the same result.

PR Head New tests on the RTX 3070
#3560 (pablogonz12), v_permlanex16_b32 without fetch-inactive b2d087e permlanex_partial_exec_matches_reference 1/1
#3587 (zed6000), both permlanes, EXEC and FI/BC 733f9e8 8/8 (the six fetch-inactive acceptance/rejection cases, permlane_rows_and_inactive_sources, permlane_fi_zero_under_divergent_exec)
this PR (#3663) 498d63b 3/3. Both wave32 tests ran on the hardware adapter. wave64_permlanex16_stays_within_each_32_lane_half has no wave64 pipeline on NVIDIA, so it ran on WARP only.

On andrewpozdnakov7-jpg's WARP failure above: permlanes_with_every_lane_live_read_across_rows passes on this card. That fits their DXC control, which pointed at WARP 1.0.22's wave reads rather than this lowering. (The system WARP here, 10.0.26100.9711, builds no wave32 pipeline and skipped the wave32 cases, so it says nothing either way.)

None of the three links the others. #3587 also covers v_permlane16_b32 and the FI/BC flags, and it has the most rejection tests. #3560 is permlanex16 only. One should land and the other two be closed or rebased onto it.

AI-assisted (Claude Code, Claude Opus 5.5 built the three heads and ran their tests on this card).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7234347583 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3663#issuecomment-7234347583). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-28T04:55:48Z. --- Two things for this PR: it's the third open one for the same instructions, and here is the NVIDIA row for all three. RTX 3070 8 GB, driver 616.56, Windows 11, hardware adapter, each PR's own new tests, 3 runs each with the same result. | PR | Head | New tests on the RTX 3070 | |---|---|---| | #3560 (pablogonz12), `v_permlanex16_b32` without fetch-inactive | `b2d087e` | `permlanex_partial_exec_matches_reference` 1/1 | | #3587 (zed6000), both permlanes, EXEC and FI/BC | `733f9e8` | 8/8 (the six fetch-inactive acceptance/rejection cases, `permlane_rows_and_inactive_sources`, `permlane_fi_zero_under_divergent_exec`) | | this PR (#3663) | `498d63b` | 3/3. Both wave32 tests ran on the hardware adapter. `wave64_permlanex16_stays_within_each_32_lane_half` has no wave64 pipeline on NVIDIA, so it ran on WARP only. | On andrewpozdnakov7-jpg's WARP failure above: `permlanes_with_every_lane_live_read_across_rows` passes on this card. That fits their DXC control, which pointed at WARP 1.0.22's wave reads rather than this lowering. (The system WARP here, 10.0.26100.9711, builds no wave32 pipeline and skipped the wave32 cases, so it says nothing either way.) None of the three links the others. #3587 also covers `v_permlane16_b32` and the FI/BC flags, and it has the most rejection tests. #3560 is `permlanex16` only. One should land and the other two be closed or rebased onto it. AI-assisted (Claude Code, Claude Opus 5.5 built the three heads and ran their tests on this card).
ColorMeBoom commented 2026-11-28 07:07:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-28T07:07:14Z.


Hardware run: RX 5700 XT (Navi 10, RDNA1, 32–64 lanes, driver 32.0.21045.29003, Windows 11 26200), head 498d63b on 63bcca4. WARP has no pipeline for a wave of 32 and skips every case here, so this is the first physical coverage:

  • All three GPU tests pass on the card: permlanes_pick_lanes_by_nibble_with_fetch_and_bound_control, permlanes_with_every_lane_live_read_across_rows and wave64_permlanex16_stays_within_each_32_lane_half.
  • Full victory-shader --lib --features host: 305 passed, 0 failed, 3 ignored.

#3587 lowers the same two instructions; it was verified on a Radeon 780M there.

AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7235728699 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3663#issuecomment-7235728699). Originally posted by [ColorMeBoom](https://github.com/ColorMeBoom) on 2026-11-28T07:07:14Z. --- Hardware run: RX 5700 XT (Navi 10, RDNA1, 32–64 lanes, driver 32.0.21045.29003, Windows 11 26200), head `498d63b` on `63bcca4`. WARP has no pipeline for a wave of 32 and skips every case here, so this is the first physical coverage: - All three GPU tests pass on the card: `permlanes_pick_lanes_by_nibble_with_fetch_and_bound_control`, `permlanes_with_every_lane_live_read_across_rows` and `wave64_permlanex16_stays_within_each_32_lane_half`. - Full `victory-shader --lib --features host`: 305 passed, 0 failed, 3 ignored. #3587 lowers the same two instructions; it was verified on a Radeon 780M there. AI use: Claude Code (Claude Opus 5.5).
andrewpozdnakov7-jpg commented 2026-11-28 07:15:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T07:15:04Z.


I cross-ran the two PRs' synthetic fixtures on 498d63b (#3663) and 733f9e8 (#3587).

WARP readback. With app-local WARP 1.0.22 and Agility 1.620.2, both heads dispatched the same three #3663 fixtures. Their output words matched one another exactly. The first failing readback in each fixture had 9/32 incorrect lanes (FI/BC matrix), 16/32 (all-active Wave32), and 32/64 (all-active Wave64). In this run the forced software adapter also handled the rows that the helper labels hardware. These counts are separate from the RX 5700 XT result above.

Fetch-inactive translation. I also ran the six CPU-only #3587 participation tests against both heads. Both accepted the three positive controls. #3587 refused the three negative cases as expected. #3663 translated and validated all three, so the refusal assertions fail. The cases are divergent EXEC, a scalar phi from a divergent branch, and a lane returned by the loop limit. This check covers translation and validation only.

The NEW-342 claim already covers adapting #2997's four-lane WARP path. The two test results above can help compare the current alternatives independently of that work.

Please retain the original Git authors if you reuse either PR's fixtures. For any contribution from this follow-up folded into another commit, please retain:

Co-authored-by: andrewpozdnakov7-jpg [email protected]

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7235813376 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3663#issuecomment-7235813376). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T07:15:04Z. --- I cross-ran the two PRs' synthetic fixtures on `498d63b` (#3663) and `733f9e8` (#3587). **WARP readback.** With app-local WARP 1.0.22 and Agility 1.620.2, both heads dispatched the same three #3663 fixtures. Their output words matched one another exactly. The first failing readback in each fixture had **9/32** incorrect lanes (FI/BC matrix), **16/32** (all-active Wave32), and **32/64** (all-active Wave64). In this run the forced software adapter also handled the rows that the helper labels `hardware`. These counts are separate from the RX 5700 XT result above. **Fetch-inactive translation.** I also ran the six CPU-only [#3587 participation tests](https://github.com/Marvisak/VIctory/blob/733f9e8584e2a35cbf0f1e066a2077ad3502f039/crates/victory-shader/src/emit/permlane_tests.rs) against both heads. Both accepted the three positive controls. #3587 refused the three negative cases as expected. #3663 translated and validated all three, so the refusal assertions fail. The cases are divergent EXEC, a scalar phi from a divergent branch, and a lane returned by the loop limit. This check covers translation and validation only. The [NEW-342 claim](https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7181547135) already covers adapting #2997's four-lane WARP path. The two test results above can help compare the current alternatives independently of that work. Please retain the original Git authors if you reuse either PR's fixtures. For any contribution from this follow-up folded into another commit, please retain: Co-authored-by: andrewpozdnakov7-jpg <[email protected]> AI-assisted with OpenAI Codex.
kilolimaVI commented 2026-11-28 21:55:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-28T21:55:46Z.


AMD Radeon 780M (RDNA3, runs both wave sizes) + WARP, Windows 11, head 498d63b. Before (main 63bcca4 + this PR's tests): all three tests fail on main's lowering. After: 3/3 pass, 5 of 5 runs, the wave32 and wave64 cases on the 780M itself (system WARP skips both sizes). Full suite: 554 passed. AI-assisted (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7246374763 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3663#issuecomment-7246374763). Originally posted by [kilolimaVI](https://github.com/kilolimaVI) on 2026-11-28T21:55:46Z. --- AMD Radeon 780M (RDNA3, runs both wave sizes) + WARP, Windows 11, head `498d63b`. Before (main `63bcca4` + this PR's tests): all three tests fail on main's lowering. After: 3/3 pass, 5 of 5 runs, the wave32 and wave64 cases on the 780M itself (system WARP skips both sizes). Full suite: 554 passed. AI-assisted (Claude).
kilolimaVI commented 2026-11-29 14:03:34 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-29T14:03:34Z.


Comparison of the four open v_permlanex16_b32 PRs on AMD Radeon 780M (RDNA3, wave32 + wave64, driver 32.0.13022.3006), each head on its own tree, its own tests with --nocapture, then the whole victory-shader lib:

PR own tests on hardware whole lib merges with kilolimaVI/VIctory integration/shader-10
this (#3663) pass (all wave32 cases skip on WARP, so this is their first device run) 305 / 0 failed clean
#3587 pass, 0/25,600 wrong at wave32 and at wave64 over 200 divergent dispatches 311 / 0 failed conflicts (2 hunks)
#3560 pass (2/2 cases) 303 / 0 failed conflicts (1 hunk)
#3393 pass, FI=1 with BOUND_CTRL 0/1 read back all 32 lanes, wave64 reduction all 64 305 / 0 failed clean

So the hardware does not separate them; all four lower the instruction correctly for what their tests cover. Per fiestorra's census on #201 one program on main is refused for v_permlanex16_b32. Which of these four the title's program needs (FI, BOUND_CTRL, inside or outside a whole-wave section) is the open question for choosing one.

AI-assisted (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7257006965 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3663#issuecomment-7257006965). Originally posted by [kilolimaVI](https://github.com/kilolimaVI) on 2026-11-29T14:03:34Z. --- Comparison of the four open `v_permlanex16_b32` PRs on AMD Radeon 780M (RDNA3, wave32 + wave64, driver 32.0.13022.3006), each head on its own tree, its own tests with `--nocapture`, then the whole victory-shader lib: | PR | own tests on hardware | whole lib | merges with `kilolimaVI/VIctory` `integration/shader-10` | |---|---|---|---| | this (#3663) | pass (all wave32 cases skip on WARP, so this is their first device run) | 305 / 0 failed | clean | | #3587 | pass, 0/25,600 wrong at wave32 and at wave64 over 200 divergent dispatches | 311 / 0 failed | conflicts (2 hunks) | | #3560 | pass (2/2 cases) | 303 / 0 failed | conflicts (1 hunk) | | #3393 | pass, FI=1 with BOUND_CTRL 0/1 read back all 32 lanes, wave64 reduction all 64 | 305 / 0 failed | clean | So the hardware does not separate them; all four lower the instruction correctly for what their tests cover. Per fiestorra's census on #201 one program on main is refused for `v_permlanex16_b32`. Which of these four the title's program needs (FI, BOUND_CTRL, inside or outside a whole-wave section) is the open question for choosing one. AI-assisted (Claude).
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/3663:upstream-pr/3663'
git switch 'upstream-pr/3663'

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/3663'
git switch 'upstream-pr/3663'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3663'
git switch 'upstream-pr/3663'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3663'
git switch 'main'
git merge --squash 'upstream-pr/3663'
git switch 'main'
git merge --ff-only 'upstream-pr/3663'
git switch 'main'
git merge 'upstream-pr/3663'
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
Marvisak/VIctory!3663
No description provided.