Skip to content

shader: lower v_permlane16_b32 - #576

Closed
NolanCotter wants to merge 4 commits into
Marvisak:mainfrom
NolanCotter:permlane16
Closed

NolanCotter wants to merge 4 commits into
Marvisak:mainfrom
NolanCotter:permlane16

Conversation

@NolanCotter

Copy link
Copy Markdown

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

devin-ai-integration Bot and others added 4 commits November 23, 2026 19:57
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 Marvisak#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>
@upipibi upipibi mentioned this pull request Nov 24, 2026
@Lyrnc

Lyrnc commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

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

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.

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

mercuryVM added a commit to mercuryVM/VIctory that referenced this pull request Nov 24, 2026
…anes and read back

Conflict in emit/lower.rs (console_lanes): this PR's spill filter plus the fork's v_permlane entry (Marvisak#576).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Marvisak

Copy link
Copy Markdown
Owner

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 Marvisak closed this Nov 25, 2026
fornorharry added a commit to NitricAcidDev/VIctory-Omega-Fork that referenced this pull request Nov 25, 2026
…r launch

From open pull requests of fxceless/victory-gta6, each reviewed, applied with
its tests and fitted to this tree:

- Marvisak#756: one sampler written into a program and used with and without a
  comparison is two static samplers; a comparison sampler with a minimum or
  maximum reduction stays a comparison.
- Marvisak#714: a mesh program that allocates in every lane keeps its LDS barriers;
  scalar reads of unordered views; both edges of a branch to one block; the
  first lane of an offset that is held per lane. With the early-start bias
  of this tree's raw views on the unordered ones too.
- Marvisak#576, in part: a loop with two empty latches, and the double flag of a
  program that lost its doubles. Not its block-local handles: 1,507 of 1,516
  compute programs of a local cache make host pipelines here as they are, and
  the nine others ask for waves of 64 lanes (older translations).
- Marvisak#646, in part: `DispatchX` counts threads where its flag says so. They ran
  as groups.
- Marvisak#676, in part: a new view of a texture already on the card needs no room;
  two views of a placed texture that differ in its filler words (the title's
  stack, another in every launch) are of one texture.
- Marvisak#481, in part: no barrier for a window of indirect arguments that this
  draw did not clamp.
- Marvisak#591: the parts of a host copy a submission asks for, not the span between
  them. Marvisak#522: table constants that flights write are filled on the card.
- Marvisak#745: samplers with modes the host does not know.

Added: an ignored test that makes a host pipeline from every compute
translation of a local cache; the staging pool's test waits for other tests'
submissions.

AI-assisted. GPU (170), shader (226) and format unit tests pass. Not run with
the title.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

6 participants