shader: lower v_cvt_i32_f64 and v_cvt_u32_f64 on proven pairs in pixel_aot #1568

Merged
JB2WIN merged 1 commit from upstream-pr/1575 into main 2026-11-24 14:48:49 +00:00
JB2WIN commented 2026-11-24 14:31:39 +00:00 (Migrated from github.com)

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


Fixes #1492

Change

tools/pixel_aot.py now lowers v_cvt_i32_f64 and v_cvt_u32_f64, but only when it can prove where the binary64 pair came from. This is the restricted slice agreed in #1492, and no HLSL double is emitted.

Provenance tracking. lower() gains a f64_words map from each word's SSA name to (record, 0|1), which says which pair the word belongs to and whether it is the low or the high word.

  • Where it is set: v_cvt_f64_i32 and v_cvt_f64_u32 record ("i32"|"u32", <uint source>). v_cvt_f64_f32 of a static source records ("static", low, high).
  • Copies: v_mov_b32 carries the entry to its new SSA value, including copies of copies.
  • Overwrites: every VGPR value is an immutable temporary, so overwriting a word drops its entry.
  • Joins: close_region (one-armed and if/else masked regions) keeps an entry only when every path carries the same record and role. The conversions themselves stay refused inside a masked region.

What is accepted. Both words must carry the same record, with the low word as word 0 and the high word as word 1.

  • A v_cvt_f64_i32 pair read by v_cvt_i32_f64, and a v_cvt_f64_u32 pair read by v_cvt_u32_f64, return the original source word. Every 32-bit integer is exact in binary64.
  • A statically known v_cvt_f64_f32 value is truncated toward zero at translation time with math.trunc. It is accepted only if it is finite and the result fits the destination.

What is refused:

  • cross-signedness (an i32 pair converted to u32, or a u32 pair converted to i32)
  • NaN, infinity and out-of-range static values (2^31 converted to i32; -1.0 and 2^32 converted to u32)
  • pairs of unknown provenance (raw constants, runtime registers)
  • a pair with only one word overwritten
  • divergent joins
  • _e64 and every modifier (clamp, omod, neg, abs)

LLVM 15 prints the unmodified form as _e32 (v_cvt_i32_f64_e32 v13, v[20:21] = 14071a7e, v_cvt_u32_f64_e32 = 142b1c7e). DPP and SDWA do not assemble for these opcodes.

Changed controls. check_cvt_f64_int_lowering and check_cvt_f64_f32_lowering used to list v_cvt_i32_f64 of an i32 pair and both out-conversions of a 1.0 pair as refused consumers. This slice supports those cases, so they move out of the reject tuples and into the new mode as positive checks, like the comparison control in #1363. The cross case v_cvt_u32_f64 of an i32 pair stays refused there, as do v_cvt_f32_f64, binary64 arithmetic and the other consumers.

Test

New mode draw-cvt-int-f64, registered as pixel_aot_cvt_int_f64_hardware and _warp. It has a 60 s timeout, skip code 77 and its own FORM_COVERAGE_RECORD, and the LLVM 15 round trip covers its programs.

  • Round trips: the #1363 rows (0, INT_MIN, INT_MAX, -1, UINT_MAX, 0x7fffffff, around 2^24). They are checked both directly and through a copy of the pair into another pair.

  • Static truncation: ±1.5, ±0.75, -0.0, and the largest values below 2^31 and 2^32.

  • Export: values go out through the uint readback with xor masks, and each result is compared bit for bit against an independent reference.

  • Refusals: the lowering controls check every refusal listed above, including one-word clobbers on each half and joins with different sources, signedness or words. Joins with equal provenance are accepted.

  • Wrong references: swapped signedness, rounding instead of truncation at ±1.5, and a swapped word each have to report pixel_mismatch.

  • Mutations: each of these makes the checks fail:

    • not checking the high word's provenance, so a clobber goes unnoticed
    • allowing the cross case
    • using round instead of math.trunc

    With main's tools/pixel_aot.py the mode fails with ValueError: Unsupported instruction 23: v_cvt_i32_f64 v13, v[16:17].

The semantics come from LLVM 15 VOP1Instructions.td. They are not checked against the ISA document and not measured on a console.

Run on commit f90f1c3c, rebased on 800a4500, 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_(int_f64|f64_)' -V   # 6/6 passed, none skipped
ctest --preset dev --no-tests=error                                       # 996/996 passed; 25 capability skips, none from this change

