shader: lower v_permlane16_b32 #576

Closed
NolanCotter wants to merge 4 commits from upstream-pr/576 into main
NolanCotter commented 2026-11-24 05:11:36 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by NolanCotter on 2026-11-24T05:11:36Z.


Depends on #499 (the arm it extends is introduced by #404; the diff shrinks to one commit as the queue lands).

Summary

  • Lowers v_permlane16_b32 (VOP3 0x377), refused at integer()'s fallthrough on main. PR #98 models it in whole-wave sections (wave.rs) but does not lower it to DXIL — this complements that work.
  • It shares the v_permlanex16_b32 arm: same nibble-of-{src2,src1} pick, same read_lane/cross_lane machinery, but the row bit is kept (same-row read) instead of XOR-flipped (other-row read). Matches the wave.rs:411 model.
  • console_lanes detector already covered it via the v_permlane prefix added in #404.
  • Test: the identity-pick selector program run through opcode 0x377 feeding an LDS store — refused on main, lowers now.

Test plan

  • cargo test -p victory-shader — 59 passed
  • cargo clippy -p victory-shader — clean
  • cargo fmt --check — clean

AI-assisted (Devin). Semantics from the AMD RDNA2 ISA opcode description and the repo's own wave.rs model; no game files used.

Generated with Devin

