shader: lower gfx1013 16-bit integer comparisons in pixel_aot #524

Manually merged
github merged 1 commit from gh-pr/524/head into gh-pr/524/base 2026-11-26 21:58:51 +00:00
Owner

@⁠Vonsek on GitHub · 2026-11-22 09:11 UTC · original
Vonsek:pixel-aot-int-compares → main · +204 −0 · 4 files · 1 commits · merged 2026-11-22 09:46 UTC

Change

tools/pixel_aot.py now lowers v_cmp_{eq,ne,lt,le,gt,ge}_{i16,u16} in the VOPC (_e32, writing vcc) and VOP3 (_e64, writing an SGPR or SGPR pair) encodings. The 32-bit integer comparisons are already on main (de229bb); these are the remaining same-width VOPC integer compares the translator refused.

  • Only the low 16 bits of each source take part. Signed operands become asint(x << 16) >> 16, unsigned ones x & 0xffff, where x is the register's 32-bit pattern. The comparison writes the same tracked lane mask as the other v_cmp_* forms, so v_cndmask_b32 consumes it unchanged under either wavefront-width spelling.
  • A source may be a VGPR, an SGPR, an integer inline constant from -16 to 64 or a literal up to 0xffff. LLVM prints a float inline constant on a 16-bit integer operand as its binary16 literal (1.0 as 0x3c00), so float tokens never name a valid operand here and are refused, as are wider literals, source modifiers, clamp and op_sel.
  • Still rejected and tested as rejected: the exec-writing v_cmpx_* forms (16- and 32-bit), v_cmp_*_{i64,u64}, v_cmp_*_f16, v_cmp_class_f16, the nonexistent v_cmp_{f,t}_{i16,u16}, reads of pending constants or samples, and comparisons outside the entry execution mask.
  • tests/form_coverage_check.py asserts that the controls alone make tools/form_coverage.py count all 24 16-bit forms and all 32 32-bit integer comparison forms (VOPC for _e32, VOP3 for _e64) in both gfx1013 and rdna2, and that the rejected neighbours are not counted. The controls now translate every 32-bit integer comparison group so those 32 forms are counted too.

Verification

  • Linux, tests/pixel_aot_check.py controls: expression checks for sign and zero extension, inline constants and the 0x8000 literal, wave64 spellings, the CPU reference against an independent truth table, and 20 rejections. Passes.
  • Linux, tests/pixel_aot_check.py binary ... (LLVM 18): the 8 new programs (24 forms) assemble with -mcpu=gfx1013, disassemble back and lower to the same HLSL. Passes.
  • Linux, tests/form_coverage_check.py: passes.
  • Fail before: with tools/pixel_aot.py reverted, the controls, the binary mode and the form coverage check all fail with Unsupported instruction ... v_cmp_ne_i16_e32.
  • D3D12 draws (draw-predicate-rounding mode): 8 shaders × 6 word pairs against the exact CPU reference, plus three references that must report pixel_mismatch: a signed shader against the unsigned reference on 0x8000 vs 0, eq replaced by ne on equal low halves, and v_cmp_*_u32 against the 16-bit reference on words whose low halves are equal but whose whole words are not. Each word is a normal binary32 value so a float move cannot flush or quiet it. Measured on Windows: every draw matches the reference and all three negative references report pixel_mismatch, on the RTX 5080 and on WARP.
  • Windows: ctest --preset dev --no-tests=error -R '^pixel_aot_predicate_rounding_(warp|hardware)$' -V at 94bb90e on Windows 11 build 26200.9974, VS Build Tools 2022 17.14 (MSVC 14.44.35207), Windows SDK 10.0.26100, DXC 1.9.2602.17: 2/2 passed. pixel_aot_predicate_rounding_hardware on an NVIDIA GeForce RTX 5080 (driver 32.0.16.1692) took 44.7 s and 40.5 s in two runs, and pixel_aot_predicate_rounding_warp took 8.7 s and 8.9 s, both under the 60 s timeout; the hardware time is mostly DXC compiles and device setup per draw. The D3D12 debug layer was not available. The full ctest --preset dev --no-tests=error passed 236/236, with bvh_wave64_hardware, bvh_wave64_warp and wave_shuffle_warp skipped.

Evidence and follow-up

  • Semantics follow the RDNA 2 ISA (16-bit VOPC compares read the low half of each source) and LLVM's operand model for gfx1013; integer inline constants are sign-extended to 16 bits. How Scarlett hardware treats a float inline constant on a 16-bit integer operand is not measured; the translator never sees one from LLVM's disassembly.
  • Fixtures were assembled with LLVM 18 locally; the Ubuntu CI job uses LLVM 15.
  • v_cmpx_* stays rejected: the translator's execution model has only the entry mask and cannot represent per-lane exec writes. 64-bit and f16 comparisons are separate follow-ups.
  • The hardware variant now uses about two thirds of its 60 s timeout on this machine; more draws in the same test may need a larger timeout or a split.
