shader: lower v_cvt_f64_f32 for statically known sources in pixel_aot #1446

Manually merged
github merged 1 commit from gh-pr/1446/head into gh-pr/1446/base 2026-11-26 23:07:46 +00:00
Owner

@⁠JB2WIN on GitHub · 2026-11-24 11:39 UTC · original
JB2WIN:shader/cvt-f64-f32 → main · +445 −1 · 5 files · 1 commits · merged 2026-11-24 11:58 UTC

Refs #1325

Change

This is the f32 widening follow-up to #1363 that was agreed in #1325. tools/pixel_aot.py lowers v_cvt_f64_f32 into a VGPR pair v[d:d+1] when its source is known at translation time.

Accepted sources. The domain is the one require_proven_i32_f32_range uses:

  • a hex literal
  • a binary32 inline constant (0, ±0.5, ±1.0, ±2.0, ±4.0, 0.15915494)
  • an SGPR that holds a tracked integer
  • a VGPR whose bits known_ssa_bits records

Any other register is refused with Unproven runtime input. The integer inline constants 1..64 and -16..-1 are subnormal or NaN patterns and are refused as well.

Result words. Both words are computed in Python and emitted as constants, so the shader contains no HLSL double and no runtime input. Normal finite values, ±0 and ±infinity convert exactly: -0 gives 0x80000000_00000000, and infinity gives exponent 0x7ff with a zero fraction. A subnormal is refused, because the binary32 input-denormal mode MODE[5:4] has no declared profile here. A NaN is refused as well (#312).

Encodings (LLVM 15.0.7, gfx1013).

  • Plain form: LLVM 15 prints the unmodified VOP1 form as v_cvt_f64_f32_e32 (v_cvt_f64_f32_e32 v[13:14], v1 is 01211a7e). The plain and _e32 spellings are lowered.

  • Modifiers: the source-modifier forms assemble and round-trip as _e64:

    Spelling Encoding
    -v1 0d0090d5 01010020
    |v1| 0d0190d5 01010000
    -|v1| both bits set
    neg(0x…), |0x…|, -|0x…| the literal forms

    Exactly these spellings are lowered. Abs is applied first, then neg, as in require_proven_i32_f32_range. A signed-zero control can tell the order apart: -|-0| must give -0, while the swapped order would give +0.

  • Refused: _e64 without a modifier, -0x… (LLVM folds it into an integer literal, not a modifier), neg(v)/abs(v), clamp, omod, DPP and SDWA (neither assembles for this opcode in LLVM 15, which the test checks), an invalid pair and masked regions.

  • Not verified: the semantics and the modifier order come from LLVM 15 and are not checked against the ISA document. They are not measured on a console.

Test

  • Mode: draw-cvt-f64-f32, registered as pixel_aot_cvt_f64_f32_hardware and _warp. It has a 60 s timeout, skip code 77 and its own FORM_COVERAGE_RECORD. The LLVM 15 round trip covers the programs, and a binary check confirms the encodings above.
  • Programs: every row is its own program, because the source must be static. There are ten groups:
    • literal sources
    • SGPR sources
    • VGPR sources
    • literal and register modifier forms
  • Rows: ±0, ±1, the largest normal value (0x7f7fffff), the smallest normal value with its negative, ±infinity and 0x3f800001 (the last fraction bit set). Both words are exported through the uint target with per-row xor masks, so the comparison stays bit-exact, and the sentinels in v12/v15 must stay unchanged.
  • Wrong references: each of these must report pixel_mismatch:
    • swapped words
    • the lost sign of -0
    • infinity exported as NaN
    • the exponent bias off by one
    • a swapped modifier order
  • Refusal controls: subnormals (0x00000001, 0x807fffff), NaNs (0x7fc00000, 0x7f800001), an unproven loaded VGPR, clamp, omod and an invalid pair.
  • Mutations: each of these mutations of the lowering turns the checks red: swapped words, a dropped sign of -0, the exponent bias +1, a swapped modifier order.
  • Against main: with main's tools/pixel_aot.py the mode fails with ValueError: Unsupported instruction 22: v_cvt_f64_f32_e32 v[13:14], 0.

Environment: commit 88dd9484, rebased on 92bd3362. NVIDIA GeForce RTX 3080 (driver 32.0.16.2124), WARP 10.0.26100.9818, Windows 11 build 26200, debug layer unavailable.

ctest --preset dev --no-tests=error -R '^pixel_aot_cvt_f64_' -V   # 4/4 passed, none skipped
ctest --preset dev --no-tests=error                              # 901/901 passed; 25 capability skips, none from this change

The pure checks pass, and so does the LLVM 15.0.7 binary round trip. On this machine the hardware test takes about 21–24 s under -j4, with about 60 DXC compiles.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

**@⁠JB2WIN** on GitHub · 2026-11-24 11:39 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1446) `JB2WIN:shader/cvt-f64-f32` → `main` · +445 −1 · 5 files · 1 commits · merged 2026-11-24 11:58 UTC Refs #1325 ## Change This is the f32 widening follow-up to #1363 that was agreed in #1325. `tools/pixel_aot.py` lowers `v_cvt_f64_f32` into a VGPR pair `v[d:d+1]` when its source is known at translation time. **Accepted sources.** The domain is the one `require_proven_i32_f32_range` uses: - a hex literal - a binary32 inline constant (0, ±0.5, ±1.0, ±2.0, ±4.0, 0.15915494) - an SGPR that holds a tracked integer - a VGPR whose bits `known_ssa_bits` records Any other register is refused with `Unproven runtime input`. The integer inline constants 1..64 and -16..-1 are subnormal or NaN patterns and are refused as well. **Result words.** Both words are computed in Python and emitted as constants, so the shader contains no HLSL `double` and no runtime input. Normal finite values, ±0 and ±infinity convert exactly: -0 gives `0x80000000_00000000`, and infinity gives exponent `0x7ff` with a zero fraction. A subnormal is refused, because the binary32 input-denormal mode `MODE[5:4]` has no declared profile here. A NaN is refused as well (#312). **Encodings (LLVM 15.0.7, gfx1013).** - **Plain form:** LLVM 15 prints the unmodified VOP1 form as `v_cvt_f64_f32_e32` (`v_cvt_f64_f32_e32 v[13:14], v1` is `01211a7e`). The plain and `_e32` spellings are lowered. - **Modifiers:** the source-modifier forms assemble and round-trip as `_e64`: | Spelling | Encoding | |---|---| | `-v1` | `0d0090d5 01010020` | | `\|v1\|` | `0d0190d5 01010000` | | `-\|v1\|` | both bits set | | `neg(0x…)`, `\|0x…\|`, `-\|0x…\|` | the literal forms | Exactly these spellings are lowered. Abs is applied first, then neg, as in `require_proven_i32_f32_range`. A signed-zero control can tell the order apart: `-|-0|` must give -0, while the swapped order would give +0. - **Refused:** `_e64` without a modifier, `-0x…` (LLVM folds it into an integer literal, not a modifier), `neg(v)`/`abs(v)`, `clamp`, `omod`, DPP and SDWA (neither assembles for this opcode in LLVM 15, which the test checks), an invalid pair and masked regions. - **Not verified:** the semantics and the modifier order come from LLVM 15 and are not checked against the ISA document. They are not measured on a console. ## Test - **Mode:** `draw-cvt-f64-f32`, registered as `pixel_aot_cvt_f64_f32_hardware` and `_warp`. It has a 60 s timeout, skip code 77 and its own `FORM_COVERAGE_RECORD`. The LLVM 15 round trip covers the programs, and a binary check confirms the encodings above. - **Programs:** every row is its own program, because the source must be static. There are ten groups: - literal sources - SGPR sources - VGPR sources - literal and register modifier forms - **Rows:** ±0, ±1, the largest normal value (`0x7f7fffff`), the smallest normal value with its negative, ±infinity and `0x3f800001` (the last fraction bit set). Both words are exported through the uint target with per-row xor masks, so the comparison stays bit-exact, and the sentinels in `v12`/`v15` must stay unchanged. - **Wrong references:** each of these must report `pixel_mismatch`: - swapped words - the lost sign of -0 - infinity exported as NaN - the exponent bias off by one - a swapped modifier order - **Refusal controls:** subnormals (`0x00000001`, `0x807fffff`), NaNs (`0x7fc00000`, `0x7f800001`), an unproven loaded VGPR, `clamp`, `omod` and an invalid pair. - **Mutations:** each of these mutations of the lowering turns the checks red: swapped words, a dropped sign of -0, the exponent bias +1, a swapped modifier order. - **Against main:** with `main`'s `tools/pixel_aot.py` the mode fails with `ValueError: Unsupported instruction 22: v_cvt_f64_f32_e32 v[13:14], 0`. Environment: commit `88dd9484`, rebased on `92bd3362`. NVIDIA GeForce RTX 3080 (driver 32.0.16.2124), WARP 10.0.26100.9818, Windows 11 build 26200, debug layer unavailable. ```powershell ctest --preset dev --no-tests=error -R '^pixel_aot_cvt_f64_' -V # 4/4 passed, none skipped ctest --preset dev --no-tests=error # 901/901 passed; 25 capability skips, none from this change ``` The pure checks pass, and so does the LLVM 15.0.7 binary round trip. On this machine the hardware test takes about 21–24 s under `-j4`, with about 60 DXC compiles. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The f32 widening follow-up to #1363 agreed in #1325. The source must be
statically known (literal, binary32 inline constant, tracked SGPR or a
VGPR with known bits), so both binary64 words are computed at
translation time. Normal values, signed zero and infinities convert
exactly; subnormals, NaNs and unproven inputs are refused. The e64
spellings LLVM 15 prints (-x, |x|, -|x|, neg(literal)) apply abs, then
neg, with a signed-zero control that distinguishes the order.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:07:45 +00:00
github manually merged commit 88dd948445 into gh-pr/1446/base 2026-11-26 23:07:46 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.