Repository navigation
rdna2spirv: a constant used as a lane mask through an SGPR (or a b32 SOP2 on EXEC) gives each lane its bit - #1792
Conversation
|
A regression in the b32 SOP2 on EXEC path, reproduced on GPU at Hand-written wave32 compute listing (not part of the PR), all 32 lanes active, run with
Same words on an AMD Radeon RDNA2 iGPU (Windows driver 32.0.21043.5001) and an RTX 4070 Ti SUPER (Windows). The new path ( Otherwise:
(AI-assisted: first flagged by a second model's code read, then reproduced on both GPUs. Synthetic listing, no game files.) |
fc8d5ad to
6275ccc
Compare
|
Thanks @Pierre-Kookis, confirmed and fixed in the new head: reproduced on the CPU (32 / 0 in lane 0, 0 / 0 elsewhere), and with the fix every lane gives 1 / 8, as |
s_and_b32 s20, exec_lo, 1 put each lane's bit in s20, which lane_masks.py classifies as data when the other operand is a constant, so s_bcnt1 of it counted 32 / 0 instead of 1 (found by @Pierre-Kookis on ItsNotRexed#1792, reproduced on AMD RDNA2 and an RTX 4070 Ti SUPER; main was right). The mask read is now only for an EXEC / VCC destination; into a plain SGPR the op keeps the data read. test_mask_src_sgpr_const.py has the case.
|
Tested 9620edd on NVIDIA GeForce GTX 1660 (Turing, TU116, subgroup 32..32), driver 620.73.04 (proprietary, Vulkan 1.4.357), Arch Linux (kernel 6.18): pass, and the regression @Pierre-Kookis reported at fc8d5ad is gone on a GPU at this head (the fix note above checked it on the CPU). Hand-written wave32 compute listing (not part of the PR), all lanes active, each lane stores
The rest, native build of runtime/ from this head, llvm-mc 23.1.5, SPIRV-Tools v2026.4:
AI-assisted run (Claude). Synthetic programs only, no game files involved. |
|
Tested Hand-written fixtures for the SHADER-304 class: an SGPR holding a lane-mask value (a literal, a user SGPR input, a copy of it, a computed value, an SOP2 on wave32,
wave64, native 64-wide subgroup,
Each word is cs_w32_sgpr_mask.asm (wave32 fixture); Local review fixture for SHADER-304 (#1841, #1792), not part of either PR: an SGPR holding a lane-mask VALUE
; (not a compare result) read as a lane mask. On RDNA2 an SGPR is one 32-bit register shared by the wave, so
; s_and_saveexec_b32 s7, sN gives EXEC &= sN bit by bit, wherever sN's value came from (ISA: EXEC is one bit per
; lane). s4 is a user SGPR input, 0x3ffffc00 = lanes 10..29.
; Each case marks the lanes it leaves on; with EXEC back to all lanes, lane 0 stores
; word = (set lanes) | (lowest set lane) << 8, from s_bcnt1 and s_ff1 of the marks (no lane: 0xffffff00).
; out[0] s_mov_b32 s20, 0x3ffffc00 (literal); s_and_saveexec_b32 s20 lanes 10..29 20 | 10<<8 = 2580
; out[1] s_and_saveexec_b32 s4 (user SGPR input) lanes 10..29 2580
; out[2] s_mov_b32 exec_lo, s4 lanes 10..29 2580
; out[3] s_mov_b32 s21, s4 (copy of the input); EXEC=0; s_or_saveexec s21 lanes 10..29 2580
; out[4] s_lshl_b32 s22, s4, 1 = 0x7ffff800 (computed); s_and_saveexec lanes 11..30 20 | 11<<8 = 2836
; out[5] s_and_b32 exec_lo, exec_lo, s4 (SOP2 on EXEC) lanes 10..29 2580
; out[6] control: v_cmp_gt_u32 vcc_lo, 16, v0; s_and_saveexec vcc_lo lanes 0..15 16
; out[7] control: s_mov_b32 s23, vcc_lo (a real mask); s_and_saveexec s23 lanes 0..15 16
; "Every lane" (an SGPR read as this lane's 0/~0 bool, any non-zero value = all lanes) gives 32 for a case.
; group: 32,1,1
; rsrc2: 0x8090
; Run: VKC_SUBGROUP_SIZE=32 VKC_SGPRS=0x3ffffc00 vk_compute_test cs_w32_sgpr_mask.spv 1 dump
; -> out[0..7] = 2580 2580 2580 2580 2836 2580 16 16
; mattr: +wavefrontsize32,-wavefrontsize64
v_mov_b32_e32 v10, 0
v_mov_b32_e32 v11, 0
v_mov_b32_e32 v12, 0
v_mov_b32_e32 v13, 0
v_mov_b32_e32 v14, 0
v_mov_b32_e32 v15, 0
v_mov_b32_e32 v16, 0
v_mov_b32_e32 v17, 0
s_mov_b32 exec_lo, -1
s_mov_b32 s20, 0x3ffffc00
s_and_saveexec_b32 s7, s20
v_mov_b32_e32 v10, 1
s_mov_b32 exec_lo, -1
s_and_saveexec_b32 s7, s4
v_mov_b32_e32 v11, 1
s_mov_b32 exec_lo, s4
v_mov_b32_e32 v12, 1
s_mov_b32 s21, s4
s_mov_b32 exec_lo, 0
s_or_saveexec_b32 s7, s21
v_mov_b32_e32 v13, 1
s_mov_b32 exec_lo, -1
s_lshl_b32 s22, s4, 1
s_and_saveexec_b32 s7, s22
v_mov_b32_e32 v14, 1
s_mov_b32 exec_lo, -1
s_and_b32 exec_lo, exec_lo, s4
v_mov_b32_e32 v15, 1
s_mov_b32 exec_lo, -1
v_cmp_gt_u32_e32 vcc_lo, 16, v0
s_and_saveexec_b32 s7, vcc_lo
v_mov_b32_e32 v16, 1
s_mov_b32 exec_lo, -1
v_cmp_gt_u32_e32 vcc_lo, 16, v0
s_mov_b32 s23, vcc_lo
s_and_saveexec_b32 s7, s23
v_mov_b32_e32 v17, 1
s_mov_b32 exec_lo, -1
v_mov_b32_e32 v20, 0
v_cmp_ne_u32_e32 vcc_lo, 0, v10
s_bcnt1_i32_b32 s30, vcc_lo
s_ff1_i32_b32 s31, vcc_lo
s_lshl_b32 s31, s31, 8
s_or_b32 s30, s30, s31
v_mov_b32_e32 v21, s30
v_cmp_ne_u32_e32 vcc_lo, 0, v11
s_bcnt1_i32_b32 s30, vcc_lo
s_ff1_i32_b32 s31, vcc_lo
s_lshl_b32 s31, s31, 8
s_or_b32 s30, s30, s31
v_mov_b32_e32 v22, s30
v_cmp_ne_u32_e32 vcc_lo, 0, v12
s_bcnt1_i32_b32 s30, vcc_lo
s_ff1_i32_b32 s31, vcc_lo
s_lshl_b32 s31, s31, 8
s_or_b32 s30, s30, s31
v_mov_b32_e32 v23, s30
v_cmp_ne_u32_e32 vcc_lo, 0, v13
s_bcnt1_i32_b32 s30, vcc_lo
s_ff1_i32_b32 s31, vcc_lo
s_lshl_b32 s31, s31, 8
s_or_b32 s30, s30, s31
v_mov_b32_e32 v24, s30
v_cmp_ne_u32_e32 vcc_lo, 0, v14
s_bcnt1_i32_b32 s30, vcc_lo
s_ff1_i32_b32 s31, vcc_lo
s_lshl_b32 s31, s31, 8
s_or_b32 s30, s30, s31
v_mov_b32_e32 v25, s30
v_cmp_ne_u32_e32 vcc_lo, 0, v15
s_bcnt1_i32_b32 s30, vcc_lo
s_ff1_i32_b32 s31, vcc_lo
s_lshl_b32 s31, s31, 8
s_or_b32 s30, s30, s31
v_mov_b32_e32 v26, s30
v_cmp_ne_u32_e32 vcc_lo, 0, v16
s_bcnt1_i32_b32 s30, vcc_lo
s_ff1_i32_b32 s31, vcc_lo
s_lshl_b32 s31, s31, 8
s_or_b32 s30, s30, s31
v_mov_b32_e32 v27, s30
v_cmp_ne_u32_e32 vcc_lo, 0, v17
s_bcnt1_i32_b32 s30, vcc_lo
s_ff1_i32_b32 s31, vcc_lo
s_lshl_b32 s31, s31, 8
s_or_b32 s30, s30, s31
v_mov_b32_e32 v28, s30
v_cmp_eq_u32_e32 vcc_lo, 0, v0
s_and_saveexec_b32 s7, vcc_lo
buffer_store_dword v21, v20, s[0:3], 0 offen
buffer_store_dword v22, v20, s[0:3], 0 offen offset:4
buffer_store_dword v23, v20, s[0:3], 0 offen offset:8
buffer_store_dword v24, v20, s[0:3], 0 offen offset:12
buffer_store_dword v25, v20, s[0:3], 0 offen offset:16
buffer_store_dword v26, v20, s[0:3], 0 offen offset:20
buffer_store_dword v27, v20, s[0:3], 0 offen offset:24
buffer_store_dword v28, v20, s[0:3], 0 offen offset:28
s_endpgmcs_w64_sgpr_mask.asm (wave64 fixture); Local review fixture for SHADER-304 (#1841, #1792), wave64: an SGPR pair holding a lane-mask VALUE read as a
; 64-bit lane mask. Lanes 32..63 take their bit from the high register. s[4:5] is a user SGPR input:
; s4 = 0x3ffffc00 (lanes 10..29), s5 = 0x0000ff00 (lanes 40..47).
; word = (set lanes) | (lowest set lane) << 8 over all 64 lanes (s_bcnt1/s_ff1_i32_b64 of the marks).
; out[0] s_mov_b64 s[24:25], 0x3ffffc00 (literal, high word 0); s_and_saveexec_b64 lanes 10..29 20 | 10<<8 = 2580
; out[1] s_mov_b64 s[20:21], s[4:5] (copy of the input); s_and_saveexec_b64 10..29, 40..47 28 | 10<<8 = 2588
; out[2] s_and_saveexec_b64 s[6:7], s[4:5] (the input) 10..29, 40..47 2588
; out[3] s_mov_b64 exec, s[4:5] 10..29, 40..47 2588
; out[4] s_and_b64 exec, exec, s[4:5] 10..29, 40..47 2588
; out[5] s_mov_b32 exec_lo, s4 (exec_hi stays all) 10..29, 32..63 52 | 10<<8 = 2612
; out[6] control: v_cmp_lt_u32 vcc, 20, v0; s_and_saveexec_b64 vcc lanes 21..63 43 | 21<<8 = 5419
; out[7] control: s_mov_b64 s[22:23], vcc (a real mask); s_and_saveexec_b64 lanes 21..63 5419
; group: 64,1,1
; mattr: -wavefrontsize32,+wavefrontsize64
; rsrc2: 0x8090
; Run: VKC_SGPRS=0x3ffffc00,0x0000ff00 vk_compute_test cs_w64_sgpr_mask.spv 1 dump --require-wave64
; -> out[0..7] = 2580 2588 2588 2588 2588 2612 5419 5419
v_mov_b32_e32 v10, 0
v_mov_b32_e32 v11, 0
v_mov_b32_e32 v12, 0
v_mov_b32_e32 v13, 0
v_mov_b32_e32 v14, 0
v_mov_b32_e32 v15, 0
v_mov_b32_e32 v16, 0
v_mov_b32_e32 v17, 0
s_mov_b64 exec, -1
s_mov_b64 s[24:25], 0x3ffffc00
s_and_saveexec_b64 s[6:7], s[24:25]
v_mov_b32_e32 v10, 1
s_mov_b64 exec, -1
s_mov_b64 s[20:21], s[4:5]
s_and_saveexec_b64 s[6:7], s[20:21]
v_mov_b32_e32 v11, 1
s_mov_b64 exec, -1
s_and_saveexec_b64 s[6:7], s[4:5]
v_mov_b32_e32 v12, 1
s_mov_b64 exec, s[4:5]
v_mov_b32_e32 v13, 1
s_mov_b64 exec, -1
s_and_b64 exec, exec, s[4:5]
v_mov_b32_e32 v14, 1
s_mov_b64 exec, -1
s_mov_b32 exec_lo, s4
v_mov_b32_e32 v15, 1
s_mov_b64 exec, -1
v_cmp_lt_u32_e32 vcc, 20, v0
s_and_saveexec_b64 s[6:7], vcc
v_mov_b32_e32 v16, 1
s_mov_b64 exec, -1
v_cmp_lt_u32_e32 vcc, 20, v0
s_mov_b64 s[22:23], vcc
s_and_saveexec_b64 s[6:7], s[22:23]
v_mov_b32_e32 v17, 1
s_mov_b64 exec, -1
v_mov_b32_e32 v20, 0
v_cmp_ne_u32_e32 vcc, 0, v10
s_bcnt1_i32_b64 s30, vcc
s_ff1_i32_b64 s31, vcc
s_lshl_b32 s31, s31, 8
s_or_b32 s30, s30, s31
v_mov_b32_e32 v21, s30
v_cmp_ne_u32_e32 vcc, 0, v11
s_bcnt1_i32_b64 s30, vcc
s_ff1_i32_b64 s31, vcc
s_lshl_b32 s31, s31, 8
s_or_b32 s30, s30, s31
v_mov_b32_e32 v22, s30
v_cmp_ne_u32_e32 vcc, 0, v12
s_bcnt1_i32_b64 s30, vcc
s_ff1_i32_b64 s31, vcc
s_lshl_b32 s31, s31, 8
s_or_b32 s30, s30, s31
v_mov_b32_e32 v23, s30
v_cmp_ne_u32_e32 vcc, 0, v13
s_bcnt1_i32_b64 s30, vcc
s_ff1_i32_b64 s31, vcc
s_lshl_b32 s31, s31, 8
s_or_b32 s30, s30, s31
v_mov_b32_e32 v24, s30
v_cmp_ne_u32_e32 vcc, 0, v14
s_bcnt1_i32_b64 s30, vcc
s_ff1_i32_b64 s31, vcc
s_lshl_b32 s31, s31, 8
s_or_b32 s30, s30, s31
v_mov_b32_e32 v25, s30
v_cmp_ne_u32_e32 vcc, 0, v15
s_bcnt1_i32_b64 s30, vcc
s_ff1_i32_b64 s31, vcc
s_lshl_b32 s31, s31, 8
s_or_b32 s30, s30, s31
v_mov_b32_e32 v26, s30
v_cmp_ne_u32_e32 vcc, 0, v16
s_bcnt1_i32_b64 s30, vcc
s_ff1_i32_b64 s31, vcc
s_lshl_b32 s31, s31, 8
s_or_b32 s30, s30, s31
v_mov_b32_e32 v27, s30
v_cmp_ne_u32_e32 vcc, 0, v17
s_bcnt1_i32_b64 s30, vcc
s_ff1_i32_b64 s31, vcc
s_lshl_b32 s31, s31, 8
s_or_b32 s30, s30, s31
v_mov_b32_e32 v28, s30
v_cmp_eq_u32_e32 vcc, 0, v0
s_and_saveexec_b64 s[6:7], vcc
buffer_store_dword v21, v20, s[0:3], 0 offen
buffer_store_dword v22, v20, s[0:3], 0 offen offset:4
buffer_store_dword v23, v20, s[0:3], 0 offen offset:8
buffer_store_dword v24, v20, s[0:3], 0 offen offset:12
buffer_store_dword v25, v20, s[0:3], 0 offen offset:16
buffer_store_dword v26, v20, s[0:3], 0 offen offset:20
buffer_store_dword v27, v20, s[0:3], 0 offen offset:24
buffer_store_dword v28, v20, s[0:3], 0 offen offset:28
s_endpgmAI-assisted (Claude): the fixtures were written with an assistant; I ran them on my own card. Synthetic programs only, no game files. |
|
Tested First Intel result for this PR. The Intel Windows driver has had EXEC-mask bugs before (#820), so it seemed worth running this change on it. Which fixtures this PR touches. I translated the same 171 GPU-test listings with Runtime built from Full
Compared test by test, all 170 have the same status on both sides, in both modes. Of the 22 changed fixtures the runner has:
CPU at this head: AI-assisted (Claude Code ran the commands; I reviewed the results). |
…32 SOP2 on EXEC) gives each lane its bit s_mov_b32 s20, 0x3ffffc00; s_and_saveexec_b32 s6, s20 left all lanes on: mask_src read the SGPR's raw value, the same non-zero constant in every invocation. The 32-bit bitwise SOP2 ops read constants raw too, so s_and_b32 exec_lo, exec_lo, 0xff00 (inline or in an SGPR) kept every lane, and s_mov_b32 exec_lo, sN did the same. mask_src now takes bit L of an SGPR holds_lane_mask doesn't flag (the high SGPR of a pair for lanes 32-63 in wave64). In wave32, a bitwise SOP2 on masks (EXEC/VCC destination or a mask source) reads both operands through mask_src (sop2_b32_srcs), and s_mov_b32 exec_lo/hi from a non-mask SGPR takes each lane's bit. A real mask is unchanged (0 / ~0 per lane). tests/semantic/test_mask_src_sgpr_const.py covers saveexec, SOP2 on EXEC (inline and SGPR), exec_lo from an SGPR, v_cndmask, a wave64 pair and masks from compares. cf_diff (self-test, 800 runs) and salu_diff (500) pass. docs/design.md row updated.
s_and_b32 s20, exec_lo, 1 put each lane's bit in s20, which lane_masks.py classifies as data when the other operand is a constant, so s_bcnt1 of it counted 32 / 0 instead of 1 (found by @Pierre-Kookis on ItsNotRexed#1792, reproduced on AMD RDNA2 and an RTX 4070 Ti SUPER; main was right). The mask read is now only for an EXEC / VCC destination; into a plain SGPR the op keeps the data read. test_mask_src_sgpr_const.py has the case.
9620edd to
f5fa44f
Compare
|
Overlap note: @Pipodi's #1875 (SHADER-200, claimed at 09:59, before my 14:10 claim) has the same |
# Conflicts: # docs/design.md
…4 mask ballot row The 06451e4 tree had two Wave64 mask ballot rows (the old short one and the PR #2222 superset); the ec8ec4c row dedup merged them into one row but kept three subset sentences from the old row after their supersets: the short lane_masks.py sentence (without the _b64-immediates/#1792 clause), the short s_bcnt/s_ff reconstruct sentence (without the v_mbcnt/mask_half clause), and the short RX 9070 XT GPU-checked sentence (2 test files instead of 4, without the CPU-checked parenthetical). Removing the three subset sentences restores the row byte-identical to the PR #2222 superset row. No code change.
A constant used as a lane mask was taken whole, not one bit per lane, whenever it came through an SGPR or through a 32-bit SOP2 on EXEC. I found it writing #1771's GPU test and posted it as a finding on #1548. Minimal wave32 cases, run in
spirv_wave_interp:s_mov_b32 s20, 0x3ffffc00/s_and_saveexec_b32 s6, s20s_and_b32 exec_lo, exec_lo, 0x0f0f00ff(inline, or via an SGPR)s_mov_b32 s20, C/s_mov_b32 exec_lo, s20s_and_saveexec_b32 s6, 0x3ffffc00ands_mov_b32 exec_lo, <imm>were already right; immediates take bit L inmask_src.Change,
tools/rdna2spirv.py:mask_srctakes bit L of an SGPR thatholds_lane_maskdoesn't flag, as it does for immediates. In a wave64 64-bit context, lanes 32-63 take their bit from the high SGPR of the pair.sop2_b32_srcs: in a wave32 program, a bitwise SOP2 (s_and/or/xor/andn2/orn2/nand/nor/xnor_b32,s_cselect_b32) that writes EXEC/VCC reads both operands throughmask_src. Into a plain SGPR it keepsmain's data read. An earlier head also took the mask read when a source held a mask, and @Pierre-Kookis found on a GPU that this brokes_and_b32 s20, exec_lo, 1; s_bcnt1_i32_b32 s21, s20(32/0 instead of 1); fixed, and now a test. Data ops, and b32 ops in wave64 programs, are unchanged. An operandmask_srcdoesn't model (float literal, M0, ...) falls back to the old raw read.s_mov_b32 exec_lo/exec_hi, sNfrom a non-mask SGPR takes each lane's bit (exec_half_write).Why a real mask is unaffected: the translator keeps 0 or ~0 per lane in a mask register, and bit L of 0 or ~0 is the same 0 or 1. So a mask the analysis didn't flag gives the same result as before.
Checks:
tests/semantic/test_mask_src_sgpr_const.py, 7 tests: saveexec with five constants (via SGPR, equal to the immediate form); SOP2 and/andn2/or/xor on EXEC with an inline and an SGPR constant;exec_lofrom an SGPR;v_cndmaskwith an SGPR mask; a wave64 pair with different halves; masks from compares (wave32/64) unchanged. Without the change, 14 subtests fail.python -I -m unittest discover -s tests/semantic: 1574 tests OK (2 skipped), including the GPU-checked mask fixtures (cs_w32_mask_imm,ps_scc_mask32, ...).tools/cf_diff.py:--self-test, then 400 structured programs × wave32/64 (800 pass) and 200 dispatch-loop × wave32/64 (400 pass).tools/salu_diff.py: 500 programs pass.Overlap with #1875 (@Pipodi, SHADER-200, claimed earlier): it has the same
mask_srccore and more (the wave64v_cndmaskpair, the SHADER-10 tier, GPU tests). Only this PR has the SOP2 on EXEC/VCC and theexec_lofrom SGPR parts. If #1875 lands first, I'll rebase this down to those parts.Overlap with #293 (@simonbronk, SHADER-21 part 1, currently conflicting): it also changes the
exec_lowrite to take bit L, and hasmask_srcread the raw register. That PR handles the other direction, masks read as data. If #293 lands first I'll rebase this onto it.docs/design.md: the "Constant lane masks" row covers SGPR-held constants and the SOP2 case. CPU only; not GPU-verified. No game files.AI-assisted (Claude Code): I reviewed and ran the change and the tests.