The pure checks and the LLVM 15.0.7 binary round trip also pass.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6584128826 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1575). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-24T14:31:39Z. --- Fixes #1492 ## Change `tools/pixel_aot.py` now lowers `v_cvt_i32_f64` and `v_cvt_u32_f64`, but only when it can prove where the binary64 pair came from. This is the restricted slice agreed in #1492, and no HLSL `double` is emitted. **Provenance tracking.** `lower()` gains a `f64_words` map from each word's SSA name to `(record, 0|1)`, which says which pair the word belongs to and whether it is the low or the high word. - **Where it is set:** `v_cvt_f64_i32` and `v_cvt_f64_u32` record `("i32"|"u32", <uint source>)`. `v_cvt_f64_f32` of a static source records `("static", low, high)`. - **Copies:** `v_mov_b32` carries the entry to its new SSA value, including copies of copies. - **Overwrites:** every VGPR value is an immutable temporary, so overwriting a word drops its entry. - **Joins:** `close_region` (one-armed and if/else masked regions) keeps an entry only when every path carries the same record and role. The conversions themselves stay refused inside a masked region. **What is accepted.** Both words must carry the same record, with the low word as word 0 and the high word as word 1. - A `v_cvt_f64_i32` pair read by `v_cvt_i32_f64`, and a `v_cvt_f64_u32` pair read by `v_cvt_u32_f64`, return the original source word. Every 32-bit integer is exact in binary64. - A statically known `v_cvt_f64_f32` value is truncated toward zero at translation time with `math.trunc`. It is accepted only if it is finite and the result fits the destination. **What is refused:** - cross-signedness (an i32 pair converted to u32, or a u32 pair converted to i32) - NaN, infinity and out-of-range static values (2^31 converted to i32; -1.0 and 2^32 converted to u32) - pairs of unknown provenance (raw constants, runtime registers) - a pair with only one word overwritten - divergent joins - `_e64` and every modifier (`clamp`, `omod`, `neg`, `abs`) LLVM 15 prints the unmodified form as `_e32` (`v_cvt_i32_f64_e32 v13, v[20:21]` = `14071a7e`, `v_cvt_u32_f64_e32` = `142b1c7e`). DPP and SDWA do not assemble for these opcodes. **Changed controls.** `check_cvt_f64_int_lowering` and `check_cvt_f64_f32_lowering` used to list `v_cvt_i32_f64` of an i32 pair and both out-conversions of a 1.0 pair as refused consumers. This slice supports those cases, so they move out of the reject tuples and into the new mode as positive checks, like the comparison control in #1363. The cross case `v_cvt_u32_f64` of an i32 pair stays refused there, as do `v_cvt_f32_f64`, binary64 arithmetic and the other consumers. ## Test New mode `draw-cvt-int-f64`, registered as `pixel_aot_cvt_int_f64_hardware` and `_warp`. It has a 60 s timeout, skip code 77 and its own `FORM_COVERAGE_RECORD`, and the LLVM 15 round trip covers its programs. - **Round trips:** the #1363 rows (0, `INT_MIN`, `INT_MAX`, -1, `UINT_MAX`, `0x7fffffff`, around 2^24). They are checked both directly and through a copy of the pair into another pair. - **Static truncation:** ±1.5, ±0.75, -0.0, and the largest values below 2^31 and 2^32. - **Export:** values go out through the uint readback with xor masks, and each result is compared bit for bit against an independent reference. - **Refusals:** the lowering controls check every refusal listed above, including one-word clobbers on each half and joins with different sources, signedness or words. Joins with equal provenance are accepted. - **Wrong references:** swapped signedness, rounding instead of truncation at ±1.5, and a swapped word each have to report `pixel_mismatch`. - **Mutations:** each of these makes the checks fail: - not checking the high word's provenance, so a clobber goes unnoticed - allowing the cross case - using `round` instead of `math.trunc` With `main`'s `tools/pixel_aot.py` the mode fails with `ValueError: Unsupported instruction 23: v_cvt_i32_f64 v13, v[16:17]`. The semantics come from LLVM 15 `VOP1Instructions.td`. They are not checked against the ISA document and not measured on a console. Run on commit `f90f1c3c`, rebased on `800a4500`, 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_(int_f64|f64_)' -V # 6/6 passed, none skipped ctest --preset dev --no-tests=error # 996/996 passed; 25 capability skips, none from this change ``` The pure checks and the LLVM 15.0.7 binary round trip also pass. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-24 15:02:06 +00:00
tedin7 commented 2026-11-24 15:02:07 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T14:37:58Z.

Review: COMMENTED


Looks good overall. Reviewed the provenance-restricted v_cvt_i32_f64 / v_cvt_u32_f64 lowering in tools/pixel_aot.py and the tests in tests/pixel_aot_check.py at f90f1c3cfe97de6067715b04e286e5c3ff57c399.

