shader: lower 32-bit scalar ALU, comparisons and SCC selects in pixel_aot #254

Merged
Vonsek merged 7 commits from upstream-pr/257 into main 2026-11-22 08:52:22 +00:00
Vonsek commented 2026-11-21 19:34:42 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T19:34:42Z.


Change

tools/pixel_aot.py now lowers gfx1013 scalar ALU instructions that work on uniform 32-bit values. Their sources can be immediates (including float inline constants as bit patterns), constant words loaded with s_buffer_load_dwordx4, and earlier scalar results. Each result becomes an HLSL uint local. A vector operand or v_mov_b32 reads a scalar result through asfloat.

  • SOP2: s_add_u32, s_sub_u32, s_add_i32, s_sub_i32, s_mul_i32, s_min_u32, s_max_u32, s_min_i32, s_max_i32, s_and_b32, s_or_b32, s_xor_b32, s_andn2_b32, s_orn2_b32, s_lshl_b32, s_lshr_b32, s_ashr_i32, s_cselect_b32
  • SOP1: s_not_b32 (s_mov_b32 was already supported)
  • SOPC: s_cmp_{eq,lg,gt,ge,lt,le}_{i32,u32}
  • SOPK: s_movk_i32 was already lowered and is now exercised by a fixture

SCC is tracked as an HLSL boolean expression, following the RDNA definitions: carry or borrow for s_add_u32 and s_sub_u32; signed overflow for s_add_i32 and s_sub_i32; the comparison result for min, max and s_cmp_*; a nonzero result for the bitwise and shift forms. s_mul_i32 leaves SCC unchanged. A shift uses the low five bits of its count. s_cselect_b32 is rejected unless the lowerer saw an SCC write. s_wqm_b64 exec, exec and the s_and_b64 exec restore clear the tracked SCC, because those instructions also write SCC.

The lowerer rejects operands still loading before s_waitcnt lgkmcnt(0) or destinations those loads will still fill; descriptor words, the texture pointer, lane masks, vcc, exec, VGPRs and unset registers; and destinations other than a plain SGPR. Scalar results are not folded to constants, so they cannot supply a texture address or a sampler word.

These neighboring forms remain unsupported and are tested as rejections: s_addc_u32, s_subb_u32, s_mul_hi_u32, s_absdiff_i32, s_nand_b32, s_xnor_b32, s_bfe_u32, s_lshl1_add_u32, s_abs_i32, s_brev_b32, 64-bit forms, s_cselect_b64, s_cmp_eq_u64, s_bitcmp1_b32, s_cmpk_eq_u32 and s_cmovk_i32.

A second commit regenerates docs/coverage/dashboard.svg with tools/form_coverage.py and tools/coverage_svg.py from a full Windows run of this branch.

Interaction with other open PRs: #232 touches the same README row (one-line conflict); #169 already conflicts with current main and this adds one more tests/pixel_aot_check.py hunk to that conflict.

Verification

  • New fixture scalar() in tests/pixel_aot_check.py: 23 SCC producers, each followed by s_cselect_b32 and an s_or_b32 into a flag word; 32-bit results mixed into a hash with s_mul_i32/s_add_u32. The 23 flags and a 17-bit fold of the hash are packed into four 10-bit fields exported as 1 + k/1024, which binary16 holds exactly, so the comparison is bitwise.
  • CPU reference: scalar_reference() is a Python interpreter written from the ISA definitions, using wide-integer range checks for carry and overflow (the translator uses an XOR-based overflow test). Every flag select takes a different arm between the two constant sets, (−16, 32, 0x80000000, 1) and (5, 5, 0x7fffffff, 0xffffffff), and each of three mutations changes the reference for at least one set: s_ashr_i32→s_lshr_b32, s_cmp_lt_i32→s_cmp_lt_u32, and swapped s_sub_u32 sources.
  • D3D12 (draw mode): the scalar program is drawn with both constant sets and compared with the reference; each mutation must report pixel_mismatch.
  • Linux, llvm-mc 18 (gfx1013): tests/pixel_aot_check.py binary ... passes (assembled, wrapped, extracted, disassembled, lowered; HLSL matches lowering the source text).
  • tests/form_coverage_check.py asserts that all 32 new SOP1/SOP2/SOPC/SOPK forms are counted against both gfx1013.tsv and rdna2.tsv, and that the rejected neighbors are not. gfx1013 forms counted by the pixel test went from 43 to 75 (SOP1/SOP2/SOPC/SOPK from 4 to 36); gfx1030 changed the same way.
  • Fail before / pass after: with only tools/pixel_aot.py reverted to main, both checks fail with Unsupported instruction 22: s_add_u32 s62, s44, s45.
  • Windows: ctest --preset dev --no-tests=error -R '^pixel_aot_' -V at 872f529 (rebased on main d311159; earlier runs at 1602962 and 38590ab gave the same result) 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. This is the first DXC compile and D3D12 draw of scalar(); it needed no changes. pixel_aot_hardware on an NVIDIA GeForce RTX 5080 (driver 32.0.16.1692) and pixel_aot_warp on the Microsoft Basic Render Driver report pixels=4096 channels=16384 max_absolute_error=0 for every draw, including both constant sets of scalar(), and the three mutations report the expected mismatch. The NaN and −0.0 constant patterns therefore arrive unchanged through the float constant buffer on both backends. The D3D12 debug layer was not available. The full ctest --preset dev --no-tests=error passed 136/136, with bvh_wave64_hardware, bvh_wave64_warp and wave_shuffle_warp skipped. On that run tools/form_coverage.py reports gfx1013 93 of 1968 forms and gfx1030 93 of 1863 (all of main's pixel programs plus this one), x64 49 of 948.

Evidence and follow-up

  • The constant words reach the shader as asuint(params[...]) of a float cbuffer. Several inputs (0xfffffff0, 0x7fffffff, 0xffffffff) are NaN bit patterns and 0x80000000 is −0.0, so the draw also checks that these patterns are not canonicalized through a bitcast.
  • Not covered: carry-in/borrow-in (s_addc_u32, s_subb_u32), s_cmov*, s_cmpk_*, bitfield and 64-bit scalar forms, and scalar results used as descriptors or branch conditions.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6533463492 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/257). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-21T19:34:42Z. --- ## Change `tools/pixel_aot.py` now lowers gfx1013 scalar ALU instructions that work on uniform 32-bit values. Their sources can be immediates (including float inline constants as bit patterns), constant words loaded with `s_buffer_load_dwordx4`, and earlier scalar results. Each result becomes an HLSL `uint` local. A vector operand or `v_mov_b32` reads a scalar result through `asfloat`. - SOP2: `s_add_u32`, `s_sub_u32`, `s_add_i32`, `s_sub_i32`, `s_mul_i32`, `s_min_u32`, `s_max_u32`, `s_min_i32`, `s_max_i32`, `s_and_b32`, `s_or_b32`, `s_xor_b32`, `s_andn2_b32`, `s_orn2_b32`, `s_lshl_b32`, `s_lshr_b32`, `s_ashr_i32`, `s_cselect_b32` - SOP1: `s_not_b32` (`s_mov_b32` was already supported) - SOPC: `s_cmp_{eq,lg,gt,ge,lt,le}_{i32,u32}` - SOPK: `s_movk_i32` was already lowered and is now exercised by a fixture SCC is tracked as an HLSL boolean expression, following the RDNA definitions: carry or borrow for `s_add_u32` and `s_sub_u32`; signed overflow for `s_add_i32` and `s_sub_i32`; the comparison result for min, max and `s_cmp_*`; a nonzero result for the bitwise and shift forms. `s_mul_i32` leaves SCC unchanged. A shift uses the low five bits of its count. `s_cselect_b32` is rejected unless the lowerer saw an SCC write. `s_wqm_b64 exec, exec` and the `s_and_b64` exec restore clear the tracked SCC, because those instructions also write SCC. The lowerer rejects operands still loading before `s_waitcnt lgkmcnt(0)` or destinations those loads will still fill; descriptor words, the texture pointer, lane masks, `vcc`, `exec`, VGPRs and unset registers; and destinations other than a plain SGPR. Scalar results are not folded to constants, so they cannot supply a texture address or a sampler word. These neighboring forms remain unsupported and are tested as rejections: `s_addc_u32`, `s_subb_u32`, `s_mul_hi_u32`, `s_absdiff_i32`, `s_nand_b32`, `s_xnor_b32`, `s_bfe_u32`, `s_lshl1_add_u32`, `s_abs_i32`, `s_brev_b32`, 64-bit forms, `s_cselect_b64`, `s_cmp_eq_u64`, `s_bitcmp1_b32`, `s_cmpk_eq_u32` and `s_cmovk_i32`. A second commit regenerates `docs/coverage/dashboard.svg` with `tools/form_coverage.py` and `tools/coverage_svg.py` from a full Windows run of this branch. Interaction with other open PRs: #232 touches the same README row (one-line conflict); #169 already conflicts with current main and this adds one more `tests/pixel_aot_check.py` hunk to that conflict. ## Verification - New fixture `scalar()` in `tests/pixel_aot_check.py`: 23 SCC producers, each followed by `s_cselect_b32` and an `s_or_b32` into a flag word; 32-bit results mixed into a hash with `s_mul_i32`/`s_add_u32`. The 23 flags and a 17-bit fold of the hash are packed into four 10-bit fields exported as `1 + k/1024`, which binary16 holds exactly, so the comparison is bitwise. - CPU reference: `scalar_reference()` is a Python interpreter written from the ISA definitions, using wide-integer range checks for carry and overflow (the translator uses an XOR-based overflow test). Every flag select takes a different arm between the two constant sets, (−16, 32, 0x80000000, 1) and (5, 5, 0x7fffffff, 0xffffffff), and each of three mutations changes the reference for at least one set: `s_ashr_i32`→`s_lshr_b32`, `s_cmp_lt_i32`→`s_cmp_lt_u32`, and swapped `s_sub_u32` sources. - D3D12 (draw mode): the scalar program is drawn with both constant sets and compared with the reference; each mutation must report `pixel_mismatch`. - Linux, llvm-mc 18 (gfx1013): `tests/pixel_aot_check.py binary ...` passes (assembled, wrapped, extracted, disassembled, lowered; HLSL matches lowering the source text). - `tests/form_coverage_check.py` asserts that all 32 new SOP1/SOP2/SOPC/SOPK forms are counted against both `gfx1013.tsv` and `rdna2.tsv`, and that the rejected neighbors are not. gfx1013 forms counted by the pixel test went from 43 to 75 (SOP1/SOP2/SOPC/SOPK from 4 to 36); gfx1030 changed the same way. - Fail before / pass after: with only `tools/pixel_aot.py` reverted to main, both checks fail with `Unsupported instruction 22: s_add_u32 s62, s44, s45`. - Windows: `ctest --preset dev --no-tests=error -R '^pixel_aot_' -V` at 872f529 (rebased on main d311159; earlier runs at 1602962 and 38590ab gave the same result) 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. This is the first DXC compile and D3D12 draw of `scalar()`; it needed no changes. `pixel_aot_hardware` on an NVIDIA GeForce RTX 5080 (driver 32.0.16.1692) and `pixel_aot_warp` on the Microsoft Basic Render Driver report `pixels=4096 channels=16384 max_absolute_error=0` for every draw, including both constant sets of `scalar()`, and the three mutations report the expected mismatch. The NaN and −0.0 constant patterns therefore arrive unchanged through the float constant buffer on both backends. The D3D12 debug layer was not available. The full `ctest --preset dev --no-tests=error` passed 136/136, with `bvh_wave64_hardware`, `bvh_wave64_warp` and `wave_shuffle_warp` skipped. On that run `tools/form_coverage.py` reports gfx1013 93 of 1968 forms and gfx1030 93 of 1863 (all of main's pixel programs plus this one), x64 49 of 948. ## Evidence and follow-up - The constant words reach the shader as `asuint(params[...])` of a float cbuffer. Several inputs (0xfffffff0, 0x7fffffff, 0xffffffff) are NaN bit patterns and 0x80000000 is −0.0, so the draw also checks that these patterns are not canonicalized through a bitcast. - Not covered: carry-in/borrow-in (`s_addc_u32`, `s_subb_u32`), `s_cmov*`, `s_cmpk_*`, bitfield and 64-bit scalar forms, and scalar results used as descriptors or branch conditions.
