Repository navigation
rdna2spirv: mask v_mbcnt_lo/hi shift count to < 32 to avoid SPIR-V OpShiftLeftLogical UB (SHADER-MBCNT-SHIFT-IN-RANGE) - #2121
Conversation
|
I checked
I set the wave-size bit in each synthetic FSSM header, checked the generated index and pinned the Vulkan subgroup to 32. Five input sets included empty and full masks, isolated high bits, alternating masks and an accumulator that wraps. Each active thread wrote its result to a distinct buffer word. The CPU reference counted set bits strictly below that lane in each logical wave. One detail for the test description: the PR's high-half interpreter case translates a wave64 shader and runs it with 32 and 64 interpreter lanes. The translator currently treats AI-assisted with OpenAI Codex ( |
|
Checked at
Looks right to me. AI-assisted (Claude Code). |
|
Tested
The counts are identical to AI-assisted (Claude Code). No game data. |
Claimed in #1608 as
SHADER-MBCNT-SHIFT-IN-RANGE.What and why
tools/rdna2spirv.py(v_mbcnt_lo_u32_b32,v_mbcnt_hi_u32_b32), the lowering emitted:OpShiftLeftLogical), the result is undefined wheneverShift >= 32, even when the shifted value sits on the unselected side ofOpSelect(the same SPIR-V ruletools/rdna2spirv.pyalready guards against inv_perm_b32,v_alignbit_b32,v_alignbyte_b32,fmt_dec_component, andbuffer_load_format).v_mbcnt_lo_u32_b32in wave64, lanes32..63hadrel = 32..63 >= 32.v_mbcnt_hi_u32_b32in both wave32 and wave64, lanes0..31hadrel = lane - 32 = 0xFFFFFFE0..0xFFFFFFFF >= 32.spirv_wave_interp, this produced_Poison("OpShiftLeftLogical by ... >= 32")in 32 lanes of every wave.relwith31(OpBitwiseAnd %uint %rel %c31) beforeOpShiftLeftLogicalis an identity wheneverinrangeis true (0 <= rel <= 31) and keeps everyOpShiftLeftLogicalshift operand strictly< 32on all lanes.Testing
tests/semantic/test_mbcnt_shift_defined.py— executes translatedv_mbcnt_lo_u32_b32andv_mbcnt_hi_u32_b32in wave32 and wave64 (plain scalar masks and lane-maskvcc, plus paired wave64 thread-rank) onspirv_wave_interp._Waveand asserts both exact per-lane outputs and zero_Poisonvalues across all lanes.origin/main:tests/semantic/test_mbcnt_shift_defined.pyfails onorigin/mainwithFAILED (failures=4)(_Poison('OpShiftLeftLogical by 32 >= 32')/_Poison('OpShiftLeftLogical by 4294967264 >= 32')across 32 lanes per wave).python -I tests/semantic/test_mbcnt_shift_defined.py -v(3/3 OK)python -m unittest discover -s tests/semantic -p test_mbcnt_lo_hi.py(28/28 OK)python -I tests/test_text_write_line_endings.py(3/3 OK)python -m compileall -q tools/rdna2spirv.py tests/semantic/test_mbcnt_shift_defined.pypython -I scripts/check_no_game_data.py tools/rdna2spirv.py tests/semantic/test_mbcnt_shift_defined.pygit diff --check