Skip to content

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

Open
Leyukaka wants to merge 2 commits into
R0Y00:cpp-migrationfrom
Leyukaka:permlane
Open

Leyukaka wants to merge 2 commits into
R0Y00:cpp-migrationfrom
Leyukaka:permlane

Conversation

@Leyukaka

Copy link
Copy Markdown
Contributor

Fixes #3021 (it needs closing by hand, since the base is not the default branch). Part of #2935. Target branch cpp-migration. Builds on #3010: the measured requests reach these ops only once DPP16 row operations are lowered. Please merge #3010 first.

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 one 32-bit literal. The decoder already reads the trailing literal word; for these two ops it now refuses a literal in S0 and two literals. 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, exec, m0, null), and an S0 that is not a VGPR;
    • a thread count not divisible by 16 (permlane16) or 32 (permlanex16).

Tests. The setup was Windows 11 with an NVIDIA GeForce RTX 5080 and DXC from the Windows SDK 10.0.26100, on #3010 (7325dd17) plus this commit.

  • native_permlane_hardware passed. Six 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.

    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;
    • a VGPR selector;
    • x16 with 16 threads, and permlane16 with 8;
    • two literals;
    • 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.

Direct compute accepted DPP16 quad_perm and the two mirrors only. It
now also lowers row_shl:N, row_shr:N and row_ror:N (N = 1..15) with full
row and bank masks. The source lane stays inside the lane's 16-lane row,
so a split guest wave64 needs no exchange. A shift whose source falls
outside the row has an unusable source, as does an EXEC-inactive source
without FI: BOUND_CTRL then supplies 0, otherwise the destination keeps
its old value. Row operations need a thread count divisible by 16.
row_share, row_xmask, the pre-GFX10 controls and partial masks stay
refused.

A new check runs 16 programs on hardware with sparse EXEC against a CPU
reference, and checks four refusals.

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.

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

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.

2 participants