shader: lower v_dot2_f32_f16 in direct Compute and Pixel DXIL #3239

Merged
legacy-code-archaeologist merged 1 commit from upstream-pr/3239 into main 2026-11-28 02:01:22 +00:00
legacy-code-archaeologist commented 2026-11-28 01:19:39 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-28T01:19:39Z.


Lower RDNA 2 VOP3P v_dot2_f32_f16 (0x13) in the direct Compute and Pixel DXIL path (src/gfx1013_direct_compute.inl), addressing #2935.

Fixes #3238
Refs #2935

Summary

  • src/gfx1013_direct_compute.inl:
    • Added v_dot2_f32_f16 lowering in DirectCompute::float_alu():
      • Decodes src0 and src1 via packed_f16_inline_constant() (inline f16 floats 240..248 with zero high half, inline ints 128..208) or operand32(), and binary32 src2 via operand32().
      • Applies op_sel[1:0], op_sel_hi[1:0], neg_lo[2:0] (pair 0 binary16 signs + src2 binary32 sign), neg_hi[1:0] (pair 1 binary16 signs in ABS), and clamp (dx.op.unary.f32 opcode 7, saturate), widening selected halves via dx.op.legacyF16ToF32 and computing ((a0 * b0) + (a1 * b1)) + c.
      • Refuses reserved op_sel[2] / neg_hi[2] bits (i.a & 0x2400), DPP/permuted encodings, special scalar registers (VCC, M0, EXEC, SCC, etc.), and unsupported or dynamic binary16 rounding/denormal modes (half_binary = true added in DirectCompute::lower()).
  • tests/native_f16_alu_check.py:
    • Extended the Python IR evaluator (_step) to evaluate dx.op.unary.f32(i32 7, ...) (Saturate).
  • tests/native_dot2_f32_f16_check.py & tests/cmake/native_packed_dot2_f16.cmake:
    • Added 26 test cases (VGPR, op_sel/op_sel_hi cross-lane swaps, op_sel_hi[2]=1, neg_lo/neg_hi, clamp, inline f16 float & integer constants on src0/src1, inline/literal/SGPR on src2, subnormals, signed zeros, inf, NaN) and 9 refusal programs (reserved modifier bits, special scalar registers on each operand, denormal flush, RTZ rounding, and dynamic conditional half_mode_known failure).
  • docs/experiments/native-dot2-f32-f16.md:
    • Documented implementation, verification, 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_packed_dot2_f16_|native_packed_dot2_|native_packed_f16_|native_f16_alu_)' -V:
    • native_packed_dot2_f16_ir: Passed (26 cases matched exact binary32 model; 9 refusals matched).
    • native_packed_dot2_f16_controls: Passed (26 cases compiled to DXIL; verified 9 refusals).
    • native_packed_dot2_f16_pixel_warp: Passed (Microsoft Basic Render Driver 10.0.26100.9711, 5 quad draws matched; debug layer unavailable).
    • native_packed_dot2_f16_pixel_hardware: Passed (NVIDIA Quadro M1000M 32.0.15.7371, 5 quad draws matched; debug layer unavailable).
    • native_packed_dot2_f16_compute_hardware: Skipped (77, Intel(R) HD Graphics 530 31.0.101.2111 requires SM 6.6 with wave32).
    • All other selected IR, controls, and pixel tests passed (the remaining *_compute_hardware / *_hardware compute tests also skipped 77 on HD 530).
  • ctest --preset dev --no-tests=error -R '^native_.*_(controls|ir)$' --output-on-failure: 67/67 passed (0 skips).
  • Four sensitivity mutants in src/gfx1013_direct_compute.inl (drop_hi_term, drop_neg_c, drop_clamp, swap_opsel_hi) all failed native_packed_dot2_f16_ir (rc=8); clean source restored and re-verified passing.
  • python -B tests/docs_links_check.py: passed (130 Markdown files, 630 links).

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5535303453 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3239). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-28T01:19:39Z. --- Lower RDNA 2 VOP3P `v_dot2_f32_f16` (`0x13`) in the direct Compute and Pixel DXIL path (`src/gfx1013_direct_compute.inl`), addressing #2935. Fixes #3238 Refs #2935 ## Summary - **`src/gfx1013_direct_compute.inl`**: - Added `v_dot2_f32_f16` lowering in `DirectCompute::float_alu()`: - Decodes `src0` and `src1` via `packed_f16_inline_constant()` (inline f16 floats `240..248` with zero high half, inline ints `128..208`) or `operand32()`, and binary32 `src2` via `operand32()`. - Applies `op_sel[1:0]`, `op_sel_hi[1:0]`, `neg_lo[2:0]` (`pair 0` binary16 signs + `src2` binary32 sign), `neg_hi[1:0]` (`pair 1` binary16 signs in `ABS`), and `clamp` (`dx.op.unary.f32` opcode `7`, saturate), widening selected halves via `dx.op.legacyF16ToF32` and computing `((a0 * b0) + (a1 * b1)) + c`. - Refuses reserved `op_sel[2]` / `neg_hi[2]` bits (`i.a & 0x2400`), DPP/permuted encodings, special scalar registers (`VCC`, `M0`, `EXEC`, `SCC`, etc.), and unsupported or dynamic binary16 rounding/denormal modes (`half_binary = true` added in `DirectCompute::lower()`). - **`tests/native_f16_alu_check.py`**: - Extended the Python IR evaluator (`_step`) to evaluate `dx.op.unary.f32(i32 7, ...)` (`Saturate`). - **`tests/native_dot2_f32_f16_check.py` & `tests/cmake/native_packed_dot2_f16.cmake`**: - Added `26` test cases (VGPR, `op_sel`/`op_sel_hi` cross-lane swaps, `op_sel_hi[2]=1`, `neg_lo`/`neg_hi`, `clamp`, inline f16 float & integer constants on `src0`/`src1`, inline/literal/SGPR on `src2`, subnormals, signed zeros, `inf`, `NaN`) and `9` refusal programs (reserved modifier bits, special scalar registers on each operand, denormal flush, RTZ rounding, and dynamic conditional `half_mode_known` failure). - **`docs/experiments/native-dot2-f32-f16.md`**: - Documented implementation, verification, 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_packed_dot2_f16_|native_packed_dot2_|native_packed_f16_|native_f16_alu_)' -V`: - `native_packed_dot2_f16_ir`: **Passed** (`26` cases matched exact binary32 model; `9` refusals matched). - `native_packed_dot2_f16_controls`: **Passed** (`26` cases compiled to DXIL; verified `9` refusals). - `native_packed_dot2_f16_pixel_warp`: **Passed** (`Microsoft Basic Render Driver` `10.0.26100.9711`, `5` quad draws matched; debug layer unavailable). - `native_packed_dot2_f16_pixel_hardware`: **Passed** (`NVIDIA Quadro M1000M` `32.0.15.7371`, `5` quad draws matched; debug layer unavailable). - `native_packed_dot2_f16_compute_hardware`: **Skipped** (`77`, `Intel(R) HD Graphics 530` `31.0.101.2111` requires SM 6.6 with wave32). - All other selected IR, controls, and pixel tests passed (the remaining `*_compute_hardware` / `*_hardware` compute tests also skipped `77` on HD 530). - `ctest --preset dev --no-tests=error -R '^native_.*_(controls|ir)$' --output-on-failure`: **67/67 passed** (`0` skips). - Four sensitivity mutants in `src/gfx1013_direct_compute.inl` (`drop_hi_term`, `drop_neg_c`, `drop_clamp`, `swap_opsel_hi`) all failed `native_packed_dot2_f16_ir` (`rc=8`); clean source restored and re-verified passing. - `python -B tests/docs_links_check.py`: passed (`130` Markdown files, `630` links). AI-assisted.
R0Y00 commented 2026-11-28 01:43:42 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-28T01:43:42Z.

