Repository navigation
shader: lower the 46 non-cmpx SDWA comparisons - #1790
Conversation
Lower the VOPC SDWA f16 predicates and class test, the f32 class test, and the 16- and 32-bit signed and unsigned integer predicates. Sources accept BYTE_0..3, WORD_0..1 and DWORD selections with sext(); VOPC SDWA has no dst_sel/dst_unused, so the result stays in vcc/vcc_lo or one SGPR. Add the draw-sdwa-cmp fixture with selection, width, signedness, sext and destination-overwrite controls, the coverage assertions, the scanner patterns and the experiments.md reproduction. Measured on 0aa6522: gfx1013 1255/1968 -> 1301/1968, gfx1030 1246/1863 -> 1292/1863.
Use a defined VGPR for the cndmask true value so the program is valid gfx1013 assembly, and add the 46-form program and the destination-overwrite control to check_binary. The gfx1013 assembly job now assembles, disassembles and re-translates every new form instead of only scanning hand-written bytes.
|
Updated at Also noting the overlap explicitly: #1670 and #1680 cover 45 of the 46 forms (28 integer, 17 binary16); this PR additionally covers |
tedin7
left a comment
There was a problem hiding this comment.
Review of bca2702c (head of this PR). Comment only, no approval.
Verdict: no blocking findings in the lowering. One whitespace failure (P2) and one note about what the device-free checks cover.
P2 – git diff --check fails. The docs hunk ends with an added blank line: git diff --check origin/main...HEAD reports docs/experiments.md:10899: new blank line at EOF. Please drop the last empty line of the file.
Semantics (tools/pixel_aot.py). I read the new branches (v_cmp_class_{f16,f32}_sdwa, v_cmp_*_f16_sdwa, v_cmp_*_{i32,u32}_sdwa, v_cmp_*_{i16,u16}_sdwa) and the helpers:
sdwa_sourcezero-extends the selected field, or sign-extends it undersext()(asuint(asint(w << (32-off-width)) >> (32-width))). That is the right field extraction for BYTE_n and WORD_n; DWORD returns the word unchanged.- 32-bit integer compares use
asintfor the signed forms and the plain uint for the unsigned ones. 16-bit forms take the low 16 bits: sign-extended byasint(w << 16) >> 16for i16, masked by0xfffffor u16. Withsexton a byte or word source the field is already sign-extended before the 16-bit narrowing, so the result is correct. - f16 compares and class tests feed the selected low 16 bits to the existing
widen16/num16/class16helpers (shared through the newf16_comparison_bitsandf16_class_bits; the oldf16_comparison/f16_classcallers go through them unchanged). f32 class usesclass32(asfloat(selected)). - The destination is
vcc,vcc_loor one SGPR; a pair is refused, nodst_sel/dst_unusedis accepted, and the entry-mask and pending-register checks match the neighbouring compare branches. - Source modifiers (
-v1,|v1|) are not parsed byvop3p_f16_wordorint_operandhere, so they end in the generic refusal. Conservative, which I think is right for this lot. scan_unsupported_shaders.pyadds four regexes that mirror the four lowering patterns.
Commands run locally (worktree at the exact SHA above, Linux)
python3 -B tests/pixel_aot_check.py(device-free controls): passed.python3 -B tests/rdna2_tools_check.py: 149 tests, OK (18 skipped).tests/docs_links_check.py(17 files, 366 links),tests/bidi_controls_check.py: clean.python3 -B tests/form_coverage_check.py: could not run here,iced_x86is not installed on this machine (error intools/form_reference.py:56, before this PR's code is reached).- Four real mutations of
tools/pixel_aot.py, each followed by the controls and then reverted withgit checkout -- .(tree clean afterwards):sextturned into zero extension: caught.- i16 compares zero-extended instead of sign-extended (
pixel_aot.pyi16 branch): not caught by the device-free controls. - i32 compares made unsigned (
asintdropped): not caught. - f32 class ignoring
src0_sel: not caught.
Note on coverage. The last three mutations are the ones the PR text says the GPU fixture draw-sdwa-cmp catches with its wrong references (signedness inverted, selections ignored). So their protection depends on pixel_aot_sdwa_cmp_{warp,hardware}, which I could not run here (it needs Windows with DXC and offscreen_check). I did not find a device-free assertion that fails if the signedness of the 32-bit forms or the selection of the class forms regresses. A couple of string-level controls on the generated HLSL (for example that v_cmp_lt_i32_sdwa emits asint( and that src0_sel:BYTE_1 shows a >> 8u) would let Linux CI notice before the Windows job does.
Not run by me: pixel_aot_sdwa_cmp_{warp,hardware} and the LLVM 15 check_binary round trip. I rely on the PR text for those.
AI-assisted; commands listed were executed locally.
Assert the signed 32-bit compare, the 16-bit sign extension and mask, and both class selections in the generated HLSL. These controls catch the signedness and selection mutations on Linux, before the Windows draws. Also remove the blank line at EOF reported by git diff --check.
|
Fixed in
Thanks for the review. |
tedin7
left a comment
There was a problem hiding this comment.
Review of head 04291bc1af781e21702a3f5ba6b23645c97c5893 (PR #1790). Comment only, no approval.
Verdict: not mergeable yet. One P2 in the new device-free guard.
P2: check_sdwa_cmp_controls fails on this head. tests/pixel_aot_check.py:4503 asserts "<< 16u) >> 16)" in model. The i16 lowering emits (asint(<word> << 16) >> 16) (no u suffix), so the assertion raises AssertionError. Reproduced by calling check_sdwa_cmp_controls(None) on this head. check_sdwa_cmp_draw runs these controls first, so pixel_aot_sdwa_cmp_<adapter> should fail before any GPU work. The lowering itself looks right: the generated line for v_cmp_lt_i16_sdwa vcc_lo, sext(s44), v18 src0_sel:BYTE_1 src1_sel:WORD_0 is (asint(asuint(asint(params[0].w << 16u) >> 24u) << 16) >> 16) < (asint(((asuint(alu20) >> 0u) & 0xffffu) << 16) >> 16). With the assertion changed to "<< 16) >> 16)" the controls pass here.
Note, not blocking: check_sdwa_cmp_controls is only reached through the draw-sdwa-cmp mode, so tests/pixel_aot_check.py with no arguments never runs it on Linux, which is how the P2 got through. The comment calling these checks device-free is true, but nothing runs them without a renderer.
Semantics (tools/pixel_aot.py), no defect found: zero-extension by default and sign-extension only with sext(); i32/u32 compare as asint/unsigned over the extended 32-bit value; i16/u16 compare the low 16 bits sign- or zero-extended; f16_comparison_bits and f16_class_bits share the predicate tables and the NaN rule with the existing forms; the lane mask is VCC or one SGPR, never a pair; exec-writing v_cmpx neighbours stay refused; dst_sel/dst_unused are refused. CMake only adds a draw test per adapter. Clean-room neutrality: nothing copied seen.
Commands executed locally (Linux):
git diff --check origin/main...HEAD: rc 0tests/docs_links_check.py: passedtests/bidi_controls_check.py: passedtests/pixel_aot_check.py: rc 0 (does not reach the failing controls, see note)tests/rdna2_tools_check.py: OK (149 tests, 18 skipped)tests/form_coverage_check.py: passedtests/pixel_aot_check.py binary llvm-mc-19 llvm-objcopy-19 /usr/lib/llvm-19/lib/libLLVM-19.so: rc 1 atcheck_f16_cvt_int16_binary(v_cmpunrelated,v_cvt_f16_i16_e32); the same failure happens on current main, so it is the LLVM 19 versus LLVM 15 expectation and not this PR. As a substitute I assembled and disassembled the PR's SDWA fixtures (46 forms plus the destination fixture and the SDWA predicate groups) with llvm-mc-19 and compared the lowering of both: all matched.
Mutations on tools/pixel_aot.py (restored after each):
- Wrong sign-extension shift: caught by
tests/pixel_aot_check.py(rc 1). - i16 sign-extension replaced by a mask: survived the default Linux run; caught by the controls once the P2 assertion is fixed.
- i32 compare made unsigned: survived the default Linux run; caught by the controls once the P2 assertion is fixed.
- Sign-extension shift off by one (controls only): survives the controls and needs the GPU draw.
Windows Server 2025: not run. The node was locked by another run (PR #1749) when I tried win2025 1790 --regex pixel_aot_sdwa_cmp.
AI-assisted; commands listed were executed locally.
tedin7
left a comment
There was a problem hiding this comment.
Review of head 04291bc1af781e21702a3f5ba6b23645c97c5893 (technical comment only, no merge from this pass).
P2, still present on this head: check_sdwa_cmp_controls fails. tests/pixel_aot_check.py:4525 asserts "<< 16u) >> 16)" in model, but the i16 lowering emits (asint(<word> << 16) >> 16) without the u suffix. Reproduced with check_sdwa_cmp_controls(None): AssertionError, rc=1. check_sdwa_cmp_draw runs these controls first, so the device test would fail before any GPU work. This repeats the earlier review on the same head.
Other gates that also block: no receipt for this head, and PRs #1915, #1612 and #1572 cite the same SDWA shader concept in their titles.
Commands run (Linux):
git diff --check origin/main...HEAD: rc=0python3 tests/docs_links_check.py: rc=0python3 tests/bidi_controls_check.py: rc=0check_sdwa_cmp_controls(None)from tests/pixel_aot_check.py: rc=1
No Windows run (the controls fail first), no receipt, no merge.
AI-assisted; commands listed were executed locally.
Match the i16 lowering's actual "<<" 16) >> 16)" spelling and register check_sdwa_cmp_controls in the default control set, so the device-free guards run in pixel_aot_check.py and the Linux CI job instead of only inside the GPU draw.
|
Fixed in p.check_sdwa_cmp_controls(None) # controls ok The Windows and gfx1013 jobs are still running on |
|
@tedin7 the P2 is fixed at |
tedin7
left a comment
There was a problem hiding this comment.
Review of head ecce2d6 (TIER_D_ISOLATED_SHADER_OPS). Comment only, no approval.
The earlier P2 (check_sdwa_cmp_controls expecting "<< 16u) >> 16)") is fixed on this head: the control now expects the emitted "<< 16) >> 16)" and passes.
Commands executed locally (clean worktree of this head):
- git diff --check origin/main...HEAD: rc 0
- python3 tests/docs_links_check.py: pass (17 Markdown files, 366 links)
- python3 tests/bidi_controls_check.py: pass (1303 files, no bidirectional controls)
- check_sdwa_cmp_controls(None) from tests/pixel_aot_check.py: rc 0
- python3 tests/rdna2_tools_check.py: 149 tests OK (18 skipped)
- python3 tests/form_coverage_check.py: not runnable locally (no iced_x86 module); it ran and passed on the Windows node and in the Linux CI job
- win2025 1790 with --regex '^pixel_aot_.*_warp$' (the default regex exceeded the cmd.exe limit): Debug 81/81 and Release /O2 81/81 passed, including pixel_aot_sdwa_cmp_warp; Windows Python checks: form_coverage_check.py ok
- GitHub checks on this head: Build and test on Windows, Assemble and translate gfx1013 fixtures and Linux Python checks all pass
Mutations of tool logic in tools/pixel_aot.py (each reverted with git checkout -- .):
- i16 comparison lowered as a zero-extended low-16 mask instead of the sign-extending shift: check_sdwa_cmp_controls fails (rc 1, assertion on "<< 16) >> 16)"). Killed.
- i32 comparison operands no longer wrapped in asint(): check_sdwa_cmp_controls fails (rc 1, assertion on "asint(((params[0].w >> 8u) & 0xffu))"). Killed.
- sext() ignored in sdwa_source: the device-free controls still pass (rc 0), so only the draw-sdwa-cmp device test covers this; its wrong reference with zero extension in place of sext() is the documented guard.
Semantics read: CMakeLists.txt only registers pixel_aot_sdwa_cmp_; VOPC SDWA destination is vcc/vcc_lo or one SGPR (pairs refused); selections are zero- or sign-extended before the existing predicate tables; the result goes through the same lane-mask state as e32/e64.
P1: 0. P2: 0.
Note: #1670, #1680 and #1923 also lower SDWA comparisons and may overlap with this PR; merge order is the maintainers' call.
AI-assisted; commands listed were executed locally.
|
@R0Y00 the review on The only open question is merge order with #1670, #1680 and #1923, which overlap on 45 of these 46 forms. If you prefer the split path, I can reduce this PR to |
… controls Rebase R0Y00#1923 onto current main (after R0Y00#1790 landed all 46 non-cmpx SDWA comparisons in tools/pixel_aot.py and tools/scan_unsupported_shaders.py) and keep the supplemental per-predicate 32-bit integer test coverage: - Four 4-channel draw programs (i32_lo, i32_hi, u32_lo, u32_hi) covering all 16 v_cmp_*_{i32,u32}_sdwa forms with 41 targeted single-channel negative controls (signed vs unsigned, sext vs zero-extend, byte/word selectors, predicate swaps) registered as pixel_aot_sdwa_int_compare_{warp,hardware} and included in check_binary. - Additional static lowering and refusal checks: whole-dword equivalence with e32, single-register destination enforcement (refusing SGPR pairs and out-of-range s106), low16 VGPR source refusal, pending sample and pending scalar source/destination refusal, non-entry mask refusal, float modifiers, clamp, dst_sel, and remaining unlowered SDWA compare neighbours (i64, v_cmpx).
… controls (#1923) Rebase #1923 onto current main (after #1790 landed all 46 non-cmpx SDWA comparisons in tools/pixel_aot.py and tools/scan_unsupported_shaders.py) and keep the supplemental per-predicate 32-bit integer test coverage: - Four 4-channel draw programs (i32_lo, i32_hi, u32_lo, u32_hi) covering all 16 v_cmp_*_{i32,u32}_sdwa forms with 41 targeted single-channel negative controls (signed vs unsigned, sext vs zero-extend, byte/word selectors, predicate swaps) registered as pixel_aot_sdwa_int_compare_{warp,hardware} and included in check_binary. - Additional static lowering and refusal checks: whole-dword equivalence with e32, single-register destination enforcement (refusing SGPR pairs and out-of-range s106), low16 VGPR source refusal, pending sample and pending scalar source/destination refusal, non-entry mask refusal, float modifiers, clamp, dst_sel, and remaining unlowered SDWA compare neighbours (i64, v_cmpx). Co-authored-by: KomaGuy <265821007+KomaGuy@users.noreply.github.com>
What this changes
Lower the remaining 46 non-
v_cmpxVOPC SDWA comparisons:v_cmp_class_f16_sdwa,v_cmp_class_f32_sdwa;VOPC SDWA carries only
src0_sel/src1_sel;llvm-mcrejectsdst_sel/dst_unusedon these instructions. The destination remainsvcc/vcc_loor one SGPR, and an SGPR pair is refused. Sources acceptBYTE_0..3,WORD_0..1andDWORD, withsext()where LLVM prints it. The lowering reuses the existing f16 and integer comparison tables and the VCC/SGPR lane-mask tracking.v_cmpx_*_sdwaand the region opener are untouched.The fixture
draw-sdwa-cmpputs all 46 forms in one program, folds each predicate into twoR32G32B32A32_UINTwords, and repeats rows with selections on every field. Negative controls cover ignored selection, reversed field width, signed versus unsigned, zero extension instead ofsext(), and a second comparison overwriting the first destination.tests/form_coverage_check.pyasserts the 46 forms count and that the non-SDWA neighbours andv_cmpx_*_sdwastay out. The scanner and its binary-decoding test recognise the new forms.Verification
Base
6f2ee280:The before row is a separate full run at
6f2ee280: 132/132 passed in 476 s. The after run adds the new fixture: 133/133 in 485 s. The gfx1013 gap set goes from 697 to 651 rows, exactly the 46 forms removed and none added.Commands:
pixel_aot_sdwa_cmp_warp: passed.pixel_aot_sdwa_cmp_hardware: passed, 1.62 s, AMD Radeon RX 9060 XT, driver32.0.32029.2010, Windows 11 build10.0.26300.10075, D3D12 debug layer unavailable.form_coverage_check.py: passed.rdna2_tools_check.py: 146 tests OK, 18 skipped.docs_links_check.py: 366 links checked.bidi_controls_check.py: 1303 files, no bidirectional controls.The 46-form program and the destination-overwrite control are also part of
check_binary, so the LLVM 15Assemble and translate gfx1013 fixturesjob assembles, disassembles and re-translates every new form. A local LLVM 23 round trip passes; the pinned LLVM 15 job is the CI check.The separate
pixel_aot_comparisons_hardwarefailure on this adapter is the pre-existing strict binary32 subnormal comparison tracked by #958; it is outside this lot and does not exercise the SDWA path.Relationship to #1670 and #1680
#1670 (28 integer forms) and #1680 (17 binary16 forms) cover 45 of the 46 forms in this PR; this PR additionally covers
v_cmp_class_f32_sdwa. Those two PRs were reviewed and have now been asked to rebase. This PR was prepared independently before they appeared. If the maintainers prefer the split path, I can reduce this PR to the missing class form or close it; I do not want to duplicate reviewed work.Scope
Fixture coverage only. This does not claim console behaviour, full port completion or title startup.
This is the lot 1a of the coverage plan; the 62
v_cmpx_*_sdwaforms remain for a later change coordinated with #987/#1413.