shader: lower SDWA forms of exact f32 arithmetic in pixel_aot #334

Manually merged
github merged 6 commits from gh-pr/334/head into gh-pr/334/base 2026-11-26 21:43:52 +00:00
Owner

@⁠Its3rr0rsWRLD on GitHub · 2026-11-21 22:32 UTC · original
Its3rr0rsWRLD:shader/sdwa-alu → main · +122 −0 · 3 files · 6 commits · merged 2026-11-22 09:51 UTC

Depends on #329. This branch contains #329's commit, so please review it after #329. Once #329 merges, only the second commit remains.

Change

This lowers the SDWA forms of the exact binary32 arithmetic that pixel_aot already handles in e32/e64 form. On gfx1013 that is v_add, v_sub, v_subrev, v_mul, v_mul_legacy, v_max, v_min, v_floor, v_ceil, v_fract and v_trunc (_f32_sdwa).

  • The operation uses the existing ALU template, with source modifiers, inline constants and clamp.
  • The result is then placed with #329's sdwa_dest: dst_sel byte, word or dword, with UNUSED_PAD or UNUSED_PRESERVE.
  • Accepted sources: only src0_sel:DWORD and src1_sel:DWORD. A byte or word source would reach the arithmetic as a zero-extended, usually subnormal binary32. Scarlett's binary32 denormal mode is not measured, so those forms stay refused.
  • Also refused: output modifiers (mul:2, div:2) and a src1_sel on a one-operand instruction.
  • Left out on purpose: v_rcp, v_sqrt, v_rsq, v_log and v_exp. They are approximations on the GPU, and this change only covers what can be compared bitwise.

Verification

Commit b860dd5 plus #329 and this change, Windows 10 Enterprise 26H2 build 26300.9974, MSVC 14.51.36231, Windows SDK 10.0.26100.0 DXC.

ctest --preset dev --no-tests=error -R '^pixel_aot_' -V
  • pixel_aot_hardware: Passed on NVIDIA GeForce RTX 4070 Ti (10de:2782), driver 32.0.16.1088.
  • pixel_aot_warp: Passed on WARP 10.0.26100.9818.
  • Each test runs 62 draws, against 54 on b860dd5 and 58 with #329 alone; the four extra draws are the four programs below. Every draw reports debug_errors=0 and max_absolute_error=0.
  • tests/pixel_aot_check.py binary passes with the four programs in the binary fixtures: LLVM 15.0.6 llvm-mc and llvm-objcopy, disassembled through libLLVM-17.so and libLLVM-18.so on Linux. The controls, tests/docs_links_check.py and tests/bidi_controls_check.py pass.

Evidence and follow-up

The fixtures are synthetic. Programs 0 to 2 draw each of the eleven operations once. Together they cover:

  • negation and absolute value on SGPR sources, and an inline 0.5;
  • clamp on a result of 5.25;
  • the legacy rule 0 × ∞ = 0;
  • placing the low byte of a sum into BYTE_3.

Program 3 keeps a product's low word in WORD_0 and a floor result's low byte in BYTE_2 of 1.0 under UNUSED_PRESERVE. It reads both back exactly. It also pads the low word of a product into WORD_1.

The reference is Python binary32 arithmetic on the constant words, and every value is exact in binary32 and after the half export. Sixteen wrong references, one per channel, each report pixel_mismatch. One of them caught my own first draft, which expected dst_sel:WORD_1 to keep the high word. Both adapters wrote the low word, as the LLVM equivalence v_lshlrev_b32 16 ⇔ dst_sel:WORD_1 says. The reference now uses the low word, and the high-word reading is kept as a wrong reference.

This branch merges cleanly with #288, #293 and #324.

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. Written with Claude Opus 5.5; verified on the hardware listed above.

🤖 Generated with Claude Code

https://claude.ai/code/session_01X1EBSe6YfE2ivQChRsx1hc

