shader: lower gfx1013 v_mad_legacy_f32 in pixel_aot #358

Manually merged
github merged 6 commits from gh-pr/358/head into gh-pr/358/base 2026-11-26 21:45:50 +00:00
Owner

@⁠denn0x on GitHub · 2026-11-21 23:16 UTC · original
denn0x:shader/mad-legacy → main · +69 −0 · 3 files · 6 commits · merged 2026-11-22 16:53 UTC

Change

Advances an independent problem: gfx1013 instruction coverage in pixel_aot. It adds one ALU table entry, extends the unary/binary/ternary regex in tools/pixel_aot.py, and adds a draw check in tests/pixel_aot_check.py. No open PR claims v_mad_legacy_f32. #288 lowers v_mad_f32 and v_mac_f32 and does not include the legacy form, and no prerequisite PR is needed.

v_mad_legacy_f32 computes S0 * S1 + S2 with the legacy (DX9) multiply rule that 0 * x is 0 for any x, including inf and NaN. It reuses the existing mul_legacy expression and follows it with an add in the same precise statement, so DXC does not contract it into an FMA.

Fixture legacy_multiply_add(). Four lanes with e64 negation, absolute value and clamp.

Draw check check_legacy_multiply_add_draws.

  • Four constant sets pair a zero with +inf and with NaN, and also use finite values.
  • Every product and sum is exact in binary32, so rounding or fusion cannot hide a fault.
  • Each set is compared bit for bit over the 64×64 target on the selected backend. The fixture is also added to check_binary.

Negative control: replacing it with v_fma_f32 must produce pixel_mismatch, because 0 * inf is NaN there.

Verification

Windows 11 build 26200, MSVC 19.50.35720, Windows SDK 10.0.26100.0, DXC 1.8.2502.11, D3D12 debug layer enabled.

  • AMD Radeon RX 9070 XT (vendor 1002, device 7550), driver 32.0.32015.7029
  • WARP: Microsoft Basic Render Driver 10.0.26100.9818
ctest --preset dev --no-tests=error -R '^pixel_aot_' -V
1/2 Test #129: pixel_aot_hardware ...............   Passed   10.66 sec
2/2 Test #132: pixel_aot_warp ...................   Passed    4.41 sec
100% tests passed, 0 tests failed out of 2
  • Mutation check (local, reverted): lowering as a plain {0} * {1} + {2} makes pixel_aot_warp fail with pixel_mismatch x=0 y=0 in the new draw.
  • Full suite: ctest --preset dev --no-tests=error gives 146 passed, 0 failed, with the bvh_wave64_warp and wave_shuffle_warp capability skips.

Not run locally: tests/pixel_aot_check.py binary, because this machine has no LLVM with gfx1013. Ubuntu CI covers it.

This is independent of #350, #353 and #356. All of them add a fixture next to the ceiling fixture, and #288 edits the same regex, so later merges need a trivial rebase.

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 (Claude Code).

