shader: lower v_frexp_mant_f16 and v_frexp_exp_i16_f16 in the direct compute path #3120

Manually merged
github merged 2 commits from github-bot/gh-3120 into gh-pr/3120/base 2026-11-27 18:08:04 +00:00 AGit
Owner

@⁠R0D4X on GitHub · 2026-11-27 16:04 UTC · original
R0D4X:feat/native-frexp-f16 → main · +226 −0 · 4 files · 2 commits · merged 2026-11-27 17:48 UTC

Fixes #3118. Refs #2935.

What this changes

  • Lowers v_frexp_mant_f16 (VOP1 0x59 / VOP3A 0x1d9) and v_frexp_exp_i16_f16 (VOP1 0x5a / VOP3A 0x1da) in src/gfx1013_direct_compute.inl using exact 32-bit integer IEEE-754 binary16 manipulation while preserving D[31:16].
  • Normalizes denormal inputs without flushing, preserves ±0.0h, ±Inf, and NaN, supports VOP3A abs/neg on src0 and clamp on v_frexp_mant_f16, and refuses unsupported modifier combinations (clamp on v_frexp_exp_i16_f16, omod, op_sel, unused VOP3 sources).

Tests & docs added

  • tests/native_frexp_f16_check.py & tests/cmake/native_frexp_f16.cmake:
    • native_frexp_f16_controls: validates emitted integer DXIL (shl i32 / lshr i32), refuses invalid modifiers, and verifies that the flush_denormals, no_clamp, and zero_high negative controls each differ.
    • native_frexp_f16_hardware: dispatches 8 binary16 edge cases (±0.0h, normals, smallest normal, largest/smallest subnormals, +Inf) across VOP1 and VOP3A (neg, abs + clamp) with pre-seeded D[31:16], matching 2048 result words and 16 sentinel guards.
  • docs/experiments/native-frexp-f16.md: experiment note and reproduction commands.

Verification

  • Commit: ebeb373d
  • Environment: Windows 11 x64 (10.0.26300.9974), MSVC 19.44.35230, Windows SDK / DXC 10.0.26100.0, NVIDIA GeForce RTX 5080 (10de:2c02, driver 32.0.16.2124).
  • ctest --preset dev --no-tests=error -R '^native_frexp_f16_|^native_ldexp_' -V: 4/4 passed (0 skipped).
  • ctest --preset release --no-tests=error -R '^native_frexp_f16_|^native_ldexp_': 4/4 passed (0 skipped).
  • tests/docs_links_check.py & tests/bidi_controls_check.py: passed.

Scope: covers synthetic direct-DXIL compute fixtures for v_frexp_mant_f16 and v_frexp_exp_i16_f16 only; does not establish full-game execution.

**@⁠R0D4X** on GitHub · 2026-11-27 16:04 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3120) `R0D4X:feat/native-frexp-f16` → `main` · +226 −0 · 4 files · 2 commits · merged 2026-11-27 17:48 UTC Fixes #3118. Refs #2935. ## What this changes - Lowers `v_frexp_mant_f16` (VOP1 `0x59` / VOP3A `0x1d9`) and `v_frexp_exp_i16_f16` (VOP1 `0x5a` / VOP3A `0x1da`) in `src/gfx1013_direct_compute.inl` using exact 32-bit integer IEEE-754 binary16 manipulation while preserving `D[31:16]`. - Normalizes denormal inputs without flushing, preserves `±0.0h`, `±Inf`, and `NaN`, supports VOP3A `abs`/`neg` on `src0` and `clamp` on `v_frexp_mant_f16`, and refuses unsupported modifier combinations (`clamp` on `v_frexp_exp_i16_f16`, `omod`, `op_sel`, unused VOP3 sources). ## Tests & docs added - `tests/native_frexp_f16_check.py` & `tests/cmake/native_frexp_f16.cmake`: - `native_frexp_f16_controls`: validates emitted integer DXIL (`shl i32` / `lshr i32`), refuses invalid modifiers, and verifies that the `flush_denormals`, `no_clamp`, and `zero_high` negative controls each differ. - `native_frexp_f16_hardware`: dispatches 8 binary16 edge cases (`±0.0h`, normals, smallest normal, largest/smallest subnormals, `+Inf`) across VOP1 and VOP3A (`neg`, `abs` + `clamp`) with pre-seeded `D[31:16]`, matching 2048 result words and 16 sentinel guards. - `docs/experiments/native-frexp-f16.md`: experiment note and reproduction commands. ## Verification - Commit: `ebeb373d` - Environment: Windows 11 x64 (`10.0.26300.9974`), MSVC `19.44.35230`, Windows SDK / DXC `10.0.26100.0`, NVIDIA GeForce RTX 5080 (`10de:2c02`, driver `32.0.16.2124`). - `ctest --preset dev --no-tests=error -R '^native_frexp_f16_|^native_ldexp_' -V`: **4/4 passed** (0 skipped). - `ctest --preset release --no-tests=error -R '^native_frexp_f16_|^native_ldexp_'`: **4/4 passed** (0 skipped). - `tests/docs_links_check.py` & `tests/bidi_controls_check.py`: **passed**. *Scope: covers synthetic direct-DXIL compute fixtures for `v_frexp_mant_f16` and `v_frexp_exp_i16_f16` only; does not establish full-game execution.*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 16:07:45 +00:00
github-bot changed target branch from main to gh-pr/3120/base 2026-11-27 18:08:04 +00:00
github manually merged commit d6fdfce67e into gh-pr/3120/base 2026-11-27 18:08:04 +00:00
Author
Owner

@⁠tedin7 on GitHub · 2026-11-27 17:48 UTC · original · reviewed

