Repository navigation
rdna2spirv: handle mixed mask pairs, wave32 VCC, and mask bit indices in s_bitcmp0/1_b32/b64 (SHADER-BITCMP64-MIXED-AND-SPECIAL-SRCS) - #2360
Conversation
… in s_bitcmp0/1_b32/b64 (SHADER-BITCMP64-MIXED-AND-SPECIAL-SRCS)
lixonik
left a comment
There was a problem hiding this comment.
Windows 11: 6/6 targeted bitcmp semantic tests passed with synthetic inputs. These cover mixed SGPR pairs, the wave32 high word, wave64 swapped halves, and a lane-mask bit index. No findings from these checks.
AI-assisted.
|
On an RTX 4090, all 136 synthetic bit-comparison dispatches at
For example, I gave the low half of an SGPR pair a lane mask of The matrix covered mixed mask/data pairs, all-ones and ordinary scalar controls, duplicate and swapped halves, direct VCC operands, and mask-derived indices. I included wave32 FSPX metadata for the full-VCC case. Each lane wrote the results for both bit polarities and both operand widths. All 28,672 output words on the PR matched, the output-buffer guards stayed intact, and all 17 PR modules passed SPIR-V validation for Vulkan 1.2. The six committed CPU semantic tests also passed. Windows 11, NVIDIA 616.64, Vulkan validation enabled. The GPU ran synthetic shader listings through the common parent’s |
wavehs
left a comment
There was a problem hiding this comment.
macOS arm64 check of #2360 (SHADER-BITCMP64-MIXED-AND-SPECIAL-SRCS). Translator-only plus one semantic test; the GPU part is MoltenVK/KosmicKrisp, and it does not reach the changed combinations (see the finding).
Tested head c26efd297 merged onto main bdbc7e923 as merge d59a3d6e6 (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_bitcmp64_mixed_and_special.py:Ran 6 tests ... OKat the head and after merging ontobdbc7e923;tests/semantic/test_scalar_bitcmp.pystill 23/23.- Negative control (test kept,
tools/rdna2spirv.pyput back tomain's):FAILED (failures=6)- lane-mask bit index, wave32(mask, -1), wave32 mixed, wave32 FSPXvcc, and wave64 swapped/mixed in both native and--wave64-emulatesubtests. The unchanged sixth test (test_wave64_bitcmp32_high_half_mask) is the parity guard, as the description says.
What I checked in the code
- The canonical
(MASK_LO, MASK_HI)wave64 pair still goes through onewave_mask; every other SGPR pair materializes each dword (lane_mask_wordfor a tracked word,load_regfor data), so(mask, data),(data, mask), swapped and duplicated pairs become the same uniform 64-bit value in every lane.lane_mask_wordis uniform: forMASK_LO/MASK_HIit returns that word regardless of the lane, which is what a scalar bit index needs. cur_masksonly ever holdsMASK,MASK_LO,MASK_HIorEITHER(tools/lane_masks.py:32-35), so the(r + i) in self.cur_masksmembership test cannot calllane_mask_wordon plain data today. It is a little brittle if a new kind is introduced (the check then means "any tracked kind"), but it is correct now.- Wave32 FSPX
vccbecomes{vcc_hi, vcc_lo}and each word is materialized on its own;src_ualready loads%vcc_hias an ordinary SGPR in wave32 and%vccforvcc_lo, so the split is consistent with the rest of the translator. - The bit-index operand now goes through
lane_mask_wordwhen it is a tracked mask, matching the b32 path.
No regressions
- Semantic suite: 500 files / 6,367 tests / 0 failed at
mainbdbc7e923; 501 files / 6,373 tests / 0 failed at the merge (+1 file, +6 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 GPU fixtures do not exercise this rule at all: the only shader with s_bitcmp is runtime/test/shaders/cs_w32_salu_ext.asm, and it uses s_bitcmp0/1_b32 on plain SGPR data, not _b64 and not a mask/mixed pair. The doc row says "Not yet GPU-verified", which is accurate; all five fixed combinations rest on spirv_mini_interp. A small cs_w64x_bitcmp_mixed.asm (or a few lines added to an existing cs_w64x_* fixture) storing SCC for a (mask, -1) wave32 pair, a swapped wave64 half pair and a mixed pair would give the rule the same kind of hardware check that cs_w64x_partial_scmp.asm gives the compare rules.
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 c26efd2.
s_bitcmp* now reads each half of an SGPR pair as what it holds (a tracked mask word as its mask, data as data) unless the pair is a real lo/hi wave mask, a wave32 vcc operand as its two words, and a lane-mask bit index through lane_mask_word; null, immediates and the 32-bit form keep their paths. wavehs' finding stands as a follow-up rather than a blocker: no GPU fixture reaches these combinations yet, and the doc row says so.
test_bitcmp64_mixed_and_special.py 6 passed (4 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). |
Item ID:
SHADER-BITCMP64-MIXED-AND-SPECIAL-SRCSSummary
Fixes
Gen.bitcmp(s_bitcmp0/1_b32ands_bitcmp0/1_b64) intools/rdna2spirv.pyfor five broken lane-mask operand combinations (matching the per-dword word-materialization model used bys_cmp_eq/lg_u64):s_bitcmp0/1_b64: when one dword ofs[r:r+1]holds a lane mask and the other holds plain scalar data,holds_lane_maskreturnedFalse, so the mask dword was loaded raw (0/0xFFFFFFFFper lane) instead of materializing the wave's 32-bit mask word.(mask, -1)(EITHER) pairs ins_bitcmp0/1_b64:holds_lane_maskreturnedTrueand calledwave_mask(s[r:r+1]), which returned(lo, 0)in wave32 and dropped the high-1word to0.s_bitcmp0/1_b64(e.g.s10 = vcc_hi,s11 = vcc_lo):holds_lane_maskreturnedTrueandwave_maskcollapsed them to canonical(lo, hi). Now only canonical wave64(MASK_LO, MASK_HI)keeps a singlewave_mask; all other SGPR pairs materialize each dword independently (lane_mask_wordwhen tracked as a mask, elseload_reg).s_bitcmp0/1_b64 vcc, bit: in wave32,vccis{vcc_hi, vcc_lo}wherevcc_locan hold a lane mask whilevcc_hiholds scalar data (or a separate mask). Previouslywave_mask(vcc)zeroed bits 32..63; nowvcc_loandvcc_hiare materialized independently.a[1]ons_bitcmp0/1_b32ands_bitcmp0/1_b64: previouslyself.src_u(a[1])read per-lane0/0xFFFFFFFFinstead ofself.lane_mask_word(a[1]).Also simplifies
_b32to useself.lane_mask_word(src0)and replaces the non-mask 64-bit fallbackself.mask_src(src0)withself.src_u(src0). Updates the contract table indocs/design.mdand addstests/semantic/test_bitcmp64_mixed_and_special.py.Verification
spirv_mini_interp; no local GPU/Vulkan/spirv-valinstalled)python -I tests/semantic/test_bitcmp64_mixed_and_special.py -v-> 6/6 OK (wave32, FSPX wave32, native wave64,--wave64-emulate)python -I tests/semantic/test_scalar_bitcmp.py-> 23/23 OKpython -I tests/test_text_write_line_endings.py-> 3/3 OKpython -m compileall -q tools/rdna2spirv.py tests/semantic/test_bitcmp64_mixed_and_special.py-> exit 0python -I scripts/check_no_game_data.py tools/rdna2spirv.py tests/semantic/test_bitcmp64_mixed_and_special.py docs/design.md-> exit 0git diff --check-> cleanorigin/main(tools/extracted fromorigin/main):tests/semantic/test_bitcmp64_mixed_and_special.pyfails 5 of 6 tests (6 failures across wave32, FSPX wave32, native wave64, and--wave64-emulate;test_wave64_bitcmp32_high_half_maskis a parity regression guard).