shader: lower v_pk_fmac_f16 in direct Compute and Pixel DXIL #3259

Merged
legacy-code-archaeologist merged 1 commit from upstream-pr/3259 into main 2026-11-28 04:27:27 +00:00
legacy-code-archaeologist commented 2026-11-28 02:28:31 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-28T02:28:31Z.


Lowers plain VOP2 v_pk_fmac_f16 (0x3c) in the direct Compute and Pixel DXIL paths, unblocking direct DXIL lowering for v_pk_fmac_f16 in the #3224 start-up census.

Fixes #3258. Refs #2935, #3224.

Summary

  • src/gfx1013_direct_compute.inl:
    • Added v_pk_fmac_f16 to packed_f16_arithmetic() (which also enables half_binary = true tracking in DirectCompute::lower()).
    • Extended packed_f16_alu(i, permuted) to accept plain VOP2 v_pk_fmac_f16 with zero modifiers (refusing _e64 / wide, subword, dpp_control, permuted, abs, neg, clamp, scale), read the in-place binary16x2 accumulator from i.dst, select low halves (0) and high halves (7), and reuse fused_half_rne() under the full 0x8000ccu binary16 mode contract.
  • tests/native_f16_alu_check.py:
    • Removed the stale negative control expecting v_pk_fmac_f16 (0x3c) to fail with direct DXIL lowering for v_pk_fmac_f16.
  • tests/native_pk_fmac_f16_check.py, tests/cmake/native_pk_fmac_f16.cmake:
    • 17 cases: distinct low/high VGPR FMA, fused cancellation (1 + 2^-6)^2 - 1 = 0x2808 (distinguishing fused fused_half_rne from unfused mul+add 0x2800), multi-accumulate into vdst, vdst aliasing src0 and vsrc1, SGPR/literal src0, inline binary16 float/integer constants (0.5, 1.0, -1.0, 0, 0x0001), binary16 subnormals, finite-to-Inf overflow, partial EXEC_LO (0xAAAAAAAA) lane preservation, signed zero, Inf, and NaN.
    • 8 refusals: VOP3 _e64 (0xD53C0000), DPP16, DPP8, SDWA, vcc_lo src0, s_round_mode 0x4, s_denorm_mode 0x3, and conditional MODE write.

