shader: lower v_madmk_f32 and v_madak_f32 in direct Compute and Pixel DXIL #3252

Manually merged
github merged 1 commit from github-bot/gh-3250 into gh-pr/3250/base 2026-11-28 04:13:26 +00:00 AGit
Owner

@⁠legacy-code-archaeologist on GitHub · 2026-11-28 01:46 UTC · original
legacy-code-archaeologist:shader/direct-mad32-k → main · +355 −3 · 4 files · 1 commits · merged 2026-11-28 04:08 UTC

Lower RDNA 2 unfused literal multiply-adds v_madmk_f32 (VOP2 0x20: S0 * K + S1) and v_madak_f32 (VOP2 0x21: S0 * S1 + K) in the direct Compute and Pixel DXIL path (src/gfx1013_direct_compute.inl), finishing the remaining #3005 unfused f32 multiply-add instructions under #2935.

Fixes #3251
Refs #2935
Refs #3005

Summary

  • src/gfx1013_direct_compute.inl:
    • Extended unfused_mad inside DirectCompute::float_alu() to include v_madmk_f32 and v_madak_f32.
    • Flushes denormal inputs to signed zero (ftz), rounds fmul separately without fast-math/FMA contraction, flushes the product, adds the flushed addend (S1 for v_madmk_f32, trailing literal K for v_madak_f32), and flushes the sum.
    • Refuses invalid non-VOP2 forms (i.wide || i.subword || i.dpp_control || permuted).
  • tests/native_mad32_k_check.py & tests/cmake/native_mad32_k.cmake:
    • Added 14 test cases verifying asymmetric K/S1 positions, unfused tie witnesses, denormal src0/K/product/sum FTZ, SGPR & inline src0, 0 * inf -> NaN, and -0.0, plus 4 refusals (VOP3 e64 forms, SDWA, DPP).
    • Covers ir, DXIL controls, SM 6.6 compute_hardware, and Pixel warp + hardware.
  • docs/experiments/native-mad32-k.md:
    • Recorded exact verification measurements, sensitivity mutants, and limits.

Verification

Host: Windows 10.0.26100, dev preset, DXC 10.0.26100.0.

  • cmake --build --preset dev --target compile_dxil native_compute_ir_dump native_store_replay offscreen_check: passed.
  • ctest --preset dev --no-tests=error -R '^(native_mad32_k_|native_mad32_)' -V:
    • native_mad32_k_ir: Passed (14 cases matched unfused FTZ model; 4 refusals matched).
    • native_mad32_k_controls: Passed (14 cases compiled with separate fmul/fadd, no tertiary.f32(i32 46,) or fast-math flags; 4 refusals matched).
    • native_mad32_k_pixel_warp: Passed (Microsoft Basic Render Driver, 3 quad draws matched).
    • native_mad32_k_pixel_hardware: Passed (NVIDIA Quadro M1000M, 3 quad draws matched; debug layer unavailable).
    • native_mad32_k_compute_hardware: Skipped (77, Intel(R) HD Graphics 530 31.0.101.2111 requires SM 6.6 with wave32).
    • Neighbor native_mad32_controls passed (native_mad32_hardware skipped 77 on HD 530).
  • ctest --preset dev --no-tests=error -R '^native_.*_(controls|ir)$' --output-on-failure: 68/68 passed (0 skips).
  • Three sensitivity mutants in src/gfx1013_direct_compute.inl (swap_madmk_madak, drop_ftz_input, drop_vop3_refusal) all failed native_mad32_k_ir (rc=8); clean source restored and re-verified passing.
  • python -B tests/docs_links_check.py: passed (131 Markdown files, 631 links).

AI-assisted.

**@⁠legacy-code-archaeologist** on GitHub · 2026-11-28 01:46 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3250) `legacy-code-archaeologist:shader/direct-mad32-k` → `main` · +355 −3 · 4 files · 1 commits · merged 2026-11-28 04:08 UTC Lower RDNA 2 unfused literal multiply-adds `v_madmk_f32` (`VOP2 0x20`: `S0 * K + S1`) and `v_madak_f32` (`VOP2 0x21`: `S0 * S1 + K`) in the direct Compute and Pixel DXIL path (`src/gfx1013_direct_compute.inl`), finishing the remaining `#3005` unfused f32 multiply-add instructions under `#2935`. Fixes #3251 Refs #2935 Refs #3005 ## Summary - **`src/gfx1013_direct_compute.inl`**: - Extended `unfused_mad` inside `DirectCompute::float_alu()` to include `v_madmk_f32` and `v_madak_f32`. - Flushes denormal inputs to signed zero (`ftz`), rounds `fmul` separately without fast-math/FMA contraction, flushes the product, adds the flushed addend (`S1` for `v_madmk_f32`, trailing literal `K` for `v_madak_f32`), and flushes the sum. - Refuses invalid non-VOP2 forms (`i.wide || i.subword || i.dpp_control || permuted`). - **`tests/native_mad32_k_check.py` & `tests/cmake/native_mad32_k.cmake`**: - Added `14` test cases verifying asymmetric `K`/`S1` positions, unfused tie witnesses, denormal `src0`/`K`/product/sum FTZ, SGPR & inline `src0`, `0 * inf -> NaN`, and `-0.0`, plus `4` refusals (`VOP3 e64` forms, SDWA, DPP). - Covers `ir`, DXIL `controls`, SM 6.6 `compute_hardware`, and Pixel `warp` + `hardware`. - **`docs/experiments/native-mad32-k.md`**: - Recorded exact verification measurements, sensitivity mutants, and limits. ## Verification Host: Windows 10.0.26100, `dev` preset, DXC `10.0.26100.0`. - `cmake --build --preset dev --target compile_dxil native_compute_ir_dump native_store_replay offscreen_check`: passed. - `ctest --preset dev --no-tests=error -R '^(native_mad32_k_|native_mad32_)' -V`: - `native_mad32_k_ir`: **Passed** (`14` cases matched unfused FTZ model; `4` refusals matched). - `native_mad32_k_controls`: **Passed** (`14` cases compiled with separate `fmul`/`fadd`, no `tertiary.f32(i32 46,)` or fast-math flags; `4` refusals matched). - `native_mad32_k_pixel_warp`: **Passed** (`Microsoft Basic Render Driver`, `3` quad draws matched). - `native_mad32_k_pixel_hardware`: **Passed** (`NVIDIA Quadro M1000M`, `3` quad draws matched; debug layer unavailable). - `native_mad32_k_compute_hardware`: **Skipped** (`77`, `Intel(R) HD Graphics 530` `31.0.101.2111` requires SM 6.6 with wave32). - Neighbor `native_mad32_controls` passed (`native_mad32_hardware` skipped `77` on HD 530). - `ctest --preset dev --no-tests=error -R '^native_.*_(controls|ir)$' --output-on-failure`: **68/68 passed** (`0` skips). - Three sensitivity mutants in `src/gfx1013_direct_compute.inl` (`swap_madmk_madak`, `drop_ftz_input`, `drop_vop3_refusal`) all failed `native_mad32_k_ir` (`rc=8`); clean source restored and re-verified passing. - `python -B tests/docs_links_check.py`: passed (`131` Markdown files, `631` links). AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 01:49:52 +00:00
github-bot changed target branch from main to gh-pr/3250/base 2026-11-28 04:13:24 +00:00
github manually merged commit 2502da4e8d into gh-pr/3250/base 2026-11-28 04:13:26 +00:00
Author
Owner

@⁠pigalot on GitHub · 2026-11-28 04:07 UTC · original · approved these changes

Independently reviewed 2502da4e integrated over main f41806a9 (tree bbca38a4). The merge is clean, and git diff --cached --check is clean.

What I traced.

  • Lowering. v_madmk_f32 (S0 * K + S1) and v_madak_f32 (S0 * S1 + K) join the existing unfused MAD path in float_alu(). The inputs are flushed, fmul and fadd are separate, the product and sum are flushed, and K comes from the instruction's literal. That matches how v_mad_f32 is already lowered and RDNA 2's no-denormal MAD.
  • Decoder. gfx1013_isa.cpp:47 already reads the trailing K dword for both opcodes.
  • Ties. I checked both by hand. 0x3f800800² rounds to even before the -1; fused gives 2^-11 + 2^-24, unfused gives 2^-11. In madak_unfused_tie_add the sum lands on 2.5 ULP; unfused rounds to even and fused rounds up.

What I ran. I built compile_dxil native_store_replay native_compute_ir_dump offscreen_check in dev and release, then ran

ctest --test-dir out/build/<preset> --no-tests=error -j 1 -V -R '^native_mad32_(k_)?.+$'

The _hardware tests ran at -j 1. All 7 pass in Debug and in Release /O2, with no skips:

  • _k_ir: "14 cases matched unfused FTZ model; 4 refusals matched".
  • _k_controls: "compiled 14 cases with separate fmul/fadd; verified 4 refusals".
  • _k_compute_hardware: "14 cases matched across 2x32 lanes and guards" on the RTX 5090.
  • _k_pixel_warp and _k_pixel_hardware: 3 quad draws each.
  • native_mad32_controls and native_mad32_hardware also pass.

The 76 ^native_.*_(controls|ir)$ tests pass in dev.

