shader: lower v_cvt_f64_i32 and v_cvt_f64_u32 in pixel_aot #1363

Manually merged
github merged 2 commits from gh-pr/1363/head into gh-pr/1363/base 2026-11-26 23:01:18 +00:00
Owner

@⁠JB2WIN on GitHub · 2026-11-24 09:22 UTC · original
JB2WIN:shader/cvt-f64-int → main · +225 −1 · 5 files · 2 commits · merged 2026-11-24 10:14 UTC

Refs #1325

Change

This is the first binary64 slice agreed in #1325. tools/pixel_aot.py lowers the exact 32-bit integer to binary64 conversions v_cvt_f64_i32 and v_cvt_f64_u32 into a VGPR pair v[d:d+1].

  • Construction: Every 32-bit integer is representable, so no rounding is involved. The two words are built from uint operations: the sign, the exponent 1023 + firstbithigh, and the bits below the leading one shifted to the top of the 52-bit fraction. No HLSL double is emitted, so the shader needs no double-precision capability and no capability skip applies. Zero gives +0.0 (both words 0), and INT_MIN gives 0xc1e00000_00000000.
  • Accepted spellings: only the unmodified VOP1 forms, plain and _e32 (LLVM 15 prints _e32 and accepts both).
  • Refused: _e64 (also without modifiers, which is narrower than necessary), clamp, omod, source modifiers, DPP, SDWA, a destination that is not a two-register VGPR range or goes above v255, and use inside a masked region.
  • Readers of the pair: later readers see two ordinary 32-bit registers. No binary64 consumer is lowered, so v_add_f64, v_mul_f64, v_cvt_*_f64, v_cmp_*_f64 and the rest stay unsupported. Arithmetic, conversions out of binary64 and v_cvt_f64_f32 are left out, as agreed.
  • Semantics source: LLVM 15 VOP1Instructions.td at llvmorg-15.0.7. Not checked against the ISA document and not measured on a console. LLVM 15 assembles unaligned pairs, so they are accepted; hardware legality is assumed, not measured.

Test

  • Mode and registration: new mode draw-cvt-f64-int, registered as pixel_aot_cvt_f64_int_hardware and pixel_aot_cvt_f64_int_warp, with a 60 s timeout, skip code 77 and its own FORM_COVERAGE_RECORD. The LLVM 15 round trip covers the programs.

  • Programs: four of them, i32_sgpr, u32_sgpr, i32_vgpr and u32_vgpr. Each writes v[13:14] and keeps distinct sentinels in v12 and v15.

  • Reference: independent of the lowering, Python struct.pack('<d', float(x)).

  • Rows: 0, INT_MIN, INT_MAX, -1, UINT_MAX, UINT_MAX - 1 and 0x7fffffff. Also 2^24 - 1, 2^24 and 2^24 + 1 with their negative counterparts, and the integer patterns 0x3f800000 and 0xbf800000.

  • Export: both words go through the R32G32B32A32_UINT target, each xor-ed with a per-row mask taken from the constants. The xor is a bijection, so the comparison stays bit for bit, and it keeps every exported word a normal binary32 or zero, which the test asserts. For example, the low word of UINT_MAX is 0xffe00000, a NaN pattern.

  • Wrong references, each of which must report pixel_mismatch:

    • swapped low and high words
    • swapped signedness
    • each sentinel replaced by a pair word
    • the exponent off by one
    • one flipped mantissa bit

    The test asserts that each kind is drawn.

Mutating the lowering (swapped words, swapped signedness, a mantissa bit, the exponent) turns draw-cvt-f64-int red each time. Against main's tools/pixel_aot.py, the mode fails with ValueError: Unsupported instruction 22: v_cvt_f64_i32_e32 v[13:14], s44.

On commit 597f1710 (rebased on 623e2112), with an NVIDIA GeForce RTX 3080 (driver 32.0.16.2124), WARP 10.0.26100.9818 and Windows 11 build 26200, debug layer unavailable:

ctest --preset dev --no-tests=error -R '^pixel_aot_(cvt_f64_int|mad64)_' -V   # 4/4 passed, none skipped
ctest --preset dev --no-tests=error                                          # 845/845 passed; 25 capability skips, none from this change

The pure checks pass (pixel_aot_check.py controls, form_coverage_check.py, rdna2_tools_check.py, pso_readiness_check.py, docs_links_check.py), and so does the LLVM 15.0.7 binary round trip.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

