shader: lower 64-bit scalar ALU and 32-bit BFE in pixel_aot #275

Merged
MarlomMedeiros merged 1 commit from upstream-pr/279 into main 2026-11-21 21:55:47 +00:00
MarlomMedeiros commented 2026-11-21 20:15:15 +00:00 (Migrated from github.com)

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


Change

Extends tools/pixel_aot.py with the 64-bit SOP1/SOP2 scalar ALU family and 32-bit scalar bitfield extracts as a non-overlapping complement to open PR #257 (pixel-aot-scalar-alu, which covers 32-bit scalar ALU, s_not_b32, s_cmp_*, s_movk_i32, and full carry/overflow/relational SCC tracking):

  • SOP1 (3 forms): s_cmov_b64, s_not_b64, s_brev_b64
  • SOP2 64-bit bitwise (5 forms): s_and_b64 (general even-aligned SGPR pairs alongside the existing exec restore), s_or_b64, s_xor_b64, s_andn2_b64, s_orn2_b64
  • SOP2 64-bit shifts & mask (4 forms): s_lshl_b64, s_lshr_b64, s_ashr_i64, s_bfm_b64
  • SOP2 32-bit bitfield extract (2 forms, explicitly rejected by #257): s_bfe_u32, s_bfe_i32

Each 64-bit result lowers to an HLSL uint2 SSA local bound across an even-aligned SGPR pair (s0..s105), and each 32-bit extract lowers to a uint local. Constant-buffer inputs are read via asuint(params[...]) and vector operands read scalar results via asfloat(...). Inline decimal integers sign-extend to 64 bits; 32-bit hex literals zero-extend for b64 operations and sign-extend for s_ashr_i64. Helper functions for shifts, s_bfm_b64, and s_bfe_* are emitted on demand so existing shaders emit unchanged HLSL.

Minimal nonzero-result SCC tracking is maintained for the newly lowered SCC-writing operations so s_cmov_b64 selects between source and existing destination pairs; s_brev_b64, s_bfm_b64, and s_cmov_b64 preserve SCC, and s_wqm_b64 and exec-restoring s_and_b64 clear it.

Complement split with PR #257 and out-of-scope boundaries

  • Zero opcode overlap with PR #257: all 32-bit SOP2 ALU forms (s_add/sub/min/max/mul/and/or/xor/andn2/orn2/lshl/lshr/ashr/cselect_*), s_not_b32, s_cmp_*, and PR #257's carry/overflow/relational SCC model remain untouched and tested as rejections here.
  • Out of scope and tested as rejections: exec save/restore (s_and_saveexec_b64, s_or_saveexec_b64, s_andn2_saveexec_b64), exec/vcc/VGPR/m0 operands, unaligned or out-of-range pairs, pending scalar load read/write overlaps, untracked SCC or unset/non-numeric destination pairs on s_cmov_b64, s_cselect_b64, s_bfe_{u,i}64, s_{nand,nor,xnor}_b64, s_cmp_eq_u64, s_bitcmp1_b64, and s_bfm_b32.

Verification

  • Commit: bc1efe7 (branched from origin/main 496fc28)
  • Fail before / pass after: origin/main:tools/pixel_aot.py rejects scalar64() with Unsupported instruction 30: s_and_b64 s[72:73], s[52:53], s[54:55].
  • Fixture & CPU reference: scalar64() in tests/pixel_aot_check.py exercises all 14 forms across two 12-word constant sets (including NaN bit patterns, negative 64-bit inputs, zero/small/>=32/wrapped shift counts, s_bfm_b64 width boundaries 0, 1..31, 32, >32, signed/unsigned s_bfe_* for offset + width < 32 and >= 32, and SCC preservation through s_cmov_b64, s_brev_b64, and s_bfm_b64). scalar64_reference() independently interprets the sequence in wide-integer Python and asserts all 10 observed SCC bits flip between the two constant sets, packing the 64-bit accumulator and 10 SCC bits into four exact binary16 fields (1 + k/1024). Four mutations (s_ashr_i64→s_lshr_b64, s_bfe_i32→s_bfe_u32, s_andn2_b64→s_and_b64, and replacing s_cmov_b64 ..., -1 with 0) must each report pixel_mismatch.
  • Windows D3D12 & docs check: Windows 11 build 26300.10075, MSVC 19.52.37029.0, DXC 1.9.2602.17:
    ctest --preset dev --no-tests=error -R '^(pixel_aot_|docs_links)' -V --output-junit C:/Users/marlo/Desktop/Xbox2Windows/out/pixel-aot-results.xml
    
    • Result: 3/3 passed (0 failed, 0 skipped)
    • pixel_aot_hardware: NVIDIA GeForce RTX 5070 (10de:2f04), driver 32.0.16.2135, debug_layer=enabled, debug_errors=0 debug_warnings=0, pixels=4096 channels=16384 max_absolute_error=0 across all draws and both constant sets; all 4 mutations triggered pixel_mismatch.
    • pixel_aot_warp: Microsoft Basic Render Driver (1414:008c), driver 10.0.26100.10068, debug_layer=enabled, debug_errors=0 debug_warnings=0, pixels=4096 channels=16384 max_absolute_error=0 across all draws and mutations.
    • docs_links: 10 Markdown files, 63 links checked, passed.
  • Form coverage:
    .\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py
    .\out\pe-env\Scripts\python.exe -B tools/form_coverage.py out/pixel-aot-results.xml --json out/pixel-aot-coverage.json
    
    • form_coverage_check.py: passed (verifies all 14 forms against gfx1013.tsv and rdna2.tsv, and confirms rejected neighbors stay uncovered).
    • Measured coverage delta vs origin/main: SOP1 3/65 -> 6/65 (+3), SOP2 1/51 -> 11/51 (+10), total gfx1013 57 -> 70 / 1968 and gfx1030 57 -> 70 / 1863 (+13 forms, 0 unmatched). Combined with PR #257 (+32 forms), SOP1 reaches 7/65 and SOP2 reaches 29/51.
  • LLVM disassembly check: Verified all 160 SOP1/SOP2 instructions in scalar64() roundtrip identically through libLLVM-20; scalar64() is also registered in check_binary() for the Ubuntu LLVM 15 CI job (tests/pixel_aot_check.py binary).

Evidence and open scope

  • Measured: synthetic fixture lowering, DXC -Gis -T ps_6_0 compilation, bitwise D3D12 readback on hardware (RTX 5070) and WARP with debug layer enabled, and instruction-form accounting.
  • Unverified / out of scope: exec save/restore semantics, SOPP control flow, scalar-computed resource descriptors or addresses, and execution of real title pixel shaders.
  • Local corpus observation (no package bytes included): running lower() over a local set of 12,101 pixel-shader binaries, s_cmov_b64 was the first unsupported instruction in 2,898 of them (24%). With this change, 2,479 of those (86%) now lower past that instruction and fail later on out-of-scope operations such as exec operands or registers written by ops outside this scope. Two-wide scalar pairs require even alignment, matching what llvm-mc accepts for the ISA; the remaining rejections are the designed loud-failure boundaries.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6533867133 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/279). Originally posted by [MarlomMedeiros](https://github.com/MarlomMedeiros) on 2026-11-21T20:15:15Z. --- ## Change Extends `tools/pixel_aot.py` with the 64-bit SOP1/SOP2 scalar ALU family and 32-bit scalar bitfield extracts as a non-overlapping complement to open PR #257 (`pixel-aot-scalar-alu`, which covers 32-bit scalar ALU, `s_not_b32`, `s_cmp_*`, `s_movk_i32`, and full carry/overflow/relational SCC tracking): - **SOP1 (3 forms):** `s_cmov_b64`, `s_not_b64`, `s_brev_b64` - **SOP2 64-bit bitwise (5 forms):** `s_and_b64` (general even-aligned SGPR pairs alongside the existing exec restore), `s_or_b64`, `s_xor_b64`, `s_andn2_b64`, `s_orn2_b64` - **SOP2 64-bit shifts & mask (4 forms):** `s_lshl_b64`, `s_lshr_b64`, `s_ashr_i64`, `s_bfm_b64` - **SOP2 32-bit bitfield extract (2 forms, explicitly rejected by #257):** `s_bfe_u32`, `s_bfe_i32` Each 64-bit result lowers to an HLSL `uint2` SSA local bound across an even-aligned SGPR pair (`s0`..`s105`), and each 32-bit extract lowers to a `uint` local. Constant-buffer inputs are read via `asuint(params[...])` and vector operands read scalar results via `asfloat(...)`. Inline decimal integers sign-extend to 64 bits; 32-bit hex literals zero-extend for `b64` operations and sign-extend for `s_ashr_i64`. Helper functions for shifts, `s_bfm_b64`, and `s_bfe_*` are emitted on demand so existing shaders emit unchanged HLSL. Minimal nonzero-result SCC tracking is maintained for the newly lowered SCC-writing operations so `s_cmov_b64` selects between source and existing destination pairs; `s_brev_b64`, `s_bfm_b64`, and `s_cmov_b64` preserve SCC, and `s_wqm_b64` and exec-restoring `s_and_b64` clear it. ### Complement split with PR #257 and out-of-scope boundaries - Zero opcode overlap with PR #257: all 32-bit SOP2 ALU forms (`s_add/sub/min/max/mul/and/or/xor/andn2/orn2/lshl/lshr/ashr/cselect_*`), `s_not_b32`, `s_cmp_*`, and PR #257's carry/overflow/relational SCC model remain untouched and tested as rejections here. - Out of scope and tested as rejections: exec save/restore (`s_and_saveexec_b64`, `s_or_saveexec_b64`, `s_andn2_saveexec_b64`), `exec`/`vcc`/VGPR/`m0` operands, unaligned or out-of-range pairs, pending scalar load read/write overlaps, untracked SCC or unset/non-numeric destination pairs on `s_cmov_b64`, `s_cselect_b64`, `s_bfe_{u,i}64`, `s_{nand,nor,xnor}_b64`, `s_cmp_eq_u64`, `s_bitcmp1_b64`, and `s_bfm_b32`. ## Verification - **Commit:** `bc1efe7` (branched from `origin/main` `496fc28`) - **Fail before / pass after:** `origin/main:tools/pixel_aot.py` rejects `scalar64()` with `Unsupported instruction 30: s_and_b64 s[72:73], s[52:53], s[54:55]`. - **Fixture & CPU reference:** `scalar64()` in `tests/pixel_aot_check.py` exercises all 14 forms across two 12-word constant sets (including NaN bit patterns, negative 64-bit inputs, zero/small/`>=32`/wrapped shift counts, `s_bfm_b64` width boundaries `0`, `1..31`, `32`, `>32`, signed/unsigned `s_bfe_*` for `offset + width < 32` and `>= 32`, and SCC preservation through `s_cmov_b64`, `s_brev_b64`, and `s_bfm_b64`). `scalar64_reference()` independently interprets the sequence in wide-integer Python and asserts all 10 observed SCC bits flip between the two constant sets, packing the 64-bit accumulator and 10 SCC bits into four exact binary16 fields (`1 + k/1024`). Four mutations (`s_ashr_i64`→`s_lshr_b64`, `s_bfe_i32`→`s_bfe_u32`, `s_andn2_b64`→`s_and_b64`, and replacing `s_cmov_b64 ..., -1` with `0`) must each report `pixel_mismatch`. - **Windows D3D12 & docs check:** Windows 11 build `26300.10075`, MSVC `19.52.37029.0`, DXC `1.9.2602.17`: ```powershell ctest --preset dev --no-tests=error -R '^(pixel_aot_|docs_links)' -V --output-junit C:/Users/marlo/Desktop/Xbox2Windows/out/pixel-aot-results.xml ``` - Result: **3/3 passed (0 failed, 0 skipped)** - `pixel_aot_hardware`: NVIDIA GeForce RTX 5070 (`10de:2f04`), driver `32.0.16.2135`, `debug_layer=enabled`, `debug_errors=0 debug_warnings=0`, `pixels=4096 channels=16384 max_absolute_error=0` across all draws and both constant sets; all 4 mutations triggered `pixel_mismatch`. - `pixel_aot_warp`: Microsoft Basic Render Driver (`1414:008c`), driver `10.0.26100.10068`, `debug_layer=enabled`, `debug_errors=0 debug_warnings=0`, `pixels=4096 channels=16384 max_absolute_error=0` across all draws and mutations. - `docs_links`: 10 Markdown files, 63 links checked, passed. - **Form coverage:** ```powershell .\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py .\out\pe-env\Scripts\python.exe -B tools/form_coverage.py out/pixel-aot-results.xml --json out/pixel-aot-coverage.json ``` - `form_coverage_check.py`: passed (verifies all 14 forms against `gfx1013.tsv` and `rdna2.tsv`, and confirms rejected neighbors stay uncovered). - Measured coverage delta vs `origin/main`: `SOP1` 3/65 -> **6/65** (+3), `SOP2` 1/51 -> **11/51** (+10), total `gfx1013` 57 -> **70 / 1968** and `gfx1030` 57 -> **70 / 1863** (+13 forms, 0 unmatched). Combined with PR #257 (+32 forms), SOP1 reaches 7/65 and SOP2 reaches 29/51. - **LLVM disassembly check:** Verified all 160 SOP1/SOP2 instructions in `scalar64()` roundtrip identically through `libLLVM-20`; `scalar64()` is also registered in `check_binary()` for the Ubuntu LLVM 15 CI job (`tests/pixel_aot_check.py binary`). ## Evidence and open scope - Measured: synthetic fixture lowering, DXC `-Gis -T ps_6_0` compilation, bitwise D3D12 readback on hardware (RTX 5070) and WARP with debug layer enabled, and instruction-form accounting. - Unverified / out of scope: exec save/restore semantics, SOPP control flow, scalar-computed resource descriptors or addresses, and execution of real title pixel shaders. - Local corpus observation (no package bytes included): running `lower()` over a local set of 12,101 pixel-shader binaries, `s_cmov_b64` was the first unsupported instruction in 2,898 of them (24%). With this change, 2,479 of those (86%) now lower past that instruction and fail later on out-of-scope operations such as `exec` operands or registers written by ops outside this scope. Two-wide scalar pairs require even alignment, matching what `llvm-mc` accepts for the ISA; the remaining rejections are the designed loud-failure boundaries.
upstream-sync closed this pull request 2026-11-24 06:42:12 +00:00
copilot-pull-request-reviewer[bot commented 2026-11-24 06:42:12 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-21T20:15:26Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6007897525 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/279#pullrequestreview-6007897525). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/copilot-pull-request-reviewer%5Bbot%5D) on 2026-11-21T20:15:26Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
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:14Z.


392c144 conflicts in tests/pixel_aot_check.py. Please keep the new single-word constant-buffer tests from #277 alongside yours. #257 also changes how scalar results and SCC are represented; when the first PR lands, please verify a 32-bit result consumed by a 64-bit operation and a 64-bit SCC producer consumed by the 32-bit select on the combined head.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7068775153 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/279#issuecomment-7068775153). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-21T20:28:14Z. --- `392c144` conflicts in `tests/pixel_aot_check.py`. Please keep the new single-word constant-buffer tests from #277 alongside yours. #257 also changes how scalar results and SCC are represented; when the first PR lands, please verify a 32-bit result consumed by a 64-bit operation and a 64-bit SCC producer consumed by the 32-bit select on the combined head.
MarlomMedeiros commented 2026-11-24 06:48:00 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by MarlomMedeiros on 2026-11-21T20:38:04Z.


Rebased onto c832696 as 0107260. The single-word constant-buffer controls from #277 are kept alongside scalar64(); both with_scalar_constant_reads() and scalar64() now sit in check_binary, and ctest -R '^(pixel_aot_|docs_links)' plus form_coverage_check.py pass on the combined head (RTX 5070 + WARP, max_absolute_error=0).

On the representation question: this branch reads scalar state through scalar_u32, which already accepts the params[k].xyzw strings the #277 path stores, so a single-word s_buffer_load_dword result is a valid 64-bit operand here. When the first of the two PRs lands I will verify on the combined head, with fixture cases, that:

  • a 32-bit result in whichever representation #257 stores is consumed by a 64-bit operand (s_and_b64 low word and an s_bfe_* source),
  • a 64-bit SCC producer (s_not_b64 or a bitwise b64 op) feeds the 32-bit select (s_cselect_b32 or the v_cndmask path).

If #257 lands first I will fold those cases into this fixture set before re-verifying; if this one lands first the same two cases apply to the follow-up.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7068895754 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/279#issuecomment-7068895754). Originally posted by [MarlomMedeiros](https://github.com/MarlomMedeiros) on 2026-11-21T20:38:04Z. --- Rebased onto c832696 as 0107260. The single-word constant-buffer controls from #277 are kept alongside `scalar64()`; both `with_scalar_constant_reads()` and `scalar64()` now sit in `check_binary`, and `ctest -R '^(pixel_aot_|docs_links)'` plus `form_coverage_check.py` pass on the combined head (RTX 5070 + WARP, `max_absolute_error=0`). On the representation question: this branch reads scalar state through `scalar_u32`, which already accepts the `params[k].xyzw` strings the #277 path stores, so a single-word `s_buffer_load_dword` result is a valid 64-bit operand here. When the first of the two PRs lands I will verify on the combined head, with fixture cases, that: - a 32-bit result in whichever representation #257 stores is consumed by a 64-bit operand (`s_and_b64` low word and an `s_bfe_*` source), - a 64-bit SCC producer (`s_not_b64` or a bitwise b64 op) feeds the 32-bit select (`s_cselect_b32` or the `v_cndmask` path). If #257 lands first I will fold those cases into this fixture set before re-verifying; if this one lands first the same two cases apply to the follow-up.
R0Y00 commented 2026-11-24 06:48:01 +00:00 (Migrated from github.com)

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


After #258 landed the new head 0107260b conflicts only in tests/pixel_aot_check.py. Please preserve its truncation draw alongside the 64-bit/BFE cases; the previously agreed combined SCC checks can follow when #257 is integrated.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7069129768 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/279#issuecomment-7069129768). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-21T20:57:24Z. --- After #258 landed the new head `0107260b` conflicts only in `tests/pixel_aot_check.py`. Please preserve its truncation draw alongside the 64-bit/BFE cases; the previously agreed combined SCC checks can follow when #257 is integrated.
MarlomMedeiros commented 2026-11-24 06:48:01 +00:00 (Migrated from github.com)

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


Rebased onto d311159 as bc1efe7. The truncate_values draw and binary registrations from #258 are preserved alongside the 64-bit/BFE fixture; both ctest -R '^(pixel_aot_|docs_links)' and form_coverage_check.py pass on the combined head. Noted on the combined SCC checks with #257: they stay queued for whichever side integrates second.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7069157851 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/279#issuecomment-7069157851). Originally posted by [MarlomMedeiros](https://github.com/MarlomMedeiros) on 2026-11-21T20:59:43Z. --- Rebased onto d311159 as bc1efe7. The `truncate_values` draw and binary registrations from #258 are preserved alongside the 64-bit/BFE fixture; both `ctest -R '^(pixel_aot_|docs_links)'` and `form_coverage_check.py` pass on the combined head. Noted on the combined SCC checks with #257: they stay queued for whichever side integrates second.
R0Y00 commented 2026-11-24 06:48:03 +00:00 (Migrated from github.com)

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


At bc1efe7, the merge conflicts are in tests/pixel_aot_check.py. Please retain the ceiling draw in the combined pixel suite. The cross-width cases with #257 remain for whichever PR lands second.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7069495298 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/279#issuecomment-7069495298). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-21T21:28:10Z. --- At `bc1efe7`, the merge conflicts are in `tests/pixel_aot_check.py`. Please retain the ceiling draw in the combined pixel suite. The cross-width cases with #257 remain for whichever PR lands second.
MarlomMedeiros commented 2026-11-24 06:48:03 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by MarlomMedeiros on 2026-11-21T21:38:12Z.


Rebased onto b53bfb0 as d8bf0c0. The ceiling() draw and check_ceiling_draws call are kept alongside scalar64(), and check_binary registers both ceiling() and scalar64(); the cube and fract draws from the same wave also remain. pixel_aot_check.py draw passes on both backends (RTX 5070 hardware + WARP, max_absolute_error=0, debug layer clean), check_controls, form_coverage_check.py and docs_links_check.py pass on the combined head. The binary mode still runs in CI (LLVM 15). Cross-width checks with #257 stay queued for whichever side lands second.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7069612951 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/279#issuecomment-7069612951). Originally posted by [MarlomMedeiros](https://github.com/MarlomMedeiros) on 2026-11-21T21:38:12Z. --- Rebased onto b53bfb0 as d8bf0c0. The `ceiling()` draw and `check_ceiling_draws` call are kept alongside `scalar64()`, and `check_binary` registers both `ceiling()` and `scalar64()`; the cube and fract draws from the same wave also remain. `pixel_aot_check.py draw` passes on both backends (RTX 5070 hardware + WARP, `max_absolute_error=0`, debug layer clean), `check_controls`, `form_coverage_check.py` and `docs_links_check.py` pass on the combined head. The binary mode still runs in CI (LLVM 15). Cross-width checks with #257 stay queued for whichever side lands second.
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!275
No description provided.