shader: add sopk scalar arithmetic to pixel aot #328

Merged
wh1skrzzz merged 3 commits from upstream-pr/333 into main 2026-11-22 09:03:39 +00:00
wh1skrzzz commented 2026-11-21 22:30:29 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by wh1skrzzz on 2026-11-21T22:30:29Z.


note: this change was partially AI assisted, the only changes that were made by an ai agent were docs/experiments.md and this pr description. that is literally all

Change

tools/pixel_aot.py now lowers s_addk_i32 and s_mulk_i32 for the straight-line gfx1013 pixel path. Both are two-operand SOPK instructions — the destination register is the source as well. LLVM prints negative 16-bit immediates as hex like 0xfffe, so the lowerer sign-extends that before a 32-bit wrapping add or multiply. s_addk_i32 also sets SCC on signed overflow, which is tracked so a later s_cmov_b64 reads the right flag; s_mulk_i32 leaves SCC alone. Out-of-range immediates, descriptor registers, vector destinations and writes that overlap a pending scalar load are rejected.

The new sopk_scalar() fixture in tests/pixel_aot_check.py drives both the assembler round trip and the D3D12 draw, with a CPU reference for the colors. SOPK coverage in gfx1013.tsv and rdna2.tsv goes from 0 to 2 of 27.

No issue is linked for this; it's part of the instruction-form coverage work in the README. The shared files are tools/pixel_aot.py, tests/pixel_aot_check.py and tools/scan_unsupported_shaders.py. PR #257 is still open and covers s_movk_i32 and other 32-bit scalar ops; #271 covers s_waitcnt_expcnt. No opcode overlap, but all three edit the pixel test file, so the second one merged may need a quick rebase. This patch applies cleanly to main at 6ee2406.

Verification

Tested at 6ee2406 on Windows 11 24H2 build 26100.1742, VS 2026 18.12.0 (MSVC 19.52.37029), SDK DXC 1.9.2602.17, Python 3.12.10 from out/pe-env, LLVM 15.0.7.

Before the change, lowering the fixture stops at ValueError: Unsupported instruction 21: s_mulk_i32 s50, 0x3. After it, with $py = .\out\pe-env\Scripts\python.exe:

  • & $py -B tests/form_coverage_check.py → form coverage checks passed
  • & $py -B tests/rdna2_tools_check.py → Ran 27 tests ... OK (skipped=1); the skip is test_llvm_comparison, which needs an external LLVM library.
  • & $py -B tests/pixel_aot_check.py binary out\llvm-mc.cmd C:\LLVM15\bin\llvm-objcopy.exe C:\LLVM15\bin\LLVM-C.dll → passed.
  • ctest --preset dev --no-tests=error -R '^pixel_aot_' -V → 2/2 passed, no skips. pixel_aot_hardware ran on an RX 6600 (driver 32.0.21045.16010) and pixel_aot_warp on WARP 10.0.26100.1301, both with the debug layer on. Each gave pixels=4096 channels=16384 max_absolute_error=0, zero debug errors and zero warnings. Both constant sets matched the CPU reference, and changing *3 to *5 produced pixel_mismatch on both.

For the coverage numbers:

ctest --preset dev --no-tests=error -R '^pixel_aot_' --output-junit "$PWD\out\pixel-aot-results.xml"
& $py -B tools/form_coverage.py out\pixel-aot-results.xml --json out\pixel-aot-coverage.json

gfx1013 is 86/1968, gfx1030 86/1863, SOPK 2/27 in both. The entry_order.asm and narrow.asm "unclassified" notices were already on main.

Evidence and follow-up
The fixture is synthetic gfx1013 assembly written for this PR, assembled at test time and wrapped in the repo's existing FSSM/XBCH envelope. It's original MIT work; no game files or dumps are involved. Expected colors come from the operand bit patterns and the ISA rules, then go through the same round-toward-zero half export, so the result doesn't depend on driver rounding.

Failure cases cover immediates above 16 bits, a texture-descriptor source, a vector destination, a write racing a pending load, and a separate check that the add's SCC reaches a later s_cmov_b64 and survives an intervening s_mulk_i32.

This only covers the straight-line subset with the test's fixed bindings; it says nothing about title pipeline state or full-game startup. Still open in SOPK: s_cmpk_, s_cmovk_i32, s_getreg/s_setreg, the subvector loop pair and the named s_waitcnt_ counters. #257 and #271 cover the neighboring forms.

The README shader row and the Offline pixel shader recompilation section of docs/experiments.md are updated. To rerun after the first-build steps:

.\tools\dev.ps1
cmake --preset dev
cmake --build --preset dev --target offscreen_check
ctest --preset dev --no-tests=error -R '^pixel_aot_' -V

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.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6535242953 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/333). Originally posted by [wh1skrzzz](https://github.com/wh1skrzzz) on 2026-11-21T22:30:29Z. --- > note: this change was partially AI assisted, the only changes that were made by an ai agent were docs/experiments.md and this pr description. that is literally all ## Change `tools/pixel_aot.py` now lowers `s_addk_i32` and `s_mulk_i32` for the straight-line gfx1013 pixel path. Both are two-operand SOPK instructions — the destination register is the source as well. LLVM prints negative 16-bit immediates as hex like `0xfffe`, so the lowerer sign-extends that before a 32-bit wrapping add or multiply. `s_addk_i32` also sets SCC on signed overflow, which is tracked so a later `s_cmov_b64` reads the right flag; `s_mulk_i32` leaves SCC alone. Out-of-range immediates, descriptor registers, vector destinations and writes that overlap a pending scalar load are rejected. The new `sopk_scalar()` fixture in `tests/pixel_aot_check.py` drives both the assembler round trip and the D3D12 draw, with a CPU reference for the colors. SOPK coverage in `gfx1013.tsv` and `rdna2.tsv` goes from 0 to 2 of 27. No issue is linked for this; it's part of the instruction-form coverage work in the README. The shared files are `tools/pixel_aot.py`, `tests/pixel_aot_check.py` and `tools/scan_unsupported_shaders.py`. PR #257 is still open and covers `s_movk_i32` and other 32-bit scalar ops; #271 covers `s_waitcnt_expcnt`. No opcode overlap, but all three edit the pixel test file, so the second one merged may need a quick rebase. This patch applies cleanly to `main` at `6ee2406`. ## Verification Tested at `6ee2406` on Windows 11 24H2 build 26100.1742, VS 2026 18.12.0 (MSVC 19.52.37029), SDK DXC 1.9.2602.17, Python 3.12.10 from `out/pe-env`, LLVM 15.0.7. Before the change, lowering the fixture stops at `ValueError: Unsupported instruction 21: s_mulk_i32 s50, 0x3`. After it, with `$py = .\out\pe-env\Scripts\python.exe`: - `& $py -B tests/form_coverage_check.py` → `form coverage checks passed` - `& $py -B tests/rdna2_tools_check.py` → `Ran 27 tests ... OK (skipped=1)`; the skip is `test_llvm_comparison`, which needs an external LLVM library. - `& $py -B tests/pixel_aot_check.py binary out\llvm-mc.cmd C:\LLVM15\bin\llvm-objcopy.exe C:\LLVM15\bin\LLVM-C.dll` → passed. - `ctest --preset dev --no-tests=error -R '^pixel_aot_' -V` → 2/2 passed, no skips. `pixel_aot_hardware` ran on an RX 6600 (driver 32.0.21045.16010) and `pixel_aot_warp` on WARP 10.0.26100.1301, both with the debug layer on. Each gave `pixels=4096 channels=16384 max_absolute_error=0`, zero debug errors and zero warnings. Both constant sets matched the CPU reference, and changing `*3` to `*5` produced `pixel_mismatch` on both. For the coverage numbers: ```powershell ctest --preset dev --no-tests=error -R '^pixel_aot_' --output-junit "$PWD\out\pixel-aot-results.xml" & $py -B tools/form_coverage.py out\pixel-aot-results.xml --json out\pixel-aot-coverage.json ``` gfx1013 is 86/1968, gfx1030 86/1863, SOPK 2/27 in both. The entry_order.asm and narrow.asm "unclassified" notices were already on main. Evidence and follow-up The fixture is synthetic gfx1013 assembly written for this PR, assembled at test time and wrapped in the repo's existing FSSM/XBCH envelope. It's original MIT work; no game files or dumps are involved. Expected colors come from the operand bit patterns and the ISA rules, then go through the same round-toward-zero half export, so the result doesn't depend on driver rounding. Failure cases cover immediates above 16 bits, a texture-descriptor source, a vector destination, a write racing a pending load, and a separate check that the add's SCC reaches a later s_cmov_b64 and survives an intervening s_mulk_i32. This only covers the straight-line subset with the test's fixed bindings; it says nothing about title pipeline state or full-game startup. Still open in SOPK: s_cmpk_*, s_cmovk_i32, s_getreg/s_setreg, the subvector loop pair and the named s_waitcnt_* counters. #257 and #271 cover the neighboring forms. The README shader row and the Offline pixel shader recompilation section of docs/experiments.md are updated. To rerun after the first-build steps: ``` .\tools\dev.ps1 cmake --preset dev cmake --build --preset dev --target offscreen_check ctest --preset dev --no-tests=error -R '^pixel_aot_' -V ``` ## 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.
upstream-sync closed this pull request 2026-11-24 06:42:28 +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!328
No description provided.