**@⁠Vonsek** on GitHub · 2026-11-22 09:11 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/524) `Vonsek:pixel-aot-int-compares` → `main` · +204 −0 · 4 files · 1 commits · merged 2026-11-22 09:46 UTC ## Change `tools/pixel_aot.py` now lowers `v_cmp_{eq,ne,lt,le,gt,ge}_{i16,u16}` in the VOPC (`_e32`, writing `vcc`) and VOP3 (`_e64`, writing an SGPR or SGPR pair) encodings. The 32-bit integer comparisons are already on main (de229bb); these are the remaining same-width VOPC integer compares the translator refused. - Only the low 16 bits of each source take part. Signed operands become `asint(x << 16) >> 16`, unsigned ones `x & 0xffff`, where `x` is the register's 32-bit pattern. The comparison writes the same tracked lane mask as the other `v_cmp_*` forms, so `v_cndmask_b32` consumes it unchanged under either wavefront-width spelling. - A source may be a VGPR, an SGPR, an integer inline constant from -16 to 64 or a literal up to `0xffff`. LLVM prints a float inline constant on a 16-bit integer operand as its binary16 literal (`1.0` as `0x3c00`), so float tokens never name a valid operand here and are refused, as are wider literals, source modifiers, `clamp` and `op_sel`. - Still rejected and tested as rejected: the exec-writing `v_cmpx_*` forms (16- and 32-bit), `v_cmp_*_{i64,u64}`, `v_cmp_*_f16`, `v_cmp_class_f16`, the nonexistent `v_cmp_{f,t}_{i16,u16}`, reads of pending constants or samples, and comparisons outside the entry execution mask. - `tests/form_coverage_check.py` asserts that the controls alone make `tools/form_coverage.py` count all 24 16-bit forms and all 32 32-bit integer comparison forms (VOPC for `_e32`, VOP3 for `_e64`) in both gfx1013 and rdna2, and that the rejected neighbours are not counted. The controls now translate every 32-bit integer comparison group so those 32 forms are counted too. ## Verification - Linux, `tests/pixel_aot_check.py` controls: expression checks for sign and zero extension, inline constants and the `0x8000` literal, wave64 spellings, the CPU reference against an independent truth table, and 20 rejections. Passes. - Linux, `tests/pixel_aot_check.py binary ...` (LLVM 18): the 8 new programs (24 forms) assemble with `-mcpu=gfx1013`, disassemble back and lower to the same HLSL. Passes. - Linux, `tests/form_coverage_check.py`: passes. - Fail before: with `tools/pixel_aot.py` reverted, the controls, the binary mode and the form coverage check all fail with `Unsupported instruction ... v_cmp_ne_i16_e32`. - D3D12 draws (`draw-predicate-rounding` mode): 8 shaders × 6 word pairs against the exact CPU reference, plus three references that must report `pixel_mismatch`: a signed shader against the unsigned reference on `0x8000` vs 0, `eq` replaced by `ne` on equal low halves, and `v_cmp_*_u32` against the 16-bit reference on words whose low halves are equal but whose whole words are not. Each word is a normal binary32 value so a float move cannot flush or quiet it. Measured on Windows: every draw matches the reference and all three negative references report `pixel_mismatch`, on the RTX 5080 and on WARP. - Windows: `ctest --preset dev --no-tests=error -R '^pixel_aot_predicate_rounding_(warp|hardware)$' -V` at 94bb90e on Windows 11 build 26200.9974, VS Build Tools 2022 17.14 (MSVC 14.44.35207), Windows SDK 10.0.26100, DXC 1.9.2602.17: 2/2 passed. `pixel_aot_predicate_rounding_hardware` on an NVIDIA GeForce RTX 5080 (driver 32.0.16.1692) took 44.7 s and 40.5 s in two runs, and `pixel_aot_predicate_rounding_warp` took 8.7 s and 8.9 s, both under the 60 s timeout; the hardware time is mostly DXC compiles and device setup per draw. The D3D12 debug layer was not available. The full `ctest --preset dev --no-tests=error` passed 236/236, with `bvh_wave64_hardware`, `bvh_wave64_warp` and `wave_shuffle_warp` skipped. ## Evidence and follow-up - Semantics follow the RDNA 2 ISA (16-bit VOPC compares read the low half of each source) and LLVM's operand model for gfx1013; integer inline constants are sign-extended to 16 bits. How Scarlett hardware treats a float inline constant on a 16-bit integer operand is not measured; the translator never sees one from LLVM's disassembly. - Fixtures were assembled with LLVM 18 locally; the Ubuntu CI job uses LLVM 15. - `v_cmpx_*` stays rejected: the translator's execution model has only the entry mask and cannot represent per-lane exec writes. 64-bit and f16 comparisons are separate follow-ups. - The hardware variant now uses about two thirds of its 60 s timeout on this machine; more draws in the same test may need a larger timeout or a split.
Lower v_cmp_{eq,ne,lt,le,gt,ge}_{i16,u16} in e32 and e64 encodings.
Only the low 16 bits of each source are compared, sign-extended or
zero-extended, and the result feeds v_cndmask_b32 through the tracked
lane mask. Float tokens, wider literals, modifiers, clamp and op_sel
are refused; v_cmpx, 64-bit, f16 and f16 class comparisons stay
rejected.

Binary fixtures cover all 24 forms. The predicate draws evaluate every
predicate on six word pairs with three references that must mismatch
(signed vs unsigned, eq vs ne, 32-bit vs 16-bit). The form coverage
check now asserts that all 16-bit and 32-bit integer comparison forms
are counted and that the rejected neighbours are not.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 21:58:48 +00:00
github manually merged commit 94bb90e716 into gh-pr/524/base 2026-11-26 21:58:51 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-22 09:31 UTC · original · edited 2026-11-22 09:36 UTC

Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T09:36:01.964944Z 94bb90e Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@⁠codex review" or "@⁠codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-22 09:31 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/524#issuecomment-7077205898) · edited 2026-11-22 09:36 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"94bb90e71660984c740512330140ecce6b8282f4","has_any_findings":false,"has_unresolved_findings":false,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-22T09:36:01.964944Z">2026-11-22T09:36:01.964944Z</relative-time> | `94bb90e` | Draft marked ready | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@⁠codex review" or "@⁠codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
This discussion has been locked. Commenting is limited to contributors.
No description provided.