Review: CHANGES_REQUESTED


The source-built Compute fixture fails on a physical adapter in both Debug and Release /O2. I tested PR head acab1a069a on main 8007a539 (trial tree 4ace676e91538352270b0b178cf6d940c662f485):

ctest --test-dir <build> --no-tests=error --output-on-failure -j 1 -R "^native_(packed_dot2(_f16)?_.*|packed_f16_inline_(ir|controls|compute_hardware)|f16_alu_(ir|hardware))$"

In both builds 11 passed, including the WARP and hardware Pixel cases, and 1 failed (no skips). In native_packed_dot2_f16_compute_hardware, the first mismatch is word 25 (case 17 after the eight guard words): inline_int_src2_129 uses zero packed operands and the positive binary32 subnormal accumulator 0x00000001. The GPU returned 0x00000000 in successive lanes (25, 57, 89, ...). This is consistent with a denormal being flushed in the emitted floating-point addition. Please establish the binary32 mode for this opcode and preserve the required result or reject an unsupported mode at compile time. Keep the failing bit-exact control, including coverage for an accumulator sourced from a register if the fix handles encoded constants specially.

RTX 4060 Laptop, driver 32.0.16.1656, Windows 11 26200.9974, standalone replay without the debug layer.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6094967202 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3239#pullrequestreview-6094967202). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-28T01:43:42Z. **Review:** CHANGES_REQUESTED --- The source-built Compute fixture fails on a physical adapter in both Debug and Release /O2. I tested PR head acab1a069a36 on main 8007a539 (trial tree 4ace676e91538352270b0b178cf6d940c662f485): ``` ctest --test-dir <build> --no-tests=error --output-on-failure -j 1 -R "^native_(packed_dot2(_f16)?_.*|packed_f16_inline_(ir|controls|compute_hardware)|f16_alu_(ir|hardware))$" ``` In both builds 11 passed, including the WARP and hardware Pixel cases, and 1 failed (no skips). In native_packed_dot2_f16_compute_hardware, the first mismatch is word 25 (case 17 after the eight guard words): inline_int_src2_129 uses zero packed operands and the positive binary32 subnormal accumulator 0x00000001. The GPU returned 0x00000000 in successive lanes (25, 57, 89, ...). This is consistent with a denormal being flushed in the emitted floating-point addition. Please establish the binary32 mode for this opcode and preserve the required result or reject an unsupported mode at compile time. Keep the failing bit-exact control, including coverage for an accumulator sourced from a register if the fix handles encoded constants specially. RTX 4060 Laptop, driver 32.0.16.1656, Windows 11 26200.9974, standalone replay without the debug layer.
legacy-code-archaeologist commented 2026-11-28 01:54:20 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-28T01:54:20Z.


@R0Y00 Thank you for catching that on RTX 4060 Laptop and reporting the exact failing case (inline_int_src2_129, 0x00000001 flushed to 0x00000000)!

Root cause: gfx1013 starts with MODE[5:4] = 3 (keep binary32 denormals) and MODE[1:0] = 0 (RNE), whereas desktop DXIL fadd and saturate (dx.op.unary.f32(i32 7, ...)) flush binary32 subnormals to zero.

Fix:

  1. Enforced the full binary16 + binary32 mode mask (((mode_bits ^ 0xf0u) & 0x8000ffu)) for v_dot2_f32_f16 (alongside consume_half_mode() refusing s_denorm_mode / s_round_mode writes that alter binary32 fields).
  2. Preserved binary32 subnormal accumulators uniformly across all src2 source kinds (inline constants, VGPRs, SGPRs, literals) and clamp: every finite nonzero binary16 * binary16 sum (a0 * b0) + (a1 * b1) is an integer multiple of 2^-48 (|sum| >= 2^-48 >> 2^-126), so a binary32 subnormal c (0 < |c| < 2^-126) is observable if and only if (a0 * b0) + (a1 * b1) == +/-0.0. Selecting cbits (or c < 0 ? 0 : cbits under clamp) when sum == +/-0.0 and c is subnormal preserves bit-exact subnormal outputs.
  3. Expanded tests/native_dot2_f32_f16_check.py: kept inline_int_src2_129 (0x00000001, now also enabled in pixel draws), added four VGPR-sourced binary32 subnormal accumulator cases (vgpr_src2_subnormal_pos, vgpr_src2_subnormal_neg 0x80400000, vgpr_src2_subnormal_clamp_pos, vgpr_src2_subnormal_clamp_neg -> +0.0), and added an s_denorm_mode 0xC (FP32 denorm flush) refusal control.

