rdna2spirv, lane_masks: handle lane-mask destinations and sources in s_bitset0/1_b32 (SHADER-BITSET32-MASK-AND-DST) #2355
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2355"
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?
Imported from ubiquitarianism/leonida. Originally posted by ShotTechOp on 2026-11-26T15:06:03Z.
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).Imported from ubiquitarianism/leonida. Originally posted by ecox982745 on 2026-11-26T15:19:52Z.
The bit-set fix passed all 66 synthetic GPU dispatches on an RTX 4090 at
69726d1ce. The same inputs matched the CPU reference in 23 of 66 dispatches on parentfbf100b1b.One case exposes the bug with a single active lane. Lane 0 sets VCC bit 0, then
s_mov_b32 s10, vcc_losaves the word1. Afters_bitset1_b32 s10, s10, the word should be3and its population count should be2in every lane. The parent returned32in lane 0 and1in lane 1. The PR returned2in all 32 lanes. The corresponding saved-high-half cases also passed in wave64 emulation.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
spirv-val --target-env vulkan1.2. The eight committed CPU tests also passed.Windows 11, NVIDIA 616.64, Vulkan validation enabled, synthetic shader listings. AI-assisted verification by OpenAI Codex (GPT-6).
Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-26T15:37:20Z.
Review: COMMENTED
Windows 11: 30/30 bitset semantic tests passed, including tracked lane-mask operands and the immediate-bitset cases. No findings.
AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by wavehs on 2026-11-26T18:26:55Z.
Review: COMMENTED
macOS arm64 check of #2355 (SHADER-BITSET32-MASK-AND-DST). Translator plus
lane_masks.pyand one semantic test; the GPU part is MoltenVK/Kosmickrisp.Tested head
69726d1cemerged ontomainbdbc7e923as mergeb56572d3e(clean; branch 21 commits behind,git merge-treeclean).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.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
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.lane_masks.stepaddition keeps a mask kind on a mask destination and drops it to data otherwise.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
mainbdbc7e923; 501 files / 6,375 tests / 0 failed at the merge (+1 file, +8 tests).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.asmis the only fixture withs_bitset0/1_b32, and it runs them on plain SGPRs (s65,s66);cs_w32_salu64.asmhas the_b64form on scalar pairs. Nothing on a GPU writes a lane mask (exec_lo,vcc_lo/vcc_hi, a mask SGPR) withs_bitsetand then counts the mask, so theput_mask/wave_lanehalf logic rests on the interpreter, which the doc row already says ("not GPU-verified"). Adding four stores to an existingcs_w32_*fixture (mask before, bitset,s_bcnt1, store) would cover it on any GPU, and would catch a wrong half split in wave64 the waycs_w64x_partial_scmp.asmdoes for compares.python -I scripts/check_no_game_data.pyon the changed files: clean.git diff --check: clean.No game files. AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by tiguan26 on 2026-11-27T04:46:24Z.
Review: APPROVED
Approving
69726d1ce.s_bitset0/1_b32on 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 inlane_masks.stepinstead of being dropped to data. On plain data the two ops keep their shift-and-or/and-not form, now in one branch. The updatedtest_scalar_alu_imm_bitset.pycase follows from that: these ops no longer clear mask tracking.test_bitset32_mask.py8 passed (4 subtests),test_scalar_alu_imm_bitset.py17 passed (265 subtests). Merged ontomaind1dff7949together 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 failuresmainhas here (7 intest_fspx_dot4_op_sel_disasm,test_int32_to_f64), andtests/test_translate.pyonlymain's ownps_sdwa_f16_const.asm(an llvm-mc version difference in this environment). AI-assisted (Claude Code, Claude Opus 5.5).Imported from ubiquitarianism/leonida. Originally posted by Tauwni on 2026-11-27T15:37:02Z.
Tested
69726d1cemerged ontomainec91d695con a Mac (profile S), where wave64 is always emulated on 32-wide subgroups: Apple M3, macOS 26.5.1, MoltenVK 1.4.2, KosmicKrisp and llvmpipe (Mesa 26.3.1). No game files.scripts/run_gpu_tests.py, auto mode, test programs frommain:mainmain+ this PRLEONIDA_W64_EMULATE=1The 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).
Imported from ubiquitarianism/leonida. Originally posted by timbot103 on 2026-11-28T03:21:01Z.
Review: CHANGES_REQUESTED
Verified head
69726d1ceon Windows 11 (semantic suites + dual-GPU control + live translation repros).The straight-line mask destination/source handling passes its semantic suites (
test_bitset32_mask.py8/8,test_scalar_alu_imm_bitset.py17/17,test_salu_bitset_b64.py5/5,test_wave64_emulate_barriers.py13/13) andcs_w32_salu_extpasses on both RTX 5080 and AMD Radeon.Blocking finding — missing
wave64_emulate_opt.pymask-reader classification causes translation crashes under--wave64-emulate:s_bitset0_b32/s_bitset1_b32now calllane_mask_wordfor a tracked bit-index operand (includingexec_loand tracked mask SGPRs;tools/rdna2spirv.py:9287-9293), which under--wave64-emulatecan invokex_roundand emit a workgroup barrier. However,tools/wave64_emulate_opt.pydoes not classifys_bitset0_b32/s_bitset1_b32as operand-1 mask readers (unlikes_flbit_*attools/wave64_emulate_opt.py:81-86, 326-335, 1232-1247, 1469-1493). As a result, both the localexeczfold and the sync-free multi-wave planner admit blocks containing that exchange, tripping hard translation assertions inside_translate:s_cbranch_execzguard (v_cmp_lt_u32_e64lanes 0..15 ->s_and_saveexec_b64->s_cbranch_execz->s_bitset1_b32 s14, exec_lo):69726d1ce:AssertionError: wave64 emulation: x_split inside a folded lane-local region(tools/rdna2spirv.py:18985).s_cbranch_scc0guard (v_cmp_eq_u32_e64 s[6:7], v0, 5, wave-0-only branch executings_bitset1_b32 s14, s6):69726d1ce:AssertionError: wave64 emulation: unexpected OpControlBarrier in sync-free multi-wave block(tools/rdna2spirv.py:19100).Requested fix: Register
s_bitset0_b32ands_bitset1_b32alongsides_flbit_*for operand-1 mask-reader detection intools/wave64_emulate_opt.py, and add both guarded--wave64-emulateregressions (single-waveexeczfold + 128-thread multi-wave divergent branch).No game data used. AI-assisted review (Codex static audit + Gemini live verification).
Imported from ubiquitarianism/leonida. Originally posted by sodove on 2026-11-28T09:15:40Z.
#2355 | head
69726d1ceca0b8579023c6aaf7bab95ed29891b0|python3 -I tests/semantic/test_bitset32_mask.py -v,python3 -I tests/semantic/test_scalar_alu_imm_bitset.py -v| red: 25 tests, 6 assertion failures | green: 25 passed | Red → greenThe added lane-mask cases failed on main while the pre-existing scalar bitset tests passed on both sides.
Pinned main
4938673668d807bf365b61284bf22b1ff8d02cc4, merged into the PR head. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Full suite: not run. AI-assisted: OpenAI Codex. Batch claim.Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T11:18:22Z.
VERIFY-2355-VEGA20-RADV: five synthetic compute fixtures, same inputs and independent per-lane integer reference on2d4735682and on its merge with69726d1ce. Both sets of modules dispatched on physical gfx906 / RADV Mesa 26.0.8, native subgroup 64. Main returned 685 wrong words out of 1,920; the merge returned 0/1,920 wrong.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.
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T19:49:16Z.
Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS, Python 3.12.16, spirv-tools + llvm-mc, main
0e8737f2a(merges cleanly; does not force a rebase of #2566 atcfd12b24f), PR head69726d1ce: green 8 OK, 0 skipped — but an open CHANGES_REQUESTEDtest_bitset32_mask.py2/8, 6 failures. Green: 8/8, 0 skipped.test_scalar_alu_imm_bitset.py17/17 on both sides (not discriminating).scripts/run_semantic_tests.py tests/semantic) and the CI translator-tests pytest selection on main and on the merge: identical to main (main: onlytest_interp_computed_ij_fallbackx2; translator-tests 2047 OK / 19 skipped). No new failure.docs/design.mdrow is added; no.asmfixture.tools/wave64_emulate_opt.pydoes not classifys_bitset0/1_b32as mask readers on operand 1, giving two AssertionErrors under--wave64-emulate("x_split inside a folded lane-local region", "unexpected OpControlBarrier"); fix + two regression tests requested. Not addressed yet (I did not reproduce that case).Gen.put_maskand the index source throughlane_mask_word. No game data.Verdict: not mergeable until the CHANGES_REQUESTED is addressed (local tests all green).
AI-assisted: Claude Code
Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-11-30T17:36:23Z.
Independent check on Windows (not the author), at
69726d1ce.tests/semantic/test_bitset32_mask.py: 8 tests OKtests/semantic/test_scalar_alu_imm_bitset.py: 17 tests OKEnvironment: Windows 11 Pro 10.0.26200.9711, Python 3.12.10, llvm-mc 21.1.8.
AI-assisted: yes (opencode).
Imported from ubiquitarianism/leonida. Originally posted by kurrutako on 2026-12-01T10:46:56Z.
Tested locally on Windows 11 with Python 3.14 and SPIRV-Tools from Vulkan SDK 1.4.363.
On the PR head
tests/semantic/test_bitset32_mask.py: 8/8 pass on69726d1.cd73ddawith only that test file copied in: 6 failures across 5 tests, so the test catches the bug.Merged into current main locally
scripts/run_semantic_tests.py tests/semantic: 554 files, 0 failed.test_feature_scanatomic-write tests) fail on this machine on plain main too.CI
vk_null_descriptor_testbuild in linux-gpu-tools;Behaviour change in the edited test:
test_scalar_alu_imm_bitset.pyno longer asserts thats_bitset0/1_b32on a mask SGPR clears lane-mask tracking. This is intended.AI-assisted (Claude Code)
Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T11:43:22Z.
Review: APPROVED
Reviewed the diff against
main:tools/lane_masks.py:271-279andtools/rdna2spirv.py:9287-9325cleanly preserve lane-mask tracking and update only the addressed lane bit (preserving the untouched wave64 half) fors_bitset0_b32/s_bitset1_b32while materializing lane-mask bit-index sources vialane_mask_word, with thorough tests intests/semantic/test_bitset32_mask.pyanddocs/design.mdupdated. Clean-room verified. Approving; please merge/rebase currentmainso CI runs green before merge.(AI-assisted review.)