<!-- greyfinch-sync:Marvisak/VIctory:issue:6575125044 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/576). Originally posted by [NolanCotter](https://github.com/NolanCotter) on 2026-11-24T05:11:36Z. --- Depends on #499 (the arm it extends is introduced by #404; the diff shrinks to one commit as the queue lands). ## Summary - Lowers `v_permlane16_b32` (VOP3 0x377), refused at `integer()`'s fallthrough on main. PR #98 models it in whole-wave sections (`wave.rs`) but does not lower it to DXIL — this complements that work. - It shares the `v_permlanex16_b32` arm: same nibble-of-{src2,src1} pick, same `read_lane`/`cross_lane` machinery, but the row bit is kept (same-row read) instead of XOR-flipped (other-row read). Matches the `wave.rs:411` model. - `console_lanes` detector already covered it via the `v_permlane` prefix added in #404. - Test: the identity-pick selector program run through opcode 0x377 feeding an LDS store — refused on main, lowers now. #### Test plan - [x] `cargo test -p victory-shader` — 59 passed - [x] `cargo clippy -p victory-shader` — clean - [x] `cargo fmt --check` — clean AI-assisted (Devin). Semantics from the AMD RDNA2 ISA opcode description and the repo's own `wave.rs` model; no game files used. Generated with [Devin](https://devin.ai)
Lyrnc commented 2026-11-24 06:56:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Lyrnc on 2026-11-24T05:58:42Z.


RDNA2 hardware check of the lane rule: it matches, for v_permlane16_b32 and for the v_permlanex16_b32 arm it shares.

Setup. AMD Radeon iGPU of a Ryzen 7 9800X3D, gfx1036 (RDNA2), AMD driver 32.0.21042.62, Windows 11 Pro 26200. A HIP kernel (assembled by the AMD driver's amd_comgr) runs v_permlane16_b32 vD, v4, s20, s21 and v_permlanex16_b32 vD, v4, s20, s21 with lane i holding i + 1, so each output names its source lane. There are 16 selectors: 0x76543210:0xfedcba98 (identity), 0x01234567:0x89abcdef (reverse), all-0, all-F, a pair swap, and 11 random. Wave32 and wave64 kernels, no op_sel (FI/BOUND_CTRL clear), all lanes active. RDNA2 desktop silicon, not the console's. No game data.

Model, as in your lowering: lane i reads lane (i & ~31) | row | nibble_(i & 15)({src2, src1}), where row = i & 16 for v_permlane16_b32 and (i & 16) ^ 16 for v_permlanex16_b32.

wave32 wave64
v_permlane16_b32, 16 selectors 16/16 16/16
v_permlanex16_b32, 16 selectors 16/16 16/16

So the same-row read (row bit kept) is right. In wave64 both stay inside each 32-lane half, as your half term keeps them.

Not covered: the FI and BOUND_CTRL bits, and inactive lanes. Your lowering refuses op_sel, so neither is needed for it.

AI use: Claude Code (Claude Opus 5.5) wrote the probes, ran them on the GPU above and drafted this comment; the numbers come from the hardware run.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7123454341 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/576#issuecomment-7123454341). Originally posted by [Lyrnc](https://github.com/Lyrnc) on 2026-11-24T05:58:42Z. --- RDNA2 hardware check of the lane rule: **it matches, for `v_permlane16_b32` and for the `v_permlanex16_b32` arm it shares.** **Setup.** AMD Radeon iGPU of a Ryzen 7 9800X3D, **gfx1036 (RDNA2)**, AMD driver 32.0.21042.62, Windows 11 Pro 26200. A HIP kernel (assembled by the AMD driver's amd_comgr) runs `v_permlane16_b32 vD, v4, s20, s21` and `v_permlanex16_b32 vD, v4, s20, s21` with lane `i` holding `i + 1`, so each output names its source lane. There are 16 selectors: `0x76543210:0xfedcba98` (identity), `0x01234567:0x89abcdef` (reverse), all-0, all-F, a pair swap, and 11 random. Wave32 and wave64 kernels, no `op_sel` (FI/BOUND_CTRL clear), all lanes active. RDNA2 desktop silicon, not the console's. No game data. Model, as in your lowering: lane `i` reads lane `(i & ~31) | row | nibble_(i & 15)({src2, src1})`, where `row = i & 16` for `v_permlane16_b32` and `(i & 16) ^ 16` for `v_permlanex16_b32`. | | wave32 | wave64 | |---|---|---| | `v_permlane16_b32`, 16 selectors | 16/16 | 16/16 | | `v_permlanex16_b32`, 16 selectors | 16/16 | 16/16 | So the same-row read (row bit kept) is right. In wave64 both stay inside each 32-lane half, as your `half` term keeps them. Not covered: the FI and BOUND_CTRL bits, and inactive lanes. Your lowering refuses `op_sel`, so neither is needed for it. AI use: Claude Code (Claude Opus 5.5) wrote the probes, ran them on the GPU above and drafted this comment; the numbers come from the hardware run.
slint6614-dev commented 2026-11-24 11:04:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by slint6614-dev on 2026-11-24T10:42:29Z.


Measured on the full retail shader pack (26,503 containers) with victory translate --validate --pipelines (pipelines on an AMD RX 9070, Windows 11, dxil.dll from SDK 10.0.26100). Counts are emitted / validated / pipelines. Merged locally with current main c7a5f49 (main: CS 1440 / 1417).

CS 1441 / 1418 (+1 validated); VS/PS and MS unchanged.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7129138137 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/576#issuecomment-7129138137). Originally posted by [slint6614-dev](https://github.com/slint6614-dev) on 2026-11-24T10:42:29Z. --- Measured on the full retail shader pack (26,503 containers) with `victory translate --validate --pipelines` (pipelines on an AMD RX 9070, Windows 11, dxil.dll from SDK 10.0.26100). Counts are emitted / validated / pipelines. Merged locally with current main c7a5f49 (main: CS 1440 / 1417). CS 1441 / **1418** (+1 validated); VS/PS and MS unchanged.
mercuryVM commented 2026-11-24 12:03:57 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T12:01:54Z.

Review: APPROVED


Tested fde38b3 (with #499 and the M0-split movrel commit underneath) on Windows 11, RTX 5070, MSVC: cargo test -p victory-shader -- --test-threads=1 72 passed, and cargo clippy -p victory-shader --all-targets is clean. victory translate --validate --pipelines on the local title executable still reports 12 of 12 programs.

  • v_permlane16_b32 reuses the permlanex16 arm and drops only the row XOR, which is the documented difference (same row of 16 versus the other row).
  • The underlying commits check out too: v_sat_pk_u8_i16 puts sat8(hi) in byte 1 and sat8(lo) in byte 0 and keeps the high half. v_movrelsd_2_b32/v_swaprel_b32 use M0[9:0] for the source and M0[25:16] for the destination, which is the split I also asked #627 for.
  • The new tests only check that the programs lower (lowers_lds). A value check through run_cases for permlane16 with a non-identity selector would catch a wrong nibble order.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6038814169 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/576#pullrequestreview-6038814169). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T12:01:54Z. **Review:** APPROVED --- Tested fde38b3 (with #499 and the M0-split movrel commit underneath) on Windows 11, RTX 5070, MSVC: `cargo test -p victory-shader -- --test-threads=1` 72 passed, and `cargo clippy -p victory-shader --all-targets` is clean. `victory translate --validate --pipelines` on the local title executable still reports 12 of 12 programs. - `v_permlane16_b32` reuses the `permlanex16` arm and drops only the row XOR, which is the documented difference (same row of 16 versus the other row). - The underlying commits check out too: `v_sat_pk_u8_i16` puts sat8(hi) in byte 1 and sat8(lo) in byte 0 and keeps the high half. `v_movrelsd_2_b32`/`v_swaprel_b32` use M0[9:0] for the source and M0[25:16] for the destination, which is the split I also asked #627 for. - The new tests only check that the programs lower (`lowers_lds`). A value check through `run_cases` for permlane16 with a non-identity selector would catch a wrong nibble order. AI-assisted (Claude Code).
catminou4 commented 2026-11-24 13:01:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T12:44:26Z.

Review: COMMENTED


Test-merge with current main (ffe310e) conflicts — needs a rebase. Main moved recently (PR #566 waterfall loops touched lower.rs/resource.rs/valu_tests.rs), so shader PRs opened before it need rebasing. I'll re-review once it merges cleanly.

<!-- greyfinch-sync:Marvisak/VIctory:review:6039403317 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/576#pullrequestreview-6039403317). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T12:44:26Z. **Review:** COMMENTED --- Test-merge with current main (`ffe310e`) **conflicts** — needs a rebase. Main moved recently (PR #566 waterfall loops touched `lower.rs`/`resource.rs`/`valu_tests.rs`), so shader PRs opened before it need rebasing. I'll re-review once it merges cleanly.
upstream-sync closed this pull request 2026-11-25 01:04:19 +00:00
Marvisak commented 2026-11-25 01:07:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:25:27Z.


Automated triage for the maintainers. Closing because another open pull request covers the same change.

See #1014. v_permlane16_b32 on top of a three-PR stack (#404, #498, #499); #1014 has both permlane forms in 49 lines.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148494586 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/576#issuecomment-7148494586). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:25:27Z. --- Automated triage for the maintainers. Closing because another open pull request covers the same change. See #1014. v_permlane16_b32 on top of a three-PR stack (#404, #498, #499); #1014 has both permlane forms in 49 lines. If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

Pull request closed

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!576
No description provided.