Re-verified locally (dev and release /O2 presets, Windows 10.0.26100):

  • ctest --preset dev & --preset release --no-tests=error --output-on-failure -j 1 -V -R '^native_(packed_dot2(_f16)?_.*|packed_f16_inline_(ir|controls|compute_hardware)|f16_alu_(ir|hardware))$':
    • native_packed_dot2_f16_ir: Passed (30 cases matched exact model; 10 refusals matched).
    • native_packed_dot2_f16_controls: Passed (30 cases compiled to DXIL; 10 refusals verified).
    • native_packed_dot2_f16_pixel_warp: Passed (Microsoft Basic Render Driver 10.0.26100.9711, 7 quad draws matched, including inline_int_src2_129 and all 4 VGPR subnormal cases).
    • native_packed_dot2_f16_pixel_hardware: Passed (NVIDIA Quadro M1000M 32.0.15.7371, 7 quad draws matched; debug layer unavailable).
    • native_packed_dot2_f16_compute_hardware: Skipped (77, Intel(R) HD Graphics 530 lacks SM 6.6 wave32 — please retest on RTX 4060 Laptop!).
  • ctest --preset dev --no-tests=error -R '^native_.*_(controls|ir)$' --output-on-failure: 69/69 passed (0 skips).
  • Verified sensitivity mutant drop_subnormal_keep fails native_packed_dot2_f16_pixel_warp (rc=8) on inline_int_src2_129 and the VGPR subnormal cases.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7231995663 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3239#issuecomment-7231995663). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-28T01:54:20Z. --- @R0Y00 Thank you for catching that on RTX 4060 Laptop and reporting the exact failing case (`inline_int_src2_129`, `0x00000001` flushed to `0x00000000`)! **Root cause:** `gfx1013` starts with `MODE[5:4] = 3` (keep binary32 denormals) and `MODE[1:0] = 0` (RNE), whereas desktop DXIL `fadd` and `saturate` (`dx.op.unary.f32(i32 7, ...)`) flush binary32 subnormals to zero. **Fix:** 1. Enforced the full binary16 + binary32 mode mask (`((mode_bits ^ 0xf0u) & 0x8000ffu)`) for `v_dot2_f32_f16` (alongside `consume_half_mode()` refusing `s_denorm_mode` / `s_round_mode` writes that alter binary32 fields). 2. Preserved binary32 subnormal accumulators uniformly across all `src2` source kinds (inline constants, VGPRs, SGPRs, literals) and `clamp`: every finite nonzero `binary16 * binary16` sum `(a0 * b0) + (a1 * b1)` is an integer multiple of `2^-48` (`|sum| >= 2^-48 >> 2^-126`), so a binary32 subnormal `c` (`0 < |c| < 2^-126`) is observable if and only if `(a0 * b0) + (a1 * b1) == +/-0.0`. Selecting `cbits` (or `c < 0 ? 0 : cbits` under `clamp`) when `sum == +/-0.0` and `c` is subnormal preserves bit-exact subnormal outputs. 3. Expanded `tests/native_dot2_f32_f16_check.py`: kept `inline_int_src2_129` (`0x00000001`, now also enabled in `pixel` draws), added four VGPR-sourced binary32 subnormal accumulator cases (`vgpr_src2_subnormal_pos`, `vgpr_src2_subnormal_neg` `0x80400000`, `vgpr_src2_subnormal_clamp_pos`, `vgpr_src2_subnormal_clamp_neg` -> `+0.0`), and added an `s_denorm_mode 0xC` (FP32 denorm flush) refusal control. **Re-verified locally (`dev` and `release` `/O2` presets, Windows 10.0.26100):** - `ctest --preset dev` & `--preset release --no-tests=error --output-on-failure -j 1 -V -R '^native_(packed_dot2(_f16)?_.*|packed_f16_inline_(ir|controls|compute_hardware)|f16_alu_(ir|hardware))$'`: - `native_packed_dot2_f16_ir`: **Passed** (`30` cases matched exact model; `10` refusals matched). - `native_packed_dot2_f16_controls`: **Passed** (`30` cases compiled to DXIL; `10` refusals verified). - `native_packed_dot2_f16_pixel_warp`: **Passed** (`Microsoft Basic Render Driver` `10.0.26100.9711`, `7` quad draws matched, including `inline_int_src2_129` and all 4 VGPR subnormal cases). - `native_packed_dot2_f16_pixel_hardware`: **Passed** (`NVIDIA Quadro M1000M` `32.0.15.7371`, `7` quad draws matched; debug layer unavailable). - `native_packed_dot2_f16_compute_hardware`: **Skipped** (`77`, `Intel(R) HD Graphics 530` lacks SM 6.6 wave32 — please retest on RTX 4060 Laptop!). - `ctest --preset dev --no-tests=error -R '^native_.*_(controls|ir)$' --output-on-failure`: **69/69 passed** (`0` skips). - Verified sensitivity mutant `drop_subnormal_keep` fails `native_packed_dot2_f16_pixel_warp` (`rc=8`) on `inline_int_src2_129` and the VGPR subnormal cases. AI-assisted.
