mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 21:50:52 +01:00
[PR #1949] rdna2spirv: decline SDWA-selected or sext() operands in Gen.imm_val (SHADER-SDWA-IMM-VAL) #1957
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#1957
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/1949
Author: @ShotTechOp
Created: 11/25/2026
Status: 🔄 Open
Base:
main← Head:fix/sdwa-imm-val📝 Commits (1)
b73b4b2rdna2spirv: decline SDWA-selected or sext() operands in Gen.imm_val (SHADER-SDWA-IMM-VAL)📊 Changes
3 files changed (+134 additions, -5 deletions)
View changed files
📝
docs/design.md(+1 -1)➕
tests/semantic/test_sdwa_shift_const_sel.py(+129 -0)📝
tools/rdna2spirv.py(+4 -4)📄 Description
Claimed as
SHADER-SDWA-IMM-VALin #1608.What changed and why
Gen.imm_val()intools/rdna2spirv.pyreturned the raw 32-bit integer value of an inline immediate or seeded SGPR constant without checking whether the operand carried an SDWA sub-dword select (sdwa_selother thanDWORD) orsext().As a result,
SHIFT_REV(v_lshlrev_b32_sdwa,v_lshrrev_b32_sdwa,v_ashrrev_i32_sdwa) constant-folded the unselected 32-bit shift amount instead of routing throughsrc_u()->sdwa_src()(tools/sdwa_diff.pyshift-const-sel):v_lshlrev_b32_sdwa v2, 2, 64 dst_sel:BYTE_0 dst_unused:UNUSED_PRESERVE src0_sel:BYTE_3 src1_sel:WORD_0:BYTE_3(2) = 0, so hardware computes0x80000040, whilemainshifted by2and produced0x80000000.v_lshrrev_b32_sdwa v2, -16, v2 ... src0_sel:BYTE_1:BYTE_1(0xFFFFFFF0) = 0xFF(& 31 = 31), whilemainshifted by-16 & 31 = 16.s_mov_b32 s4, 0x05040300+v_lshlrev_b32_sdwa v1, s4, v1 ... src0_sel:BYTE_1):BYTE_1 = 3, whilemainshifted bys4 & 31 = 0.Fix:
tools/rdna2spirv.py:Gen.imm_val(): returnNonewhena.get("sext")ora.get("sdwa_sel", "DWORD") != "DWORD"(matching how it already declinesabs/neg), so callers fall back tosrc_u()->sdwa_src()while preserving constant folding for plainDWORDoperands."sdwa_sel" in a[...]checks inv_bfi_b32andv_bfm_b32.docs/design.md: note theGen.imm_valSDWA guard in theSDWAcontract row.tests/semantic/test_sdwa_shift_const_sel.py: add semantic execution +spirv_asm.assemble+sdwa_diff.referencecross-check tests for inline constants, negative inline constants, seeded SGPRs,BYTE_0..3/WORD_0..1/DWORD, andsext()across all three_sdwashift ops.(Note:
tools/sdwa_diff.pyis intentionally untouched to avoid conflicting with open PR #1653.)Negative control (RED on
origin/mainb0f3d39-> GREEN on this branch)LEONIDA_TOOLS_DIR=<origin/main tools> python -I tests/semantic/test_sdwa_shift_const_sel.py: FAILED (5 failures across all 3 tests) — inline shifts returned[0x80000000, 0x8000, 0xFFFF8000, 0x80]instead of[0x80000040, 1, 0xFFFFFFFF, 0x80], SGPR shifts returned[1, 256, 0x80000000, 3]instead of[8, 16, 0xFC000000, 6], and all 3sdwa_diff.referencecases mismatched.python -I tools/sdwa_diff.py --known --ops v_lshlrev_b32,v_lshrrev_b32,v_ashrrev_i32 --programs 30 --seed 1onorigin/main: 28 pass, 2 mismatch (exit 1).test_sdwa_shift_const_sel.py, and 100 pass, 0 mismatch, 0 skipped intools/sdwa_diff.py --known --ops v_lshlrev_b32,v_lshrrev_b32,v_ashrrev_i32 --programs 100 --seed 1.Tests run (Windows 11, Python 3.12.10, CPU / standard library only; no GPU or game files)
python -I tests/semantic/test_sdwa_shift_const_sel.py -v-> 3/3 OK (alsopython -m unittest discover -s tests/semantic -p test_sdwa_shift_const_sel.py-> OK)python -I tools/sdwa_diff.py --known --ops v_lshlrev_b32,v_lshrrev_b32,v_ashrrev_i32 --programs 100 --seed 1-> 100 pass, 0 mismatch, 0 skippedpython -I tests/semantic/test_alu_sdwa_hw.py-> OKpython -I tests/semantic/test_sdwa_carry.py-> OKpython -I tests/test_sdwa_diff.py-> OKtests/test_docs_*.pysuites -> 12/12 OKpython -m compileall -q tools/rdna2spirv.py tests/semantic/test_sdwa_shift_const_sel.py-> OKpython -I scripts/check_no_game_data.py tools/rdna2spirv.py docs/design.md tests/semantic/test_sdwa_shift_const_sel.py-> OKgit diff --check-> cleanAI-assisted: yes.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.