Semantic & Edge-Case Review

  • Provenance tracking (f64_words): v_cvt_f64_i32 / v_cvt_f64_u32 and static v_cvt_f64_f32 tag both destination words with (record, 0) and (record, 1). v_mov_b32 preserves provenance when copying a VGPR, while any other write assigns a fresh alu* name not in f64_words, invalidating partial overwrites.
  • Safety & edge cases:
    • Cross-signedness (i32 <-> u32), swapped/clobbered words, divergent joins, raw constants, _e64 spellings/modifiers (clamp, -v, |v|, mul:2), DPP/SDWA, masked execution, and pending/overlapping sample registers are all refused.
    • Static v_cvt_f64_f32 sources check math.isfinite(value), truncate toward zero (math.trunc(value)), and verify exact range ([-0x80000000, 0x7fffffff] for i32, [0, 0xffffffff] for u32), emitting {result & 0xffffffff}u without HLSL double.
  • Negative & binary coverage: check_cvt_int_f64_lowering(), check_cvt_int_f64_binary(), and check_cvt_int_f64_draws() cover round-trips, static truncations (including -0.75, -0.0, ±1.5, 2^31, INT_MIN), signedness/rounding/word/slot/sentinel mismatches, and LLVM encoding/disassembly round-trips.

Verification

  • Linux (LLVM 19):
    • python3 -B tests/pixel_aot_check.py — passed.
    • check_cvt_int_f64_binary with llvm-mc-19, llvm-objcopy-19, libLLVM-19.so — passed.
    • python3 -B tests/docs_links_check.py and python3 -B tests/bidi_controls_check.py — passed.
  • Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP):
    • Debug (--preset dev): offscreen_check built (3.96s), ctest --preset dev -R '^pixel_aot_cvt_int_f64_' 2/2 passed (4.95s).
    • Release /O2 (--preset release): offscreen_check built (1.45s), ctest --preset release -R '^pixel_aot_cvt_int_f64_' 2/2 passed (4.65s).
    • tests/pixel_aot_check.py — passed (13.5s).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6041245017 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1575#pullrequestreview-6041245017). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T14:37:58Z. **Review:** COMMENTED --- Looks good overall. Reviewed the provenance-restricted `v_cvt_i32_f64` / `v_cvt_u32_f64` lowering in `tools/pixel_aot.py` and the tests in `tests/pixel_aot_check.py` at `f90f1c3cfe97de6067715b04e286e5c3ff57c399`. ### Semantic & Edge-Case Review - **Provenance tracking (`f64_words`)**: `v_cvt_f64_i32` / `v_cvt_f64_u32` and static `v_cvt_f64_f32` tag both destination words with `(record, 0)` and `(record, 1)`. `v_mov_b32` preserves provenance when copying a VGPR, while any other write assigns a fresh `alu*` name not in `f64_words`, invalidating partial overwrites. - **Safety & edge cases**: - Cross-signedness (`i32 <-> u32`), swapped/clobbered words, divergent joins, raw constants, `_e64` spellings/modifiers (`clamp`, `-v`, `|v|`, `mul:2`), DPP/SDWA, masked execution, and pending/overlapping sample registers are all refused. - Static `v_cvt_f64_f32` sources check `math.isfinite(value)`, truncate toward zero (`math.trunc(value)`), and verify exact range (`[-0x80000000, 0x7fffffff]` for `i32`, `[0, 0xffffffff]` for `u32`), emitting `{result & 0xffffffff}u` without HLSL `double`. - **Negative & binary coverage**: `check_cvt_int_f64_lowering()`, `check_cvt_int_f64_binary()`, and `check_cvt_int_f64_draws()` cover round-trips, static truncations (including `-0.75`, `-0.0`, `±1.5`, `2^31`, `INT_MIN`), signedness/rounding/word/slot/sentinel mismatches, and LLVM encoding/disassembly round-trips. ### Verification - **Linux (LLVM 19)**: - `python3 -B tests/pixel_aot_check.py` — passed. - `check_cvt_int_f64_binary` with `llvm-mc-19`, `llvm-objcopy-19`, `libLLVM-19.so` — passed. - `python3 -B tests/docs_links_check.py` and `python3 -B tests/bidi_controls_check.py` — passed. - **Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP)**: - Debug (`--preset dev`): `offscreen_check` built (`3.96s`), `ctest --preset dev -R '^pixel_aot_cvt_int_f64_'` **2/2 passed** (`4.95s`). - Release `/O2` (`--preset release`): `offscreen_check` built (`1.45s`), `ctest --preset release -R '^pixel_aot_cvt_int_f64_'` **2/2 passed** (`4.65s`). - `tests/pixel_aot_check.py` — passed (`13.5s`). 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!1568
No description provided.