**@⁠Its3rr0rsWRLD** on GitHub · 2026-11-21 22:32 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/334) `Its3rr0rsWRLD:shader/sdwa-alu` → `main` · +122 −0 · 3 files · 6 commits · merged 2026-11-22 09:51 UTC **Depends on #329.** This branch contains #329's commit, so please review it after #329. Once #329 merges, only the second commit remains. ## Change This lowers the SDWA forms of the exact binary32 arithmetic that `pixel_aot` already handles in e32/e64 form. On gfx1013 that is `v_add`, `v_sub`, `v_subrev`, `v_mul`, `v_mul_legacy`, `v_max`, `v_min`, `v_floor`, `v_ceil`, `v_fract` and `v_trunc` (`_f32_sdwa`). - The operation uses the existing `ALU` template, with source modifiers, inline constants and `clamp`. - The result is then placed with #329's `sdwa_dest`: `dst_sel` byte, word or dword, with `UNUSED_PAD` or `UNUSED_PRESERVE`. - **Accepted sources:** only `src0_sel:DWORD` and `src1_sel:DWORD`. A byte or word source would reach the arithmetic as a zero-extended, usually subnormal binary32. Scarlett's binary32 denormal mode is not measured, so those forms stay refused. - **Also refused:** output modifiers (`mul:2`, `div:2`) and a `src1_sel` on a one-operand instruction. - **Left out on purpose:** `v_rcp`, `v_sqrt`, `v_rsq`, `v_log` and `v_exp`. They are approximations on the GPU, and this change only covers what can be compared bitwise. ## Verification Commit b860dd5 plus #329 and this change, Windows 10 Enterprise 26H2 build 26300.9974, MSVC 14.51.36231, Windows SDK 10.0.26100.0 DXC. ```powershell ctest --preset dev --no-tests=error -R '^pixel_aot_' -V ``` - `pixel_aot_hardware`: Passed on NVIDIA GeForce RTX 4070 Ti (10de:2782), driver 32.0.16.1088. - `pixel_aot_warp`: Passed on WARP 10.0.26100.9818. - Each test runs 62 draws, against 54 on b860dd5 and 58 with #329 alone; the four extra draws are the four programs below. Every draw reports `debug_errors=0` and `max_absolute_error=0`. - `tests/pixel_aot_check.py binary` passes with the four programs in the binary fixtures: LLVM 15.0.6 `llvm-mc` and `llvm-objcopy`, disassembled through `libLLVM-17.so` and `libLLVM-18.so` on Linux. The controls, `tests/docs_links_check.py` and `tests/bidi_controls_check.py` pass. ## Evidence and follow-up The fixtures are synthetic. Programs 0 to 2 draw each of the eleven operations once. Together they cover: - negation and absolute value on SGPR sources, and an inline 0.5; - `clamp` on a result of 5.25; - the legacy rule 0 × ∞ = 0; - placing the low byte of a sum into `BYTE_3`. Program 3 keeps a product's low word in `WORD_0` and a floor result's low byte in `BYTE_2` of 1.0 under `UNUSED_PRESERVE`. It reads both back exactly. It also pads the low word of a product into `WORD_1`. The reference is Python binary32 arithmetic on the constant words, and every value is exact in binary32 and after the half export. Sixteen wrong references, one per channel, each report `pixel_mismatch`. One of them caught my own first draft, which expected `dst_sel:WORD_1` to keep the high word. Both adapters wrote the low word, as the LLVM equivalence `v_lshlrev_b32 16` ⇔ `dst_sel:WORD_1` says. The reference now uses the low word, and the high-word reading is kept as a wrong reference. This branch merges cleanly with #288, #293 and #324. ## 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. Written with Claude Opus 5.5; verified on the hardware listed above. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01X1EBSe6YfE2ivQChRsx1hc
Lower v_mov_b32_sdwa and v_cvt_f32_f16_sdwa: byte, word and dword source selections with optional sign extension, and byte or word destinations with UNUSED_PAD or UNUSED_PRESERVE, following the instruction equivalences in LLVM's SIPeepholeSDWA. UNUSED_SEXT stays refused. Two programs with two constant sets each read every field back exactly, and both join the gfx1013 binary fixtures.

AI-assisted: yes (Claude Opus 5.5)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01X1EBSe6YfE2ivQChRsx1hc
Refuse UNUSED_PRESERVE into an untracked or non-numeric register instead of assuming zero, check provenance only when bits are kept, and accept negative inline float sources, as found in review.

AI-assisted: yes (Claude Opus 5.5)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01X1EBSe6YfE2ivQChRsx1hc
Lower the SDWA forms of add, sub, subrev, mul, mul_legacy, max, min, floor, ceil, fract and trunc with whole-dword sources, placing the result with the SDWA destination rules. Four programs draw every operation and the byte and word placements exactly; they join the gfx1013 binary fixtures.

AI-assisted: yes (Claude Opus 5.5)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01X1EBSe6YfE2ivQChRsx1hc
Use the stricter sdwa_dest from #329 for partial UNUSED_PRESERVE results instead of a separate destination check.

AI-assisted: yes (Claude Opus 5.5)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01X1EBSe6YfE2ivQChRsx1hc
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 21:43:50 +00:00
github manually merged commit 7ac7b5c0c7 into gh-pr/334/base 2026-11-26 21:43:52 +00:00
Author
Owner

@⁠Its3rr0rsWRLD on GitHub · 2026-11-21 23:11 UTC · original

Rebased onto the updated #329 (e99c9bc). The SDWA arithmetic branch now uses the stricter sdwa_dest for partial UNUSED_PRESERVE results instead of its own destination check, with controls for v0, v8 and v20 (ceaa756). The only rebase conflict was the check_controls block, and both sets of controls are kept.

Rerun on Windows 10 Enterprise 26H2 build 26300.9974 with ctest --preset dev --no-tests=error -R '^pixel_aot_' -V, merged with current main (bc24dfd): pixel_aot_hardware (RTX 4070 Ti, driver 32.0.16.1088) and pixel_aot_warp (WARP 10.0.26100.9818) pass with 63 draws each against 55 on main. Every draw reports debug_errors=0 and max_absolute_error=0. tests/pixel_aot_check.py binary passes on Linux with LLVM 15.0.6 tools and libLLVM 17 and 18.

AI-assisted: yes. Claude Opus 5.5 replying from this account.

**@⁠Its3rr0rsWRLD** on GitHub · 2026-11-21 23:11 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/334#issuecomment-7070708715) Rebased onto the updated #329 (e99c9bc). The SDWA arithmetic branch now uses the stricter `sdwa_dest` for partial `UNUSED_PRESERVE` results instead of its own destination check, with controls for `v0`, `v8` and `v20` (ceaa756). The only rebase conflict was the `check_controls` block, and both sets of controls are kept. Rerun on Windows 10 Enterprise 26H2 build 26300.9974 with `ctest --preset dev --no-tests=error -R '^pixel_aot_' -V`, merged with current main (bc24dfd): `pixel_aot_hardware` (RTX 4070 Ti, driver 32.0.16.1088) and `pixel_aot_warp` (WARP 10.0.26100.9818) pass with 63 draws each against 55 on main. Every draw reports `debug_errors=0` and `max_absolute_error=0`. `tests/pixel_aot_check.py binary` passes on Linux with LLVM 15.0.6 tools and libLLVM 17 and 18. AI-assisted: yes. Claude Opus 5.5 replying from this account.
This discussion has been locked. Commenting is limited to contributors.
No description provided.