Skip to content

shader: lower v_permlane16_b32 and v_permlanex16_b32 in direct compute - #3022

Merged
pigalot merged 3 commits into
R0Y00:mainfrom
Leyukaka:permlane
Nov 27, 2026
Merged

pigalot merged 3 commits into
R0Y00:mainfrom
Leyukaka:permlane

Conversation

@Leyukaka

@Leyukaka Leyukaka commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #3021. Part of #2935. Target branch main. The measured requests reach these ops only once DPP16 row operations are lowered; that is #3010, now on main.

Change (src/gfx1013_compute_native.cpp, src/gfx1013_direct_compute.inl): direct compute now lowers v_permlane16_b32 and v_permlanex16_b32.

  • Lane i of a 16-lane row reads S0 from lane sel = ({S2, S1} >> (4 * (i & 15))) & 15. permlane16 reads from the same row. permlanex16 reads from the other row of the same 32-lane half.
  • S1 and S2 are uniform: SGPRs, inline constants, or the one trailing 32-bit literal, which both may reference. A literal in S0 is refused. Each lane picks its 4-bit field at run time.
  • op_sel[0] is FI and op_sel[1] is BOUND_CTRL.
  • For an inactive source lane, I assumed the DPP rule. Without FI, an inactive source gives 0 with BOUND_CTRL; otherwise D keeps its old value. The readback checks the lowering against that model, not RDNA2 itself.
  • A row and its pair stay inside one 32-lane half. On the wave64 path each half is one physical wave32, so the lowering uses the physical lane index and the matching EXEC half.
  • Refused:
    • other op_sel bits, abs, neg, clamp and omod;
    • a non-uniform or special selector (VGPR, vcc_lo, vcc_hi on the wave64 path, exec, m0, null), and an S0 that is not a VGPR. In wave32, vcc_hi is ordinary scalar data;
    • a thread count not divisible by 16 (permlane16) or 32 (permlanex16).

Tests. The setup was Windows 11 build 26300.9974 with an NVIDIA GeForce RTX 5080 (driver 32.0.16.2101) and DXC from the Windows SDK 10.0.26100, on main 6057071b plus this branch. The D3D12 debug layer is not installed. Release and Debug (dev preset) builds both pass.

  • native_permlane_hardware passed. Seven wave32 programs ran in two 64-thread groups with sparse guest EXEC. All 2,064 output words matched a CPU reference, sentinels included. The programs are:

    • x16 with BOUND_CTRL and a literal-plus-SGPR selector;
    • x16 with FI and two SGPRs;
    • x16 with inline 0 selectors;
    • permlane16 with BOUND_CTRL and a literal-plus-SGPR selector;
    • permlane16 with two SGPRs;
    • x16 with an SGPR in S1 and a literal in S2;
    • x16 with the same literal in S1 and S2.

    The selectors differ per row lane, and S1 differs from S2.

  • native_permlane_controls passed. A wave32 request and a split-wave64 container compile. These are refused:

    • op_sel bit 2;
    • clamp;
    • a VGPR selector;
    • x16 with 16 threads, and permlane16 with 8;
    • an inline S0.
  • Wave64 is covered by that compile case only, not by a readback.

  • The 9 native_dpp*, native_lane*, native_wave*, native_readlane* and native_permlane* tests pass.

Mutation checks, run by hand; each fails the hardware check:

  • reading the same row for x16;
  • swapping S1 and S2;
  • ignoring BOUND_CTRL.

Measured on a local capture (counts and instruction shape only) with compile_dxil --jobs 8 gfx1013-direct-cs@36 --requests.

AI-assisted.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Independent retest at 125f5313 stacked on #3010 (7325dd17). I rebuilt compile_dxil and native_store_replay and ran native_permlane_controls and native_permlane_hardware separately with ctest --preset <dev|release> --no-tests=error -V -R '^native_permlane_(controls|hardware)$'. Both passed in Debug and Release /O2 without skips. The hardware replay matched 128 result words plus all guards in each of six cases with the inbox D3D12 runtime (Windows 11 build 26200.9974, RTX 4060 Laptop driver 32.0.16.1656, replay debug layer off). No WARP test is registered.

