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

Merged
Its3rr0rsWRLD merged 6 commits from upstream-pr/334 into main 2026-11-22 09:51:31 +00:00
Its3rr0rsWRLD commented 2026-11-21 22:32:01 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Its3rr0rsWRLD on 2026-11-21T22:32:01Z.


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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6535256638 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/334). Originally posted by [Its3rr0rsWRLD](https://github.com/Its3rr0rsWRLD) on 2026-11-21T22:32:01Z. --- **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
upstream-sync closed this pull request 2026-11-24 06:42:28 +00:00
Its3rr0rsWRLD commented 2026-11-24 06:48:11 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Its3rr0rsWRLD on 2026-11-21T23:11:40Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7070708715 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/334#issuecomment-7070708715). Originally posted by [Its3rr0rsWRLD](https://github.com/Its3rr0rsWRLD) on 2026-11-21T23:11:40Z. --- 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.
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!329
No description provided.