upstream-sync closed this pull request 2026-11-24 06:42:04 +00:00
chatgpt-codex-connector[bot commented 2026-11-24 06:47:55 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T19:37:03Z.


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-21T19:41:56.213167Z 7b9adbb 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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7068151953 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/257#issuecomment-7068151953). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-21T19:37:03Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"7b9adbb5b73d9ed86806c8243454e622c163a174","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-21T19:41:56.213167Z">2026-11-21T19:41:56.213167Z</relative-time> | `7b9adbb` | 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>
MarlomMedeiros commented 2026-11-24 06:47:56 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by MarlomMedeiros on 2026-11-21T19:44:59Z.


Heads-up to avoid duplicate work: I'm building the complementary half of the SALU block as a separate PR - the 64-bit forms this PR leaves out (s_cmov_b64, s_and/or/xor/andn2/orn2_b64, s_lshl/lshr/ashr_b64) plus s_bfe_u32/i32 which this explicitly rejects.

Local corpus frequency justifies the split: s_cmov_b64 alone is the largest uncovered SOP form in the inspected package's pixel corpus (58.7k hits across a 1.5k-shader sample, present in ~97% of pixel programs), and the _b64 ALU family adds ~22k more. No overlap with the 32-bit forms lowered here; the PR body will name this PR as the complementary half.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7068249263 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/257#issuecomment-7068249263). Originally posted by [MarlomMedeiros](https://github.com/MarlomMedeiros) on 2026-11-21T19:44:59Z. --- Heads-up to avoid duplicate work: I'm building the complementary half of the SALU block as a separate PR - the 64-bit forms this PR leaves out (`s_cmov_b64`, `s_and/or/xor/andn2/orn2_b64`, `s_lshl/lshr/ashr_b64`) plus `s_bfe_u32/i32` which this explicitly rejects. Local corpus frequency justifies the split: `s_cmov_b64` alone is the largest uncovered SOP form in the inspected package's pixel corpus (58.7k hits across a 1.5k-shader sample, present in ~97% of pixel programs), and the `_b64` ALU family adds ~22k more. No overlap with the 32-bit forms lowered here; the PR body will name this PR as the complementary half.
R0Y00 commented 2026-11-24 06:47:57 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T19:59:23Z.


At 7b9adbb, tests/pixel_aot_check.py conflicts with main. Please preserve both the new scalar/SCC tests and the landed fract controls when reconciling the test file, then rerun the LLVM round trip and pixel draw checks.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7068422384 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/257#issuecomment-7068422384). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-21T19:59:23Z. --- At `7b9adbb`, `tests/pixel_aot_check.py` conflicts with main. Please preserve both the new scalar/SCC tests and the landed fract controls when reconciling the test file, then rerun the LLVM round trip and pixel draw checks.
R0Y00 commented 2026-11-24 06:47:59 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T20:28:01Z.


c8d5ca2 now conflicts in README.md and tests/pixel_aot_check.py after #277 landed. Please keep the single-word constant-buffer draw and its readiness controls alongside the scalar/SCC coverage.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7068772464 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/257#issuecomment-7068772464). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-21T20:28:01Z. --- `c8d5ca2` now conflicts in `README.md` and `tests/pixel_aot_check.py` after #277 landed. Please keep the single-word constant-buffer draw and its readiness controls alongside the scalar/SCC coverage.
R0Y00 commented 2026-11-24 06:48:02 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T21:27:49Z.


At efd3012, the merge conflicts are in docs/coverage/dashboard.svg and tests/pixel_aot_check.py. Please regenerate the dashboard with #294's clipping fix and preserve the ceiling controls alongside the SCC tests.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7069491301 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/257#issuecomment-7069491301). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-21T21:27:49Z. --- At `efd3012`, the merge conflicts are in `docs/coverage/dashboard.svg` and `tests/pixel_aot_check.py`. Please regenerate the dashboard with #294's clipping fix and preserve the ceiling controls alongside the SCC tests.
R0Y00 commented 2026-11-24 06:48:06 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T21:59:02Z.


At efd3012 the merge conflicts are in docs/coverage/dashboard.svg, docs/experiments.md, tests/form_coverage_check.py, tests/pixel_aot_check.py, tools/pixel_aot.py. With #279 on main, preserve its 64-bit scalar representation and add the agreed combined cases: a 32-bit result consumed by a 64-bit operation, and a 64-bit SCC producer feeding a 32-bit select. Regenerate the dashboard from the preserved measurement.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7069856270 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/257#issuecomment-7069856270). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-21T21:59:02Z. --- At `efd3012` the merge conflicts are in `docs/coverage/dashboard.svg`, `docs/experiments.md`, `tests/form_coverage_check.py`, `tests/pixel_aot_check.py`, `tools/pixel_aot.py`. With #279 on main, preserve its 64-bit scalar representation and add the agreed combined cases: a 32-bit result consumed by a 64-bit operation, and a 64-bit SCC producer feeding a 32-bit select. Regenerate the dashboard from the preserved measurement.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!254
No description provided.