startup: lower VOPC SDWA compares in gfx2hlsl #1908
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1915"
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 MasterDomino on 2026-11-24T21:06:15Z.
Refs #1906
What and why
tools/startup/gfx2hlsl.pycompare()refused every compare with an_sdwasuffix. In a local startup run onmain, 12 pipeline requests stopped atunsupported: v_cmpx_le_i32_sdwa.tools/disasm_rdna2.pyalready decodes VOPC SDWA in full (_decode_vopc_sdwa). This change lowers the SDWA forms of the compare tablecompare()already has.Change
src0_sel/src1_selfield through the existingsdwa_source(), sign-extended when the decoder printssext(). The compare reads the extended 32-bit value as its type:int(...)for i32, unsigned for u32.<name>: f32 SDWA compares are not lowered). Their predicates are shared with the non-SDWA forms, whoselg/nlgare not ordered for NaN (#1920), so no f32 SDWA lowering is claimed until those predicates are verified independently. Review follow-up in800a8e34.v_cmpx_*_sdwa(two operands; gfx10 forbidssdst_en). Forv_cmp_*_sdwa,vcc_loor the SGPR the decoder prints, throughset_sandmasks. EXEC masking is the same as in the non-SDWA path.v_cmp_class_*,v_cmpx_class_*), with the same message as before. Also refused: every f32 SDWA compare, a missing or repeated select, an unknown select value, and any SDWA modifier other thansrc0_sel/src1_sel(clamp,dst_sel,dst_unused,src2_sel,mul:2). So are a destination other thanvcc_lo, EXEC or an SGPR, the wrong operand count, and 16-bit compares.v_cmpdispatch inStage.one()already ran before the VOP1/VOP2_sdwaroute. It now passesmodstocompare().tests/offscreen_check.cppgains--startup-pixel-words <vs> <ps> <width> <height> <expected.bin>. It draws through the existingcheck_startup_flat_parampath over a width × height target and compares every pixel's four words with a file. It reports the first differing pixel and the number of differing pixels.Tests
Commit
925198a1onupstream/main94dbdbf0. Windows 11 build 26300.9974, DXC 1.8.2502.11 and FXC from Windows SDK 10.0.26100, D3D12 debug layer enabled (debug_errors=0 debug_warnings=0).Translator check against a reference (pure Python, also runs on Linux):
The check covers all 32 i32/u32 compares the decoder names (f, lt, eq, le, gt, ne, ge, t;
v_cmpandv_cmpx). Destinations arev_cmpintovcc_lo,v_cmpinto an SGPR andv_cmpxinto EXEC. Each source takes every select (BYTE_0..3, WORD_0/1, DWORD) withsext()on and off. That makes 9408 forms. Each form is built from the VOP_SDWA9Be fields, decoded bytools/disasm_rdna2.pyand translated. The emitted HLSL runs through the integer evaluator fromstartup_gfx2hlsl_bit_alu_check.pyover 64 source pairs (602,112 evaluations). The reference is the selected field, zero- or sign-extended in plain Python integers, then compared as the type says. Result:9408 integer forms x 64 pairs (602112 evaluations) equal the reference: ok. The check also confirms that the value set separates every condition from a lowering without the select or withoutsext(). It also checks:sext(s3)BYTE_3,-16);neg/abson both sources, all three destinations) are refused, and so is every byte or word select on a float source;Result: PASS, 1.9 s.
LLVM 15 round trip:
With LLVM 15.0.7, LLVM's C API disassembles all 9889 accepted forms and the pixel fixture exactly as
tools/disasm_rdna2.pydoes. Result: PASS. Thebinary <llvm-mc>mode assembles the same decoded text with llvm-mc and compares it with the words built in the test. Run locally withllvm-mc15.0.7 (from a conda LLVM 15 package):llvm-mc assembles 9889 decoded VOPC SDWA forms to the same words: ok,llvm-mc assembles the pixel fixture to the same words: ok, PASS. Both modes are added to the LLVM 15 list in.github/workflows/windows.yml(binary llvm-mc-15,decode libLLVM-15.so.1), and the controls are added to the platform-independent Python list.Draw on WARP and the RX 9070 XT:
The pixel program is source-built (
v_mul_u32_u24_e32 v1, 0x9b5d, v0, thenv_cmpx_le_i32_sdwa -16, sext(v1) src0_sel:DWORD src1_sel:BYTE_1, thenexp mrt0 v0, v0, v0, v0 done vm). It reads the packed screen position, so the compare decides per pixel which of 16 × 16 pixels survive: 160 do. Every pixel's four words are compared with a CPU reference: survivors hold the packed position, and discarded pixels keep the clear value -1.0. The pixel stage is compiled with FXCps_5_1and DXCps_6_0.No capability skips.
Other tests run:
ctest --preset dev --no-tests=error -R '^startup_' -j 4: 259 passed, 0 failed, 4 skipped (exit 77). The skipped tests arestartup_view_heap_{warp,hardware}andstartup_logical_view_{warp,hardware}. On this machine the adapter accepts enough descriptors that the logical view tables are not needed. None of the four is related to this change.ctest --preset dev --no-tests=error -R '^(startup_gfx2hlsl_|rdna2_tools|docs_links)': 29/29 passed.python -B tools/run_checks_parallel.py <the 61 checks of the python-linux job, including tests/form_coverage_check.py, tests/rdna2_tools_check.py, tests/docs_links_check.py and tests/bidi_controls_check.py>: all 61 passed.tests/form_coverage_check.pymeasurespixel_aot's accepted forms, not gfx2hlsl, so it needs no update.Negative controls
v1in place of the selected field). The other zero-extends the byte (((v1 >> 8u) & 0xffu)). Both hold on WARP and hardware, with both compilers:pixel mismatch (1,0): expected bf800000,bf800000,bf800000,bf800000 actual 00000001,00000001,00000001,00000001 / 120 of 256 pixels differpixel mismatch (1,0): expected bf800000,bf800000,bf800000,bf800000 actual 00000001,00000001,00000001,00000001 / 96 of 256 pixels differ9408 integer forms x 64 pairs ... equal the reference. The mutants are:sdwa_sourceignoring the select;sext();upstream/maintranslator. The new check stops atgfx2hlsl.Unsupported: v_cmp_f_i32_sdwa.Recount on the loading path
I re-translated the same local startup run's 185 pipeline requests offline with
upstream/mainand with this branch. Aggregate counts only:v_cmpx_le_i32_sdwa: 12 onmain, 0 on this branch.v_cmpx_le_i32_sdwa <const>, sext(vN) src0_sel:DWORD src1_sel:BYTE_0and stop at the next refusal,s_nor_b32(12).v_cmp_ne_i32_sdwa sN, sN, vN … BYTE_0(9) andv_cmpx_ne_i32_sdwa sN, vN … BYTE_0(3). The translator check above covers both forms. The class forms (v_cmp_class_f32_sdwa, 39;v_cmpx_class_f32_sdwa, 12) also remain.Not covered
lgas!=andnlgas!(a != b). For a NaN operand the ISA gives the opposite result in both cases. That affects the non-SDWA forms and is tracked in #1920; f32 SDWA forms are refused here until it is settled.v_cmp_class_*,v_cmpx_class_*, SDWA or not) stay refused. They need a class condition incompare(). That is the follow-up named in #1906.v_cmp_tru_f32and 16-bit compares stay refused, as before.🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T21:14:58Z.
Review: CHANGES_REQUESTED
The integer SDWA fixture exercises the new select and sign-extension behavior, including the reported loading refusal. The f32 matrix currently compares only against the existing non-SDWA HLSL text. That oracle shares a predicate issue: RDNA2 LG is ordered less-or-greater and NLG is its negation, while the table emits != and its negation. Those expressions can disagree on NaN. Please keep this slice integer-only, or establish the f32 predicates independently with finite unequal/equal and NaN cases on the actual emitted FXC/DXC paths. In particular, LG should be false and NLG true for a NaN input. The new f32 SDWA support should not inherit the shared predicate without evidence.
AMD RDNA 2 ISA
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T21:16:21Z.
Review: COMMENTED
Review of exact head
925198a1a5ccbfa36f7e4cbb27d59175d4d2c64d(title and body are neutral; the diff touches.github/workflows/windows.yml,CMakeLists.txt,docs/experiments.md,docs/startup-runtime.md,tests/offscreen_check.cpp,tests/startup_gfx2hlsl_vopc_sdwa_check.py,tools/startup/gfx2hlsl.py).Verdict: no P1, no P2, no P3 found.
Commands run locally (against
origin/main...HEAD):git diff --check origin/main...HEAD: clean, rc=0tests/docs_links_check.py: "Self-test passed. Checked 18 Markdown files and 377 links."tests/bidi_controls_check.py: "Checked 1339 tracked source, script and build/CI files: no bidirectional controls."tests/startup_gfx2hlsl_vopc_sdwa_check.py(plain): PASS.tests/startup_gfx2hlsl_vopc_sdwa_check.py binary llvm-mc-19: "llvm-mc assembles 9889 decoded VOPC SDWA forms to the same words: ok", PASS. (The workflow passesllvm-mc-15; I hadllvm-mc-19.)tests/startup_gfx2hlsl_vopc_sdwa_check.py decode libLLVM-19.so: "LLVM disassembles 9889 VOPC SDWA forms as tools/disasm_rdna2.py does: ok", PASS. (The workflow passeslibLLVM-15.so.1.)x2w_pipe.py win2025 1915 --targets offscreen_check --regex '^startup_gfx2hlsl_vopc_sdwa(_warp)?$'on Windows Server 2025 (Debug and Release /O2): 2/2 passed in both (startup_gfx2hlsl_vopc_sdwaand the 16 x 16 pixel drawstartup_gfx2hlsl_vopc_sdwa_warp, which exercises the new--startup-pixel-wordsoperation).Mutations (applied to
tools/startup/gfx2hlsl.pyon top of the exact head,startup_gfx2hlsl_vopc_sdwa_check.pyplain run, then restored; the checkout stayed clean):sdwa_source(self.u(token), selection, sext)changed to passFalsefor sext (no sign extension): 5 MISMATCH lines, the run asserts. Caught.'int(%s)' % word if typ == 'i32' else wordchanged to alwaysword(i32 compared as unsigned): 7 MISMATCH lines. Caught.if selection != 'DWORD': raisechanged toif False(byte/word select accepted on a float source): 12 MISMATCH lines. Caught.v_cmp_*_sdwa(if not writes_exec and ops[0] not in ...) disabled: the run crashes withTypeError: 'NoneType' object is not subscriptable. Caught (and it shows the guard is load-bearing:vcc_hiandnullreachreg_rangeotherwise).What I checked by reading and probing:
sdwa_sourcewith sext: forBYTE_1,asuint(asint(v << 16u) >> 24u)is the sign-extended byte; forWORD_1,asuint(asint(v << 0u) >> 16u)is the sign-extended high word. Both match the ISA meaning. u32 reads the extended value as unsigned and i32 wraps it inint().Stage.one: float-|v1|with DWORD selects emits-abs(F(v1)), the same as the non-SDWA form;sext(v1)on a float source, a doublesext(sext(v1)),src0_sel:BYTE_9, a repeatedsrc0_sel, a missingsrc1_sel, and destinationsvcc_hiandnullare all refused withUnsupported, not a crash.run_startup_pixel_wordsrejects non-numeric or out-of-range sizes and an expected file that is too short or too long, and counts every differing pixel.Limits: only WARP was available (the
hardwarevariant of the draw test was not run). Localllvm-mcandlibLLVMare version 19, not the 15 used in the workflow.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T21:24:37Z.
Review: APPROVED
Rechecked the integer-only head. On this exact commit the 9,408 integer forms x 64 inputs and mutation controls pass, all 720 f32 SDWA forms are refused and the startup translator neighbors pass. The existing floating-point comparison follow-up remains #1920.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T21:24:55Z.
Review: COMMENTED
Follow-up review of exact head
800a8e34d2368b497720c233491e941ac69321f6(delta since925198a1:docs/experiments.md,docs/startup-runtime.md,tests/startup_gfx2hlsl_vopc_sdwa_check.py,tools/startup/gfx2hlsl.py).Verdict: no P1, no P2, no P3 found at this head.
Correction to my review of
925198a1: I wrote that the f32 SDWA text "equals the non-SDWA form's" and treated that as correct. That oracle shares thelg/nlgtable entries ({0} != {1}and its negation), which are not the ordered RDNA 2 definitions for NaN. The earlier request for changes was right and I missed it. Refusing f32 SDWA compares, as this head does, is the safe fix; the non-SDWA predicates are tracked in #1920.Commands run locally (against
origin/main...HEAD):git diff --check origin/main...HEAD: clean, rc=0tests/docs_links_check.py: "Checked 18 Markdown files and 377 links." (self-test passed)tests/bidi_controls_check.py: "Checked 1339 tracked source, script and build/CI files: no bidirectional controls."tests/startup_gfx2hlsl_vopc_sdwa_check.py(plain),binary llvm-mc-19(9889 forms, same words),decode libLLVM-19.so(9889 forms): all PASS.x2w_pipe.py win2025 1915 --targets offscreen_check --regex '^startup_gfx2hlsl_vopc_sdwa(_warp)?$'on Windows Server 2025 (Debug and Release /O2): 2/2 passed in both.Mutations (
tools/startup/gfx2hlsl.pyon top of the exact head, plain check run, then restored; the checkout stayed clean):if False and sdwa and typ == 'f32'): 13 MISMATCH lines. Caught.lgandnlg(the conditions the review named): 1 MISMATCH ("720 float SDWA forms refused"). Caught, so a partial refusal is detected.sdwa_source(..., False)): 5 MISMATCH lines, the run asserts. Caught.int()wrap removed): 7 MISMATCH lines. Caught.What I checked by reading: the refusal sits after the condition-table check and before any operand is read, so class compares and unknown conditions keep their old messages and all 720 f32 SDWA forms get the same message. The integer lowering, destination rules and pixel-words operation are unchanged from the previous head, and the docs now say f32 SDWA is refused (#1920).
Limits: only WARP was available here; the hardware variant was not run by me (the author reports it). Local
llvm-mcandlibLLVMare version 19, the workflow uses 15.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-24T21:09:36Z.
The llvm-mc encode mode now also passes locally:
startup_gfx2hlsl_vopc_sdwa_check.py binarywith llvm-mc 15.0.7 assembles all 9,889 decoded VOPC SDWA forms and the pixel fixture to the same words (PASS). Description updated.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-24T21:20:04Z.
Agreed, and taken as integer-only in
800a8e34:<name>: f32 SDWA compares are not lowered), so none of them inherits the sharedlg/nlgpredicates.neg/abson both sources, all destinations) and every byte or word select on a float source are refused.Results at
800a8e34:startup_gfx2hlsl_*: 27/27, includingstartup_gfx2hlsl_vopc_sdwa_{warp,hardware}on WARP and the RX 9070 XT.binarywith llvm-mc 15.0.7: PASS.decodewith LLVM-C 15.0.7: PASS.The f32 predicates themselves are #1920. I'm establishing them there independently: finite equal and unequal, ±0, ±inf, denormal and NaN cases, on the emitted FXC and DXC paths, with LG false and NLG true for a NaN input. f32 SDWA can follow once that holds.
@tedin7 thanks for the mutation run; none of the integer paths you probed changed.
AI-assisted.