**@⁠JB2WIN** on GitHub · 2026-11-24 09:22 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1363) `JB2WIN:shader/cvt-f64-int` → `main` · +225 −1 · 5 files · 2 commits · merged 2026-11-24 10:14 UTC Refs #1325 ## Change This is the first binary64 slice agreed in #1325. `tools/pixel_aot.py` lowers the exact 32-bit integer to binary64 conversions `v_cvt_f64_i32` and `v_cvt_f64_u32` into a VGPR pair `v[d:d+1]`. - **Construction:** Every 32-bit integer is representable, so no rounding is involved. The two words are built from `uint` operations: the sign, the exponent `1023 + firstbithigh`, and the bits below the leading one shifted to the top of the 52-bit fraction. No HLSL `double` is emitted, so the shader needs no double-precision capability and no capability skip applies. Zero gives `+0.0` (both words 0), and `INT_MIN` gives `0xc1e00000_00000000`. - **Accepted spellings:** only the unmodified VOP1 forms, plain and `_e32` (LLVM 15 prints `_e32` and accepts both). - **Refused:** `_e64` (also without modifiers, which is narrower than necessary), `clamp`, `omod`, source modifiers, DPP, SDWA, a destination that is not a two-register VGPR range or goes above v255, and use inside a masked region. - **Readers of the pair:** later readers see two ordinary 32-bit registers. No binary64 consumer is lowered, so `v_add_f64`, `v_mul_f64`, `v_cvt_*_f64`, `v_cmp_*_f64` and the rest stay unsupported. Arithmetic, conversions out of binary64 and `v_cvt_f64_f32` are left out, as agreed. - **Semantics source:** LLVM 15 `VOP1Instructions.td` at `llvmorg-15.0.7`. Not checked against the ISA document and not measured on a console. LLVM 15 assembles unaligned pairs, so they are accepted; hardware legality is assumed, not measured. ## Test - **Mode and registration:** new mode `draw-cvt-f64-int`, registered as `pixel_aot_cvt_f64_int_hardware` and `pixel_aot_cvt_f64_int_warp`, with a 60 s timeout, skip code 77 and its own `FORM_COVERAGE_RECORD`. The LLVM 15 round trip covers the programs. - **Programs:** four of them, `i32_sgpr`, `u32_sgpr`, `i32_vgpr` and `u32_vgpr`. Each writes `v[13:14]` and keeps distinct sentinels in `v12` and `v15`. - **Reference:** independent of the lowering, Python `struct.pack('<d', float(x))`. - **Rows:** 0, `INT_MIN`, `INT_MAX`, -1, `UINT_MAX`, `UINT_MAX - 1` and `0x7fffffff`. Also 2^24 - 1, 2^24 and 2^24 + 1 with their negative counterparts, and the integer patterns `0x3f800000` and `0xbf800000`. - **Export:** both words go through the `R32G32B32A32_UINT` target, each xor-ed with a per-row mask taken from the constants. The xor is a bijection, so the comparison stays bit for bit, and it keeps every exported word a normal binary32 or zero, which the test asserts. For example, the low word of `UINT_MAX` is `0xffe00000`, a NaN pattern. - **Wrong references, each of which must report `pixel_mismatch`:** - swapped low and high words - swapped signedness - each sentinel replaced by a pair word - the exponent off by one - one flipped mantissa bit The test asserts that each kind is drawn. Mutating the lowering (swapped words, swapped signedness, a mantissa bit, the exponent) turns `draw-cvt-f64-int` red each time. Against `main`'s `tools/pixel_aot.py`, the mode fails with `ValueError: Unsupported instruction 22: v_cvt_f64_i32_e32 v[13:14], s44`. On commit `597f1710` (rebased on `623e2112`), with an NVIDIA GeForce RTX 3080 (driver 32.0.16.2124), WARP 10.0.26100.9818 and Windows 11 build 26200, debug layer unavailable: ```powershell ctest --preset dev --no-tests=error -R '^pixel_aot_(cvt_f64_int|mad64)_' -V # 4/4 passed, none skipped ctest --preset dev --no-tests=error # 845/845 passed; 25 capability skips, none from this change ``` The pure checks pass (`pixel_aot_check.py controls`, `form_coverage_check.py`, `rdna2_tools_check.py`, `pso_readiness_check.py`, `docs_links_check.py`), and so does the LLVM 15.0.7 binary round trip. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The first binary64 slice agreed in #1325: the exact 32-bit integer to
binary64 conversions into a VGPR pair, built from uint operations with
no HLSL double. New mode draw-cvt-f64-int compares both words against a
struct.pack bit reference, with adjacent-register sentinels and
swapped-word, signedness, exponent and mantissa negative controls.
Every binary64 consumer stays refused.

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:01:16 +00:00
github manually merged commit 844cc9ecc1 into gh-pr/1363/base 2026-11-26 23:01:18 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-24 10:13 UTC · original

I integrated this with #1349 in 844cc9ec. The conversion can now feed an existing binary64 comparison, so the old rejection control has become a positive lowering check. Arithmetic and reverse conversions are still rejected. Conversion and comparison readbacks both passed on RTX 4060 Laptop and WARP, along with form coverage and the lowering controls. GitHub is checking the combined head.

