shader: lower SDWA moves and half widening in pixel_aot #324
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/329"
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 R0Y00/Xbox2Windows. Originally posted by Its3rr0rsWRLD on 2026-11-21T22:20:08Z.
Change
pixel_aotrefused every SDWA instruction. This lowers the SDWA forms ofv_mov_b32andv_cvt_f32_f16, which shaders use to unpack bytes and halves. It also addssdwa_sourceandsdwa_desthelpers that later SDWA lowerings can reuse.src0_seltakesBYTE_0–BYTE_3,WORD_0/WORD_1orDWORD. The selection is zero-extended, or sign-extended undersext().dst_selwrites the low bits of the result into that byte or word.UNUSED_PADzeroes the other bits.UNUSED_PRESERVEkeeps them from the destination's tracked value, or uses zero when the destination has none.v_cvt_f32_f16widensWORD_0orWORD_1through the existingwiden16, and appliesabs,negandclampafter widening as the e64 form does. It accepts onlydst_sel:DWORD.UNUSED_SEXT;Sources for the semantics. The selection and padding rules follow the instruction equivalences in LLVM 15's
SIPeepholeSDWA.cpp:v_lshlrev_b32by 16 or 24 becomesdst_sel:WORD_1/BYTE_3 dst_unused:UNUSED_PAD;v_lshrrev_b32/v_ashrrev_i32by 16 become a zero- or sign-extendedsrc0_sel:WORD_1;UNUSED_PRESERVE.That pass never produces
UNUSED_SEXT, and I couldn't confirm from a source I could quote how it treats the bits below a byte or word field, so it stays refused rather than guessed.Verification
Commit
6ee2406plus this change, Windows 10 Enterprise 26H2 build 26300.9974, MSVC 14.51.36231, Windows SDK 10.0.26100.0 DXC.pixel_aot_hardware: Passed on NVIDIA GeForce RTX 4070 Ti (10de:2782), driver 32.0.16.1088.pixel_aot_warp: Passed on WARP 10.0.26100.9818.6ee2406; the four extra draws are two programs × two constant sets. Every draw reportsdebug_errors=0andmax_absolute_error=0.tests/pixel_aot_check.py binarypasses with both programs in the binary fixtures: LLVM 15.0.6llvm-mcandllvm-objcopy, disassembled throughlibLLVM-17.soandlibLLVM-18.soon Linux. The controls,tests/docs_links_check.pyandtests/bidi_controls_check.pypass.Evidence and follow-up
Both programs are synthetic.
The
UNUSED_PRESERVEprogram movesWORD_1of one constant, and a sign-extendedBYTE_2of another, intoWORD_0of a register holding 1.0. The word is then 1 + f × 2^-23, and(v - 1) × 2^23is split into the two bytes of f. A zeroed high half would make the word a subnormal, and the readback would fail.The
UNUSED_PADprogram does three things:BYTE_0intoBYTE_3, which gives an exact power of two;WORD_0intoWORD_1;-|x|.The reference works on the integer words in Python and does not use the lowering. Thirteen wrong references each report
pixel_mismatch: the neighbouring byte or word, a zero-extended negative byte, a sign-extended positive byte, and the other half for widening. The translator on6ee2406rejects both programs at their first SDWA instruction.Next steps would be SDWA forms of the other supported VOP1/VOP2 operations,
UNUSED_SEXTonce its effect on the lower bits is pinned down, and thedst_sel:WORD_1packing form ofv_cvt_f16_f32after #324.This branch merges cleanly with #288, #293 and #324.
Checklist
AI-assisted: yes. Written with Claude Opus 5.5; verified on the hardware listed above.
🤖 Generated with Claude Code
https://claude.ai/code/session_01X1EBSe6YfE2ivQChRsx1hc
Imported from R0Y00/Xbox2Windows. Originally posted by alexander-src on 2026-11-21T22:27:43Z.
Checked
a96a328on Linux (python3 -B tests/pixel_aot_check.py binary llvm-mc llvm-objcopy libLLVM.sopassed with LLVM 23.1).A few edge cases caught in
v_mov_b32_sdwaintools/pixel_aot.py:old = vector.get(dst)only checksisinstance(old, str), sov_mov_b32_sdwa v0, v12 dst_sel:WORD_0 dst_unused:UNUSED_PRESERVE src0_sel:WORD_0reads"bary_i"and emitsasuint(bary_i) & 0xffff0000u(undeclared identifier in HLSL; same forv1andv8/v9). Checkingold.startswith(("sample", "alu", "params["))only whendst_sel != "DWORD"andunused == "UNUSED_PRESERVE"fixes that and avoids rejectingDWORDorUNUSED_PADoverwrites of a previously packed register.UNUSED_PRESERVE,if unused == "UNUSED_PAD" or old is None: return fieldsilently substitutes zero for an untracked destination (such asv20), even though hardware preserves whatever was inv20. RaisingValueErrorwhenUNUSED_PRESERVEtargets an untracked register (withdst_sel != "DWORD") would matchpixel_aot's strict tracking contract elsewhere and avoid hiding an undefined-bit read.llvm-mc -mcpu=gfx1013assembles and disassembles negative float inline constants likev_mov_b32_sdwa v12, -0.5 dst_sel:DWORD dst_unused:UNUSED_PAD src0_sel:DWORD, while the regex([vs]\d+|-?\d+|\d+\.\d+)rejects-0.5,-1.0,-2.0, and-4.0.AI-assisted: yes.
Imported from R0Y00/Xbox2Windows. Originally posted by Its3rr0rsWRLD on 2026-11-21T23:11:39Z.
Thanks, @alexander-src, all three confirmed and fixed in
e99c9bc:sdwa_destnow checks provenance only when bits are kept (dst_selnotDWORDandUNUSED_PRESERVE). It refuses a destination that is untracked (v20) or non-numeric (v0,v1,v8,v9) instead of assuming zero.DWORDandUNUSED_PADwrites may still replace any register. The docs paragraph says so.v_mov_b32_sdwa v12, -0.5 ...lowers throughasuint((-0.5f)).The refusals, the -0.5 move and a
DWORD/UNUSED_PRESERVEoverwrite are new controls. Before the fix, the old code emittedasuint(bary_i)forv0and zero-filledv20.Rerun on Windows 10 Enterprise 26H2 build 26300.9974 with
ctest --preset dev --no-tests=error -R '^pixel_aot_' -V, merged with current main (bc24dfd):pixel_aot_hardware(RTX 4070 Ti, driver 32.0.16.1088) andpixel_aot_warp(WARP 10.0.26100.9818) pass with 59 draws each against 55 on main. Every draw reportsdebug_errors=0andmax_absolute_error=0.tests/pixel_aot_check.py binaryand the controls pass on Linux with LLVM 15.0.6 tools and libLLVM 18.AI-assisted: yes. Claude Opus 5.5 replying from this account.