Review of d6fdfce67e (the change from ebeb373d, updated with main; the PR's own diff is unchanged).

Code: same structure as the f32 frexp lowering, on the low 16 bits of src0. Zero, Inf and NaN keep the input (mantissa op) or give 0 (exponent op); normal inputs give sign | 0.5h | fraction and exponent - 14; denormals are normalized with a four-step shift count, which gives exponent p - 23 for a denormal with its top bit at position p, as frexp expects. The result goes to D[15:0] and D[31:16] is kept, the same convention the other 16-bit results in this file use; the test seeds the high half of the destination and checks it survives. Clamp is refused on the exponent op and clamps the mantissa to [0, 1.0h]; omod, op_sel, DPP/SDWA and unused sources are refused. The reference is computed independently. No other open PR covers these two opcodes in the direct compute path.

Windows results are in the comment below.

Commands: git diff origin/main...pull/3120/head -- src/ tests/ (read), plus the Windows commands listed in the comment.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-27 17:48 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3120#pullrequestreview-6091726254) · **reviewed** Review of d6fdfce67e940cba8b6e7900c11b3707d41949bd (the change from ebeb373d, updated with main; the PR's own diff is unchanged). Code: same structure as the f32 frexp lowering, on the low 16 bits of src0. Zero, Inf and NaN keep the input (mantissa op) or give 0 (exponent op); normal inputs give sign | 0.5h | fraction and exponent - 14; denormals are normalized with a four-step shift count, which gives exponent p - 23 for a denormal with its top bit at position p, as frexp expects. The result goes to D[15:0] and D[31:16] is kept, the same convention the other 16-bit results in this file use; the test seeds the high half of the destination and checks it survives. Clamp is refused on the exponent op and clamps the mantissa to [0, 1.0h]; omod, op_sel, DPP/SDWA and unused sources are refused. The reference is computed independently. No other open PR covers these two opcodes in the direct compute path. Windows results are in the comment below. Commands: `git diff origin/main...pull/3120/head -- src/ tests/` (read), plus the Windows commands listed in the comment. AI-assisted; commands listed were executed locally.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-27 17:48 UTC · original

Windows Server 2025 verification of d6fdfce67e940cba8b6e7900c11b3707d41949bd (D3D12 WARP, MSVC 14.44.35207):

  • dev: cmake --build --preset dev --target compile_dxil native_store_replay; ctest --preset dev -R <native sweep>: 100% tests passed out of 128 (74 passed, 54 hardware legs skipped)
  • release: cmake --build --preset release --target compile_dxil native_store_replay; ctest --preset release -R <native sweep>: 100% tests passed out of 128 (74 passed, 54 skipped)

<native sweep> = every native_* test except native_startup_request_cache_hardware, which fails on WARP-only hosts with or without this PR (wave lane count 32 requested, WARP offers 4; the test comes from #2955). native_frexp_f16_controls passed in both presets; the _hardware leg skips on WARP because it needs a physical wave32 adapter.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-27 17:48 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3120#issuecomment-7224808034) Windows Server 2025 verification of `d6fdfce67e940cba8b6e7900c11b3707d41949bd` (D3D12 WARP, MSVC 14.44.35207): - dev: `cmake --build --preset dev --target compile_dxil native_store_replay`; `ctest --preset dev -R <native sweep>`: 100% tests passed out of 128 (74 passed, 54 hardware legs skipped) - release: `cmake --build --preset release --target compile_dxil native_store_replay`; `ctest --preset release -R <native sweep>`: 100% tests passed out of 128 (74 passed, 54 skipped) `<native sweep>` = every `native_*` test except `native_startup_request_cache_hardware`, which fails on WARP-only hosts with or without this PR (wave lane count 32 requested, WARP offers 4; the test comes from #2955). `native_frexp_f16_controls` passed in both presets; the `_hardware` leg skips on WARP because it needs a physical wave32 adapter. AI-assisted; commands listed were executed locally.
Author
Owner

@⁠chadhyatt on GitHub · 2026-11-27 19:39 UTC · original

The private direct-compute intake found a concrete untested operand case at 429f11d5110: the f16 frexp lowering takes operand32(src0) & 0xffff. Inline float sources 240-248 are f32 patterns in operand32 (e.g. 1.0 = 0x3f800000, whose low half is zero), while the equivalent binary16 source is 0x3c00. The frexp mantissa/exp for inline 1.0 should be 0.5h/1, not zero/0. Reuse the existing half operand decode convention and include inline 0.5, -1, 1 and 0.159 cases, plus signed NaN/negative-clamp reference controls. The f16 implementation also needs a proven half MODE/denorm contract or a typed refusal for unsupported FTZ/RTZ modes; graphics direct-path admission should remain unclaimed until measured. This is a static source finding, not new hardware evidence.

**@⁠chadhyatt** on GitHub · 2026-11-27 19:39 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3120#issuecomment-7226741066) The private direct-compute intake found a concrete untested operand case at `429f11d5110`: the f16 frexp lowering takes `operand32(src0) & 0xffff`. Inline float sources 240-248 are f32 patterns in `operand32` (e.g. 1.0 = `0x3f800000`, whose low half is zero), while the equivalent binary16 source is `0x3c00`. The frexp mantissa/exp for inline 1.0 should be 0.5h/1, not zero/0. Reuse the existing half operand decode convention and include inline 0.5, -1, 1 and 0.159 cases, plus signed NaN/negative-clamp reference controls. The f16 implementation also needs a proven half MODE/denorm contract or a typed refusal for unsupported FTZ/RTZ modes; graphics direct-path admission should remain unclaimed until measured. This is a static source finding, not new hardware evidence.
This discussion has been locked. Commenting is limited to contributors.
No description provided.