shader: lower v_permlane16_b32 #576

Closed
github-bot wants to merge 4 commits from gh-pr/576/head into gh-pr/576/base
Owner

@⁠NolanCotter on GitHub · 2026-11-24 05:11 UTC · original
NolanCotter:permlane16 → main · +284 −27 · 1 files · 4 commits · closed without merging

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

**@⁠NolanCotter** on GitHub · 2026-11-24 05:11 UTC · [original](https://github.com/Marvisak/VIctory/pull/576) `NolanCotter:permlane16` → `main` · +284 −27 · 1 files · 4 commits · closed without merging 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)
Each lane reads src0 of a lane in the other row of 16 of its 32-lane
half, the pick taken from nibble i of the {src2, src1} selector. The
lowering mirrors the whole-wave model wave.rs already uses for the op,
through the same cross_lane/read_lane machinery as v_writelane_b32, and
the console_lanes detector now covers the v_permlane family so host
lanes are relabeled where the op appears.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Both M0-relative VGPR moves the IR already enumerates but the emitter
refused. movrelsd_2 and swaprel split M0 in two fields — the source's
offset is M0[9:0], the destination's M0[25:16] (the RDNA2 ISA's opcode
description) — where the other movrel forms use the whole register for
both. The existing select chains factor into read_at/write_at closures.

A swap writes both operand ranges, so a register can carry two write
tokens: write_at picks the first or the last and reads the value an
earlier chain left, which also keeps the swap a no-op when both sides
name the same register.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Each signed i16 half of src0 saturates to an unsigned byte, packed
into the destination's low 16 bits; the register's high half is kept
(the GFX10 partial write, as v_cvt_f16_f32 — LLVM models the def as
VOP1Inst_t16). src() refuses abs/neg, write_i refuses clamp/omod, and
a nonzero op_sel is refused.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
The same-row sibling of v_permlanex16_b32: each lane reads src0 of the
lane picked by its nibble of {src2, src1}, in its own row of 16 of the
32-lane half — the shared arm just skips the row flip. IR-modeled in
ir.rs and whole-wave-modeled in wave.rs (open PR #98) but refused at
valu_op's fallthrough on main.

Smoke test runs the identity-pick selector program through opcode 0x377
(the same-row form) feeding an LDS store.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:08:58 +00:00
github-bot closed this pull request 2026-11-26 04:08:58 +00:00
Author
Owner

@⁠Lyrnc on GitHub · 2026-11-24 05:58 UTC · original

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.

**@⁠Lyrnc** on GitHub · 2026-11-24 05:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/576#issuecomment-7123454341) 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.
Author
Owner

@⁠slint6614-dev on GitHub · 2026-11-24 10:42 UTC · original

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.

**@⁠slint6614-dev** on GitHub · 2026-11-24 10:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/576#issuecomment-7129138137) 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.
Author
Owner

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

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.

**@⁠Marvisak** on GitHub · 2026-11-25 00:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/576#issuecomment-7148494586) 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

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