startup: lower 16-bit integer VOPC compares in gfx2hlsl (Part of #1723) #2361
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2369"
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 legacy-code-archaeologist on 2026-11-25T13:54:56Z.
Change
tools/startup/gfx2hlsl.pynow lowers the 16-bit integer VOPC comparesv_cmp_{lt,eq,le,gt,ne,ge}_{i16,u16}andv_cmpx_{lt,eq,le,gt,ne,ge}_{i16,u16}in the_e32and_e64encodings (48 forms). Before this change every one of them was refused as an unknown instruction. Part of #1723 (claimed in https://github.com/R0Y00/Xbox2Windows/issues/1723#issuecomment-7161903409).S0.i16/S0.u16(AMD RDNA 2 ISA guide). An i16 register reads asasint(x << 16u) >> 16u, a u16 register asx & 0xffffu. LLVM 15 selectsv_cmp_lt_i16_e32on whole VGPRs foricmp slt i16of truncated values, which matches this reading.0xffff.vcc, an SGPR lane mask, or EXEC forv_cmpx) use the existing 32-bit integer compare path unchanged.vcc/exec/m0as a source,op_sel,clamp, the NEG/ABS bits of the_e64form (checked in the raw word, since the disassembler prints NEG on inline 1 as-1), and the SDWA forms (tools/pixel_aot.pykeeps its own lowering of those).Shared interface: none. No open PR adds these forms to gfx2hlsl; I checked the
+lines of every open PR that touchestools/startup/gfx2hlsl.py.Verification
All runs:
43608f2eplus this commit, Windows 11 10.0.26100, debug layer unavailable.cmake --build --preset devctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_' -j 2ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_cmp16_' -V(default hardware = NVIDIA Quadro M1000M, driver 32.0.15.7371)XBOX2WINDOWS_ADAPTER=Intel(Intel HD Graphics 530, driver 31.0.101.2111)XBOX2WINDOWS_ADAPTER=Quadropython -B tests/startup_gfx2hlsl_cmp16_check.py binary <llvm-mc> <llvm-objcopy>tests/startup_gfx2hlsl_vopc_sdwa_check.py,form_coverage_check.py,docs_links_check.py,bidi_controls_check.py,rdna2_tools_check.pyBinary mode note: the official LLVM 15.0.7 Windows build ships no
llvm-mc. Locally a wrapper passed thellvm-mcarguments to that build's integrated assembler (clang -cc1as), and itsllvm-objcopyextracted.text. The CI LLVM 15 job runs the same mode withllvm-mc-15/llvm-objcopy-15; that run has not happened yet.Negative control: the new test file on
417a101cwithout the translator change stops at the first translated case withUnsupported: v_cmp_eq_i16(exit 1). In draw mode, two mutated lowerings (i16 read zero-extended, u16 read as the whole word) must each fail against the reference and match their own image. A separate mutation run over the lowering detected 9 of 9 mutations; that scratch script is not part of the PR.Not covered: no gfx1013 hardware run; the draws check the translated HLSL on desktop adapters against a reference written from the ISA meaning.
Evidence and follow-up
Fixtures are source-built: synthetic VOPC words, checked against LLVM 15 encodings, and three source-built pixel programs (a
v_cmpx_le_i16_e32kill, av_cmpx_gt_u16_e64kill, and all six relations of the i16/u16 e32 and e64 forms folded into mask words). No game data.Design review note: the design went through four rounds of independent critic and readiness review. The last critic round still had two open points (mutant image definition, the
s0that the disassembler prints for an_e64v_cmpx); I chose to proceed at that point, and both are addressed in the implementation (image(how)per-pixel reference, and a control that writess0, runsv_cmpx_le_i16_e64and readss0back).Possible follow-ups (not in this PR, to keep one behavior):
destinations()returnsops[0]for every non-s_cmpinstruction, so av_cmpx_*_e64marks its printeds0, and an_e32v_cmpxwith an SGPRsrc0marks that SGPR, as written. This only loses constant/uniform proofs (no wrong value found), and it applies to the 32-bit forms too. A branch test (av_cmpxin a skipped branch, then a read ofs0) would pin it.destinations()docstring says "Compares write none", which does not match the code above; best fixed together with the item before.vopc_sdwa,dpp_*,f32_lg, ...) exit 77 on the first capability skip before reporting earlier failures; this PR fixes that only in the new check.docs: new section "Startup translator: 16-bit integer compares" in
docs/experiments.md;AGENTS.mdlists the check; CI runs the no-argument mode on Linux and the binary mode in the LLVM 15 job.Checklist
This change was AI-assisted (Claude Code), with independent read-only reviews before commit.
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T13:57:40Z.
Review: COMMENTED
Review of head
5c937b2851f9c8a86951d76a073d4e8d83a9eb88(comment only, no approval).Result: no P1, no P2.
What I checked:
tools/startup/gfx2hlsl.py:_low16_sourcereads an i16 register asasint(x << 16u) >> 16uand a u16 register asx & 0xffffu. Both match the RDNA 2S0.i16/S0.u16meaning (bits 15:0 only). Inline integers -16..64 and literals up to0xfffffold to the right signed or unsigned constant. Float inline constants, wider literals, register ranges,vcc/exec/m0, and SDWA are refused.check_encoding: the NEG/ABS test on the raw VOP3 words (word0 & 0x700,word1 & 0xe0000000) is the right place, because the printed-1is ambiguous with inline 1 plus NEG.f/ton 16-bit in gfx10) are enforced before the table lookup. The 32-bit destination and EXEC path is reused unchanged.CMakeLists.txt(controls + warp + hardware),windows.yml(both lists),AGENTS.md,docs/experiments.md.Part of #1723line and aVerificationblock.Commands run locally in a worktree of this head:
python3 -B tests/startup_gfx2hlsl_cmp16_check.py->PASS(controls, 71 refusals).python3 tests/docs_links_check.py->Checked 19 Markdown files and 460 links.python3 tests/bidi_controls_check.py->Checked 1646 ... no bidirectional controls.git diff --check origin/main...HEAD-> clean.AssertionError: ('K', 'no sext', 0)).0x1ffff-> test reportsFAILin the refusals section.Not run:
binarymode (needsllvm-mc-15, not installed here).drawmode and a Windows VM run. At review time the Windows CI jobs were still pending. The PR body reports WARP and hardware draws passed. The Windows CI result should be green before merging.Nit (not blocking): none.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-25T14:25:54Z.
I reproduced the follow-up you listed for the sibling draw checks. On current main, a recorded comparison failure followed by renderer exit 77 returns 77 in the VOPC SDWA and DPP family. I’m taking the test-harness follow-up separately: verify the ordering in each affected accumulator, preserve an ordinary capability skip, and add a regression check.