Verification (dev and release /O2, Windows 10.0.26100)

  • ctest --preset dev --no-tests=error -V -R '^native_(pk_fmac_f16|packed_f16)_' & ctest --preset release --no-tests=error -V -R '^native_pk_fmac_f16_':
    • native_pk_fmac_f16_ir: Passed (17 cases matched exact rational model; 8 refusals matched).
    • native_pk_fmac_f16_controls: Passed (17 cases compiled to DXIL; 8 refusals verified).
    • native_pk_fmac_f16_pixel_warp: Passed (4 quad draws matched on WARP).
    • native_pk_fmac_f16_pixel_hardware: Passed (4 quad draws matched; host hardware pixel adapter is NVIDIA Quadro M1000M, 32.0.15.7371, debug_layer=unavailable).
    • native_pk_fmac_f16_compute_hardware: Skipped (77) (Intel(R) HD Graphics 530, vendor 8086, device 191b, driver 31.0.101.2111 lacks SM 6.6 wave32 — needs testing on a wave32-capable GPU).
    • native_packed_f16_* & native_packed_f16_inline_* (dev): all non-compute-hardware tests Passed (_compute_hardware skipped 77 on HD 530).
  • ctest --preset dev --no-tests=error -V -R '^native_f16_alu_ir$' & --preset release: Passed (82 results, 13 refusals); the remaining 70 native_.*_(controls|ir) tests in dev also passed prior to the single-line stale refusal removal in tests/native_f16_alu_check.py.
  • Sensitivity mutants caught (rc=8): using low half for high lane (fmac ? 3u :), disabling fused for fmac (fused_cancellation mismatch), and removing v_pk_fmac_f16 from packed_f16_arithmetic all failed native_pk_fmac_f16_ir.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5535812169 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3259). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-28T02:28:31Z. --- Lowers plain VOP2 `v_pk_fmac_f16` (`0x3c`) in the direct Compute and Pixel DXIL paths, unblocking `direct DXIL lowering for v_pk_fmac_f16` in the #3224 start-up census. Fixes #3258. Refs #2935, #3224. ### Summary - **`src/gfx1013_direct_compute.inl`:** - Added `v_pk_fmac_f16` to `packed_f16_arithmetic()` (which also enables `half_binary = true` tracking in `DirectCompute::lower()`). - Extended `packed_f16_alu(i, permuted)` to accept plain VOP2 `v_pk_fmac_f16` with zero modifiers (refusing `_e64` / `wide`, `subword`, `dpp_control`, `permuted`, `abs`, `neg`, `clamp`, `scale`), read the in-place binary16x2 accumulator from `i.dst`, select low halves (`0`) and high halves (`7`), and reuse `fused_half_rne()` under the full `0x8000ccu` binary16 mode contract. - **`tests/native_f16_alu_check.py`:** - Removed the stale negative control expecting `v_pk_fmac_f16` (`0x3c`) to fail with `direct DXIL lowering for v_pk_fmac_f16`. - **`tests/native_pk_fmac_f16_check.py`, `tests/cmake/native_pk_fmac_f16.cmake`:** - `17` cases: distinct low/high VGPR FMA, fused cancellation `(1 + 2^-6)^2 - 1 = 0x2808` (distinguishing fused `fused_half_rne` from unfused mul+add `0x2800`), multi-accumulate into `vdst`, `vdst` aliasing `src0` and `vsrc1`, SGPR/literal `src0`, inline binary16 float/integer constants (`0.5`, `1.0`, `-1.0`, `0`, `0x0001`), binary16 subnormals, finite-to-Inf overflow, partial `EXEC_LO` (`0xAAAAAAAA`) lane preservation, signed zero, Inf, and NaN. - `8` refusals: VOP3 `_e64` (`0xD53C0000`), DPP16, DPP8, SDWA, `vcc_lo` `src0`, `s_round_mode 0x4`, `s_denorm_mode 0x3`, and conditional `MODE` write. ### Verification (`dev` and `release` `/O2`, Windows `10.0.26100`) - `ctest --preset dev --no-tests=error -V -R '^native_(pk_fmac_f16|packed_f16)_'` & `ctest --preset release --no-tests=error -V -R '^native_pk_fmac_f16_'`: - `native_pk_fmac_f16_ir`: **Passed** (`17` cases matched exact rational model; `8` refusals matched). - `native_pk_fmac_f16_controls`: **Passed** (`17` cases compiled to DXIL; `8` refusals verified). - `native_pk_fmac_f16_pixel_warp`: **Passed** (`4` quad draws matched on WARP). - `native_pk_fmac_f16_pixel_hardware`: **Passed** (`4` quad draws matched; host hardware pixel adapter is `NVIDIA Quadro M1000M`, `32.0.15.7371`, `debug_layer=unavailable`). - `native_pk_fmac_f16_compute_hardware`: **Skipped (`77`)** (`Intel(R) HD Graphics 530`, vendor `8086`, device `191b`, driver `31.0.101.2111` lacks SM 6.6 wave32 — needs testing on a wave32-capable GPU). - `native_packed_f16_*` & `native_packed_f16_inline_*` (`dev`): all non-compute-hardware tests **Passed** (`_compute_hardware` skipped `77` on HD 530). - `ctest --preset dev --no-tests=error -V -R '^native_f16_alu_ir$'` & `--preset release`: **Passed** (`82` results, `13` refusals); the remaining `70` `native_.*_(controls|ir)` tests in `dev` also passed prior to the single-line stale refusal removal in `tests/native_f16_alu_check.py`. - Sensitivity mutants caught (`rc=8`): using low half for high lane (`fmac ? 3u :`), disabling `fused` for `fmac` (`fused_cancellation` mismatch), and removing `v_pk_fmac_f16` from `packed_f16_arithmetic` all failed `native_pk_fmac_f16_ir`. AI-assisted.