Negative control and mutants. Each mutant was rebuilt in dev and run against all five new tests.

Mutant Result
src/gfx1013_direct_compute.inl back to main killed in all five: "direct DXIL lowering for v_madmk_f32"
madmk K and S1 swapped killed: _ir, _pixel_warp, both hardware tests
madmk K not flushed killed: _ir (madmk_ftz_lit_k), _pixel_warp
madak addend read from src2 killed: _ir, _pixel_warp, both hardware tests
product not flushed killed: _ir (madmk_ftz_product), _pixel_warp
encoding refusal dropped killed: _ir, _controls

Afterwards I restored and rebuilt; the restored build passes again and git diff --quiet is clean.

Non-blocking. On the RTX 5090, both hardware tests pass with the two flush mutants. The driver flushes f32 denormals itself, so only _ir and WARP pin the explicit flushes. That is enough on this host, but a GPU that keeps f32 denormals would be the one to show it.

Verdict: approve on 2502da4e.

Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088, Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; SDK 10.0.28000.0 DXC (the one CTest picked up); Python 3.12.10; wave32; D3D12 debug layer enabled in the pixel tests.
CI: Build and test on Windows passes on 2502da4e.

This reply was AI-assisted.

**@⁠pigalot** on GitHub · 2026-11-28 04:07 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3250#pullrequestreview-6095681763) · **approved these changes** Independently reviewed `2502da4e` integrated over `main` `f41806a9` (tree `bbca38a4`). The merge is clean, and `git diff --cached --check` is clean. **What I traced.** - **Lowering.** `v_madmk_f32` (`S0 * K + S1`) and `v_madak_f32` (`S0 * S1 + K`) join the existing unfused MAD path in `float_alu()`. The inputs are flushed, `fmul` and `fadd` are separate, the product and sum are flushed, and K comes from the instruction's literal. That matches how `v_mad_f32` is already lowered and RDNA 2's no-denormal MAD. - **Decoder.** `gfx1013_isa.cpp:47` already reads the trailing K dword for both opcodes. - **Ties.** I checked both by hand. `0x3f800800`² rounds to even before the `-1`; fused gives `2^-11 + 2^-24`, unfused gives `2^-11`. In `madak_unfused_tie_add` the sum lands on 2.5 ULP; unfused rounds to even and fused rounds up. **What I ran.** I built `compile_dxil native_store_replay native_compute_ir_dump offscreen_check` in `dev` and `release`, then ran ```powershell ctest --test-dir out/build/<preset> --no-tests=error -j 1 -V -R '^native_mad32_(k_)?.+$' ``` The `_hardware` tests ran at `-j 1`. All 7 pass in Debug and in Release `/O2`, with no skips: - `_k_ir`: "14 cases matched unfused FTZ model; 4 refusals matched". - `_k_controls`: "compiled 14 cases with separate fmul/fadd; verified 4 refusals". - `_k_compute_hardware`: "14 cases matched across 2x32 lanes and guards" on the RTX 5090. - `_k_pixel_warp` and `_k_pixel_hardware`: 3 quad draws each. - `native_mad32_controls` and `native_mad32_hardware` also pass. The 76 `^native_.*_(controls|ir)$` tests pass in `dev`. **Negative control and mutants.** Each mutant was rebuilt in `dev` and run against all five new tests. | Mutant | Result | |---|---| | `src/gfx1013_direct_compute.inl` back to `main` | killed in all five: "direct DXIL lowering for v_madmk_f32" | | madmk K and S1 swapped | killed: `_ir`, `_pixel_warp`, both hardware tests | | madmk K not flushed | killed: `_ir` (`madmk_ftz_lit_k`), `_pixel_warp` | | madak addend read from src2 | killed: `_ir`, `_pixel_warp`, both hardware tests | | product not flushed | killed: `_ir` (`madmk_ftz_product`), `_pixel_warp` | | encoding refusal dropped | killed: `_ir`, `_controls` | Afterwards I restored and rebuilt; the restored build passes again and `git diff --quiet` is clean. **Non-blocking.** On the RTX 5090, both hardware tests pass with the two flush mutants. The driver flushes f32 denormals itself, so only `_ir` and WARP pin the explicit flushes. That is enough on this host, but a GPU that keeps f32 denormals would be the one to show it. **Verdict:** approve on `2502da4e`. Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088, Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; SDK 10.0.28000.0 DXC (the one CTest picked up); Python 3.12.10; wave32; D3D12 debug layer enabled in the pixel tests. CI: `Build and test on Windows` passes on `2502da4e`. This reply was AI-assisted.
This discussion has been locked. Commenting is limited to contributors.
No description provided.