Repository navigation
rdna2spirv, lane_masks: handle lane-mask destinations and sources in s_bitset0/1_b32 (SHADER-BITSET32-MASK-AND-DST) - #2355
Conversation
…s_bitset0/1_b32 (SHADER-BITSET32-MASK-AND-DST)
|
The bit-set fix passed all 66 synthetic GPU dispatches on an RTX 4090 at
One case exposes the bug with a single active lane. Lane 0 sets VCC bit 0, then The remaining probes covered setting and clearing EXEC and VCC bits, using either VCC half as the bit-index source, wrapped indices including 32 and 63, and ordinary scalar controls. I checked every output word and the untouched tail of each buffer. All 13 PR modules passed Windows 11, NVIDIA 616.64, Vulkan validation enabled, synthetic shader listings. AI-assisted verification by OpenAI Codex (GPT-6). |
lixonik
left a comment
There was a problem hiding this comment.
Windows 11: 30/30 bitset semantic tests passed, including tracked lane-mask operands and the immediate-bitset cases. No findings.
AI-assisted.
wavehs
left a comment
There was a problem hiding this comment.
macOS arm64 check of #2355 (SHADER-BITSET32-MASK-AND-DST). Translator plus lane_masks.py and one semantic test; the GPU part is MoltenVK/Kosmickrisp.
Tested head 69726d1ce merged onto main bdbc7e923 as merge b56572d3e (clean; branch 21 commits behind, git merge-tree clean).
Environment: Apple M3 Pro, arm64 (subgroups 4..32), macOS 27.2.1, CPython 3.15.2, SPIRV-Tools v2026.4, llvm-mc 23.1.5, MoltenVK 1.4.0; KosmicKrisp and lavapipe = Mesa 26.3.0.
The new test passes, and the control bites
python -I tests/semantic/test_bitset32_mask.py:Ran 8 tests ... OKat the head and after merging ontobdbc7e923; the updatedtests/semantic/test_scalar_alu_imm_bitset.pystill passes.- Negative control (test kept,
tools/rdna2spirv.pyandtools/lane_masks.pyput back tomain's):FAILED (failures=6)- mask bit-index source, wave32vcc_lo+ mask SGPR, wave64 VCC/SGPR halves in native and--wave64-emulate, and the twolane_maskschecks that a mask kind survives. So both the emission and the tracking are pinned.
What I checked in the code
- The mask path updates only the addressed lane:
hit = (SubgroupLocalInvocationId == (S0 & 31) [+32 for a wave64 high half]), thenput_maskwrites 0 / ~0 or keeps the old per-lane bit. The untouched half of a wave64 EXEC/VCC is preserved, and SCC is not written, which matches the row and the ISA. The non-mask path keeps the old bit math, ands_bitset0_b32now shares it withs_bitset1_b32instead of a separate block. - The
lane_masks.stepaddition keeps a mask kind on a mask destination and drops it to data otherwise. - Nit, not a failure: for a wave64
vcc_lo/vcc_hiwrite whenstate["vcc"]is a fullMASK,stepreturns without changing the kind. Native reads go through the live%vcc/%vcc_hi, and the new wave64 test reads the result throughs_bcnt1_i32_b64 vccin both native and--wave64-emulateand passes, so I could not make it stale; a one-line comment saying why the full-mask kind is kept would save the next reader the same detour.
No regressions
- Semantic suite: 500 files / 6,367 tests / 0 failed at
mainbdbc7e923; 501 files / 6,375 tests / 0 failed at the merge (+1 file, +8 tests). - GPU fixtures (268): MoltenVK 195 PASS / 3 FAIL / 70 SKIP, KosmicKrisp 190 / 5 / 73, identical at
mainand the merge after normalising the per-run temp directory; same pre-existing failures (cs_fma_fused,cs_imgatomic_ext,ps_ssharpon MV;cs_bvh,cs_bvh32,cs_imgatomic_ext,ps_cndmask_sign_mods,ps_valu16_mad_selon KK).
Finding
The mask-destination path has no GPU fixture. cs_w32_salu_ext.asm is the only fixture with s_bitset0/1_b32, and it runs them on plain SGPRs (s65, s66); cs_w32_salu64.asm has the _b64 form on scalar pairs. Nothing on a GPU writes a lane mask (exec_lo, vcc_lo/vcc_hi, a mask SGPR) with s_bitset and then counts the mask, so the put_mask/wave_lane half logic rests on the interpreter, which the doc row already says ("not GPU-verified"). Adding four stores to an existing cs_w32_* fixture (mask before, bitset, s_bcnt1, store) would cover it on any GPU, and would catch a wrong half split in wave64 the way cs_w64x_partial_scmp.asm does for compares.
python -I scripts/check_no_game_data.py on the changed files: clean. git diff --check: clean.
No game files. AI-assisted.
tiguan26
left a comment
There was a problem hiding this comment.
Approving 69726d1.
s_bitset0/1_b32 on a lane mask now follows the translator's mask model: a lane holds only its own bit, so setting or clearing bit n changes lane n's value alone (n + 32 for the high half in wave64), and the destination stays a tracked mask in lane_masks.step instead of being dropped to data. On plain data the two ops keep their shift-and-or/and-not form, now in one branch. The updated test_scalar_alu_imm_bitset.py case follows from that: these ops no longer clear mask tracking.
test_bitset32_mask.py 8 passed (4 subtests), test_scalar_alu_imm_bitset.py 17 passed (265 subtests). Merged onto main d1dff7949 together with #2397, #2416 and the other three of this series below (no conflicts), on Linux with Python 3.13. The full translator suite (run_semantic_tests.py tests/semantic) on that tree has only the 8 failures main has here (7 in test_fspx_dot4_op_sel_disasm, test_int32_to_f64), and tests/test_translate.py only main's own ps_sdwa_f16_const.asm (an llvm-mc version difference in this environment). AI-assisted (Claude Code, Claude Opus 5.5).
|
Tested
The failures are the same on both sides (the known ones: #1724, #1518 and #1774 on MoltenVK, #2229's on KosmicKrisp). The translator suite passes with no failures. Evidence: MEASURED, 1 run each. This only shows that nothing changes on Apple drivers. It says nothing about the game. AI-assisted (Claude Code, Claude Opus 5.5). |
timbot103
left a comment
There was a problem hiding this comment.
Verified head 69726d1ce on Windows 11 (semantic suites + dual-GPU control + live translation repros).
The straight-line mask destination/source handling passes its semantic suites (test_bitset32_mask.py 8/8, test_scalar_alu_imm_bitset.py 17/17, test_salu_bitset_b64.py 5/5, test_wave64_emulate_barriers.py 13/13) and cs_w32_salu_ext passes on both RTX 5080 and AMD Radeon.
Blocking finding — missing wave64_emulate_opt.py mask-reader classification causes translation crashes under --wave64-emulate:
s_bitset0_b32 / s_bitset1_b32 now call lane_mask_word for a tracked bit-index operand (including exec_lo and tracked mask SGPRs; tools/rdna2spirv.py:9287-9293), which under --wave64-emulate can invoke x_round and emit a workgroup barrier. However, tools/wave64_emulate_opt.py does not classify s_bitset0_b32 / s_bitset1_b32 as operand-1 mask readers (unlike s_flbit_* at tools/wave64_emulate_opt.py:81-86, 326-335, 1232-1247, 1469-1493). As a result, both the local execz fold and the sync-free multi-wave planner admit blocks containing that exchange, tripping hard translation assertions inside _translate:
- 64-thread
s_cbranch_execzguard (v_cmp_lt_u32_e64lanes 0..15 ->s_and_saveexec_b64->s_cbranch_execz->s_bitset1_b32 s14, exec_lo):- Live repro on
69726d1ce:
AssertionError: wave64 emulation: x_split inside a folded lane-local region(tools/rdna2spirv.py:18985).
- Live repro on
- 128-thread divergent
s_cbranch_scc0guard (v_cmp_eq_u32_e64 s[6:7], v0, 5, wave-0-only branch executings_bitset1_b32 s14, s6):- Live repro on
69726d1ce:
AssertionError: wave64 emulation: unexpected OpControlBarrier in sync-free multi-wave block(tools/rdna2spirv.py:19100).
- Live repro on
Requested fix: Register s_bitset0_b32 and s_bitset1_b32 alongside s_flbit_* for operand-1 mask-reader detection in tools/wave64_emulate_opt.py, and add both guarded --wave64-emulate regressions (single-wave execz fold + 128-thread multi-wave divergent branch).
No game data used. AI-assisted review (Codex static audit + Gemini live verification).
|
#2355 | head The added lane-mask cases failed on main while the pre-existing scalar bitset tests passed on both sides. Pinned main |
|
No unwritten results or changed guard words; zero Khronos validation errors or synchronization hazards. The PR’s eight targeted semantic tests and 17 adjacent scalar tests passed on the merge. The native evidence is for fixed wave64, not wave32 emulation. AI-assisted. |
Item:
SHADER-BITSET32-MASK-AND-DSTProblem
In
tools/rdna2spirv.py,s_bitset0_b32ands_bitset1_b32always appliedold & ~(1 << (b & 31))/old | (1 << (b & 31))directly toself.src_u(a[0])and wrote back viaself.dst(a[0], r), whiletools/lane_masks.pydropped mask tracking fora[0]on both opcodes:a[0]holds a lane mask (vcc_lo/vcc_hiholding a mask, or a mask SGPR tracked bylane_masks.py), each invocation holds only its own lane's bit (0or0xFFFFFFFF), so ORing1 << kturned every inactive lane non-zero (activating all 32 lanes) and ANDing~(1 << k)left the targeted lane non-zero (0xFFFFFFDFetc.).tools/lane_masks.py, mutating a lane mask withs_bitset0/1_b32droppeda[0]fromstate, causing downstream mask consumers (s_bcnt1_i32_b32,s_ff1_i32_b32,s_bcnt1_i32_b64, etc.) to read per-lane0/0xFFFFFFFFas scalar data instead of collecting the wave mask.a[1]holds a lane mask (e.g.s_bitset1_b32 s10, vcc_lo),self.src_u(a[1])read each lane's0/0xFFFFFFFFinstead of the wave's 32-bit mask word, producing divergent per-lane shifts (bit 0 vs bit 31).Fix
tools/lane_masks.py: PreserveMASK/MASK_LO/MASK_HI(and wave64vccmask status forvcc_lo/vcc_hi) whens_bitset0_b32ors_bitset1_b32mutates an existing lane mask; clear tracking to plain data when mutating non-mask orEITHERconstants.tools/rdna2spirv.py: Merges_bitset0_b32ands_bitset1_b32into one handler. Materialize a lane-mask bit-index source viaGen.lane_mask_word. Whenself.holds_lane_mask(a[0]), comparewave_lane()against(b & 31)(or(b & 31) + 32for a wave64 high half) and update only the addressed lane viaGen.put_mask(keeping the untouched half of EXEC/VCC in wave64 and updating%vcc_hiwhena[0]isvcc_hi).docs/design.md: Document thes_bitset0_b32/s_bitset1_b32lane-mask contract row.tests/semantic/test_bitset32_mask.py(and updatedtests/semantic/test_scalar_alu_imm_bitset.pycomment/loop): Add wave32, wave64, and--wave64-emulatetests for EXEC, VCC, mask SGPRs, and lane-mask bit-index sources.Verification
AI-assisted: yes.
Environment: Windows 11, Python 3.12.10, CPU-only (no game files, no
spirv-val, not GPU-verified).python -I tests/semantic/test_bitset32_mask.py -v-> 8/8 OK (wave32, wave64 native,--wave64-emulate)python -I tests/semantic/test_scalar_alu_imm_bitset.py-> 17/17 OKpython -I tests/semantic/test_salu_bitset_b64.py-> 5/5 OKpython -I tests/semantic/test_salu_b32_lane_masks.py-> 8/8 OK (1 skipped:spirv-valabsent)python -I tests/test_lane_masks.py-> OKpython -I tests/test_text_write_line_endings.py-> 3/3 OKpython -m compileall -q tools/rdna2spirv.py tools/lane_masks.py tests/semantic/test_bitset32_mask.py tests/semantic/test_scalar_alu_imm_bitset.py-> 0python -I scripts/check_no_game_data.py ...-> 0git diff --check-> 0origin/mainfbf100b1):tests/semantic/test_bitset32_mask.pyagainstorigin/main'stools/fails 6/8 assertions (test_wave32_vcc_lo_and_mask_sgpr_bitset,test_wave64_vcc_and_mask_sgpr_halves_bitsetnative & emulate,test_lane_mask_bit_index_source_uses_wave_mask_word, and bothLaneMasksBitset32Testspreservation checks).