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

Merged
JB2WIN merged 1 commit from upstream-pr/1446 into main 2026-11-24 11:58:06 +00:00
JB2WIN commented 2026-11-24 11:39:37 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-24T11:39:37Z.


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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6580926869 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1446). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-24T11:39:37Z. --- 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)
upstream-sync closed this pull request 2026-11-24 12:03:05 +00:00
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!1439
No description provided.