pigalot commented 2026-11-28 04:26:09 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-28T04:26:09Z.

Review: APPROVED


Independently reviewed a6513f54 integrated over main dbb933d1 (tree cc413710). The merge is clean and git diff --cached --check is clean.

What I traced.

  • v_pk_fmac_f16 is VOP2 0x3c. The low lane computes S0.lo * S1.lo + D.lo and the high lane S0.hi * S1.hi + D.hi, with one rounding each. The PR reads the accumulator from i.dst, which the decoder already stores as 256 + vdst. It selects all-low (0) and all-high (7) halves with no negation, and reuses fused_half_rne().
  • The fmac branch refuses _e64/wide, SDWA, DPP, abs, neg, clamp and scale. It keeps the same 0x8000cc binary16 mode gate and the same source decode as the VOP3P forms. Inline constants therefore get the zero-high-half rule from packed_f16_inline_constant().
  • The line removed from tests/native_f16_alu_check.py is the old "not lowered yet" refusal for this opcode. The new fixture replaces it with positive cases, so no test is weakened.

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_pk_fmac_f16_.+$'. The _hardware tests ran at -j 1. All 5 pass in Debug and in Release /O2, with no skips:

  • _ir and _controls: 17 cases and 8 refusals.
  • _pixel_warp and _pixel_hardware: 4 quad draws each.
  • _compute_hardware: "17 cases matched across 2x32 lanes and guards" on the RTX 5090, at wave32. This is the run the PR body could not do on its HD 530.

The neighbours also pass in both presets: the 86 native_f16_alu_*, native_packed_f16_* and ^native_.*_(controls|ir)$ tests, and their 6 _hardware tests.

Negative control and mutants. Each was rebuilt in dev and run against all 5 tests:

Mutant Result
src/gfx1013_direct_compute.inl back to main dbb933d1 killed: "direct DXIL lowering for v_pk_fmac_f16" in all 5
high lane reads low halves (7u → 0u) killed (_ir case 0 vgpr_basic, both pixel tests, compute)
high lane takes the accumulator low half (7u → 3u) killed (_ir case 0, both pixel tests, compute)
fmac not fused killed (_ir case 1 fused_cancellation and others, _controls, both pixel tests, compute)
accumulator read from src0 instead of vdst killed (_ir case 0, both pixel tests, compute)
fmac skips the binary16 mode gate killed (_ir and _controls refusal 7, the conditional MODE write)
_e64 / wide accepted killed (_ir and _controls refusal 0)

Restored and rebuilt afterwards; git diff --quiet is clean.

Non-blocking. The new permuted refusal in the fmac branch isn't reached by the fixture. The DPP16 and DPP8 refusals stop earlier, with "unsupported DPP arithmetic".

