shader: lower gfx1013 24-bit integer multiplies in pixel_aot #536

Merged
alexander-src merged 1 commit from upstream-pr/542 into main 2026-11-22 14:00:40 +00:00
alexander-src commented 2026-11-22 10:11:32 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by alexander-src on 2026-11-22T10:11:32Z.


Change

Lower gfx1013 24-bit vector integer multiplies in tools/pixel_aot.py, covering both VOP2 (_e32) and VOP3 (_e64) encodings (+8 forms in both gfx1013.tsv and rdna2.tsv):

  • v_mul_u32_u24 (_e32, _e64): unsigned 24-bit multiply (S0[23:0] * S1[23:0]) low 32 bits via mul24_u32.
  • v_mul_i32_i24 (_e32, _e64): signed 24-bit multiply (sext24(S0) * sext24(S1)) low 32 bits via mul24_i32 (unsigned multiply of sign-extended operands to avoid signed overflow UB).
  • v_mul_hi_u32_u24 (_e32, _e64): unsigned 48-bit product shifted right by 32 via mul24_hi_u32 using 12-bit partial products in pure 32-bit uint arithmetic.
  • v_mul_hi_i32_i24 (_e32, _e64): signed 48-bit product arithmetic-shifted right by 32 via mul24_hi_i32 (pulling in mul24_hi_u32 automatically in dependency order, with exact two's-complement carry when lo == 0).

All four helpers are emitted lazily via SALU_HELPERS using pure SM 6.0 32-bit integer arithmetic (no 64-bit integer shader capability required), keeping existing shader outputs unchanged byte for byte. Float source modifiers, clamp, SDWA forms, out-of-range VGPRs (v256+), WQM blocks and pending-load or pending-sample hazards are rejected. Added LLVM assemble/disassemble coverage, batched draw tests (--check-pixel-batch) across five constant sets with six wrong-mode controls and a mutated-shader control (v_mul_hi_i32_i24_e32 -> v_mul_hi_u32_u24_e32), form-coverage assertions in tests/form_coverage_check.py, and documentation in docs/experiments.md.

Verification

Tested on Linux x64 at commit 1430530 (based on 914d241) with Python 3 (requirements-dev.txt installed) and LLVM 23.1.4 (llvm-mc, llvm-objcopy, /usr/lib/libLLVM.so):

  • python -B tests/pixel_aot_check.py binary llvm-mc llvm-objcopy /usr/lib/libLLVM.so: passed.
  • python -B tests/form_coverage_check.py: passed (verifies all 8 VOP2/VOP3 forms in gfx1013.tsv and rdna2.tsv).
  • python -B tests/pso_readiness_check.py: passed.
  • LLVM_LIB=/usr/lib/libLLVM.so LLVM_MC=llvm-mc LLVM_OBJCOPY=llvm-objcopy python -B tests/rdna2_tools_check.py: passed (33 tests, OK).
  • python -B tests/docs_links_check.py: passed (10 Markdown files, 112 links).
  • python -B tests/bidi_controls_check.py: passed (506 tracked files).
  • Independent Python fuzz of all four HLSL helpers against exact arbitrary-precision 48-bit Python arithmetic across 1,000,529 operand pairs (full Cartesian product of 23 boundary/upper-garbage corners plus 1,000,000 random 32-bit pairs): 0 mismatches.

Could not run DXC / D3D12 WARP or hardware draws locally on Linux (missing Windows SDK, DXC and D3D12 runtime); Windows CI runs pixel_aot_blend_scalar_warp and pixel_aot_blend_scalar_hardware.

Evidence and follow-up

All fixtures are synthetic gfx1013 assembly programs written directly in tests/pixel_aot_check.py (MIT). Because the upper byte (bits [31:24]) is ignored by hardware and signed negative products with lo == 0 (such as -2^23 * 512 = -2^32) require adding 1 to ~hi, the draw batch includes nonzero upper bytes on every constant set and explicit negative controls for unmasked 32-bit operands, signed/unsigned swaps and missing low-zero carry. Follow-up work can lower v_mad_i32_i24 / v_mad_u32_u24 and v_mul_lo_u32 / v_mul_hi_{i32,u32}.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted: yes.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6541139505 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/542). Originally posted by [alexander-src](https://github.com/alexander-src) on 2026-11-22T10:11:32Z. --- ## Change Lower gfx1013 24-bit vector integer multiplies in `tools/pixel_aot.py`, covering both VOP2 (`_e32`) and VOP3 (`_e64`) encodings (+8 forms in both `gfx1013.tsv` and `rdna2.tsv`): - `v_mul_u32_u24` (`_e32`, `_e64`): unsigned 24-bit multiply `(S0[23:0] * S1[23:0])` low 32 bits via `mul24_u32`. - `v_mul_i32_i24` (`_e32`, `_e64`): signed 24-bit multiply `(sext24(S0) * sext24(S1))` low 32 bits via `mul24_i32` (unsigned multiply of sign-extended operands to avoid signed overflow UB). - `v_mul_hi_u32_u24` (`_e32`, `_e64`): unsigned 48-bit product shifted right by 32 via `mul24_hi_u32` using 12-bit partial products in pure 32-bit `uint` arithmetic. - `v_mul_hi_i32_i24` (`_e32`, `_e64`): signed 48-bit product arithmetic-shifted right by 32 via `mul24_hi_i32` (pulling in `mul24_hi_u32` automatically in dependency order, with exact two's-complement carry when `lo == 0`). All four helpers are emitted lazily via `SALU_HELPERS` using pure SM 6.0 32-bit integer arithmetic (no 64-bit integer shader capability required), keeping existing shader outputs unchanged byte for byte. Float source modifiers, `clamp`, SDWA forms, out-of-range VGPRs (`v256+`), WQM blocks and pending-load or pending-sample hazards are rejected. Added LLVM assemble/disassemble coverage, batched draw tests (`--check-pixel-batch`) across five constant sets with six wrong-mode controls and a mutated-shader control (`v_mul_hi_i32_i24_e32` -> `v_mul_hi_u32_u24_e32`), form-coverage assertions in `tests/form_coverage_check.py`, and documentation in `docs/experiments.md`. ## Verification Tested on Linux x64 at commit `1430530` (based on `914d241`) with Python 3 (`requirements-dev.txt` installed) and LLVM 23.1.4 (`llvm-mc`, `llvm-objcopy`, `/usr/lib/libLLVM.so`): - `python -B tests/pixel_aot_check.py binary llvm-mc llvm-objcopy /usr/lib/libLLVM.so`: passed. - `python -B tests/form_coverage_check.py`: passed (verifies all 8 `VOP2`/`VOP3` forms in `gfx1013.tsv` and `rdna2.tsv`). - `python -B tests/pso_readiness_check.py`: passed. - `LLVM_LIB=/usr/lib/libLLVM.so LLVM_MC=llvm-mc LLVM_OBJCOPY=llvm-objcopy python -B tests/rdna2_tools_check.py`: passed (33 tests, OK). - `python -B tests/docs_links_check.py`: passed (10 Markdown files, 112 links). - `python -B tests/bidi_controls_check.py`: passed (506 tracked files). - Independent Python fuzz of all four HLSL helpers against exact arbitrary-precision 48-bit Python arithmetic across 1,000,529 operand pairs (full Cartesian product of 23 boundary/upper-garbage corners plus 1,000,000 random 32-bit pairs): 0 mismatches. Could not run DXC / D3D12 WARP or hardware draws locally on Linux (missing Windows SDK, DXC and D3D12 runtime); Windows CI runs `pixel_aot_blend_scalar_warp` and `pixel_aot_blend_scalar_hardware`. ## Evidence and follow-up All fixtures are synthetic gfx1013 assembly programs written directly in `tests/pixel_aot_check.py` (MIT). Because the upper byte (`bits [31:24]`) is ignored by hardware and signed negative products with `lo == 0` (such as `-2^23 * 512 = -2^32`) require adding 1 to `~hi`, the draw batch includes nonzero upper bytes on every constant set and explicit negative controls for unmasked 32-bit operands, signed/unsigned swaps and missing low-zero carry. Follow-up work can lower `v_mad_i32_i24` / `v_mad_u32_u24` and `v_mul_lo_u32` / `v_mul_hi_{i32,u32}`. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted: yes.
upstream-sync closed this pull request 2026-11-24 06:43:36 +00:00
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!536
No description provided.