shader: read inline float sources as binary16 in v_frexp_mant_f16 and v_frexp_exp_i16_f16 #3149

Manually merged
github merged 2 commits from github-bot/gh-3147 into gh-pr/3147/base 2026-11-27 20:28:55 +00:00 AGit
Owner

@⁠JohnConnorNPC on GitHub · 2026-11-27 18:22 UTC · original
JohnConnorNPC:fix/frexp-f16-inline-const → main · +66 −5 · 4 files · 2 commits · merged 2026-11-27 20:28 UTC

Refs #3120.

What this changes

v_frexp_mant_f16 and v_frexp_exp_i16_f16 in src/gfx1013_direct_compute.inl read their source with
and(operand32(src0), 65535). For an inline float (encodings 240–248), constant32 returns the f32 bit
pattern (0x3f800000 for 1.0), so the op saw the low half of that pattern, 0x0000. As a result
v_frexp_mant_f16 v3, 1.0 gave 0x0000 instead of 0x3800, and v_frexp_exp_i16_f16 v3, 1.0 gave 0
instead of 1.

The fix makes an inline float read its binary16 value, as v_add_f16 already does in the same file. The
nine-entry table that v_add_f16 kept locally (halves[]) is now a shared member, inline_half_words,
next to inline_float_words, and both ops read it. Register, literal and integer-constant sources are
unchanged, and so is v_add_f16.

Test added

native_frexp_f16_ir (tests/native_frexp_f16_check.py ir, registered in
tests/cmake/native_frexp_f16.cmake) needs no GPU and no DXC. It builds one compute container, dumps the
IR with native_compute_ir_dump, and evaluates lane 0 with interpret() from native_f16_alu_check.py.
It covers 22 results:

  • all nine inline floats with both ops (VOP1);
  • three VOP3A forms: |-2.0| with clamp, -1.0 and -1/(2pi);
  • one VGPR source as a control.

Each result keeps a seeded D[31:16]. Two rows are pinned independently of the lowering:

  • 1.0 gives exponent 1 and mantissa 0x3800;
  • 1/(2pi) (0x3118) gives exponent 0xfffe and mantissa 0x3918.

Verification

Commit a7b31d1f on 429f11d5. The tools were cross-built on Linux with clang-cl 19 and the xwin SDK
(ninja -j1 native_compute_ir_dump, Release). The checks ran with an embeddable Windows Python under Wine
(Proton Experimental):

  • python -B tests/native_frexp_f16_check.py ir native_compute_ir_dump.exe:
    • before the fix (429f11d5): fails, 19 of 22 rows wrong. The first one is row 4,
      v_frexp_mant_f16 v3, 1.0: got beef0000, expected beef3800.
    • with the fix: passes, 22 results matched, inline floats read as binary16.
  • Paired mutation: I restored only the old operand line on the final tree (byte copy, sha256 and mode
    recorded), rebuilt, and the check failed with the same 19 rows. After restoring the file (hash
    matched) and rebuilding, it passed again.
  • python -B tests/native_f16_alu_check.py ir native_compute_ir_dump.exe: passes before and after,
    82 results match the model; 16 refusals carry the named diagnostic. This shows v_add_f16 reads the
    shared table unchanged.
  • ctest -N --no-tests=error -R '^native_frexp_f16_': lists native_frexp_f16_controls,
    native_frexp_f16_hardware and native_frexp_f16_ir.
  • tests/docs_links_check.py and tests/bidi_controls_check.py: pass.

Not run:

  • native_frexp_f16_controls, because it calls dxc.exe.
  • native_frexp_f16_hardware, because no GPU was used.

A Windows reviewer can run all three with:

cmake --build --preset dev --target compile_dxil native_store_replay native_compute_ir_dump
ctest --preset dev --no-tests=error -R '^native_frexp_f16_' -V

CI: the PR job runs the pr presets. Their fixed test allowlist contains no native_* test, and the
pr build preset does not build native_compute_ir_dump. So PR CI checks that the change compiles, not
the new test.

Scope: a synthetic direct-compute IR fixture for the inline-float source of these two ops only. It does
not establish full-game execution.

This PR was AI-assisted.

