Skip to content

shader: lower the 46 non-cmpx SDWA comparisons - #1790

Merged
R0Y00 merged 4 commits into
R0Y00:mainfrom
lambirou:shader/sdwa-cmp
Nov 24, 2026
Merged

R0Y00 merged 4 commits into
R0Y00:mainfrom
lambirou:shader/sdwa-cmp

Conversation

@lambirou

@lambirou lambirou commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Lower the remaining 46 non-v_cmpx VOPC SDWA comparisons:

  • 16 binary16 predicates, v_cmp_class_f16_sdwa, v_cmp_class_f32_sdwa;
  • 8 signed and 8 unsigned 32-bit predicates;
  • 6 signed and 6 unsigned 16-bit predicates.

VOPC SDWA carries only src0_sel/src1_sel; llvm-mc rejects dst_sel/dst_unused on these instructions. The destination remains vcc/vcc_lo or one SGPR, and an SGPR pair is refused. Sources accept BYTE_0..3, WORD_0..1 and DWORD, with sext() where LLVM prints it. The lowering reuses the existing f16 and integer comparison tables and the VCC/SGPR lane-mask tracking. v_cmpx_*_sdwa and the region opener are untouched.

The fixture draw-sdwa-cmp puts all 46 forms in one program, folds each predicate into two R32G32B32A32_UINT words, and repeats rows with selections on every field. Negative controls cover ignored selection, reversed field width, signed versus unsigned, zero extension instead of sext(), and a second comparison overwriting the first destination. tests/form_coverage_check.py asserts the 46 forms count and that the non-SDWA neighbours and v_cmpx_*_sdwa stay out. The scanner and its binary-decoding test recognise the new forms.

Verification

Base 6f2ee280:

Reference Before After Delta
gfx1013 1271/1968 1317/1968 +46
gfx1030 1262/1863 1308/1863 +46

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:

ctest --preset dev --no-tests=error -R '^(pixel_aot_|compute_store_aot_)' -E '_hardware$' -j 1 --output-junit out/build/dev/out/wave1-submit.xml
python -B tools/form_coverage.py out/build/dev/out/wave1-submit.xml --records out/build/dev/form_coverage --json out/wave1-submit.json
python -B tests/form_coverage_check.py
python -B tests/rdna2_tools_check.py
python -B tests/docs_links_check.py
python -B tests/bidi_controls_check.py
  • Full non-hardware shader run: 133/133 passed, 0 failed, 0 skipped, 485 s.
  • pixel_aot_sdwa_cmp_warp: passed.
  • pixel_aot_sdwa_cmp_hardware: passed, 1.62 s, AMD Radeon RX 9060 XT, driver 32.0.32029.2010, Windows 11 build 10.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 15 Assemble and translate gfx1013 fixtures job 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_hardware failure 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_*_sdwa forms remain for a later change coordinated with #987/#1413.

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.
@lambirou

Copy link
Copy Markdown
Contributor Author

Updated at bca2702c with a test-only commit: the 46-form program and the destination-overwrite control are now in check_binary, so the gfx1013 assembly job round-trips every new form. The fixture also uses a defined VGPR for the v_cndmask true value; the previous inline 1 was 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.

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_source zero-extends the selected field, or sign-extends it under sext() (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 asint for the signed forms and the plain uint for the unsigned ones. 16-bit forms take the low 16 bits: sign-extended by asint(w << 16) >> 16 for i16, masked by 0xffff for u16. With sext on 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/class16 helpers (shared through the new f16_comparison_bits and f16_class_bits; the old f16_comparison/f16_class callers go through them unchanged). f32 class uses class32(asfloat(selected)).
  • The destination is vcc, vcc_lo or one SGPR; a pair is refused, no dst_sel/dst_unused is accepted, and the entry-mask and pending-register checks match the neighbouring compare branches.
  • Source modifiers (-v1, |v1|) are not parsed by vop3p_f16_word or int_operand here, so they end in the generic refusal. Conservative, which I think is right for this lot.
  • scan_unsupported_shaders.py adds 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_x86 is not installed on this machine (error in tools/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 with git checkout -- . (tree clean afterwards):
    • sext turned into zero extension: caught.
    • i16 compares zero-extended instead of sign-extended (pixel_aot.py i16 branch): not caught by the device-free controls.
    • i32 compares made unsigned (asint dropped): 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.
@lambirou

Copy link
Copy Markdown
Contributor Author

Fixed in 04291bc1:

  • Removed the extra blank line at EOF in docs/experiments.md; git diff --check origin/main...HEAD is clean.
  • Added device-free assertions in check_sdwa_cmp_controls for 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.py and bidi_controls_check.py pass locally. The gfx1013 assembly job already round-trips the 46-form fixture at bca2702c; CI is rerunning on this head.

Thanks for the review.

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 0
  • tests/docs_links_check.py: passed
  • tests/bidi_controls_check.py: passed
  • tests/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: passed
  • tests/pixel_aot_check.py binary llvm-mc-19 llvm-objcopy-19 /usr/lib/llvm-19/lib/libLLVM-19.so: rc 1 at check_f16_cvt_int16_binary (v_cmp unrelated, 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):

  1. Wrong sign-extension shift: caught by tests/pixel_aot_check.py (rc 1).
  2. i16 sign-extension replaced by a mask: survived the default Linux run; caught by the controls once the P2 assertion is fixed.
  3. i32 compare made unsigned: survived the default Linux run; caught by the controls once the P2 assertion is fixed.
  4. 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 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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=0
  • python3 tests/docs_links_check.py: rc=0
  • python3 tests/bidi_controls_check.py: rc=0
  • check_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.
@lambirou

Copy link
Copy Markdown
Contributor Author

Fixed in ecce2d6b: the i16 assertion now matches the emitted << 16) >> 16) spelling, and check_sdwa_cmp_controls is registered in the default _CONTROL_SUBCHECKS set. python -B tests/pixel_aot_check.py now runs it without a renderer, and the Linux CI job is green on this head. The direct call also passes:

p.check_sdwa_cmp_controls(None)  # controls ok

The Windows and gfx1013 jobs are still running on ecce2d6b.

@lambirou

Copy link
Copy Markdown
Contributor Author

@tedin7 the P2 is fixed at ecce2d6b: the assertion matches << 16) >> 16), and check_sdwa_cmp_controls is 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?

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 -- .):

  1. 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.
  2. i32 comparison operands no longer wrapped in asint(): check_sdwa_cmp_controls fails (rc 1, assertion on "asint(((params[0].w >> 8u) & 0xffu))"). Killed.
  3. 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.

@lambirou

Copy link
Copy Markdown
Contributor Author

@R0Y00 the review on ecce2d6b is 0 P1 / 0 P2; all three GitHub checks are green, and win2025 ran 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_sdwa or close it in favour of those; otherwise it is the complete 46-form version.

@R0Y00
R0Y00 merged commit a20fc74 into R0Y00:main Nov 24, 2026
5 checks passed
KomaGuy added a commit to KomaGuy/Xbox2Windows that referenced this pull request Nov 25, 2026
… 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).
@lambirou
lambirou deleted the shader/sdwa-cmp branch November 25, 2026 15:07
MasterDomino pushed a commit that referenced this pull request Nov 25, 2026
… 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>
@tedin7 tedin7 mentioned this pull request Nov 26, 2026
5 tasks done
@R0Y00 R0Y00 mentioned this pull request Nov 26, 2026
5 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants