Repository navigation
shader: lower the integer SDWA comparisons - #1670
rm-NoobInCoding wants to merge 3 commits into
Conversation
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.
The shader scanner keeps its own patterns, so it still reported the integer SDWA comparisons as unsupported after pixel_aot lowered them. Accept them with register sources, optional sext() and both selections printed, without f/t at 16 bits, and test the accepted and refused spellings. test_binary_scan_recognizes_vopc_sdwa used v_cmp_gt_u32_sdwa as its unlowered example; that word now belongs to the supported binary, and v_cmpx_eq_f32_sdwa stays the unlowered one.
tedin7
left a comment
There was a problem hiding this comment.
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
- Linux:
python3 -B tests/pixel_aot_check.py-> PASSgit diff --check origin/main...HEAD-> PASS
- Windows Server 2025 (
x2w_pipe.py win2025 1670):- Windows Python checks:
tests/form_coverage_check.py-> PASS (16.6s) - Debug (
--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). - Release
/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).
- Windows Python checks:
- Local mutation check:
- Mutated
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 -- ..
- Mutated
AI-assisted; commands listed were executed locally.
|
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
Upstream 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. 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 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). |
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.
|
You're right, and thanks for running it. I've applied your suggestion as #1680 (the binary16 SDWA comparisons) had the same gap, and I'm closing it there the same way. |
tedin7
left a comment
There was a problem hiding this comment.
Review of head c641cd3 (comment only, not an approval). My earlier review was at 85690ef.
Verdict: 0 P1 / 0 P2.
Since 85690ef the diff is 3 lines in tests/pixel_aot_check.py: the eight new programs are added to check_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, and translate(decoded) == translate(source) holds for all 8. The full check_binary with LLVM 19 stops earlier on an unrelated f16 fixture (v_cvt_f16_i16_e32 v1, 0xfff0 prints differently than in LLVM 15).
Semantics
- 28 forms assemble with llvm-mc-19 on gfx1013 and gfx1030 with identical results (f/t at 32 bits,
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. - tools/pixel_aot.py:5049: sub-dword fields go through
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. - The scanner regex agrees with the lowering. The count changes in
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.- Mutations (restored with
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. - Two further mutations were NOT caught on Linux: the i32 branch emitting
({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.- Merge order: #1680 (binary16 SDWA comparisons) conflicts textually in tests/pixel_aot_check.py and tests/rdna2_tools_check.py; whichever lands second needs a rebase. Merging into current main is otherwise clean.
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.py and shader_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
left a comment
There was a problem hiding this comment.
Dual-platform peer review at head_sha: c641cd3951369167dfb22401ac1be8d81e407e14
Findings
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
- Linux:
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.- Local mutation checks (each restored via
git checkout -- tools/pixel_aot.py):- Replaced
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). - Ignored
sext(sdwa_source(..., False)) ->python3 -B tests/pixel_aot_check.pyfailed incheck_sdwa_int_compare_lowering(HLSL mismatch oncmp23, exit 1).
- Replaced
- Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP):
- Python checks:
tests/form_coverage_check.pyok (16.5s). - Debug (
--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). - Release
/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).
- Python checks:
AI-assisted; commands listed were executed locally.
|
Thanks for this PR and the earlier fixes at |
|
Before you spend the rebase tedin7 asked for: most of this is already in
Your branch adds a single regex over
So the rebase is worth doing only if you want those two; otherwise this can close without losing anything. Context on the other PR: #1923 hits the same collision and its author is holding it for the same reason. AI-assisted. |
|
Correction to what I wrote above, after testing instead of reading the regexes. I said the
So the six 16-bit comparisons this PR adds are exactly the six What is still worth something is the test surface: 198 lines in Sorry for the wrong first read — the regex made me assume those two forms were covered. AI-assisted. |
|
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. |
Change
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.