help wanted: GPU translation, part 6 (cross-lane operations) #2125
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows#2125
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@denn0x on GitHub · 2026-11-25 00:55 UTC · original
The startup translator models one lane, so every instruction that reads another lane is refused. In a private executable's pixel programs (decode only, aggregate counts), 695 programs use DPP (19,902 instructions), and none of those reads the lane itself. Hundreds more use
v_readlane/v_writelane/v_permlanex16.Each item below is one PR. Each needs the ISA or LLVM 15 semantics cited, a source-built fixture, and a negative control that fails when the lane is wrong.
quad_perm:[0,0,0,0],[1,1,1,1],[2,2,2,2](withbound_ctrl)ddx_coarse/ddy_coarse, orQuadReadLaneAtin SM 6.0+ pixel stagesquad_perm:[1,0,3,2],[2,3,0,1],[3,2,1,0]QuadReadAcrossX/QuadReadAcrossY/QuadReadAcrossDiagonal(SM 6.0)[1,1,3,3],[0,0,2,2],[2,3,2,3],[0,1,0,1]QuadReadLaneAtrow_mirror,row_half_mirror,v_permlanex16_b32 ..., 0, 0,v_readlane_b32 ..., 31WaveActiveMin/Max/Sum; refuse partial shapesv_writelane_b32 vN, sM, k...v_readlane_b32 sM, vN, kwith constant kNotes:
v_readlanereads a lane whatever EXEC says. Any proof that a value is uniform must cover lanes outside the entry mask, or the lane select must be shown to be active. See the question on #2032.@tedin7 on GitHub · 2026-11-25 01:23 UTC · original
Picking up Items A (quad broadcast DPP), B (quad swap DPP), and C (pair broadcast DPP) as separate small PRs with WARP readback tests.
@tedin7 on GitHub · 2026-11-25 02:36 UTC · original
Picking up Item E (constant-lane SGPR spill/reload
v_writelane_b32/v_readlane_b32in pixel stages) with unit + D3D12 WARP readback tests.@tedin7 on GitHub · 2026-11-25 02:47 UTC · original
Picking up Item D DPP slice (row_mirror / row_half_mirror wave reductions) on top of the merged DPP base; v_permlanex16/v_readlane remain in #2032.
@tedin7 on GitHub · 2026-11-25 02:48 UTC · original
Releasing the Item D row_mirror / row_half_mirror claim: these read lanes outside the 2x2 quad, and the translator can only prove whole-quad EXEC, so a sound lowering needs a whole-wave EXEC proof (or the whole-reduction recognition) first. Free for anyone with a plan for that.
@roansystemlabs on GitHub · 2026-11-25 05:06 UTC · original
I'd like to take item D, the wave reductions, with a plan for the whole-wave EXEC problem raised when it was released. If someone already has it in progress, I'll step back and review.
Plan: recognise the complete reduction rather than lowering its instructions one by one.
First slice (one PR):
Later slices, each its own PR: float min/max with the NaN rules already used in the translator, then wave64 if the census shows it.
Evidence: source-built chains assembled with LLVM 15 llvm-mc for gfx1013 (encodings checked on the bytes), translated and compiled with DXC ps_6_0, drawn on WARP and an RTX 3070 with fenced readback against a CPU reference per desktop wave (the lane count is read and reported per adapter, not assumed). Partly covered quads exercise helper lanes. Negative controls: every partial chain refused with its reason, and mutations (Sum for Max, wrong identity, readlane 30, one mirror step removed, guard removed) must fail. Not tested: AMD hardware and console wave64.
@denn0x, if the census can share the aggregate shape of these chains (step order, operations, whether EXEC is saved first), I'll match the first slice to it; otherwise it follows the documented Mesa and LLVM form and says so.
AI-assisted.
@denn0x on GitHub · 2026-11-25 05:26 UTC · original
Thanks for taking item D. Here is the aggregate shape from our census of a private executable's pixel programs: decode only, distinct pixel programs counted once, numbers only.
How many:
v_permlanex16_b32. Most of those pairs have other blockers as well.EXEC: every chain starts with
s_or_saveexec ..., -1, so all lanes are enabled. All 725 do; none runs at the entry EXEC.Step order: the steps run in the same order in every chain:
quad_perm:[1,0,3,2]quad_perm:[2,3,0,1]row_half_mirrorrow_mirrorv_permlanex16_b32 ..., 0, 0The first two steps are DPP16 quad swaps on the same operation. Your plan starts at the mirrors, so it would need to accept those two steps as part of the chain.
Operations: only three appear.
v_or_b32v_min_u32, thenv_max_u32on the same inputv_min_u32alonev_min_u32+v_max_u32+v_or_b32in one stretchThe min-then-max chains run back to back: the second saves EXEC again before its own reduction.
We see no
v_add_nc_u32, no signed min/max and no float operations. Sov_or_b32(WaveActiveBitOr) is the most common case here, and it is not in the first slice as written.s_or_saveexec_b32)s_mov_b32 exec_lo, ..., thenv_readlane_b32 ..., 31s_or_saveexec_b64)v_readlane_b32 ..., 0, and..., 63in the min/max chains; EXEC restored withs_mov_b64 exec, ...So wave64 is about a quarter of the chains.
AI-assisted.
@roansystemlabs on GitHub · 2026-11-25 05:42 UTC · original
@denn0x thank you, this is exactly what the first slice needed. I'll change it to match the census before running the final checks:
s_or_saveexec_b32 ..., -1and includes the twoquad_permswaps ([1,0,3,2], then[2,3,0,1]) beforerow_half_mirror,row_mirror,v_permlanex16_b32 ..., 0, 0andv_readlane_b32 ..., 31, with EXEC restored bys_mov_b32 exec_lo, ....v_or_b32toWaveActiveBitOr, andv_min_u32/v_max_u32toWaveActiveMin/WaveActiveMax, including the min-then-max pair run back to back with its own saveexec.v_add_nc_u32and the signed forms come out of this slice, since the census has none.readlane 0/63,s_mov_b64 exec) becomes the second slice.One open point decides whether the lowering is sound: the instructions between
s_or_saveexec ..., -1and the firstquad_perm. With every lane enabled, the lanes that were inactive on entry must hold the operation's identity (0 for OR, UINT_MAX for min, 0 for max), or the reduction picks up stale values. If the census can show the aggregate shape of that stretch (for example av_cndmaskon the saved mask, av_movunder the entry EXEC, or nothing), I'll accept exactly that form and refuse the rest by name. Until then the translator keeps refusing these chains.AI-assisted.
@Miffedrandir on GitHub · 2026-11-26 10:25 UTC · original
@roansystemlabs answering your open point on item D, from a local capture of graphics pipeline requests (decode only, aggregate counts, distinct pixel programs counted once; 578 programs, 225 with chains, 614 chains: 574 wave32, 40 wave64).
The stretch between
s_or_saveexec_b32 ..., -1and the firstquad_permis always exactly onev_cndmask_b32_e64 vT, <identity>, vSrc, sSaved, wheresSavedis the saveexec destination and the identity is0forv_or_b32(214 chains),-1forv_min_u32(180) and0forv_max_u32(180). All 574 wave32 chains match one of three exact shapes:s_or_saveexec_b32 s, -1→v_cndmask_b32_e64 vT, 0, vX, s→v_or_b32_dpp vT, vT, vTwithquad_perm:[1,0,3,2],quad_perm:[2,3,0,1],row_half_mirror,row_mirror(allrow_mask:0xf bank_mask:0xf fi:1) →v_permlanex16_b32 vU, vT, 0, 0→v_or_b32_e32 vT, vU, vT→s_mov_b32 exec_lo, s→v_readlane_b32 sR, vT, 31immediately.-1. Its readlane is not immediate: afters_mov_b32 exec_lo, scomes av_cndmask_b32_sdwa, then the next chain'ss_or_saveexec_b32 ..., -1, and only thenv_readlane_b32 sR, vT, 31.s_or_saveexec_b32 s', -1→ (the MIN'sv_readlane_b32 ..., 31) →v_cndmask_b32_e64 vT, 0, vX, s'→ the same four DPP steps →v_permlanex16_b32→v_max_u32_e32→s_mov_b32 exec_lo, s'→v_readlane_b32 ..., 31immediately.So a matcher that requires the readlane right after the restore would miss the 180 MIN chains, and one that requires the
v_cndmaskright after the saveexec would miss the 180 MAX chains. Other points:s_lshr_b32/s_lshl_b32,s_sub_i32) and usereadlane ..., 63. I didn't break them down further.s_ff1_i32_b32), and each lane gates its work on its own bit (v_bfe_u32 v, vMask, sBit, 1→v_cmpx_ne_i32). That supports your contract that per-pixel results don't depend on which pixels share a wave.Happy to run your branch against this capture and report the refusal counts before and after. AI-assisted.
@roansystemlabs on GitHub · 2026-11-26 12:43 UTC · original
@Miffedrandir thank you, this was the missing piece. Your three shapes match what the branch now recognises:
v_cndmask_b32_e64 vT, <identity>, vX, sSwith0/-1/0, under the saveexec's own SGPR; any other fill, constant or mask is refused by name;v_cndmask_b32_sdwa(lowered as usual), the MAX chain'ss_or_saveexec_b32 ..., -1, then the readlane, which the MAX chain carries before its fill. It is refused if anything in between rewrites the MIN'svT, if that readlane overwrites the MAX's saved EXEC, or if no MAX chain carries it.The DPP steps accept
fi:1(every lane is on, so it decides nothing), and the combine takesvT, vU, vTas in your shape 1. Wave64 stays out for the next slice.The PR is #2835. We'd gladly take your offer: running the branch against your capture and posting the refusal counts before and after (graphics pipelines failing, and how many of them still stop first at a reduction chain) would be the best check of the shapes that we can't run ourselves.
AI-assisted.
@SimSalabimse on GitHub · 2026-11-27 20:11 UTC · original
Claiming the #2125 item D follow-up: wave32 reduction chains in pixel programs that also have branches. #2835 already accepts the straight-line OR, MIN and MAX shapes. This slice keeps that matcher and allows the same chain when the rest of the program has branches, provided the chain itself stays straight, has no branch target inside it, and EXEC is saved and restored as in the accepted shapes. Wave64 stays out of this PR. Tests will be source-built pixel fixtures with a uniform branch before and after the chain, a control that a branch into the chain stays refused, and WARP plus hardware readback against a CPU reduction.
AI-Assisted