shader: lower the binary16 SDWA comparisons #1680
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!1680
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1680/head"
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?
@rm-NoobInCoding on GitHub · 2026-11-24 16:59 UTC · original
rm-NoobInCoding:shader/sdwa-f16-compare→main· +269 −11 · 6 files · 3 commits · closed without mergingChange
tools/pixel_aot.pylowered the SDWA comparisons only for binary32, with whole-dword selections. This PR lowers the 16 binary16 predicatesv_cmp_{f,lt,eq,le,gt,lg,ge,o,u,nge,nlg,ngt,nle,neq,nlt,tru}_f16_sdwaandv_cmp_class_f16_sdwa:WORD_1selects the high half of a source.WORD_0andDWORDleave the low half, which is what the e32 form reads. So a comparison with both selectionsDWORDand no modifier emits the same HLSL as its e32 spelling, and a control asserts this.-,|x|and-|x|apply after the selection.num16on the selected, modified encodings and compare the widened values. The class test readsclass16of the selected, modified half against the mask register.f16_cmp_operand,f16_comparisonandf16_classgain an optional high-half selection; existing callers are unchanged.Refused:
sext();neg(2.0)and similar);execas the destination;DWORD, or with a modifier;v_cmpxSDWA forms.tools/scan_unsupported_shaders.pykeeps its own patterns, so it accepts the same forms.test_sdwa_f16_compare_instructionschecks the accepted and refused spellings.Coverage: +17 gfx1013 and gfx1030 SDWA forms.
Verification
Base
c864f138, patcha8a67061. Windows 11 build 26300,devpreset, DXC 10.0.26100.0, NVIDIA GeForce RTX 4070 (driver 32.0.16.1714) and WARP.plus every platform-independent Python check listed in AGENTS.md.
pixel_aot_sdwa_f16_compare_hardwareandpixel_aot_sdwa_f16_compare_warp: 2/2 passed, no skips. Both coverage records list all 17 forms.pixel_aot_check.pystatic controls, including the newcheck_sdwa_f16_compare_lowering: passed.rdna2_tools_check.py: OK, 18 skipped without LLVM.The fixture (
tests/pixel_aot_check.py draw-sdwa-f16-compare):R32G32B32A32_UINTreadback target. Three words hold the 16 predicates as bits under (src0, src1, src0_sel, src1_sel) = (A, B,WORD_1,WORD_0), (-B, |A|,WORD_1,DWORD) and (-|A|, B,DWORD,WORD_1). The fourth word holds four class tests of C against the mask D.pixel_mismatch. That is 12 draws from one compile.WORD_1makespixel_aot_sdwa_f16_compare_warpfail.LLVM 15 round trip: not run locally (no LLVM with gfx1013 on this host). The first commit did not put the new forms through it:
check_binaryassembled nov_cmp_*_f16_sdwaprogram. A later commit adds thesdwa_f16_comparesprogram to its fixtures, so theAssemble and translate gfx1013 fixturesjob assembles it, disassembles it with LLVM 15, and requires the disassembly to translate exactly like the source text. After review,check_sdwa_f16_compare_loweringalso pins each selection (src0, src1 and the class test) at text level, so a lowering that ignores any one of them fails without a GPU.Evidence and follow-up
All inputs are synthetic. The draws show that the translated shader computes the stated comparisons on desktop GPUs, not that the console does. Related: #1670 lowers the integer SDWA comparisons. The two PRs touch neighbouring code but are independent. The
v_cmpx_*_sdwaforms remain uncovered.Checklist
AI-assisted.
@rm-NoobInCoding on GitHub · 2026-11-24 17:12 UTC · original
Thanks, agreed: the text-level guard only covered src0. Fixed in
e182ad78(tests only, no lowering change).check_sdwa_f16_compare_loweringnow pins the exact operands of each selection, so a GPU is no longer needed to catch them:src0_sel:WORD_1 src1_sel:WORD_0:num16/widen16of A's high half, and B's low half with no shift;src0_sel:WORD_0 src1_sel:WORD_1: A's low half with no shift, andnum16/widen16of B's high half;v_cmp_class_f16_sdwa vcc_lo, -v18, v16 src0_sel:WORD_1 src1_sel:DWORD: the whole line,class16(((A >> 16) & 0xffff) ^ 0x8000) & B, so the negation is applied after the selection and the mask is read whole;WORD_0: the low half, no shift.Your three mutations, rerun against
e182ad78on Windows (Python 3.14):highs=(False, sel1 == "WORD_1")highs=(sel0 == "WORD_1", False)high=FalseWith the lowering restored:
pixel_aot_check.pystatic controls andform_coverage_check.pypass, andpixel_aot_sdwa_f16_compare_hardware(RTX 4070) and_warppass 2/2.@tedin7 on GitHub · 2026-11-24 18:34 UTC · original
This PR currently has merge conflicts with
main. Could you please rebase it onto the latestmainso it can be checked for merge?AI-assisted.
@tedin7 on GitHub · 2026-11-26 02:23 UTC · original
I tried to bring this branch up to date with main so it could go through the full cycle. It no longer merges cleanly, and the conflict is not a mechanical one: #1790 (merged 2026-11-24) already lowers the same slice, the 16 binary16
v_cmp_*_f16_sdwapredicates andv_cmp_class_f16_sdwa, intools/pixel_aot.py(f16_comparison_bits,f16_class_bits), and its lot also covers the f32 and 16/32-bit integer SDWA compares.Resolving it would mean choosing between two implementations of the same lowering, so I did not push anything to this branch. Leaving the decision to @R0Y00 and @rm-NoobInCoding. If this PR still adds something that main lacks (for example the
WORD_1high-half selection tests or the scanner entries intools/scan_unsupported_shaders.py), a rebuild of the diff on top of current main containing only that would be the smallest path.Commands executed:
git merge origin/mainin a scratch worktree (conflicts intools/pixel_aot.py,tests/pixel_aot_check.py,tests/rdna2_tools_check.py,docs/experiments.md), thengit merge --abort;git log -S f16_comparison_bits origin/main.AI-assisted; commands listed were executed locally.
@R0Y00 on GitHub · 2026-11-26 04:47 UTC · original
Main already covers the 16 binary16 SDWA predicates and the binary16 class form in #1790, with source-field selection, distinct mask destinations, and a binary round trip. The current comparison controls pass. Thanks for the NaN, signed-zero, and half-selection investigations. Any extra discriminating rows can extend the existing fixture directly. Closing this implementation as superseded.
@tedin7 on GitHub · 2026-11-24 17:08 UTC · original · reviewed
Review of head
a8a670616c9f2b9f4ce679094d391e3fb0c6cbf2.Linux limits. Linux x86_64,
llvm-mc-19(CI pins 15), Python 3.14. No Windows, no DXC, no GPU, so I could NOT run the newdraw-sdwa-f16-compare/pixel_aot_sdwa_f16_compare_<adapter>tests. The NaN, -0/+0 and sign-handling claims are only checked by those draws; I checked the translation text and the machine encodings.What I ran
check_sdwa_f16_compare_lowering()fromtests/pixel_aot_check.py, called directly: passes in 0.1 s.llvm-mc-19 -mcpu=gfx1010(WORD_1/WORD_0/DWORD,-v,|v|,-|v|, SGPR destination,v_cmp_class_f16_sdwawith WORD_1 and DWORD) and decoded each back with the in-treedisasm_rdna2.decode_instruction: all round-trip to the same text.sext(v18)is not accepted byllvm-mc-19for these float compares, matching the PR's refusal.highs=(False, sel1 == "WORD_1")): the static check FAILED, as intended.highs=(sel0 == "WORD_1", False)): the static check STILL PASSED.high=False): the static check STILL PASSED.git checkout -- ..Findings
v_cmp_lt. A wrong src1 selection and a wrong class-test selection are caught only by the GPU draws (SDWA_F16_SETSandSDWA_F16_WRONG_MODELScover src1 and class), which run on Windows. On a Linux or no-GPU run they are unguarded. A one-line text assertion forsrc0_sel:WORD_0 src1_sel:WORD_1and one forv_cmp_class_f16_sdwa ... src0_sel:WORD_1would close that.-,|x|,-|x|are applied after the high-half selection (f16_cmp_operand,(word >> 16u)first, then abs/neg on the 16 bits). That is the SDWA order I expect; confirm with the draws.num16of both, the negated forms are!ordered || !rel, so a NaN in either half is unordered. -0 vs +0 compares equal through the widened float. Both rely on the existingf16_comparison, whose behavior the new draws exercise; I did not re-derive them on a GPU.sext, constants,v_cmpx, class mask with WORD selection, exec as destination, v106) are covered bymust_reject.tools/scan_unsupported_shaders.pyhas two new regexes that match the same shapes.Verdict: the lowering looks right, and the binary forms are valid. The Linux-runnable guard is weaker than the PR text suggests. Not approving.
AI-assisted; commands listed were executed locally.
@tedin7 on GitHub · 2026-11-24 17:29 UTC · original · reviewed
Review of head
377919df1c8212935299b297f572289892686f97(3 commits on main: the loweringa8a67061I reviewed before, pluse182ad78and377919df, both tests only; the delta froma8a67061is +24/-5 intests/pixel_aot_check.py).Linux limits. Linux x86_64,
llvm-mc-19andllvm-objcopy-19(CI pins 15), Python 3.14. No CMake configure and noctest(the two newpixel_aot_sdwa_f16_compare_<adapter>registrations are unexercised), no Windows, no DXC, no GPU. Thedraw-sdwa-f16-comparedraws, the "12 draws from one compile" and the RTX 4070 and WARP results are not reproduced by me. The NaN, signed-zero and denormal behaviour is only checked by those draws.Earlier findings, now addressed. My review of
a8a67061showed that ignoring WORD_1 on src1, or in the class test, still passed the text-level check.e182ad78pins the exact operands for both selections and for the class test with and without the modifier;377919dfadds the SDWA program to thebinaryfixtures.What I ran on this head
check_sdwa_f16_compare_lowering()called directly: PASS.sdwa_f16_compares()(234 instructions, 52 SDWA lines) assembled withllvm-mc-19 -mcpu=gfx1013, objcopy'd, disassembled with the in-treedisassemble()against libLLVM 19, thentranslate_intof the decoded text equalstranslate_intof the source text. The fullbinarymode with llvm-mc-19 stops earlier incheck_f16_cvt_int16_binary(v_cvt_f16_i16_e32 v1, 0xfff0, an unrelated check; likely LLVM 19 against 15 formatting, which I did not confirm), so I did not get a fullbinarypass.tools/pixel_aot.py, each run against the static check and the round trip, then restored (git statusclean):bool cmp22line (this passed ona8a67061).a8a67061).git diff --check origin/main...HEAD: clean; no non-ASCII bytes added.tests/rdna2_tools_check.py(OK, 18 skipped),tests/bidi_controls_check.pyandtests/docs_links_check.py: pass.git merge-treeagainst current main (68969ed8): no conflicts.Findings
llvm-mc-15path for the new fixture is still unconfirmed. Thedrawresults above stay the author's measurements.AI-assisted review; commands listed were executed locally.
Pull request closed