shader: add sopk scalar arithmetic to pixel aot #328
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/333"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by wh1skrzzz on 2026-11-21T22:30:29Z.
Change
tools/pixel_aot.pynow lowerss_addk_i32ands_mulk_i32for 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 like0xfffe, so the lowerer sign-extends that before a 32-bit wrapping add or multiply.s_addk_i32also sets SCC on signed overflow, which is tracked so a laters_cmov_b64reads the right flag;s_mulk_i32leaves 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 intests/pixel_aot_check.pydrives both the assembler round trip and the D3D12 draw, with a CPU reference for the colors. SOPK coverage ingfx1013.tsvandrdna2.tsvgoes 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.pyandtools/scan_unsupported_shaders.py. PR #257 is still open and coverss_movk_i32and other 32-bit scalar ops; #271 coverss_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 tomainat6ee2406.Verification
Tested at
6ee2406on 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 fromout/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 istest_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_hardwareran on an RX 6600 (driver 32.0.21045.16010) andpixel_aot_warpon WARP 10.0.26100.1301, both with the debug layer on. Each gavepixels=4096 channels=16384 max_absolute_error=0, zero debug errors and zero warnings. Both constant sets matched the CPU reference, and changing*3to*5producedpixel_mismatchon both.For the coverage numbers:
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:
Checklist