shader: lower the integer SDWA comparisons #1670
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!1670
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1670/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:46 UTC · original
rm-NoobInCoding:shader/sdwa-int-compare→main· +272 −8 · 6 files · 3 commits · closed without mergingChange
tools/pixel_aot.pylowered the SDWA comparisons only for binary32 with whole-dword selections. The integer SDWA comparisons were refused:v_cmp_{f,lt,eq,le,gt,ne,ge,t}_{i32,u32}_sdwa;v_cmp_{lt,eq,le,gt,ne,ge}_{i16,u16}_sdwa(gfx10 has no f/t forms at 16 bits).This PR lowers these 28 forms with byte and word selections:
sext(). The selection uses the existingsdwa_source(), as for the SDWA integer operations.DWORDemits the same HLSL as its e32 spelling. A control asserts this.Refused:
sext(or a missing selection;execas the destination;v_cmpxand 64-bit SDWA forms.tools/scan_unsupported_shaders.pykeeps its own patterns, so a second commit accepts the same forms there, without f/t at 16 bits, and addstest_sdwa_int_compare_instructions.test_binary_scan_recognizes_vopc_sdwaused the word forv_cmp_gt_u32_sdwa vcc_lo, v1, v2 src0_sel:WORD_1 src1_sel:DWORDas its unlowered example; that word now sits in the supported binary, decoded bytools/disasm_rdna2.pyinto the syntax the lowering expects, andv_cmpx_eq_f32_sdwastays the unlowered example.Coverage: +28 gfx1013 and gfx1030 SDWA forms.
Verification
Base
578d1e1c, patches389422b9,85690efeand the round-trip commit. Windows 11 build 26300,devpreset, DXC 10.0.26100.0, NVIDIA GeForce RTX 4070 (driver 32.0.16.1714) and WARP.pixel_aot_sdwa_int_compare_hardwareandpixel_aot_sdwa_int_compare_warp: 2/2 passed, no skips. Both coverage records list all 28 forms.rdna2_tools_check.py: 146 tests OK (18 skipped without LLVM). All 49 platform-independent Python checks listed in AGENTS.md passed on the patch.check_sdwa_int_compare_lowering),form_coverage_check.py, docs links and bidi controls passed.The fixture (
tests/pixel_aot_check.py draw-sdwa-int-compare):s44copied tov20) with B (s45copied tov18) and selects 1.0 or 0 throughv_cndmask_b32.BYTE_1+sext /BYTE_2,WORD_1/WORD_0+sext,BYTE_3+sext /WORD_1,WORD_0+sext /BYTE_0, andDWORD/BYTE_3+sext.pixel_mismatch. The models are: selections ignored,sext()ignored, signedness swapped, and, for the 16-bit kinds, the whole selected word compared. That is 28 controls; a static check asserts each one has a distinguishing pair. In total, 132 draws from 8 compiles.sext()makespixel_aot_sdwa_int_compare_warpfail on the first program, with the passing rows reported asmismatch.LLVM 15 round trip: not run locally (no LLVM with gfx1013 on this host). The first two commits did not put the new forms through it:
check_binaryassembled nov_cmp_*_sdwainteger program (thanks @triggered02). The third commit adds the eightsdwa_int_predicate_groupprograms to its fixtures, so theAssemble and translate gfx1013 fixturesjob now assembles each program, disassembles it with LLVM 15, and requires the disassembly to translate exactly like the source text.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. The
v_cmpx_*_sdwaforms, which also writeexec, remain uncovered.Checklist
AI-assisted.
v_cmp_*_{i32,u32}_sdwa (eight relations each) and v_cmp_*_{i16,u16}_sdwa (six each; gfx10 has no f/t forms at 16 bits) were refused. Each source is now its selected byte or word field, zero-extended or sign-extended under sext() as for the SDWA integer operations, and the comparison is the e32 one on those words; the 16-bit kinds read the low 16 bits of the selected word. A whole-dword source is read exactly as the e32 form reads it, so DWORD/DWORD selections emit the e32 HLSL. draw-sdwa-int-compare draws the 28 forms in eight programs under five selection configurations on 13 pairs, with 28 negative controls drawn against wrong models (selections ignored, sext() ignored, signedness swapped, whole selected word compared at 16 bits). It runs as pixel_aot_sdwa_int_compare_{hardware,warp} with its own coverage record.check_binary assembled the SDWA integer operations but none of the v_cmp_*_{i32,u32,i16,u16}_sdwa programs, so the LLVM 15 job never saw the new forms. Add the eight sdwa_int_predicate_group programs to its fixtures: each is assembled, disassembled with LLVM 15 and must translate exactly like its source text.@triggered02 on GitHub · 2026-11-24 17:00 UTC · original
Ran the LLVM job on this head. It passes, but it does not do what the PR body says it does, so the useful part of this comment is the second half.
The run. Independent run of the repository workflow on head
389422b9, in a fork rather than upstream, so it is a fresh execution rather than a re-read of the existing check:triggered02/Xbox2Windows, workflowwindows.ymlviaworkflow_dispatchon the PR head138615257733)ubuntu-22.04, step installsllvm-15and runstests/pixel_aot_check.py binary llvm-mc-15 llvm-objcopy-15 libLLVM-15.so.1from theCOMMON_LLVMlist inwindows.ymlUpstream CI on the same commit shows the same job green. I could not run it on Windows locally: this host has no LLVM 15 and no 7-Zip to extract a portable copy, and installing one machine-wide needs elevation I do not have. So this is the Ubuntu runner's LLVM, not a second platform.
The gap. The round trip does not assemble any of the 28 forms this PR adds.
check_binary()intests/pixel_aot_check.pyextends its fixture list with the SDWA operations (SDWA_ARITH,SDWA_UNARY,SDWA_PRESERVE_BODY,SDWA_PAD_BODY,sdwa_integer_group) but nothing that emitsv_cmp_*_{i32,u32,i16,u16}_sdwa; this PR does not touch that list. The only binary-side coverage is intests/rdna2_tools_check.py, and it is hand-written bytes:f904887d01000506moves from theunloweredsample to thesupportedsample, and the count assertion goes 2 → 3. That tests the scanner's recognition, not that an assembler accepts the text LLVM 15 will print back.So "the Ubuntu job is the first assembler check" is not accurate — no assembler sees these forms. The PR's real coverage is the static lowering check and the 132 draws, which do not depend on LLVM at all.
What would close it. Add the integer comparisons to the round trip, either by extending
check_binary()with the eightsdwa_int_predicate_group(kind, program)programs or as a dedicatedcheck_sdwa_int_compare_binary(): assemble each program, re-disassemble it, translate the disassembly, and require the HLSL to equal the text-input translation (the same pattern as the SDWA integer operations). That makes the Ubuntu job genuine coverage for the new forms and would catch a mnemonic or operand-order mistake that the text-input fixtures cannot see.I am happy to send that as a patch on top of this branch — I can verify it with the same workflow run in the fork, which is the only way I can run LLVM 15 here. Say the word and I will open it as a PR against your branch, or post the diff here if you prefer to apply it yourself.
Not claimed: that the new lowering is correct on hardware. My draws and static checks are not part of this comment; this is only about what the LLVM job does and does not cover.
AI-assisted (Claude Code).
@rm-NoobInCoding on GitHub · 2026-11-24 17:14 UTC · original
You're right, and thanks for running it.
check_binarynever assembled av_cmp_*_sdwainteger program, so my "first assembler check" line was wrong.I've applied your suggestion as
c641cd39: the eightsdwa_int_predicate_group(kind, program)programs are now in thecheck_binaryfixtures. Each is assembled with LLVM 15, disassembled, and the disassembly must translate exactly like the source text, the same pattern the SDWA integer operations use. No patch needed from your side. I can't run LLVM 15 on this host either, so theAssemble and translate gfx1013 fixturesjob on this push is the check; I'll follow up if it finds a spelling mismatch. The PR description is corrected.pixel_aot_check.pystatic controls pass locally.#1680 (the binary16 SDWA comparisons) had the same gap, and I'm closing it there the same way.
@tedin7 on GitHub · 2026-11-24 18:34 UTC · original
Thanks for this PR and the earlier fixes at
c641cd39;mainhas moved on and this branch now has a merge conflict.Could you rebase onto the current
mainand push so we can re-verify and merge? AI-assisted.@thepatrickworld on GitHub · 2026-11-25 10:50 UTC · original
Before you spend the rebase tedin7 asked for: most of this is already in
main, so here is what the rebase will actually leave.mainnow lowers the SDWA integer comparisons in two branches oftools/pixel_aot.py:Your branch adds a single regex over
(i32|u32|i16|u16)with the fullINT_COMPAREset, so after a rebase:i32/u32half is already there;i16/u16half is already there foreq,ne,lt,le,gt,ge;v_cmp_f_(i16|u16)_sdwaandv_cmp_t_(i16|u16)_sdwa— the two constant-result forms, whichmainstill refuses because its 16-bit regex lists only the six real comparisons.So the rebase is worth doing only if you want those two; otherwise this can close without losing anything.
INT_COMPAREisf, lt, eq, le, gt, ne, ge, t, sofandtare the whole delta.Context on the other PR: #1923 hits the same collision and its author is holding it for the same reason.
AI-assisted.
@thepatrickworld on GitHub · 2026-11-25 10:50 UTC · original
Correction to what I wrote above, after testing instead of reading the regexes.
I said the
v_cmp_f_(i16|u16)_sdwaandv_cmp_t_(i16|u16)_sdwaforms would be the remaining delta. They are not:mainrefuses both — callingpixel_aot.lower(["v_cmp_f_i16_sdwa ..."], 20, 24, [1,2,3,4], constant_descriptor=64)raisesUnsupported instruction;INT_COMPARE, but the code documents that the hardware does not have them.So the six 16-bit comparisons this PR adds are exactly the six
mainalready carries (eq, ne, lt, le, gt, ge), and all eight 32-bit ones are there too. After a rebase this PR adds no coverage at all — it can close without losing anything, and the rebase tedin7 asked for is not worth doing for the translation itself.What is still worth something is the test surface: 198 lines in
tests/pixel_aot_check.pyagainst whatmaincarries for the same forms, plus therdna2_tools_check.pyround trip. If you would rather not rebase a branch that adds nothing, that material could be ported intomainseparately.Sorry for the wrong first read — the regex made me assume those two forms were covered.
AI-assisted.
@R0Y00 on GitHub · 2026-11-26 04:46 UTC · original
Main already lowers the 28 integer SDWA predicates in #1790. #1923 adds per-predicate 32-bit draw and refusal controls. The current 46-form controls and binary scanner check pass. For any extra 16-bit draw cases, please extend the existing fixture while keeping its single-SGPR destination rule. Thanks for the detailed signedness and selection comparisons. Closing this implementation as superseded.
@tedin7 on GitHub · 2026-11-24 17:00 UTC · original · reviewed
Peer review of #1670 (
85690efe5b0b6d95a98a8d9b290bddf372d84647): no defects found (0 P1, 0 P2).Summary
tools/pixel_aot.py: lowers all 28 integer SDWA comparison forms (v_cmp_{f,lt,eq,le,gt,ne,ge,t}_{i32,u32}_sdwaandv_cmp_{lt,eq,le,gt,ne,ge}_{i16,u16}_sdwa), applyingsdwa_source(..., bool(sext))on sub-dword selections and matching the e32 operand/sign-extension semantics onDWORDand 16-bit forms, while rejecting 16-bitf/t, unbalancedsext(, constants, float modifiers,execdestinations, andv_cmpx/64-bit forms.tests/pixel_aot_check.py,CMakeLists.txt,docs/experiments.md: addscheck_sdwa_int_compare_lowering(covering all 28 forms, HLSL bit-extraction, e32 equivalence onDWORD, and 11 rejection cases),check_sdwa_int_predicate_draws(8 programs x 13 pairs + 28 negative-control wrong models), andpixel_aot_sdwa_int_compare_${adapter}withFORM_COVERAGE_RECORD. Title-neutral andgit diff --checkclean.Verification
python3 -B tests/pixel_aot_check.py-> PASSgit diff --check origin/main...HEAD-> PASSx2w_pipe.py win2025 1670):tests/form_coverage_check.py-> PASS (16.6s)--preset dev):cmake --build --preset dev --target offscreen_check+ctest --preset dev -R '^(pixel_aot_sdwa_int_compare_warp|pixel_aot_sdwa_integer_warp|pixel_aot_sdwa_unary_warp|pixel_aot_comparisons_warp|pixel_aot_compare_warp|pixel_aot_warp)$'-> 6/6 passed (20.65s:pixel_aot_sdwa_int_compare_warp3.05s;*_hardwareexcluded on VM)./O2(--preset release):cmake --build --preset release --target offscreen_check+ctest --preset release -R '^(pixel_aot_sdwa_int_compare_warp|pixel_aot_sdwa_integer_warp|pixel_aot_sdwa_unary_warp|pixel_aot_comparisons_warp|pixel_aot_compare_warp|pixel_aot_warp)$'-> 6/6 passed (20.68s:pixel_aot_sdwa_int_compare_warp3.06s).sdwa_source(..., bool(sext))->sdwa_source(..., False)intools/pixel_aot.py;python3 -B tests/pixel_aot_check.pyfailed as expected (AssertionErrorincheck_sdwa_int_compare_lowering, exit code 1). Restored viagit checkout -- ..AI-assisted; commands listed were executed locally.
@tedin7 on GitHub · 2026-11-24 17:31 UTC · original · reviewed
Review of head
c641cd3951(comment only, not an approval). My earlier review was at85690efe5b.Verdict: 0 P1 / 0 P2.
Since
85690efethe diff is 3 lines in tests/pixel_aot_check.py: the eight new programs are added tocheck_binary, which closes the gap that the LLVM round trip assembled none of the new forms. I ran those 8 programs through a copy of that loop with llvm-mc-19 (-mcpu=gfx1013): assemble, extract, disassemble, andtranslate(decoded) == translate(source)holds for all 8. The fullcheck_binarywith LLVM 19 stops earlier on an unrelated f16 fixture (v_cvt_f16_i16_e32 v1, 0xfff0prints differently than in LLVM 15).Semantics
sext()on either source, SGPR sources,s6destination).v_cmp_f_i16_sdwaandv_cmp_t_u16_sdwaare rejected by the assembler, which matches the 16-bit exclusion in the lowering and the scanner.sdwa_source(zero- or sign-extended undersext()); 16-bit forms take the low 16 bits of the selected word; i32 and u32 compare signed and unsigned; whole-dword selection matches the e32 spelling (a control asserts the same HLSL); a register holding only a low half is refused on sub-dword selections.test_binary_scan_recognizes_vopc_sdwafollow from a word moving from unlowered to supported; no assertion is weakened. No new test asserts source text.Run
python3 -B tests/pixel_aot_check.py,tests/rdna2_tools_check.py(146 OK, 18 skipped),tests/docs_links_check.py,tests/bidi_controls_check.py,tests/shader_census_check.py,tests/shader_corpus_report_check.py: all pass.git checkout -- <file>, green again):bool(sext)->Falsein the sub-dword path failscheck_sdwa_int_compare_loweringon thecmp23line; addingf|tto the scanner's 16-bit list fails rdna2_tools_check onv_cmp_f_i16_sdwa.({word})instead ofasint({word}), and the u16 branch comparing the whole word without& 0xffffu.Non-blocking
check_sdwa_int_compare_loweringpins the HLSL only for i16 program 0 and u32 program 0, so i32 signedness and the u16 mask are guarded only by the Windows draws. One static assertion for an i32 line and one for a u16 line would close that on Linux.Not run on Linux: the 132 draws and 28 negative controls (
pixel_aot_sdwa_int_compare_{hardware,warp}), DXC, D3D12, LLVM 15,form_coverage_check.pyandshader_probe_check.py(need iced_x86 and pefile). Real-hardware behaviour of the 16-bit selections is not established by any check here.AI-assisted; commands listed were executed locally.
@tedin7 on GitHub · 2026-11-24 17:40 UTC · original · reviewed
Dual-platform peer review at
head_sha:c641cd3951369167dfb22401ac1be8d81e407e14Findings
No blocking issues (0 P1, 0 P2).
tools/pixel_aot.pyandtools/scan_unsupported_shaders.py: lower the 28 integer SDWA comparison forms (v_cmp_{f,lt,eq,le,gt,ne,ge,t}_{i32,u32}_sdwaandv_cmp_{lt,eq,le,gt,ne,ge}_{i16,u16}_sdwa) withBYTE_0..3,WORD_0..1,DWORD, optionalsext(...), and lane-mask destination (vcc/vcc_lo/SGPR), while rejecting 16-bitf/t, unbalancedsext(, inline constants/literals, float modifiers,exec,v_cmpx, and 64-bit forms. Whole-DWORDselections reuseint_operand/int16_operandso emitted HLSL matches_e32.tests/pixel_aot_check.py,tests/rdna2_tools_check.py,CMakeLists.txt(test-only registrationpixel_aot_sdwa_int_compare_${adapter}),docs/experiments.md: include static lowering/refusal controls, LLVM assemble/disassemble round trip incheck_binaryfor all 8 programs, WARP draw checks with 28 negative-model mismatch controls, and scanner parity; title-neutral.Verification
git diff --check origin/main...HEAD: clean.python3 tests/docs_links_check.py: passed (16 Markdown files, 348 links).python3 tests/bidi_controls_check.py: passed (1276 tracked files).python3 -B tests/rdna2_tools_check.py -k test_binary_scan_recognizes_vopc_sdwa -k test_sdwa_int_compare_instructions: 2 tests ran, OK.python3 -B tests/pixel_aot_check.py: passed.llvm-mc-19 -arch=amdgcn -mcpu=gfx1013 -show-encoding: verified encodings forv_cmp_lt_i32_sdwa,v_cmp_gt_u32_sdwa,v_cmp_ge_u16_sdwa,v_cmp_ne_i16_sdwa.git checkout -- tools/pixel_aot.py):if kind in ("i16", "u16") and op in ("f", "t"):withif False:->python3 -B tests/pixel_aot_check.pyfailed incheck_sdwa_int_compare_lowering(AssertionError: translate accepted invalid input, exit 1).sext(sdwa_source(..., False)) ->python3 -B tests/pixel_aot_check.pyfailed incheck_sdwa_int_compare_lowering(HLSL mismatch oncmp23, exit 1).tests/form_coverage_check.pyok (16.5s).--preset dev):ctest --preset dev -R '^(pixel_aot_sdwa_int_compare_warp|rdna2_tools_check)$' --parallel 4 --no-tests=error --output-on-failure: 2/2 passed (5.66s:pixel_aot_sdwa_int_compare_warp2.47s,rdna2_tools_check5.59s)./O2(--preset release):ctest --preset release -R '^(pixel_aot_sdwa_int_compare_warp|rdna2_tools_check)$' --parallel 4 --no-tests=error --output-on-failure: 2/2 passed (5.94s:pixel_aot_sdwa_int_compare_warp2.35s,rdna2_tools_check5.87s).AI-assisted; commands listed were executed locally.
Pull request closed