The AMD RDNA 2 ISA guide, §12.12 confirms the selector packing, row pairing and FI/BOUND_CTRL bit positions. The desktop readback exercises the proposed inactive-source model. The exact preserve-versus-zero behavior still needs a native RDNA 2 result. All 47 measured requests are flagged wave64, while the current wave64 control only compiles. Please coordinate with #3006 on a split-wave64 bit-exact readback with different lower/upper EXEC masks, so selecting the wrong half fails at a known lane.

R0Y00 commented Nov 27, 2026

Copy link
Copy Markdown
Owner

#3010 is now on main as 1ec2c938. I checked 125f5313 against main 354c6870: an immediate base change still shows the pre-squash #3010 commit and conflicts in docs/experiments.md. Please rebuild this PR branch from current main with only the permlane change, then change this existing PR’s base to main. Keep the prior review and the inactive-source scope note linked. I’ll recheck against the new head with native_permlane_(controls|hardware) and the DPP16 row regressions.

@Leyukaka
Leyukaka changed the base branch from cpp-migration to main November 27, 2026 17:35
@Leyukaka

Copy link
Copy Markdown
Collaborator Author

Rebuilt from current main (63a30dc1) with only the permlane change (b99a223f); the base is now main, and the description is updated.

AI-assisted.

@JohnConnorNPC

Copy link
Copy Markdown
Collaborator

