shader: lower v_cvt_norm_i16_f16 and v_cvt_norm_u16_f16 in direct DXIL #3294

Manually merged
github merged 1 commit from github-bot/gh-3292 into main 2026-11-28 08:31:57 +00:00 AGit
Owner

@⁠legacy-code-archaeologist on GitHub · 2026-11-28 05:43 UTC · original
legacy-code-archaeologist:shader/direct-cvt-norm-f16 → main · +449 −16 · 4 files · 1 commits · merged 2026-11-28 08:27 UTC

Fixes #3293, Refs #2935.

Summary

  • Lowers VOP1 (0x63 / 0x64) and VOP3 (0x1e3 / 0x1e4) v_cvt_norm_i16_f16 and v_cvt_norm_u16_f16 in DirectCompute::float_alu() (src/gfx1013_direct_compute.inl) for both direct Compute and Pixel DXIL, sharing unary binary16 source decoding and op_sel[3] half-preserving destination merge with v_fract_f16.
  • Evaluates round_rne(clamp(x, -1, 1) * 32767) (i16) and round_rne(clamp(x, 0, 1) * 65535) (u16) in exact 32-bit integer arithmetic (matching tools/pixel_aot.py::f16_cvt_norm_result to avoid binary32 double-rounding on 0x3801..0x3804 / 0xb801..0xb802 and preserve binary16 subnormals), mapping ±0.0 and NaN to 0 and saturating |x| >= 1.0 (±Inf included).
  • Supports VOP3 abs[0], neg[0], op_sel[0], op_sel[3], and VGPR / SGPR / literal / inline-constant sources under the strict ((mode_bits ^ 0xf0u) & 0x8000ccu) binary16 mode gate, while refusing clamp, omod, unused modifier bits, high-half op_sel on non-VGPR sources, DPP/SDWA, special scalar sources (106), and non-default/dynamic binary16 modes.
  • Adds tests/native_cvt_norm_f16_check.py, tests/cmake/native_cvt_norm_f16.cmake, and docs/experiments/native-cvt-norm-f16.md (30 cases, 11 refusals across Compute IR/DXIL/lossless 16-bit Pixel readback + Compute SM 6.6 wave32 replay).

Verification

All checks passed on Windows 11 with SDK 10.0.26100.0 (dev and release /O2 presets):

  • python -B tests/docs_links_check.py: passed (143 Markdown files, 663 links)
  • ctest --preset dev & ctest --preset release (-R '^(native_cvt_norm_f16_|native_fract_f16_|native_f16_alu_ir)'): 9 passed, 2 skipped in each preset:
    • native_cvt_norm_f16_ir (30 cases, 11 refusals) & native_cvt_norm_f16_controls (30 cases compiled, 11 refusals): passed
    • native_cvt_norm_f16_pixel_warp (Microsoft Basic Render Driver, 15 draws / 30 cases) & native_cvt_norm_f16_pixel_hardware (NVIDIA Quadro M1000M driver 32.0.15.7371, debug_layer=unavailable, 15 draws / 30 cases): passed
    • native_f16_alu_ir (435 results, 39 refusals) & native_fract_f16_{ir,controls,pixel_warp,pixel_hardware} (32 cases, 10 refusals, 16 pixel draws): passed
    • native_cvt_norm_f16_compute_hardware & native_fract_f16_compute_hardware: skipped (77 on local Intel HD Graphics 530 31.0.101.2111 lacking SM 6.6 wave32)
  • Sensitivity mutants on dev (native_cvt_norm_f16_ir): dropping RNE tie-to-even rounding failed at slot 10 (i16_half_tie_even, 0xdead3fff != 0xdead4000, plus 7+ other halfway/subnormal cases); dropping is_nan failed at slot 8 (i16_nan_zero, 0xdead7fff != 0xdead0000) and slot 28 (i16_inline_int_193_nan).

AI-assisted.

