shader: lower v_permlanex16_b32 #404

Closed
NolanCotter wants to merge 1 commit from upstream-pr/404 into main
NolanCotter commented 2026-11-24 02:57:37 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by NolanCotter on 2026-11-24T02:57:37Z.


Summary

  • Lowers v_permlanex16_b32 in valu_op: 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 same math wave.rs already uses to model the op, built through the cross_lane/read_lane machinery v_writelane_b32 uses.
  • v_permlane16_b32 (same row, PR #98's wave.rs model) stays refused; a follow-up can share this arm's index math.
  • The console_lanes detector now covers the v_permlane family so a compute program using the op gets console lane relabeling.
  • opsel != 0 is rejected rather than silently ignored.
  • Adds a smoke test that lowers a hand-encoded compute program (v_permlanex16_b32 feeding an LDS store); it failed on main with the write missing and passes now.

Test plan

  • cargo test -p victory-shader — 57 passed (was 56 + 1 failing before the fix)
  • cargo clippy -p victory-shader — clean
  • cargo fmt --check — clean

AI-assisted change (Devin). Verified against the lane math already in emit/wave.rs; no game shaders were used.

Generated with Devin

<!-- greyfinch-sync:Marvisak/VIctory:issue:6573592380 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/404). Originally posted by [NolanCotter](https://github.com/NolanCotter) on 2026-11-24T02:57:37Z. --- ## Summary - Lowers `v_permlanex16_b32` in `valu_op`: 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 same math `wave.rs` already uses to model the op, built through the `cross_lane`/`read_lane` machinery `v_writelane_b32` uses. - `v_permlane16_b32` (same row, PR #98's wave.rs model) stays refused; a follow-up can share this arm's index math. - The `console_lanes` detector now covers the `v_permlane` family so a compute program using the op gets console lane relabeling. - `opsel != 0` is rejected rather than silently ignored. - Adds a smoke test that lowers a hand-encoded compute program (`v_permlanex16_b32` feeding an LDS store); it failed on main with the write missing and passes now. #### Test plan - [x] `cargo test -p victory-shader` — 57 passed (was 56 + 1 failing before the fix) - [x] `cargo clippy -p victory-shader` — clean - [x] `cargo fmt --check` — clean AI-assisted change (Devin). Verified against the lane math already in `emit/wave.rs`; no game shaders were used. Generated with [Devin](https://devin.ai)
mercuryVM commented 2026-11-24 06:52:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T05:53:02Z.

Review: APPROVED


Tested d505b0e on Windows 11, RTX 5070, MSVC: cargo test --workspace --no-fail-fast passes (265 passed, 0 failed). victory translate <title exe> --validate --pipelines gives the same counts before and after: 12 of 12 programs emitted, 12 validated, 12 pipelines. The 12 embedded programs are vertex and pixel only, so they don't use this op.

  • I checked the index math against the RDNA2 definition:
    • The selector nibble for lane i is (i & 15) * 4 bits into {src2, src1}, and & 31 after picking the word gives the right shift for nibbles 8–15.
    • (lane & ~31) | ((lane & 16) ^ 16) | pick addresses the other row of the same 32-lane half.
  • Refusing op_sel != 0 is the right call. For permlane, op_sel[0] and op_sel[1] are FI and BOUND_CTRL, which this lowering does not model.
  • One semantic gap, not blocking: with FI=0, a lane whose source lane is inactive keeps its old vdst on hardware, but read_lane returns the inactive lane's value. That only matters for partially active waves.
  • The new test checks that the program lowers, but not the values it produces. A run_cases test in valu_tests.rs with a non-identity selector would also check the lanes on hardware and WARP.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6034352898 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/404#pullrequestreview-6034352898). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T05:53:02Z. **Review:** APPROVED --- Tested d505b0e on Windows 11, RTX 5070, MSVC: `cargo test --workspace --no-fail-fast` passes (265 passed, 0 failed). `victory translate <title exe> --validate --pipelines` gives the same counts before and after: 12 of 12 programs emitted, 12 validated, 12 pipelines. The 12 embedded programs are vertex and pixel only, so they don't use this op. - I checked the index math against the RDNA2 definition: - The selector nibble for lane `i` is `(i & 15) * 4` bits into `{src2, src1}`, and `& 31` after picking the word gives the right shift for nibbles 8–15. - `(lane & ~31) | ((lane & 16) ^ 16) | pick` addresses the other row of the same 32-lane half. - Refusing `op_sel != 0` is the right call. For permlane, op_sel[0] and op_sel[1] are FI and BOUND_CTRL, which this lowering does not model. - One semantic gap, not blocking: with FI=0, a lane whose source lane is inactive keeps its old `vdst` on hardware, but `read_lane` returns the inactive lane's value. That only matters for partially active waves. - The new test checks that the program lowers, but not the values it produces. A `run_cases` test in `valu_tests.rs` with a non-identity selector would also check the lanes on hardware and WARP. AI-assisted (Claude Code).
jeremygold02 commented 2026-11-24 06:55:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-24T04:32:39Z.


Thanks @NolanCotter for adding v_permlanex16_b32 lowering. I tested head d505b0e4c5e3d29a7d027e639d70651386f71b2a with:

cargo test --locked -p victory-shader --lib permlanex16_reads_a_lane_of_the_other_row -- --test-threads=1

Result: 1 passed, 0 failed (69 filtered out). The synthetic wave test verifies the instruction reads the selected lane from the other 16-lane row. It checks the lowering model, not behavior in an executing title.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7122115466 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/404#issuecomment-7122115466). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-24T04:32:39Z. --- Thanks @NolanCotter for adding `v_permlanex16_b32` lowering. I tested head `d505b0e4c5e3d29a7d027e639d70651386f71b2a` with: ``` cargo test --locked -p victory-shader --lib permlanex16_reads_a_lane_of_the_other_row -- --test-threads=1 ``` Result: 1 passed, 0 failed (69 filtered out). The synthetic wave test verifies the instruction reads the selected lane from the other 16-lane row. It checks the lowering model, not behavior in an executing title.
Lyrnc commented 2026-11-24 06:56:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Lyrnc on 2026-11-24T06:02:25Z.


RDNA2 hardware check of the lane rule: matches.

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_permlanex16_b32 vD, v4, s20, s21 with lane i holding i + 1. There are 16 selectors (identity, reverse, all-0, all-F, a pair swap, 11 random), in wave32 and wave64 kernels, without op_sel, all lanes active. RDNA2 desktop silicon, not the console's. No game data.

Lane i reads lane (i & ~31) | ((i & 16) ^ 16) | nibble_(i & 15)({src2, src1}), that is, the other row of its own 32-lane half: 16/16 selectors in wave32 and 16/16 in wave64. The same run checked v_permlane16_b32 (own row) for #576, also 32/32.

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:7123515499 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/404#issuecomment-7123515499). Originally posted by [Lyrnc](https://github.com/Lyrnc) on 2026-11-24T06:02:25Z. --- RDNA2 hardware check of the lane rule: **matches.** 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_permlanex16_b32 vD, v4, s20, s21` with lane `i` holding `i + 1`. There are 16 selectors (identity, reverse, all-0, all-F, a pair swap, 11 random), in wave32 and wave64 kernels, without `op_sel`, all lanes active. RDNA2 desktop silicon, not the console's. No game data. Lane `i` reads lane `(i & ~31) | ((i & 16) ^ 16) | nibble_(i & 15)({src2, src1})`, that is, the other row of its own 32-lane half: 16/16 selectors in wave32 and 16/16 in wave64. The same run checked `v_permlane16_b32` (own row) for #576, also 32/32. 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:35Z.


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:7129140065 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/404#issuecomment-7129140065). Originally posted by [slint6614-dev](https://github.com/slint6614-dev) on 2026-11-24T10:42:35Z. --- 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.
MichaelSmithAI commented 2026-11-24 11:04:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by MichaelSmithAI on 2026-11-24T10:52:53Z.


We ran the DXIL emitted by d505b0e on an RTX 4090 under Wine/vkd3d-proton 3.2. For an all-active Wave32 guest, lane i held 29 + i and the two selector words were 0x5312e4b0 and 0x98fc6ad7. All 32 output words matched the cross-row rule measured on RDNA2 above. For example, lanes 0 and 16 returned 45 and 29, and lanes 1 and 17 returned 56 and 40. Microsoft DXV accepted the emitted shader.

A separate 64-thread Wave64 guest fixture also validated, but the emitted shader requested WaveSize=64. This adapter advertises only 32, so pipeline creation was refused and no Wave64 result was recorded. These controls used synthetic inputs; the single newly validated title program in the RX 9070 report has no pixel or buffer readback here.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7129367699 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/404#issuecomment-7129367699). Originally posted by [MichaelSmithAI](https://github.com/MichaelSmithAI) on 2026-11-24T10:52:53Z. --- We ran the DXIL emitted by `d505b0e` on an RTX 4090 under Wine/vkd3d-proton 3.2. For an all-active Wave32 guest, lane `i` held `29 + i` and the two selector words were `0x5312e4b0` and `0x98fc6ad7`. All 32 output words matched the cross-row rule measured on RDNA2 above. For example, lanes 0 and 16 returned 45 and 29, and lanes 1 and 17 returned 56 and 40. Microsoft DXV accepted the emitted shader. A separate 64-thread Wave64 guest fixture also validated, but the emitted shader requested `WaveSize=64`. This adapter advertises only 32, so pipeline creation was refused and no Wave64 result was recorded. These controls used synthetic inputs; the single newly validated title program in the RX 9070 report has no pixel or buffer readback here.
catminou4 commented 2026-11-24 14:03:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T13:19:33Z.

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:6039898078 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/404#pullrequestreview-6039898078). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T13:19:33Z. **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 00:05:26 +00:00
Marvisak commented 2026-11-25 00:06:57 +00:00 (Migrated from github.com)

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


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

See #1014. v_permlanex16_b32 through waveReadLaneAt; #1014 lowers it and v_permlane16_b32 with the same lane math in one change, without the three-PR stack.

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:7148073423 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/404#issuecomment-7148073423). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:02:35Z. --- Automated triage for the maintainers. Closing because another open pull request covers the same change. See #1014. v_permlanex16_b32 through waveReadLaneAt; #1014 lowers it and v_permlane16_b32 with the same lane math in one change, without the three-PR stack. 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!404
No description provided.