**@⁠JohnConnorNPC** on GitHub · 2026-11-27 18:22 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3147) `JohnConnorNPC:fix/frexp-f16-inline-const` → `main` · +66 −5 · 4 files · 2 commits · merged 2026-11-27 20:28 UTC Refs #3120. ## What this changes `v_frexp_mant_f16` and `v_frexp_exp_i16_f16` in `src/gfx1013_direct_compute.inl` read their source with `and(operand32(src0), 65535)`. For an inline float (encodings 240–248), `constant32` returns the f32 bit pattern (`0x3f800000` for 1.0), so the op saw the low half of that pattern, `0x0000`. As a result `v_frexp_mant_f16 v3, 1.0` gave `0x0000` instead of `0x3800`, and `v_frexp_exp_i16_f16 v3, 1.0` gave `0` instead of `1`. The fix makes an inline float read its binary16 value, as `v_add_f16` already does in the same file. The nine-entry table that `v_add_f16` kept locally (`halves[]`) is now a shared member, `inline_half_words`, next to `inline_float_words`, and both ops read it. Register, literal and integer-constant sources are unchanged, and so is `v_add_f16`. ## Test added `native_frexp_f16_ir` (`tests/native_frexp_f16_check.py ir`, registered in `tests/cmake/native_frexp_f16.cmake`) needs no GPU and no DXC. It builds one compute container, dumps the IR with `native_compute_ir_dump`, and evaluates lane 0 with `interpret()` from `native_f16_alu_check.py`. It covers 22 results: - all nine inline floats with both ops (VOP1); - three VOP3A forms: `|-2.0|` with `clamp`, `-1.0` and `-1/(2pi)`; - one VGPR source as a control. Each result keeps a seeded `D[31:16]`. Two rows are pinned independently of the lowering: - 1.0 gives exponent `1` and mantissa `0x3800`; - `1/(2pi)` (`0x3118`) gives exponent `0xfffe` and mantissa `0x3918`. ## Verification Commit `a7b31d1f` on `429f11d5`. The tools were cross-built on Linux with clang-cl 19 and the xwin SDK (`ninja -j1 native_compute_ir_dump`, Release). The checks ran with an embeddable Windows Python under Wine (Proton Experimental): - `python -B tests/native_frexp_f16_check.py ir native_compute_ir_dump.exe`: - before the fix (`429f11d5`): **fails**, 19 of 22 rows wrong. The first one is row 4, `v_frexp_mant_f16 v3, 1.0`: got `beef0000`, expected `beef3800`. - with the fix: **passes**, `22 results matched, inline floats read as binary16`. - Paired mutation: I restored only the old operand line on the final tree (byte copy, sha256 and mode recorded), rebuilt, and the check **failed** with the same 19 rows. After restoring the file (hash matched) and rebuilding, it **passed** again. - `python -B tests/native_f16_alu_check.py ir native_compute_ir_dump.exe`: **passes** before and after, `82 results match the model; 16 refusals carry the named diagnostic`. This shows `v_add_f16` reads the shared table unchanged. - `ctest -N --no-tests=error -R '^native_frexp_f16_'`: lists `native_frexp_f16_controls`, `native_frexp_f16_hardware` and `native_frexp_f16_ir`. - `tests/docs_links_check.py` and `tests/bidi_controls_check.py`: **pass**. Not run: - `native_frexp_f16_controls`, because it calls `dxc.exe`. - `native_frexp_f16_hardware`, because no GPU was used. A Windows reviewer can run all three with: ```powershell cmake --build --preset dev --target compile_dxil native_store_replay native_compute_ir_dump ctest --preset dev --no-tests=error -R '^native_frexp_f16_' -V ``` **CI:** the PR job runs the `pr` presets. Their fixed test allowlist contains no `native_*` test, and the `pr` build preset does not build `native_compute_ir_dump`. So PR CI checks that the change compiles, not the new test. *Scope: a synthetic direct-compute IR fixture for the inline-float source of these two ops only. It does not establish full-game execution.* This PR was AI-assisted.
The lowering masked the f32 pattern of an inline float (240-248) to its low
16 bits, so v_frexp_mant_f16 v3, 1.0 gave 0x0000 instead of 0x3800. Read the
binary16 table that v_add_f16 already uses, now shared as inline_half_words,
and add native_frexp_f16_ir, which evaluates the emitted IR for all nine
constants without a GPU or DXC.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 18:26:27 +00:00
Author
Owner

@⁠KelboLive on GitHub · 2026-11-27 18:56 UTC · original · approved these changes