Thank you for the rebuild onto main and for the careful write-up. I reviewed 042cb0b8 and its merge onto current main (80668b97). The wave32 lowering matches the RDNA2 pseudocode as I read it: selector packing, row pairing, and FI/BOUND_CTRL handled like the existing DPP lowering. native_permlane_controls passes on both trees in a Release cross build. A few requests before merge:

  1. Split wave64 (from the earlier review). On main, requests always use the wave32 model, so the wave64 branch of lower_permlane is only compiled, never read back. As a check, I changed auto exec = wave64 ? select(upper_half, read(127), read(126)) : read(126); to auto exec = read(126);. Both native_permlane_controls and native_permlane_hardware still pass. Since all 47 measured requests are flagged wave64, could you either add a split-wave64 readback with different lower/upper EXEC masks (with shader: read the wave size of slot 67 compute requests from .sa #3006 or through a container replay), or refuse the two ops on the wave64 path until that readback exists, and open a linked follow-up issue? If the maintainer prefers to track it in shader: read the wave size of slot 67 compute requests from .sa #3006, a link to that decision is enough.
  2. CI coverage. The pull-request CI job runs the pr test preset, which selects neither native_permlane_controls nor native_permlane_hardware. The 69 tests in the Windows job don't include them, so your RTX 5080 Release run is the only Windows evidence at this head. Could you add the exact command, the driver version, Windows build and debug-layer status, and a Debug run (e.g. ctest --preset dev --no-tests=error -V -R '^native_permlane_(controls|hardware)$')? A manual "Windows checks → Run workflow" run of the branch would also do for the controls.
  3. Doc base. docs/experiments/native-permlane.md still says "on shader: lower DPP16 row_shl, row_shr and row_ror in direct compute #3010 (7325dd17) plus this change". That commit is shader: lower DPP16 row_shl, row_shr and row_ror in direct compute #3010's pre-squash head and isn't in main's history. Could you copy the two bases from the PR body into the doc: the tested commit (main 63a30dc1 plus this branch), and the base of the 2,689-request count (cpp-migration 999e17cd plus shader: lower DPP16 row_shl, row_shr and row_ror in direct compute #3010)?

Smaller points, take or leave:

  • LLVM accepts v_permlanex16_b32 v1, v2, 0x492f0381, 0x492f0381 for gfx1013. It encodes word 1 as 0x03FDFF02, the same as the "two literals" control, and only rejects two different literals. Either accept S1 = S2 = the same literal (operand32 already returns i.literal for both) and make that control a compiled case, or reword the refusal message as a deliberate scope limit.
  • The abs/neg/clamp/omod refusal has no control. Removing || i.neg || i.abs || i.clamp || i.scale keeps the suite green. One row (e.g. clamp, word 0 0xD7788001) would pin it.
  • In wave32, vcc_hi (s107) is accepted as a selector, which matches initialize()'s treatment of s107 as ordinary scalar data. The body's "vcc" in the refused list could say "vcc_lo (and vcc_hi in wave64)".
  • With the decoder's i.src[0] == 255 clause removed, an S0 literal is still refused by the lowering ("S0 must be a VGPR"). The clause is redundant; keep or drop as you prefer.

For the record, on a different stack (RTX 4070 Ti SUPER, Linux driver 550.163.01, vkd3d-proton under Proton experimental-11.0, debug layer off), native_permlane_hardware passed all six readbacks at 042cb0b8 and on its merge with main 80668b97. Your three manual mutants (same row for x16, swapped S1/S2, ignored BOUND_CTRL) each failed it, as did ignoring FI and testing the destination lane's EXEC bit instead of the source's. Only the wave64 EXEC-half change above stayed green.

This comment was AI-assisted.

Lane i of a 16-lane row reads S0 from lane ({S2,S1} >> 4*(i & 15)) & 15
of its row (permlane16) or of the other row of its 32-lane half
(permlanex16). S1 and S2 are uniform: SGPRs, inline constants or one
32-bit literal (the decoder now refuses a literal in S0 or two
literals). op_sel[0] is FI and op_sel[1] is BOUND_CTRL, with the DPP
rule for an inactive source (assumed). Rows stay inside one physical
wave32, also on the wave64 path. Other op_sel bits, modifiers,
non-uniform or special selectors and thread counts that leave a
partial row or pair are refused.

A new check runs six programs on hardware against a CPU reference and
checks the refusals; wave64 is covered by a compile case.

AI-assisted.
Bit 20 of .sa dword 4 is the wave32 flag (R0Y00#2999). Setting it keeps these
32-lane fixtures on the wave32 model once the request reader honours
it; without that reader the bit is ignored.

AI-assisted.
S1 and S2 of v_permlane16_b32 / v_permlanex16_b32 may both reference the
one trailing literal word, as LLVM encodes it; that form now compiles and
is read back. A literal in S0 stays refused. A clamp control pins the
abs/neg/clamp/omod refusal. The experiment note gives the tested base
(main 6057071 plus this branch) and the measurement base (cpp-migration
999e17c plus R0Y00#3010), and says the wave64 branch is compiled only.

AI-assisted.
@Leyukaka

Copy link
Copy Markdown
Collaborator Author

Thank you for the review and for the second-stack run. Rebased on main 6057071b; the new commit is b912ad58. The description is updated to match.

  1. Split wave64: agreed. On main the wave64 branch of lower_permlane is only compiled by the container control, never read back, so your read(126) mutant survives. The experiment note now says so. The wave64 path is not refused here: the maintainer asked to coordinate the split-wave64 readback with shader: read the wave size of slot 67 compute requests from .sa #3006 (shader: lower v_permlane16_b32 and v_permlanex16_b32 in direct compute #3022 (review)).
  2. Windows evidence at this head:
    • Setup: Windows 11 build 26300.9974, NVIDIA GeForce RTX 5080, driver 32.0.16.2101 (NVIDIA 621.01), DXC from the Windows SDK 10.0.26100.
    • Debug layer: unavailable. The D3D12 SDK layers (Graphics Tools) are not installed on this machine.
    • Release: ctest --test-dir out/build/release -R "native_permlane|native_dpp|native_lane|native_direct_container", 9 of 9 passed.
    • Debug: cmake --preset dev, cmake --build --preset dev --target compile_dxil native_store_replay, then ctest --preset dev --no-tests=error -R '^native_permlane_(controls|hardware)$'. Both passed.
  3. Doc base: the note now gives both bases. The tests ran on main 6057071b plus this branch. The 2,689-request count comes from cpp-migration 999e17cd plus shader: lower DPP16 row_shl, row_shr and row_ror in direct compute #3010.

Smaller points:

  • Same literal in S1 and S2: now accepted. The "two literals" control became a compiled and read-back case, cross-shared-literal. Its words are 0xD7780001 0x03FDFF02 0x492F0381, with eight different selectors, the same for row lanes 0-7 and 8-15. A literal in S0 is still refused, and the message now says exactly that: "permlane S0 cannot be a literal".
  • Modifier refusal: a clamp control (0xD7788001 0x00341902) now pins it. Removing i.clamp from that check fails native_permlane_controls.
  • vcc_hi: the note now says that selectors refuse vcc_lo, and vcc_hi on the wave64 path. In wave32, vcc_hi is ordinary scalar data.
  • The i.src[0] == 255 clause: I kept it as the decoder-level refusal for a literal S0.

AI-assisted.

@pigalot pigalot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I reviewed b912ad58 merged over main f6206217. The merge is clean (tree 03bd58f5) and git diff --cached --check is clean.

What I traced.

  • Against the RDNA2 definition:

    • the selector for row lane L is nibble L & 7 of S1 for lanes 0..7 and of S2 for lanes 8..15;
    • v_permlane16_b32 reads lane row_base | sel of the current row;
    • v_permlanex16_b32 flips row bit 4, so each row reads the other row of its pair.
  • op_sel: bit 0 is FI and bit 1 is BOUND_CTRL. Without FI, an inactive source lane gives 0 under BOUND_CTRL and keeps D otherwise. Guest EXEC still predicates the write.

  • Refusals: S0 must be a VGPR, and a literal S0 is refused in the decoder. Modifiers and the other op_sel bits are refused.

  • Earlier requests: R0Y00's rebuild from main and the base change are done. JohnConnorNPC's points are each answered at this head:

    • the doc bases are corrected;
    • a shared S1/S2 literal is accepted, with a read-back case;
    • a clamp control is added;
    • the vcc_hi wording is fixed.

    The split-wave64 readback is deferred to #3006, as the maintainer asked.

What I ran. I built compile_dxil native_store_replay native_compute_ir_dump offscreen_check in dev and release, then ran

python .agentic\scripts\with_gpu_lock.py ctest --test-dir out/build/<preset> --no-tests=error -j 1 -V -R '^(native_permlane_(controls|hardware)|native_dpp[a-z0-9_]*_hardware|native_direct_container|native_lane[a-z0-9_]*)$'
  • Results: 8 of 9 pass in Debug and Release /O2. native_lane_spill_descriptor_warp reports a 77 skip in both builds; it is an existing WARP test that this PR doesn't touch.
  • Hardware coverage: native_permlane_hardware matched 128 results and all guards in each of its seven cases, including cross-shared-literal.
  • Negative control: on main d6912f58, the PR's native_permlane_check.py fails in both modes. controls gets requests=7 compiled=0 refused=7 ("direct DXIL lowering for v_permlanex16_b32"), and the hardware replay compile fails.

Mutants in src/gfx1013_direct_compute.inl. For each, I rebuilt in dev and ran native_permlane_(controls|hardware):

Mutant Result
x16 keeps its own row killed (cross-literal-bound word 8: 0x0 vs 0x25)
S1/S2 swapped killed (word 8: 0x2c vs 0x25)
BOUND_CTRL ignored killed (word 24: 0x21 vs 0x0)
FI ignored killed (cross-sgprs-fi word 24: 0x21 vs 0x15)
the destination lane's EXEC bit tested instead of the source's killed (word 24)
nibble index from lane bits 0..1 only killed (word 12)
modifier refusal removed killed (controls)
special-SGPR selector refusal reduced to "not a VGPR" survives

Restored and rebuilt afterwards; git diff --quiet is clean.

Non-blocking.

  • Selector refusal: the selector refusal is pinned only by the VGPR case (v2/v3/s13). No control uses vcc_lo, m0 or exec as a selector. The refusal is a scope limit, not a correctness need, since operand32 can read those numerically. One control row would pin it.
  • Wave64: the wave64 EXEC-half path is still unread, as you noted. #3006 is still open.
  • CI: the pr CI preset doesn't select native_permlane_*, so this run and yours are the Windows evidence at this head.

Verdict: approve on b912ad58.

Environment: NVIDIA GeForce RTX 5090 driver 610.88, Windows 11 25H2 build 26200.9974, MSVC 19.52.37029, Windows SDK 10.0.28000.0 DXC, Python 3.12.10, wave32, debug layer off.
CI: Build and test on Windows passes on b912ad58.

This reply was AI-assisted.

@pigalot
pigalot merged commit c1de64a into R0Y00:main Nov 27, 2026
5 checks passed
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.

cpp-migration: lower v_permlane16_b32 and v_permlanex16_b32 in the direct C++ compute path

4 participants