shader: lower v_cvt_f64_i32 and v_cvt_f64_u32 in pixel_aot #1356

Merged
JB2WIN merged 2 commits from upstream-pr/1363 into main 2026-11-24 10:14:56 +00:00
JB2WIN commented 2026-11-24 09:22:01 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-24T09:22:01Z.


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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6578592694 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1363). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-24T09:22:01Z. --- 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)
tedin7 commented 2026-11-24 10:02:31 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T09:28:44Z.

Review: COMMENTED


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).
<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6036695798 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1363#pullrequestreview-6036695798). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T09:28:44Z. **Review:** COMMENTED --- 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`).
upstream-sync closed this pull request 2026-11-24 11:02:37 +00:00
R0Y00 commented 2026-11-24 11:02:59 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T10:13:47Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7128491660 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1363#issuecomment-7128491660). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T10:13:47Z. --- 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.
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!1356
No description provided.