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

Merged
JohnConnorNPC merged 2 commits from upstream-pr/3147 into main 2026-11-27 20:28:13 +00:00
JohnConnorNPC commented 2026-11-27 18:22:27 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-27T18:22:27Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5531308286 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3147). Originally posted by [JohnConnorNPC](https://github.com/JohnConnorNPC) on 2026-11-27T18:22:27Z. --- 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.
tedin7 commented 2026-11-27 20:28:00 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-27T20:28:00Z.

Review: COMMENTED


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

This fixes the inline-constant gap I pointed out on #3123 and #3125 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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6093069567 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3147#pullrequestreview-6093069567). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-27T20:28:00Z. **Review:** COMMENTED --- Review of d8b40a76814668bd39b63cf0da8cd567d3e133b5 (updated with main). Comment only. This fixes the inline-constant gap I pointed out on #3123 and #3125 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 commented 2026-11-27 20:28:02 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-27T20:28:02Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7227533650 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3147#issuecomment-7227533650). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-27T20:28:02Z. --- 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.
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!3147
No description provided.