Verdict: approve on a6513f54.

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.exe (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 a6513f54.

This reply was AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6095802933 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3259#pullrequestreview-6095802933). Originally posted by [pigalot](https://github.com/pigalot) on 2026-11-28T04:26:09Z. **Review:** APPROVED --- Independently reviewed `a6513f54` integrated over `main` `dbb933d1` (tree `cc413710`). The merge is clean and `git diff --cached --check` is clean. **What I traced.** - `v_pk_fmac_f16` is VOP2 `0x3c`. The low lane computes `S0.lo * S1.lo + D.lo` and the high lane `S0.hi * S1.hi + D.hi`, with one rounding each. The PR reads the accumulator from `i.dst`, which the decoder already stores as `256 + vdst`. It selects all-low (`0`) and all-high (`7`) halves with no negation, and reuses `fused_half_rne()`. - The fmac branch refuses `_e64`/`wide`, SDWA, DPP, `abs`, `neg`, `clamp` and `scale`. It keeps the same `0x8000cc` binary16 mode gate and the same source decode as the VOP3P forms. Inline constants therefore get the zero-high-half rule from `packed_f16_inline_constant()`. - The line removed from `tests/native_f16_alu_check.py` is the old "not lowered yet" refusal for this opcode. The new fixture replaces it with positive cases, so no test is weakened. **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_pk_fmac_f16_.+$'`. The `_hardware` tests ran at `-j 1`. All 5 pass in Debug and in Release `/O2`, with no skips: - `_ir` and `_controls`: 17 cases and 8 refusals. - `_pixel_warp` and `_pixel_hardware`: 4 quad draws each. - `_compute_hardware`: "17 cases matched across 2x32 lanes and guards" on the RTX 5090, at wave32. This is the run the PR body could not do on its HD 530. The neighbours also pass in both presets: the 86 `native_f16_alu_*`, `native_packed_f16_*` and `^native_.*_(controls|ir)$` tests, and their 6 `_hardware` tests. **Negative control and mutants.** Each was rebuilt in `dev` and run against all 5 tests: | Mutant | Result | |---|---| | `src/gfx1013_direct_compute.inl` back to `main` `dbb933d1` | killed: "direct DXIL lowering for v_pk_fmac_f16" in all 5 | | high lane reads low halves (`7u` → `0u`) | killed (`_ir` case 0 `vgpr_basic`, both pixel tests, compute) | | high lane takes the accumulator low half (`7u` → `3u`) | killed (`_ir` case 0, both pixel tests, compute) | | fmac not fused | killed (`_ir` case 1 `fused_cancellation` and others, `_controls`, both pixel tests, compute) | | accumulator read from src0 instead of `vdst` | killed (`_ir` case 0, both pixel tests, compute) | | fmac skips the binary16 mode gate | killed (`_ir` and `_controls` refusal 7, the conditional MODE write) | | `_e64` / `wide` accepted | killed (`_ir` and `_controls` refusal 0) | Restored and rebuilt afterwards; `git diff --quiet` is clean. **Non-blocking.** The new `permuted` refusal in the fmac branch isn't reached by the fixture. The DPP16 and DPP8 refusals stop earlier, with "unsupported DPP arithmetic". **Verdict:** approve on `a6513f54`. 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.exe` (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 `a6513f54`. This reply was AI-assisted.
Leyukaka commented 2026-11-28 04:35:26 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-28T04:35:26Z.


A note after merge, from reading the diff (not run). I found nothing wrong in the lowering: it uses the same fused helper as v_pk_fma_f16, reads D before writing it, and pairs low with low and high with high.

The fixture's fused-rounding case does not separate a fused result from a binary32 multiply-add, though. fused_cancellation uses low halves 0x3c10 * 0x3c10 + 0xbc00:

  • The product 1 + 2^-5 + 2^-12 is exact in binary32, so a fused result and a binary32 fmul + fadd + round-to-binary16 both give 0x2808.
  • Only a binary16 multiply-add gives something else (0x2800).

The pixel_aot discriminator in docs/experiments.md, 0x3e00 * 0x3956 + 0x0001, separates the two: the fused result is 0x3c01, and a binary32 multiply-add gives 0x3c00. Adding it to all_cases() would pin the single rounding. The controls string checks (unaryBits.i32(i32 33, and mul i32) are consistent with the helper being emitted, but do not check its rounding.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7234135324 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3259#issuecomment-7234135324). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-28T04:35:26Z. --- A note after merge, from reading the diff (not run). I found nothing wrong in the lowering: it uses the same fused helper as `v_pk_fma_f16`, reads D before writing it, and pairs low with low and high with high. The fixture's fused-rounding case does not separate a fused result from a binary32 multiply-add, though. `fused_cancellation` uses low halves `0x3c10 * 0x3c10 + 0xbc00`: - The product `1 + 2^-5 + 2^-12` is exact in binary32, so a fused result and a binary32 `fmul` + `fadd` + round-to-binary16 both give `0x2808`. - Only a binary16 multiply-add gives something else (`0x2800`). The pixel_aot discriminator in `docs/experiments.md`, `0x3e00 * 0x3956 + 0x0001`, separates the two: the fused result is `0x3c01`, and a binary32 multiply-add gives `0x3c00`. Adding it to `all_cases()` would pin the single rounding. The `controls` string checks (`unaryBits.i32(i32 33,` and `mul i32`) are consistent with the helper being emitted, but do not check its rounding. AI-assisted.
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!3259
No description provided.