**@⁠R0Y00** on GitHub · 2026-11-24 10:13 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1363#issuecomment-7128491660) I integrated this with #1349 in 844cc9ec. The conversion can now feed an existing binary64 comparison, so the old rejection control has become a positive lowering check. Arithmetic and reverse conversions are still rejected. Conversion and comparison readbacks both passed on RTX 4060 Laptop and WARP, along with form coverage and the lowering controls. GitHub is checking the combined head.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 09:28 UTC · original · reviewed

Technical peer review at commit 597f17106ff3a60d6b325f16354a71740876a5fc (LGTM, no blocking findings):

Code audit:

  • tools/pixel_aot.py: v_cvt_f64_(i32|u32)(?:_e32)? lowers exact 32-bit signed/unsigned integer to binary64 into an adjacent VGPR pair v[d:d+1] (last == first + 1, last <= 255, mask == "entry", neither register in sample_dest). Constructs both binary64 words from uint operations (firstbithigh, 0u - c{i}x for signed negation, 0 -> +0.0) without emitting HLSL double, reads src before writing the destination pair, and leaves _e64, modifiers, DPP/SDWA, masked regions, and binary64 consumers rejected.
  • tests/pixel_aot_check.py, tests/form_coverage_check.py, CMakeLists.txt, docs/experiments.md: adds check_cvt_f64_int_lowering(), draw-cvt-f64-int (pixel_aot_cvt_f64_int_hardware and pixel_aot_cvt_f64_int_warp) with FORM_COVERAGE_RECORD, and non-vacuous negative controls (swapped words, swapped signedness, sentinel overwrite, exponent +1, flipped mantissa bit).

Checks:

  • Linux: docs_links_check.py (16 Markdown files, 301 links), bidi_controls_check.py (1145 files), pixel_aot_check.py, rdna2_tools_check.py (138 tests, 18 skipped), and form_coverage_check.py all passed; git diff --check clean.
  • Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP):
    • Debug (--preset dev, offscreen_check): pixel_aot_cvt_f64_int_hardware (2.97s) + pixel_aot_cvt_f64_int_warp (2.98s) — 2/2 passed (3.05s).
    • Release /O2 (--preset release, offscreen_check): pixel_aot_cvt_f64_int_hardware (2.74s) + pixel_aot_cvt_f64_int_warp (2.77s) — 2/2 passed (2.85s).
    • Windows Python checks: tests/form_coverage_check.py passed (40.53s).
**@⁠tedin7** on GitHub · 2026-11-24 09:28 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1363#pullrequestreview-6036695798) · **reviewed** Technical peer review at commit `597f17106ff3a60d6b325f16354a71740876a5fc` (LGTM, no blocking findings): **Code audit:** - `tools/pixel_aot.py`: `v_cvt_f64_(i32|u32)(?:_e32)?` lowers exact 32-bit signed/unsigned integer to binary64 into an adjacent VGPR pair `v[d:d+1]` (`last == first + 1`, `last <= 255`, `mask == "entry"`, neither register in `sample_dest`). Constructs both binary64 words from `uint` operations (`firstbithigh`, `0u - c{i}x` for signed negation, `0` -> `+0.0`) without emitting HLSL `double`, reads `src` before writing the destination pair, and leaves `_e64`, modifiers, DPP/SDWA, masked regions, and binary64 consumers rejected. - `tests/pixel_aot_check.py`, `tests/form_coverage_check.py`, `CMakeLists.txt`, `docs/experiments.md`: adds `check_cvt_f64_int_lowering()`, `draw-cvt-f64-int` (`pixel_aot_cvt_f64_int_hardware` and `pixel_aot_cvt_f64_int_warp`) with `FORM_COVERAGE_RECORD`, and non-vacuous negative controls (swapped words, swapped signedness, sentinel overwrite, exponent +1, flipped mantissa bit). **Checks:** - **Linux**: `docs_links_check.py` (16 Markdown files, 301 links), `bidi_controls_check.py` (1145 files), `pixel_aot_check.py`, `rdna2_tools_check.py` (138 tests, 18 skipped), and `form_coverage_check.py` all passed; `git diff --check` clean. - **Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP)**: - Debug (`--preset dev`, `offscreen_check`): `pixel_aot_cvt_f64_int_hardware` (`2.97s`) + `pixel_aot_cvt_f64_int_warp` (`2.98s`) — **2/2 passed** (`3.05s`). - Release `/O2` (`--preset release`, `offscreen_check`): `pixel_aot_cvt_f64_int_hardware` (`2.74s`) + `pixel_aot_cvt_f64_int_warp` (`2.77s`) — **2/2 passed** (`2.85s`). - Windows Python checks: `tests/form_coverage_check.py` passed (`40.53s`).
This discussion has been locked. Commenting is limited to contributors.
No description provided.