**@⁠KelboLive** on GitHub · 2026-11-27 18:56 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3147#pullrequestreview-6092316428) · **approved these changes**
github-bot changed target branch from main to gh-pr/3147/base 2026-11-27 20:28:53 +00:00
github manually merged commit d8b40a7681 into gh-pr/3147/base 2026-11-27 20:28:55 +00:00
Author
Owner

@⁠tedin7 on GitHub · 2026-11-27 20:28 UTC · original · reviewed

Review of d8b40a7681 (updated with main). Comment only.

This fixes the inline-constant gap I pointed out on #3125 and #3127 for the already merged #3120: v_frexp_mant_f16 / v_frexp_exp_i16_f16 now read sources 240-248 as their binary16 values, through a shared inline_half_words table that v_add_f16 also uses now (same nine values as its old local halves[], so that path is unchanged). The new native_frexp_f16_ir test needs no GPU: it evaluates the emitted IR for all nine inline constants, abs/neg/clamp forms and a VGPR source against frexp_f16, with two pinned rows independent of the lowering, so it runs in CI and on WARP hosts.

The change is in src/gfx1013_direct_compute.inl, which the cpp-migration branch also changes; it merges cleanly there and the native sweep passes on that merge too (comment below).

Windows results are in the comment below.

Commands: git diff origin/main...pull/3147/head (read), git merge-tree --write-tree origin/cpp-migration pull/3147/head, plus the Windows commands listed in the comment.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-27 20:28 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3147#pullrequestreview-6093069567) · **reviewed** Review of d8b40a76814668bd39b63cf0da8cd567d3e133b5 (updated with main). Comment only. This fixes the inline-constant gap I pointed out on #3125 and #3127 for the already merged #3120: `v_frexp_mant_f16` / `v_frexp_exp_i16_f16` now read sources 240-248 as their binary16 values, through a shared `inline_half_words` table that `v_add_f16` also uses now (same nine values as its old local `halves[]`, so that path is unchanged). The new `native_frexp_f16_ir` test needs no GPU: it evaluates the emitted IR for all nine inline constants, abs/neg/clamp forms and a VGPR source against `frexp_f16`, with two pinned rows independent of the lowering, so it runs in CI and on WARP hosts. The change is in `src/gfx1013_direct_compute.inl`, which the `cpp-migration` branch also changes; it merges cleanly there and the native sweep passes on that merge too (comment below). Windows results are in the comment below. Commands: `git diff origin/main...pull/3147/head` (read), `git merge-tree --write-tree origin/cpp-migration pull/3147/head`, plus the Windows commands listed in the comment. AI-assisted; commands listed were executed locally.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-27 20:28 UTC · original

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

  • dev: cmake --build --preset dev --target compile_dxil native_store_replay native_compute_ir_dump; ctest --preset dev -R <native sweep>: 100% tests passed out of 133 (77 passed, 56 hardware legs skipped), including native_frexp_f16_ir and native_frexp_f16_controls
  • release: same targets with --preset release; ctest --preset release -R <native sweep>: 100% tests passed out of 133 (77 passed, 56 skipped)
  • The same dev and release sweep on this head merged with cpp-migration (a0f67731): 100% tests passed out of 133 in both presets

<native sweep> = every native_* test except native_startup_request_cache_hardware, which fails on WARP-only hosts with or without this PR.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-27 20:28 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3147#issuecomment-7227533650) Windows Server 2025 verification of `d8b40a76814668bd39b63cf0da8cd567d3e133b5` (D3D12 WARP, MSVC 14.44.35207): - dev: `cmake --build --preset dev --target compile_dxil native_store_replay native_compute_ir_dump`; `ctest --preset dev -R <native sweep>`: 100% tests passed out of 133 (77 passed, 56 hardware legs skipped), including `native_frexp_f16_ir` and `native_frexp_f16_controls` - release: same targets with `--preset release`; `ctest --preset release -R <native sweep>`: 100% tests passed out of 133 (77 passed, 56 skipped) - The same dev and release sweep on this head merged with `cpp-migration` (`a0f67731`): 100% tests passed out of 133 in both presets `<native sweep>` = every `native_*` test except `native_startup_request_cache_hardware`, which fails on WARP-only hosts with or without this PR. AI-assisted; commands listed were executed locally.
This discussion has been locked. Commenting is limited to contributors.
No description provided.