**@⁠legacy-code-archaeologist** on GitHub · 2026-11-28 05:43 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3292) `legacy-code-archaeologist:shader/direct-cvt-norm-f16` → `main` · +449 −16 · 4 files · 1 commits · merged 2026-11-28 08:27 UTC Fixes #3293, Refs #2935. ## Summary - Lowers VOP1 (`0x63` / `0x64`) and VOP3 (`0x1e3` / `0x1e4`) `v_cvt_norm_i16_f16` and `v_cvt_norm_u16_f16` in `DirectCompute::float_alu()` (`src/gfx1013_direct_compute.inl`) for both direct Compute and Pixel DXIL, sharing unary binary16 source decoding and `op_sel[3]` half-preserving destination merge with `v_fract_f16`. - Evaluates `round_rne(clamp(x, -1, 1) * 32767)` (`i16`) and `round_rne(clamp(x, 0, 1) * 65535)` (`u16`) in exact 32-bit integer arithmetic (matching `tools/pixel_aot.py::f16_cvt_norm_result` to avoid binary32 double-rounding on `0x3801..0x3804` / `0xb801..0xb802` and preserve binary16 subnormals), mapping `±0.0` and `NaN` to `0` and saturating `|x| >= 1.0` (`±Inf` included). - Supports VOP3 `abs[0]`, `neg[0]`, `op_sel[0]`, `op_sel[3]`, and VGPR / SGPR / literal / inline-constant sources under the strict `((mode_bits ^ 0xf0u) & 0x8000ccu)` binary16 mode gate, while refusing `clamp`, `omod`, unused modifier bits, high-half `op_sel` on non-VGPR sources, DPP/SDWA, special scalar sources (`106`), and non-default/dynamic binary16 modes. - Adds `tests/native_cvt_norm_f16_check.py`, `tests/cmake/native_cvt_norm_f16.cmake`, and `docs/experiments/native-cvt-norm-f16.md` (`30` cases, `11` refusals across Compute IR/DXIL/lossless 16-bit Pixel readback + Compute SM 6.6 wave32 replay). ## Verification All checks passed on Windows 11 with SDK `10.0.26100.0` (`dev` and `release` `/O2` presets): - `python -B tests/docs_links_check.py`: passed (`143` Markdown files, `663` links) - `ctest --preset dev` & `ctest --preset release` (`-R '^(native_cvt_norm_f16_|native_fract_f16_|native_f16_alu_ir)'`): `9` passed, `2` skipped in each preset: - `native_cvt_norm_f16_ir` (`30` cases, `11` refusals) & `native_cvt_norm_f16_controls` (`30` cases compiled, `11` refusals): passed - `native_cvt_norm_f16_pixel_warp` (Microsoft Basic Render Driver, `15` draws / `30` cases) & `native_cvt_norm_f16_pixel_hardware` (NVIDIA Quadro M1000M driver `32.0.15.7371`, `debug_layer=unavailable`, `15` draws / `30` cases): passed - `native_f16_alu_ir` (`435` results, `39` refusals) & `native_fract_f16_{ir,controls,pixel_warp,pixel_hardware}` (`32` cases, `10` refusals, `16` pixel draws): passed - `native_cvt_norm_f16_compute_hardware` & `native_fract_f16_compute_hardware`: skipped (`77` on local Intel HD Graphics 530 `31.0.101.2111` lacking SM 6.6 wave32) - Sensitivity mutants on `dev` (`native_cvt_norm_f16_ir`): dropping RNE tie-to-even rounding failed at slot `10` (`i16_half_tie_even`, `0xdead3fff != 0xdead4000`, plus `7+` other halfway/subnormal cases); dropping `is_nan` failed at slot `8` (`i16_nan_zero`, `0xdead7fff != 0xdead0000`) and slot `28` (`i16_inline_int_193_nan`). AI-assisted.
Lower VOP1 (0x63/0x64) and VOP3 (0x1e3/0x1e4) v_cvt_norm_i16_f16 and v_cvt_norm_u16_f16 in DirectCompute::float_alu() using exact 32-bit integer round-to-nearest-even arithmetic (matching pixel_aot::f16_cvt_norm_result), sharing unary half-source decode/destination-half merge with v_fract_f16, enforcing the 0x8000ccu binary16 mode gate, and adding IR/DXIL/WARP/hardware tests plus native-cvt-norm-f16.md. Fixes #3291, Refs #2935. AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 05:48:54 +00:00
Author
Owner

@⁠JohnConnorNPC on GitHub · 2026-11-28 06:45 UTC · original

Thanks for this. The lowering checks out: the integer model matches an exact fractions.Fraction reference and pixel_aot.f16_cvt_norm_result on all finite binary16 inputs for both kinds, and ir and controls pass on this head merged into main 19358dae (Linux clang-cl build, CPU-only under Wine).

Could you add one case before merge? Positive NaN on v_cvt_norm_u16_f16 isn't pinned. The only u16 NaN case is u16_neg_nan_zero (0xFC01), and the sign term already zeroes that one.

  • Mutant: in the u16 branch, zero_out = ir.value("or i1 " + is_zero + ", " + sign) (drops is_nan). It still passes native_cvt_norm_f16_check.py ir (30 cases matched exact model; 11 refusals matched) and controls (compiled 30 cases to DXIL; verified 11 refusals).
  • That mutant changes 1023 inputs (every positive NaN gives 0xffff instead of 0) but none of the 30 cases. The pixel and compute modes compare against the same Case.expected(), so they can't catch it either.
  • As a control, ge_one uge → ugt fails ir at i16_pos_one_and_over, so the harness does catch a mutant that a case reaches.

Suggested fix: Case('u16_pos_nan_zero', 'u16', 257, 0x7E00). Compute goes to 31 of 32 slots, and pixel gets 30 full-EXEC cases with no padding.

This comment was AI-assisted.

**@⁠JohnConnorNPC** on GitHub · 2026-11-28 06:45 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3292#issuecomment-7235497934) Thanks for this. The lowering checks out: the integer model matches an exact `fractions.Fraction` reference and `pixel_aot.f16_cvt_norm_result` on all finite binary16 inputs for both kinds, and `ir` and `controls` pass on this head merged into main `19358dae` (Linux clang-cl build, CPU-only under Wine). Could you add one case before merge? Positive NaN on `v_cvt_norm_u16_f16` isn't pinned. The only u16 NaN case is `u16_neg_nan_zero` (`0xFC01`), and the sign term already zeroes that one. - Mutant: in the u16 branch, `zero_out = ir.value("or i1 " + is_zero + ", " + sign)` (drops `is_nan`). It still passes `native_cvt_norm_f16_check.py ir` (`30 cases matched exact model; 11 refusals matched`) and `controls` (`compiled 30 cases to DXIL; verified 11 refusals`). - That mutant changes 1023 inputs (every positive NaN gives `0xffff` instead of `0`) but none of the 30 cases. The pixel and compute modes compare against the same `Case.expected()`, so they can't catch it either. - As a control, `ge_one` `uge` → `ugt` fails `ir` at `i16_pos_one_and_over`, so the harness does catch a mutant that a case reaches. Suggested fix: `Case('u16_pos_nan_zero', 'u16', 257, 0x7E00)`. Compute goes to 31 of 32 slots, and pixel gets 30 full-EXEC cases with no padding. This comment was AI-assisted.
github manually merged commit 24c958ff2c into main 2026-11-28 08:31:57 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.