**@⁠denn0x** on GitHub · 2026-11-21 23:16 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/358) `denn0x:shader/mad-legacy` → `main` · +69 −0 · 3 files · 6 commits · merged 2026-11-22 16:53 UTC ## Change Advances an independent problem: gfx1013 instruction coverage in `pixel_aot`. It adds one `ALU` table entry, extends the unary/binary/ternary regex in `tools/pixel_aot.py`, and adds a draw check in `tests/pixel_aot_check.py`. No open PR claims `v_mad_legacy_f32`. #288 lowers `v_mad_f32` and `v_mac_f32` and does not include the legacy form, and no prerequisite PR is needed. `v_mad_legacy_f32` computes `S0 * S1 + S2` with the legacy (DX9) multiply rule that `0 * x` is 0 for any x, including inf and NaN. It reuses the existing `mul_legacy` expression and follows it with an add in the same `precise` statement, so DXC does not contract it into an FMA. **Fixture `legacy_multiply_add()`.** Four lanes with e64 negation, absolute value and `clamp`. **Draw check `check_legacy_multiply_add_draws`.** - Four constant sets pair a zero with +inf and with NaN, and also use finite values. - Every product and sum is exact in binary32, so rounding or fusion cannot hide a fault. - Each set is compared bit for bit over the 64×64 target on the selected backend. The fixture is also added to `check_binary`. **Negative control:** replacing it with `v_fma_f32` must produce `pixel_mismatch`, because 0 * inf is NaN there. ## Verification Windows 11 build 26200, MSVC 19.50.35720, Windows SDK 10.0.26100.0, DXC 1.8.2502.11, D3D12 debug layer enabled. - AMD Radeon RX 9070 XT (vendor 1002, device 7550), driver 32.0.32015.7029 - WARP: Microsoft Basic Render Driver 10.0.26100.9818 ```powershell ctest --preset dev --no-tests=error -R '^pixel_aot_' -V ``` ```text 1/2 Test #129: pixel_aot_hardware ............... Passed 10.66 sec 2/2 Test #132: pixel_aot_warp ................... Passed 4.41 sec 100% tests passed, 0 tests failed out of 2 ``` - **Mutation check (local, reverted):** lowering as a plain `{0} * {1} + {2}` makes `pixel_aot_warp` fail with `pixel_mismatch x=0 y=0` in the new draw. - **Full suite:** `ctest --preset dev --no-tests=error` gives 146 passed, 0 failed, with the `bvh_wave64_warp` and `wave_shuffle_warp` capability skips. Not run locally: `tests/pixel_aot_check.py binary`, because this machine has no LLVM with gfx1013. Ubuntu CI covers it. This is independent of #350, #353 and #356. All of them add a fixture next to the ceiling fixture, and #288 edits the same regex, so later merges need a trivial rebase. ## 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 (Claude Code)._
Lower the legacy multiply-add as the existing legacy multiply followed by
an unfused add, so a zero factor hides an infinite or NaN partner. A draw
fixture uses exact constant sets with e64 modifiers and clamp. A fused
multiply-add substitution is the negative control.

AI-assisted (Claude Code).
The draw fixture was not yet in check_binary, so the LLVM assemble and
disassemble check did not cover it.

AI-assisted (Claude Code).
gfx10 VOP3 accepts at most two scalar operands, so llvm-mc rejected the
three-SGPR forms. Two constants now move to VGPRs first; the values and
expected results are unchanged.

AI-assisted (Claude Code).
# Conflicts:
#	docs/experiments.md
#	tests/pixel_aot_check.py
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 21:45:48 +00:00
github manually merged commit dab393d59c into gh-pr/358/base 2026-11-26 21:45:50 +00:00
Author
Owner

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

Updated to df922c4:

  • 4e223ba adds legacy_multiply_add() to check_binary. The original commit left it out, so the LLVM round trip did not cover it.
  • df922c4 fixes what that round trip then caught. The Linux job failed with invalid operand (violates constant bus restrictions), because gfx10 VOP3 accepts at most two scalar operands and the fixture used three SGPRs per instruction. The fixture now moves s46 and s47 to v18 and v19 first. The operand values and expected results are unchanged.

Rerun on df922c4, with the RX 9070 XT (driver 32.0.32015.7029) and WARP 10.0.26100.9818 and the debug layer on: ctest --preset dev --no-tests=error -R '^pixel_aot_' passes 2/2.

AI-assisted (Claude Code).

**@⁠denn0x** on GitHub · 2026-11-21 23:22 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/358#issuecomment-7070833427) Updated to `df922c4`: - **`4e223ba`** adds `legacy_multiply_add()` to `check_binary`. The original commit left it out, so the LLVM round trip did not cover it. - **`df922c4`** fixes what that round trip then caught. The Linux job failed with `invalid operand (violates constant bus restrictions)`, because gfx10 VOP3 accepts at most two scalar operands and the fixture used three SGPRs per instruction. The fixture now moves `s46` and `s47` to `v18` and `v19` first. The operand values and expected results are unchanged. Rerun on `df922c4`, with the RX 9070 XT (driver 32.0.32015.7029) and WARP 10.0.26100.9818 and the debug layer on: `ctest --preset dev --no-tests=error -R '^pixel_aot_'` passes 2/2. _AI-assisted (Claude Code)._
This discussion has been locked. Commenting is limited to contributors.
No description provided.