rdna2spirv: extract per-lane bits when reading plain scalar data in VCC as a lane mask (SHADER-VCC-DATA-MASK-SRC) #1943
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1943"
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-25T16:23:25Z.
Claimed as
SHADER-VCC-DATA-MASK-SRCin #1608.What changed and why
When VCC (
vcc/vcc_lo/vcc_hi) is written as plain scalar data (e.g.s_mov_b32 vcc_lo, K,s_mov_b32 vcc_hi, K, SGPR copies, or scalar ALU/loads) and left uncertified bytools/lane_masks.py, reading it as a lane mask throughGen.mask_src()(v_cndmask_b32,v_add_co_ci_u32,s_*_saveexec_*,s_mov_b32 exec_lo, vcc_lo,s_and_b32 exec_hi, exec_hi, vcc_hi, etc.) was broken in both wave32 and wave64:tools/rdna2spirv.py,Gen.mask_src):_scalar_word_lane_bit()extraction forvcc/vcc_lowas gated onself.wave32_vcc_pointer(only set when the shader hads_load_* ..., vcc).s_mov_b32 vcc_lo, 0x00000002followed byv_cndmask_b32_e64 v6, 3, 5, vcc_loreturned raw0x2instead of bitlane & 31, enabling every lane instead of lane 1 alone.tools/rdna2spirv.py,Gen.mask_src,Gen.mask_dst,Gen.mov64,Gen.put_mask):mask_src()loaded only%vccand returned it raw without loading%vcc_hifor lanes 32..63 or extracting bitlane & 31. Sos_mov_b32 vcc_lo, 0+s_mov_b32 vcc_hi, 0x80000001saw0on all 64 lanes, ands_mov_b32 vcc_lo, 0x2saw non-zero on all 64 lanes.vcc_hiplain-data mask reads (e.g.s_and_b32 exec_hi, exec_hi, vcc_hi) also loaded%vccinstead of%vcc_hi.vcc(mask_dst,mov64, and high-halfput_mask) now mirror this lane's0/~0bit into%vcc_hi(matching howmask_dstalready mirrors SGPR pairs into boths[r]ands[r+1]), so a control-flow join between a certifiedv_cmpmask and a plain-datavcc_lo/vcc_hiwrite (ors_mov_b64 vcc, s[4:5]from uncertified data SGPRs) stays exact on all 64 lanes on every path.Fix:
tools/rdna2spirv.py:Gen.mask_src: whennot self.holds_lane_mask(a)forvcc/vcc_lo/vcc_hi, extract bitlane & 31via_scalar_word_lane_bit()unconditionally (wave32vcc/vcc_lofrom%vcc; wave64 32-bitvcc_hifrom%vcc_hi; wave64 64-bitvccfrom%vccfor lanes 0..31 and%vcc_hifor lanes 32..63, matching the SGPR-pair fallback right above it). Certified masks still load%vccdirectly with zero extra instructions.Gen.mask_dst/Gen.mov64/Gen.put_mask: mirror wave64vccper-lane mask writes into%vcc_hi(wave32%vcc_hiremains untouched as an independent SGPR).docs/design.md: document plain-data VCC lane-bit extraction in theConstant lane masks (Gen.mask_src immediates)contract row.tests/semantic/test_vcc_data_mask_src.py: add wave32, wave64, and--wave64-emulateexecution tests (v_cndmask_b32,v_add_co_ci_u32,s_and_saveexec_b32,s_and_b32 exec_hi, ..., vcc_hi,s_mov_b64 vcc, s[4:5], and wave64 certified-mask/plain-data CFG join), each assembled withtools/spirv_asm.py.Negative control (RED on
origin/mainb0f3d39-> GREEN on this branch)LEONIDA_TOOLS_DIR=<origin/main tools> python -I tests/semantic/test_vcc_data_mask_src.py: FAILED (9 failures across 5 of 6 tests) — wave32vcc_locndmask/carry-in selected all 32 lanes, wave64vcc_lo/vcc_hicndmask (native +--wave64-emulate) and carry-in ignored%vcc_hiand selected all/no lanes, wave64vcc_hihalf-mask read read%vcc, and the wave64 CFG join failed on the plain-data branch.Tests run (Windows 11, Python 3.12.10, CPU / standard library only; no GPU or game files)
python -I tests/semantic/test_vcc_data_mask_src.py -v-> 6/6 OK (alsopython -m unittest discover -s tests/semantic -p test_vcc_data_mask_src.py-> OK)python -I tests/semantic/test_wave64_vcc_half_write.py-> 7/7 OKpython -I tests/semantic/test_wave64_vcc_data_branch.py-> 5/5 OKpython -I tests/semantic/test_vcmp_dst_wave32_vcchi.py-> 7/7 OKpython -I tests/semantic/test_sload_vcc_base.py-> 5/5 OKpython -I tests/semantic/test_control_flow_vcc.py-> 24/24 OKpython -I tests/semantic/test_vcc_tuple_fallback.py-> 5/5 OKpython -I tests/semantic/test_mask_src_sgpr_const.py-> 7/7 OKpython -I tests/semantic/test_salu_b32_lane_masks.py-> 9/9 OK (1 skip)python -I tests/semantic/test_salu64_bitwise_data.py-> 11/11 OKpython -m unittest discover -s tests/semantic -p test_exec_computed.py-> 2/2 OKpython -m unittest discover -s tests/semantic -p test_value_semantics.py-> 41/41 OKpython -I tests/test_lane_masks.py-> OKpython -I tests/test_wint_diff.py-> 29/29 OKpython -I tests/test_text_write_line_endings.py-> 3/3 OKtests/test_docs_*.pysuites + allGroupNonUniformsemantic tests -> OKpython -m compileall -q tools/rdna2spirv.py tests/semantic/test_vcc_data_mask_src.py-> OKpython -I scripts/check_no_game_data.py tools/rdna2spirv.py docs/design.md tests/semantic/test_vcc_data_mask_src.py-> OKgit diff --check-> cleanAI-assisted: yes.
Imported from ubiquitarianism/leonida. Originally posted by efeekrb on 2026-11-25T17:45:18Z.
Tested on an NVIDIA GeForce RTX 4060 Laptop GPU (NVIDIA 610.78), Windows 11 build 26300, with an Intel UHD iGPU also present (
LEONIDA_VK_DEVICE=4060). This PR's diff applies cleanly tomainat24a29f8(where the test programs were built) and tomainatb9320a118(git apply --check).tests/semantic/test_vcc_data_mask_src.pyran 6 tests, OK.run_gpu_tests.py, full suite, with the PR applied: 274/274 shaders translated and pass spirv-val. Native 209/264 passed, 54 skipped, 1 failed;LEONIDA_W64_EMULATE=1243/264 passed, 20 skipped, 1 failed. The one failure iscs_imgatomic_ext(the one #1518 addresses), and the counts are identical tomainat24a29f8without this PR.So no change on this GPU in either mode. The suite shows no regression; it does not tell whether a fixture exercises the rule this PR changes. No game files; counts and pass/fail lines only. AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T12:39:41Z.
Verified on physical gfx906, native subgroup 64 (RADV Mesa 26.0.8), with synchronization validation enabled. Same nine compute shaders and seven inputs against main
d48a957bbandc82d668d0merged with it. With bits 0 and 31 set in the high VCC word only, main selected no lanes; the merge selected exactly lanes 32 and 63. Moving those bits to the low word made main select all 64 lanes; the merge selected only 0 and 31.Matching GPU readbacks went from 36/63 to 63/63 (1,398 wrong data words to zero). This includes carry-in, EXEC high-half reads and both paths of joins between compare-generated masks and plain VCC data. The SGPR-pair move and compare-generated-mask controls passed on both. All 18 modules passed
spirv-val; all guards matched and no shader dispatch reported a validation error or synchronization hazard.AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-29T00:00:33Z.
Tested
c82d668d0merged (no commit) withmainaa918e5d9. Python 3.12.4, Windows 11 10.0.26300, CPU only, withLLVM_MC(conda-forge llvm-tools) and SPIRV-Tools from the Vulkan SDK 1.4.363.1.check_no_game_data.pyis clean.tests/semantic/test_vcc_data_mask_src.py, 6 tests pass.tools/rdna2spirv.pyback tomain, it fails (plain VCC data read as a lane mask: the lanes keep9where1is expected).Overlap check across #1973, #1977, #1990, #1943, #1994, #1996 and #1803 (same translator area):
s_wqm, #1990 forsrc64_data/is_mask_op;s_movintoexec_hi, #1996 form0/scc;docs/design.md, between #1990, #1943 and #1994.main(docs/design.mdtaken frommain), each PR's own test file passes. The full semantic suite (scripts/run_semantic_tests.py tests/semantic -j 4, 528 files, 6513 tests) fails in 2 files:test_valu_cvt_f16_int16_mods, which fails on plainmaintoo;test_wave64_emulate_opt, which comes from #1990 alone (see #1990).No blocker from my side.
AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-29T00:13:16Z.
Merged after TheGeogeo's red/green check (check) (Windows, Python tests, no GPU needed) and a local re-check here. Merged after local re-verification: this PR merged onto
maine81999180without conflict, and its test file(s) (tests/semantic/test_vcc_data_mask_src.py) pass there. Earlier today the same tests failed onmainwithout the PR (red/green) and a bundle with other open PRs showed no new failures.check_no_game_data.pyis clean. Windows 11, Python 3.14; no GPU needed for these tests.AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes.