mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 23:05:53 +01:00
[PR #2121] rdna2spirv: mask v_mbcnt_lo/hi shift count to < 32 to avoid SPIR-V OpShiftLeftLogical UB (SHADER-MBCNT-SHIFT-IN-RANGE) #2126
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#2126
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/2121
Author: @ShotTechOp
Created: 11/25/2026
Status: 🔄 Open
Base:
main← Head:fix/mbcnt-shift-in-range📝 Commits (1)
4d683b6rdna2spirv: mask v_mbcnt_lo/hi shift count to < 32 to avoid SPIR-V UB📊 Changes
2 files changed (+136 additions, -2 deletions)
View changed files
➕
tests/semantic/test_mbcnt_shift_defined.py(+131 -0)📝
tools/rdna2spirv.py(+5 -2)📄 Description
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🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.