shader: lower v_cvt_f64_f32 in direct compute path #3369

Merged
R0D4X merged 2 commits from upstream-pr/3369 into main 2026-11-29 10:32:11 +00:00
R0D4X commented 2026-11-28 14:49:40 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0D4X on 2026-11-28T14:49:40Z.


Fixes #3368. Refs #2935.

Summary

  • Lower VOP1/VOP3A v_cvt_f64_f32 (0x10 / 0x190) in the native direct-DXIL compute path (src/gfx1013_direct_compute.inl):
    • Constructs the exact IEEE-754 binary64 word pair v[d:d+1] from a binary32 source using pure 32-bit integer arithmetic and dx.op.unaryBits.i32(33) (FirstbitHi), requiring neither DoublePrecisionFloatShaderOps nor Int64ShaderOps.
    • Handles normals, binary32 subnormals (normalized to exact binary64 normals), signed zero (±0.0), ±Inf, and sNaN/qNaN quieting (| 0x00400000 with payload preserved).
    • Supports VOP1 and VOP3A encodings with VGPR, SGPR, inline-float (240..248), and 32-bit literal sources, VOP3A abs/neg, and overlapping D[0] == S0; refuses pixel_stage, graphics_input, clamp, omod, op_sel, subword, dpp, unused VOP3 sources/modifiers, and dst == v255.
  • Register v_cvt_f64_f32 as a 64-bit VGPR pair write in clear_vector_spills (src/gfx1013_compute_native.cpp).
  • Add tests/native_cvt_f64_f32_check.py (ir CPU evaluation + controls + hardware), tests/cmake/native_f64_f32_cvt.cmake, and docs/experiments/native-cvt-f64-f32.md.

