Skip to content

shader: lower v_permlanex16_b32 - #404

Closed
NolanCotter wants to merge 1 commit into
Marvisak:mainfrom
NolanCotter:permlanex16-b32
Closed

NolanCotter wants to merge 1 commit into
Marvisak:mainfrom
NolanCotter:permlanex16-b32

Conversation

@NolanCotter

Copy link
Copy Markdown

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 Shaders: model v_permlane16_b32 in whole-wave sections #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

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>
@jeremygold02

Copy link
Copy Markdown
Contributor

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.

@upipibi upipibi mentioned this pull request Nov 24, 2026
@NolanCotter NolanCotter mentioned this pull request Nov 24, 2026
3 tasks done

@mercuryVM mercuryVM left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

mercuryVM added a commit to mercuryVM/VIctory that referenced this pull request Nov 24, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Lyrnc

Lyrnc commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Marvisak

Copy link
Copy Markdown
Owner

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.

@Marvisak Marvisak closed this Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants