Skip to content

rdna2spirv: a constant used as a lane mask through an SGPR (or a b32 SOP2 on EXEC) gives each lane its bit - #1792

Merged
ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
LouisRiverstone:mask-src-sgpr-const
Nov 22, 2026
Merged

ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
LouisRiverstone:mask-src-sgpr-const

Conversation

@LouisRiverstone

@LouisRiverstone LouisRiverstone commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

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:

code hardware before
s_mov_b32 s20, 0x3ffffc00 / s_and_saveexec_b32 s6, s20 lanes 10..29 all 32 lanes
s_and_b32 exec_lo, exec_lo, 0x0f0f00ff (inline, or via an SGPR) the constant's 12 lanes all 32
s_mov_b32 s20, C / s_mov_b32 exec_lo, s20 C's lanes every lane, for any non-zero C

s_and_saveexec_b32 s6, 0x3ffffc00 and s_mov_b32 exec_lo, <imm> were already right; immediates take bit L in mask_src.

Change, tools/rdna2spirv.py:

  • mask_src takes bit L of an SGPR that holds_lane_mask doesn'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 through mask_src. Into a plain SGPR it keeps main'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 broke s_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 operand mask_src doesn't model (float literal, M0, ...) falls back to the old raw read.
  • s_mov_b32 exec_lo/exec_hi, sN from 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_lo from an SGPR; v_cndmask with 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_src core and more (the wave64 v_cndmask pair, the SHADER-10 tier, GPU tests). Only this PR has the SOP2 on EXEC/VCC and the exec_lo from 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_lo write to take bit L, and has mask_src read 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.

@Pierre-Kookis

Copy link
Copy Markdown

A regression in the b32 SOP2 on EXEC path, reproduced on GPU at fc8d5ad1; main 89b047c gets it right. An s_and_b32 of exec_lo with a constant now gives a per-lane mask, but the result is then read as plain data by s_bcnt1_i32_b32.

Hand-written wave32 compute listing (not part of the PR), all 32 lanes active, run with vk_compute_test ... 1 dump:

s_and_b32 s20, exec_lo, 1
s_bcnt1_i32_b32 s21, s20          ; ISA: s20 = 1, s21 = 1
s_and_b32 s22, exec_lo, 0xff00
s_bcnt1_i32_b32 s23, s22          ; ISA: s22 = 0xff00, s23 = 8
v_mov_b32_e32 v1, s21
v_mov_b32_e32 v2, s23             ; both stored per lane
lane 0 (s21, s23) lanes 1..31 (s21, s23)
main 89b047cd 1, 8 1, 8
this PR fc8d5ad1 32, 0 0, 0

Same words on an AMD Radeon RDNA2 iGPU (Windows driver 32.0.21043.5001) and an RTX 4070 Ti SUPER (Windows).

The new path (tools/rdna2spirv.py ~2989) stores the lane's own bit (0 / ~0 per lane) into s20, but tools/lane_masks.py (~149-152) clears s20's mask classification when the other operand is a constant. s_bcnt1 then takes the plain-data OpBitCount path on a per-lane value. Either keep s20 classified as a mask after this op, or produce the wave's word, as main does.

Otherwise:

  • GPU suite: AMD 152/166 passed (14 skipped), NV 127/166 (39 skipped), NV emulated 158/166 (8 skipped), 0 FAIL.
  • tests/semantic/test_mask_src_sgpr_const.py: 6 passed.

(AI-assisted: first flagged by a second model's code read, then reproduced on both GPUs. Synthetic listing, no game files.)

@LouisRiverstone

Copy link
Copy Markdown
Contributor Author

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 main. sop2_b32_srcs now uses the mask read only when the destination is EXEC / VCC (the case this PR is for: s_and_b32 exec_lo, exec_lo, <const>); into a plain SGPR, which lane_masks.py calls data when the other operand is a constant, the op keeps main's data read. Your listing is now MaskAndConstantIntoAnSgpr in test_mask_src_sgpr_const.py (fails on the previous head). Suite 1574 OK; cf_diff 600 runs and salu_diff 500 programs pass. The design row says it too.

LouisRiverstone added a commit to LouisRiverstone/Leonida that referenced this pull request Nov 22, 2026
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.
@Impre-visible

Copy link
Copy Markdown

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 s21 | s23 << 8, run with vk_compute_test ... 1 dump:

s_and_b32 s20, exec_lo, 1
s_bcnt1_i32_b32 s21, s20          ; ISA: s21 = 1
s_and_b32 s22, exec_lo, 0xff00
s_bcnt1_i32_b32 s23, s22          ; ISA: s23 = 8
lanes 0..7 (the dumped words)
this PR 9620edd2 0x801 in every lane (s21 = 1, s23 = 8)
main 99f99890 0x801 in every lane

The rest, native build of runtime/ from this head, llvm-mc 23.1.5, SPIRV-Tools v2026.4:

  • every module test_mask_src_sgpr_const.py translates, also run through spirv-as + spirv-val: 24 distinct modules, 24 pass; its 7 tests are OK
  • tests/semantic: 1574 OK
  • build.py: 182 translated, 182 pass spirv-val; check.py: 119 of 154 pass, 35 skipped
  • run_gpu_tests.py: 175/175 translated and pass spirv-val; 130/170 passed, 40 skipped, 0 failed; with LEONIDA_W64_EMULATE=1: 161/170 passed, 9 skipped (8 fixtures run by the d3d12 tests, 1 needs a 64-wide fragment subgroup), 0 failed

AI-assisted run (Claude). Synthetic programs only, no game files involved.

@lyricalfrog3

Copy link
Copy Markdown

Tested 9620edd2 on AMD Radeon RX 6700 XT (gfx1031, RDNA2, RADV NAVI22, subgroup 32..64), Mesa 26.1.6-1, Debian 13 (kernel 7.3.4); llvm-mc 21.1.8, SPIRV-Tools 2026.4; harness vk_compute_test built from main 003e7812: pass, wave32 and native wave64.

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 exec_lo) read as a lane mask, with two compare-mask controls. This PR gives the expected EXEC in every case, including the wave64 cases where lanes 32..63 take their bit from the pair's high register, which run here without emulation. Compared with main and with #1841 on the same fixtures (details there, #1841 fixes only the literal case):

wave32, VKC_SGPRS=0x3ffffc00:

word where the mask value comes from expected (lanes) main 003e7812 #1841 03f93c7c #1792 9620edd2
0 s_mov_b32 s20, 0x3ffffc00 (literal), s_and_saveexec_b32 s7, s20 2580 (10..29) 32 2580 2580
1 s_and_saveexec_b32 s7, s4, s4 a user SGPR input 2580 32 32 2580
2 s_mov_b32 exec_lo, s4 2580 32 32 2580
3 s_mov_b32 s21, s4 (copy of the input), EXEC=0, s_or_saveexec_b32 s7, s21 2580 32 32 2580
4 s_lshl_b32 s22, s4, 1 (computed, 0x7ffff800), s_and_saveexec_b32 2836 (11..30) 32 32 2836
5 s_and_b32 exec_lo, exec_lo, s4 2580 32 32 2580
6 control: v_cmp_gt_u32 vcc_lo, 16, v0, saveexec on vcc_lo 16 (0..15) 16 16 16
7 control: that compare copied to s23, saveexec on s23 16 16 16 16

wave64, native 64-wide subgroup, VKC_SGPRS=0x3ffffc00,0x0000ff00:

word where the mask value comes from expected main #1841 #1792
0 s_mov_b64 s[24:25], 0x3ffffc00 (literal), s_and_saveexec_b64 2580 (10..29) 64 2580 2580
1 s_mov_b64 s[20:21], s[4:5] (copy of the input), s_and_saveexec_b64 2588 (10..29, 40..47) 64 64 2588
2 s_and_saveexec_b64 s[6:7], s[4:5] 2588 64 64 2588
3 s_mov_b64 exec, s[4:5] 2588 64 64 2588
4 s_and_b64 exec, exec, s[4:5] 2588 64 64 2588
5 s_mov_b32 exec_lo, s4 (exec_hi stays all) 2612 (10..29, 32..63) 64 64 2612
6, 7 controls: v_cmp_lt_u32 vcc, 20, v0, directly and copied to s[22:23] 5419 (21..63) 5419 5419 5419

Each word is (lanes left on) | (lowest lane) << 8 of the EXEC a case produces (from s_bcnt1/s_ff1 of VALU marks, as in cs_w32_mask_imm.asm); 32 or 64 means every lane. The GPU readback on the RX 6700 XT matches the repo's CPU interpreter (spirv_mini_interp.run_workgroup) word for word for all three translators, wave32 (VKC_SUBGROUP_SIZE=32) and native wave64 (--require-wave64, compute subgroup size 64).

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_endpgm
cs_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_endpgm

AI-assisted (Claude): the fixtures were written with an assistant; I ran them on my own card. Synthetic programs only, no game files.

@Bladureau

Copy link
Copy Markdown

Tested 9620edd2 (on main 003e7812, so including the sop2_b32_srcs fix for @Pierre-Kookis's report) on Intel UHD Graphics (Raptor Lake, "Intel(R) RaptorLake-S Mobile Graphics Controller", subgroup 8..32), driver 101.7092, Vulkan 1.4.323, Windows 11 Pro (build 26300): pass, no regression.

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 main's and this PR's tools/rdna2spirv.py and compared the .spv files. 23 change, natively and with --wave64-emulate: cs_global_neg_offset, cs_imgload, cs_imgload_d16, cs_sample_lz_int_d16, cs_w32_mask_imm, cs_w32_permute, cs_w64_mask_imm, cs_w64x_andn2_exec, cs_w64x_ballot, cs_w64x_load_ballot_load, cs_w64x_mask_reuse2, cs_w64x_permute, cs_w64x_saveexec_b64, cs_wavemask, ps_cmp_nlg, ps_gather_wrap, ps_scc_mask32, ps_scc_minmax, ps_sdwa, ps_texoff, ps_texoff_implicit, ps_wqm, and cs_bench_mix (not part of the runner). For these listings the SPIR-V is the same at 9620edd2 as at the previous head 6275ccc6. All 171 translate and pass spirv-val on both sides.

Runtime built from 003e7812 (scripts\build_runtime.ps1, MSVC 19.52) and used for both sides; the PR changes no C++. llvm-mc 23.1.6 (AMDGPU), SPIRV-Tools v2026.4. Driver selected with VK_LOADER_DRIVERS_SELECT=igvk*.

Full scripts/run_gpu_tests.py, main alone vs main + this PR:

Mode main 003e7812 this PR
Normal 115/170 passed, 55 skipped, 0 failed 115/170 passed, 55 skipped, 0 failed
LEONIDA_W64_EMULATE=1 145/170 passed, 25 skipped, 0 failed 145/170 passed, 25 skipped, 0 failed

Compared test by test, all 170 have the same status on both sides, in both modes. Of the 22 changed fixtures the runner has:

  • emulated: 19 run and PASS. ps_scc_mask32, ps_texoff and ps_texoff_implicit skip (no VK_KHR_fragment_shader_barycentric / VK_KHR_maintenance8 here).
  • normal: 11 run and PASS (cs_global_neg_offset, cs_imgload, cs_imgload_d16, cs_sample_lz_int_d16, cs_w32_mask_imm, cs_w32_permute, ps_cmp_nlg, ps_gather_wrap, ps_scc_minmax, ps_sdwa, ps_wqm). The wave64 ones skip: no 64-wide subgroup.

CPU at this head: python -m unittest discover -s tests/semantic 1574 OK. test_mask_src_sgpr_const.py gives 7 OK, and 14 failures when run against main's translator, so it does test the change. compileall OK.

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

Copy link
Copy Markdown
Contributor Author

Overlap note: @Pipodi's #1875 (SHADER-200, claimed at 09:59, before my 14:10 claim) has the same mask_src core: bit L of a non-mask SGPR, the high SGPR for lanes 32-63, plus the wave64 v_cndmask pair read, the SHADER-10 tier, GPU tests and corpus counts. Its plan works for me. If #1875 lands first, I will rebase this PR down to the parts it lacks: sop2_b32_srcs (32-bit SOP2 into EXEC/VCC with a constant, with @Pierre-Kookis's fix), s_mov_b32 exec_lo/exec_hi, sN, and the tests for them. If this lands first, #1875 keeps the rest, as its description says.

ItsNotRexed added a commit that referenced this pull request Nov 22, 2026
# Conflicts:
#	docs/design.md
@ItsNotRexed
ItsNotRexed merged commit fd936d2 into ItsNotRexed:main Nov 22, 2026
10 of 11 checks passed
ItsNotRexed pushed a commit that referenced this pull request Nov 22, 2026
…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.
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