Verification

  • Commit: dbf57ab0
  • Environment: Windows 11 x64 (10.0.26300.9974), MSVC 19.44.35230, Windows SDK / DXC 10.0.26100.0, NVIDIA GeForce RTX 5080 (10de:2c02, driver 32.0.16.2140), D3D12 debug layer off.
  • Commands & results:
    • cmake --build --preset dev --target native_compute_ir_dump compile_dxil native_store_replay & release: succeeded.
    • ctest --preset dev --no-tests=error -R '^native_cvt_f64_f32_' -V: 3/3 passed (0 skipped); 32 CPU-evaluated IR words + 7 refusals + 2064 hardware readback words matched.
    • ctest --preset release --no-tests=error -R '^native_cvt_f64_f32_' -V: 3/3 passed (0 skipped); all 2064 hardware words matched.
    • tests/docs_links_check.py, tests/bidi_controls_check.py, git diff --check: passed.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5541325758 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3369). Originally posted by [R0D4X](https://github.com/R0D4X) on 2026-11-28T14:49:40Z. --- Fixes #3368. Refs #2935. ### Summary - Lower VOP1/VOP3A `v_cvt_f64_f32` (`0x10` / `0x190`) in the native direct-DXIL compute path (`src/gfx1013_direct_compute.inl`): - Constructs the exact IEEE-754 binary64 word pair `v[d:d+1]` from a binary32 source using pure 32-bit integer arithmetic and `dx.op.unaryBits.i32(33)` (`FirstbitHi`), requiring neither `DoublePrecisionFloatShaderOps` nor `Int64ShaderOps`. - Handles normals, binary32 subnormals (normalized to exact binary64 normals), signed zero (`±0.0`), `±Inf`, and `sNaN`/`qNaN` quieting (`| 0x00400000` with payload preserved). - Supports VOP1 and VOP3A encodings with VGPR, SGPR, inline-float (`240..248`), and 32-bit literal sources, VOP3A `abs`/`neg`, and overlapping `D[0] == S0`; refuses `pixel_stage`, `graphics_input`, `clamp`, `omod`, `op_sel`, `subword`, `dpp`, unused VOP3 sources/modifiers, and `dst == v255`. - Register `v_cvt_f64_f32` as a 64-bit VGPR pair write in `clear_vector_spills` (`src/gfx1013_compute_native.cpp`). - Add `tests/native_cvt_f64_f32_check.py` (`ir` CPU evaluation + `controls` + `hardware`), `tests/cmake/native_f64_f32_cvt.cmake`, and `docs/experiments/native-cvt-f64-f32.md`. ### Verification - Commit: `dbf57ab0` - Environment: Windows 11 x64 (`10.0.26300.9974`), MSVC `19.44.35230`, Windows SDK / DXC `10.0.26100.0`, NVIDIA GeForce RTX 5080 (`10de:2c02`, driver `32.0.16.2140`), D3D12 debug layer off. - Commands & results: - `cmake --build --preset dev --target native_compute_ir_dump compile_dxil native_store_replay` & `release`: succeeded. - `ctest --preset dev --no-tests=error -R '^native_cvt_f64_f32_' -V`: 3/3 passed (0 skipped); 32 CPU-evaluated IR words + 7 refusals + 2064 hardware readback words matched. - `ctest --preset release --no-tests=error -R '^native_cvt_f64_f32_' -V`: 3/3 passed (0 skipped); all 2064 hardware words matched. - `tests/docs_links_check.py`, `tests/bidi_controls_check.py`, `git diff --check`: passed.
KelboLive commented 2026-11-28 20:46:29 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-28T20:46:29Z.

Review: APPROVED


LGTM — exact IEEE-754 binary32->binary64 widening using pure 32-bit integer ops and FirstbitHi.

Covers normals, subnormals (normalized to exact binary64 normals), signed zero, ±Inf, and sNaN/qNaN quieting. No DoublePrecisionFloatShaderOps or Int64ShaderOps needed. The IR dump, DXIL controls, and hardware tests are comprehensive (2064 words). Refusals cover clamp, omod, op_sel, unused sources, and dst==v255. The clear_vector_spills addition for the 64-bit VGPR pair is correct.

Ready to land.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6100017056 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3369#pullrequestreview-6100017056). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-11-28T20:46:29Z. **Review:** APPROVED --- LGTM — exact IEEE-754 binary32->binary64 widening using pure 32-bit integer ops and FirstbitHi. Covers normals, subnormals (normalized to exact binary64 normals), signed zero, ±Inf, and sNaN/qNaN quieting. No DoublePrecisionFloatShaderOps or Int64ShaderOps needed. The IR dump, DXIL controls, and hardware tests are comprehensive (2064 words). Refusals cover clamp, omod, op_sel, unused sources, and dst==v255. The clear_vector_spills addition for the 64-bit VGPR pair is correct. Ready to land.
KelboLive commented 2026-11-28 21:09:31 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-28T21:09:31Z.

Review: APPROVED


LGTM — clean, exact IEEE-754 widening.

Lowers VOP1/VOP3A v_cvt_f64_f32 using pure 32-bit integer arithmetic and FirstbitHi (dx.op.unaryBits.i32 33). No DoublePrecisionFloatShaderOps or Int64ShaderOps needed. Covers normals, subnormals (exact widening), signed zero, +-Inf, sNaN/qNaN quieting. Supports VGPR/SGPR/literal/inline-float/overlap sources, VOP3A abs/neg, overlapping D[0]==S0. 8 cases x 2 variants, 7 refusals, 4 negative controls.

Ready to land.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6100097713 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3369#pullrequestreview-6100097713). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-11-28T21:09:31Z. **Review:** APPROVED --- LGTM — clean, exact IEEE-754 widening. Lowers VOP1/VOP3A v_cvt_f64_f32 using pure 32-bit integer arithmetic and FirstbitHi (dx.op.unaryBits.i32 33). No DoublePrecisionFloatShaderOps or Int64ShaderOps needed. Covers normals, subnormals (exact widening), signed zero, +-Inf, sNaN/qNaN quieting. Supports VGPR/SGPR/literal/inline-float/overlap sources, VOP3A abs/neg, overlapping D[0]==S0. 8 cases x 2 variants, 7 refusals, 4 negative controls. Ready to land.
KelboLive commented 2026-11-28 21:57:25 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-28T21:57:25Z.

Review: APPROVED


LGTM — clean, exact IEEE-754 widening.

Lowers VOP1/VOP3A v_cvt_f64_f32 using pure 32-bit integer arithmetic and FirstbitHi (dx.op.unaryBits.i32 33). No DoublePrecisionFloatShaderOps or Int64ShaderOps needed. Covers normals, subnormals (exact widening), signed zero, +-Inf, sNaN/qNaN quieting. Supports VGPR/SGPR/literal/inline-float/overlap sources, VOP3A abs/neg, overlapping D[0]==S0. 8 cases x 2 variants, 7 refusals, 4 negative controls.

Ready to land.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6100253991 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3369#pullrequestreview-6100253991). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-11-28T21:57:25Z. **Review:** APPROVED --- LGTM — clean, exact IEEE-754 widening. Lowers VOP1/VOP3A v_cvt_f64_f32 using pure 32-bit integer arithmetic and FirstbitHi (dx.op.unaryBits.i32 33). No DoublePrecisionFloatShaderOps or Int64ShaderOps needed. Covers normals, subnormals (exact widening), signed zero, +-Inf, sNaN/qNaN quieting. Supports VGPR/SGPR/literal/inline-float/overlap sources, VOP3A abs/neg, overlapping D[0]==S0. 8 cases x 2 variants, 7 refusals, 4 negative controls. Ready to land.
Leyukaka commented 2026-11-29 04:45:00 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-29T04:45:00Z.

Review: COMMENTED


Commenting on head dbf57ab0. Diff read against main 212d4b5f; nothing built or run.

Needs a rebase, no code change requested: git merge-tree --write-tree origin/main dbf57ab0 conflicts in src/gfx1013_compute_native.cpp, because #3367 added v_cvt_f64_i32/v_cvt_f64_u32 to the same pair list in clear_vector_spills (main lines 561-563). Keeping both sets of names resolves it. src/gfx1013_direct_compute.inl merges cleanly.

The lowering at src/gfx1013_direct_compute.inl:3103-3153 matches binary32 -> binary64 widening by reading: normal exponent + 896, subnormal exponent 905 - clz with the leading bit masked off (0x80400001 gives 0xB8000000_40000000), zero with its sign, Inf, and NaN with bit 22 set and the payload kept. f32 input denormals are kept, and that is the only mode that reaches this code: mode_bits starts at 0xf0, and consume_half_mode does not accept a write that changes the f32 denorm or round bits (main lines 4499-4545), so such a write stays refused. Only i32 ops and FirstbitHi are emitted, and _controls checks the DXIL for no double/i64. No test on main asserts a refusal of this opcode in direct compute.

Non-blocking test gaps. The inputs are 8 sampled values x 2 variants. Both Inf slots are -Inf, there is no qNaN input, and the only modifier case is -|x|. So by reading, these changes still pass:

  • inf_hi = 0xFFF00000 (sign ignored)
  • abs + neg replaced by x | 0x80000000, or neg implemented as or
  • the quiet bit set with xor instead of or
  • dropping v_cvt_f64_f32 from the clear_vector_spills pair list (the fixture has no v_writelane_b32 spill)

A +Inf input covers the first, |x| alone and -x alone on a negative input cover the second, and a qNaN input covers the third. The four "negative controls" compare the Python reference with altered flags against the unaltered reference. They show that the reference distinguishes those cases, not that the test fails on a broken lowering.

The checks pass, but none of the three new tests ran on this PR: the pr test preset's include list does not match native_cvt_f64_f32_*. On pushes to main the dev preset runs with -E '_hardware$', so only _ir and _controls are selected in CI.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6101443475 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3369#pullrequestreview-6101443475). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-29T04:45:00Z. **Review:** COMMENTED --- Commenting on head `dbf57ab0`. Diff read against `main` `212d4b5f`; nothing built or run. Needs a rebase, no code change requested: `git merge-tree --write-tree origin/main dbf57ab0` conflicts in `src/gfx1013_compute_native.cpp`, because #3367 added `v_cvt_f64_i32`/`v_cvt_f64_u32` to the same `pair` list in `clear_vector_spills` (main lines 561-563). Keeping both sets of names resolves it. `src/gfx1013_direct_compute.inl` merges cleanly. The lowering at `src/gfx1013_direct_compute.inl:3103-3153` matches binary32 -> binary64 widening by reading: normal exponent + 896, subnormal exponent 905 - clz with the leading bit masked off (0x80400001 gives 0xB8000000_40000000), zero with its sign, Inf, and NaN with bit 22 set and the payload kept. f32 input denormals are kept, and that is the only mode that reaches this code: `mode_bits` starts at 0xf0, and `consume_half_mode` does not accept a write that changes the f32 denorm or round bits (main lines 4499-4545), so such a write stays refused. Only i32 ops and FirstbitHi are emitted, and `_controls` checks the DXIL for no `double`/`i64`. No test on main asserts a refusal of this opcode in direct compute. Non-blocking test gaps. The inputs are 8 sampled values x 2 variants. Both Inf slots are -Inf, there is no qNaN input, and the only modifier case is `-|x|`. So by reading, these changes still pass: - `inf_hi = 0xFFF00000` (sign ignored) - abs + neg replaced by `x | 0x80000000`, or neg implemented as `or` - the quiet bit set with `xor` instead of `or` - dropping `v_cvt_f64_f32` from the `clear_vector_spills` pair list (the fixture has no `v_writelane_b32` spill) A +Inf input covers the first, `|x|` alone and `-x` alone on a negative input cover the second, and a qNaN input covers the third. The four "negative controls" compare the Python reference with altered flags against the unaltered reference. They show that the reference distinguishes those cases, not that the test fails on a broken lowering. The checks pass, but none of the three new tests ran on this PR: the `pr` test preset's include list does not match `native_cvt_f64_f32_*`. On pushes to `main` the dev preset runs with `-E '_hardware$'`, so only `_ir` and `_controls` are selected in CI.
R0D4X commented 2026-11-29 08:26:55 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0D4X on 2026-11-29T08:26:55Z.


Merged upstream/main (2397aad3) keeping both v_cvt_f64_i32/v_cvt_f64_u32 and v_cvt_f64_f32 in clear_vector_spills, and closed the three non-blocking test gaps @Leyukaka noted:

  • Added +Inf (with -x -> -Inf) so both infinity signs are verified.
  • Added qNaN (0x7fc00005) alongside sNaN (0x7f800005) so xor vs or on the quiet bit fails.
  • Added standalone |x| (abs_m=1) and standalone -x (neg_m=1) on negative inputs.

Verified on NVIDIA GeForce RTX 5080 (10de:2c02, driver 32.0.16.2140), Windows 11 (10.0.26300.9974), MSVC 19.44.35230, SDK DXC 10.0.26100.0:

  • ctest --preset dev --no-tests=error -R '^native_cvt_f64_f32_' -V: 3/3 passed (0 skipped).
  • ctest --preset release --no-tests=error -R '^native_cvt_f64_f32_' -V: 3/3 passed (0 skipped).
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7253110939 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3369#issuecomment-7253110939). Originally posted by [R0D4X](https://github.com/R0D4X) on 2026-11-29T08:26:55Z. --- Merged `upstream/main` (`2397aad3`) keeping both `v_cvt_f64_i32`/`v_cvt_f64_u32` and `v_cvt_f64_f32` in `clear_vector_spills`, and closed the three non-blocking test gaps @Leyukaka noted: - Added `+Inf` (with `-x -> -Inf`) so both infinity signs are verified. - Added `qNaN` (`0x7fc00005`) alongside `sNaN` (`0x7f800005`) so `xor` vs `or` on the quiet bit fails. - Added standalone `|x|` (`abs_m=1`) and standalone `-x` (`neg_m=1`) on negative inputs. Verified on NVIDIA GeForce RTX 5080 (`10de:2c02`, driver `32.0.16.2140`), Windows 11 (`10.0.26300.9974`), MSVC `19.44.35230`, SDK DXC `10.0.26100.0`: - `ctest --preset dev --no-tests=error -R '^native_cvt_f64_f32_' -V`: **3/3 passed** (0 skipped). - `ctest --preset release --no-tests=error -R '^native_cvt_f64_f32_' -V`: **3/3 passed** (0 skipped).
Leyukaka commented 2026-11-29 08:39:59 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-29T08:39:59Z.

Review: APPROVED


Approving head 0969302a. Diff read against main b8c68ee9; nothing built or run.

The conflict is resolved: clear_vector_spills now has v_cvt_f64_i32, v_cvt_f64_u32 and v_cvt_f64_f32 in the pair list (src/gfx1013_compute_native.cpp:561), and git merge-tree --write-tree origin/main 0969302a is clean. The net change is still the same 5 files, and the v_cvt_f64_f32 block in src/gfx1013_direct_compute.inl is unchanged from dbf57ab0.

The three test gaps are closed in tests/native_cvt_f64_f32_check.py:

  • 0x7F800000, # +Inf (-x -> -Inf): plain expects hi 0x7FF00000, the -x variant expects 0xFFF00000, so an inf_hi that ignores the sign fails either way.
  • elif idx in (1, 4): ... abs_m=1 # |x| alone on 0x80000000 and 0x80400001, and elif idx in (2, 5, 7): ... neg_m=1 # -x alone on 0xBF800001: dropping abs, or neg implemented as or, fails.
  • 0x7FC00005, # qNaN with payload 5: setting the quiet bit with xor gives 0x7FF00000_A0000000 instead of 0x7FF80000_A0000000 and fails.

native_cvt_f64_f32_ir compares every stored word with lane_results(), so by reading these three mutants fail in that test.

Still open, non-blocking:

  • Removing v_cvt_f64_f32 from the clear_vector_spills pair list still passes: the fixture has no v_writelane_b32/v_readlane_b32.
  • The pr test preset does not match native_cvt_f64_f32_*, so the checks on this head are green without having run these tests. On pushes to main, ctest --preset dev -E '_hardware$' selects _ir and _controls.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6102118687 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3369#pullrequestreview-6102118687). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-29T08:39:59Z. **Review:** APPROVED --- Approving head `0969302a`. Diff read against `main` `b8c68ee9`; nothing built or run. The conflict is resolved: `clear_vector_spills` now has `v_cvt_f64_i32`, `v_cvt_f64_u32` and `v_cvt_f64_f32` in the `pair` list (`src/gfx1013_compute_native.cpp:561`), and `git merge-tree --write-tree origin/main 0969302a` is clean. The net change is still the same 5 files, and the `v_cvt_f64_f32` block in `src/gfx1013_direct_compute.inl` is unchanged from `dbf57ab0`. The three test gaps are closed in `tests/native_cvt_f64_f32_check.py`: - `0x7F800000, # +Inf (-x -> -Inf)`: plain expects hi `0x7FF00000`, the `-x` variant expects `0xFFF00000`, so an `inf_hi` that ignores the sign fails either way. - `elif idx in (1, 4): ... abs_m=1 # |x| alone` on `0x80000000` and `0x80400001`, and `elif idx in (2, 5, 7): ... neg_m=1 # -x alone` on `0xBF800001`: dropping abs, or neg implemented as `or`, fails. - `0x7FC00005, # qNaN with payload 5`: setting the quiet bit with `xor` gives `0x7FF00000_A0000000` instead of `0x7FF80000_A0000000` and fails. `native_cvt_f64_f32_ir` compares every stored word with `lane_results()`, so by reading these three mutants fail in that test. Still open, non-blocking: - Removing `v_cvt_f64_f32` from the `clear_vector_spills` pair list still passes: the fixture has no `v_writelane_b32`/`v_readlane_b32`. - The `pr` test preset does not match `native_cvt_f64_f32_*`, so the checks on this head are green without having run these tests. On pushes to `main`, `ctest --preset dev -E '_hardware$'` selects `_ir` and `_controls`.
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!3369
No description provided.