R0Y00 commented 2026-11-28 02:00:29 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-28T02:00:29Z.

Review: APPROVED


Re-reviewed 057dae6c60 on main 50e4f763 (tested tree 6ad305dc0f). The earlier RTX Compute mismatch is gone. The old inline 0x00000001 accumulator and new positive, negative, and clamped VGPR cases preserve the expected bits, and the FP32 flush-mode control refuses as expected. The integer select covers the subnormal accumulator regardless of its operand source, when the binary16 product sum is zero.

ctest --test-dir <build> --no-tests=error --output-on-failure -j 1 -R "^native_(packed_dot2(_f16)?_.*|packed_f16_inline_(ir|controls|compute_hardware)|f16_alu_(ir|hardware))$"

Debug 12/12 and Release /O2 12/12, no skips. Physical Compute and Pixel checks used the RTX 4060 Laptop GPU (32.0.16.1656); the Pixel WARP run used inbox WARP 10.0.26100.9818. Windows 11 26200.9974, standalone replay without the debug layer.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6095073418 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3239#pullrequestreview-6095073418). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-28T02:00:29Z. **Review:** APPROVED --- Re-reviewed 057dae6c603b on main 50e4f763 (tested tree 6ad305dc0f7ee69e6ede30efac32e508886db9d1). The earlier RTX Compute mismatch is gone. The old inline 0x00000001 accumulator and new positive, negative, and clamped VGPR cases preserve the expected bits, and the FP32 flush-mode control refuses as expected. The integer select covers the subnormal accumulator regardless of its operand source, when the binary16 product sum is zero. ``` ctest --test-dir <build> --no-tests=error --output-on-failure -j 1 -R "^native_(packed_dot2(_f16)?_.*|packed_f16_inline_(ir|controls|compute_hardware)|f16_alu_(ir|hardware))$" ``` Debug 12/12 and Release /O2 12/12, no skips. Physical Compute and Pixel checks used the RTX 4060 Laptop GPU (32.0.16.1656); the Pixel WARP run used inbox WARP 10.0.26100.9818. Windows 11 26200.9974, standalone replay without the debug layer.
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!3239
No description provided.