shader: lower the 46 non-cmpx SDWA comparisons #1783
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1790"
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 lambirou on 2026-11-24T18:43:08Z.
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.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T19:29:51Z.
Review: COMMENTED
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 --checkfails. The docs hunk ends with an added blank line:git diff --check origin/main...HEADreportsdocs/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.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.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)).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.-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).tools/pixel_aot.py, each followed by the controls and then reverted withgit checkout -- .(tree clean afterwards):sextturned into zero extension: caught.pixel_aot.pyi16 branch): not caught by the device-free controls.asintdropped): not caught.src0_sel: not caught.Note on coverage. The last three mutations are the ones the PR text says the GPU fixture
draw-sdwa-cmpcatches with its wrong references (signedness inverted, selections ignored). So their protection depends onpixel_aot_sdwa_cmp_{warp,hardware}, which I could not run here (it needs Windows with DXC andoffscreen_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 thatv_cmp_lt_i32_sdwaemitsasint(and thatsrc0_sel:BYTE_1shows 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 15check_binaryround trip. I rely on the PR text for those.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by lambirou on 2026-11-24T19:22:56Z.
Updated at
bca2702cwith a test-only commit: the 46-form program and the destination-overwrite control are now incheck_binary, so the gfx1013 assembly job round-trips every new form. The fixture also uses a defined VGPR for thev_cndmasktrue value; the previous inline1was not valid assembly for that operand.Also noting the overlap explicitly: #1670 and #1680 cover 45 of the 46 forms (28 integer, 17 binary16); this PR additionally covers
v_cmp_class_f32_sdwa. If you prefer the split path, I can reduce this PR to the missing class form or close it in favour of those two. I do not want to duplicate reviewed work.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T20:23:04Z.
Review: COMMENTED
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_controlsfails on this head.tests/pixel_aot_check.py:4503asserts"<< 16u) >> 16)" in model. The i16 lowering emits(asint(<word> << 16) >> 16)(nousuffix), so the assertion raisesAssertionError. Reproduced by callingcheck_sdwa_cmp_controls(None)on this head.check_sdwa_cmp_drawruns these controls first, sopixel_aot_sdwa_cmp_<adapter>should fail before any GPU work. The lowering itself looks right: the generated line forv_cmp_lt_i16_sdwa vcc_lo, sext(s44), v18 src0_sel:BYTE_1 src1_sel:WORD_0is(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_controlsis only reached through thedraw-sdwa-cmpmode, sotests/pixel_aot_check.pywith 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 asasint/unsigned over the extended 32-bit value; i16/u16 compare the low 16 bits sign- or zero-extended;f16_comparison_bitsandf16_class_bitsshare the predicate tables and the NaN rule with the existing forms; the lane mask is VCC or one SGPR, never a pair; exec-writingv_cmpxneighbours stay refused;dst_sel/dst_unusedare 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):tests/pixel_aot_check.py(rc 1).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.
Imported from R0Y00/Xbox2Windows. Originally posted by lambirou on 2026-11-24T20:15:31Z.
Fixed in
04291bc1:docs/experiments.md;git diff --check origin/main...HEADis clean.check_sdwa_cmp_controlsfor the signed 32-bit compare (asint), the 16-bit sign extension and mask, and the f16/f32 class selections. Those are the mutations that previously passed on Linux.python -B tests/pixel_aot_check.py,form_coverage_check.py,rdna2_tools_check.py,docs_links_check.pyandbidi_controls_check.pypass locally. The gfx1013 assembly job already round-trips the 46-form fixture atbca2702c; CI is rerunning on this head.Thanks for the review.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T21:10:12Z.
Review: COMMENTED
Review of head
04291bc1af781e21702a3f5ba6b23645c97c5893(technical comment only, no merge from this pass).P2, still present on this head:
check_sdwa_cmp_controlsfails.tests/pixel_aot_check.py:4525asserts"<< 16u) >> 16)" in model, but the i16 lowering emits(asint(<word> << 16) >> 16)without theusuffix. Reproduced withcheck_sdwa_cmp_controls(None):AssertionError, rc=1.check_sdwa_cmp_drawruns 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=1No Windows run (the controls fail first), no receipt, no merge.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by lambirou on 2026-11-24T21:24:34Z.
Fixed in
ecce2d6b: the i16 assertion now matches the emitted<< 16) >> 16)spelling, andcheck_sdwa_cmp_controlsis registered in the default_CONTROL_SUBCHECKSset.python -B tests/pixel_aot_check.pynow runs it without a renderer, and the Linux CI job is green on this head. The direct call also passes:The Windows and gfx1013 jobs are still running on
ecce2d6b.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T21:35:01Z.
Review: COMMENTED
Review of head
ecce2d6bf1(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):
Mutations of tool logic in tools/pixel_aot.py (each reverted with git checkout -- .):
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.
Imported from R0Y00/Xbox2Windows. Originally posted by lambirou on 2026-11-24T21:30:28Z.
@tedin7 the P2 is fixed at
ecce2d6b: the assertion matches<< 16) >> 16), andcheck_sdwa_cmp_controlsis now in the default_CONTROL_SUBCHECKS, so the Linux job exercises it. All three Windows checks are green on this head. Could you re-review when you have a moment?Imported from R0Y00/Xbox2Windows. Originally posted by lambirou on 2026-11-24T21:45:08Z.
@R0Y00 the review on
ecce2d6bis 0 P1 / 0 P2; all three GitHub checks are green, andwin2025ran the full^pixel_aot_.*_warp$set 81/81 in Debug and Release. The PR is ready for merge.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
v_cmp_class_f32_sdwaor close it in favour of those; otherwise it is the complete 46-form version.