shader: lower 64-bit float ALU and conversions in gfx2hlsl (Part of #1723) #2078

Closed
github-bot wants to merge 3 commits from gh-pr/2078/head into gh-pr/2078/base
Owner

@⁠tedin7 on GitHub · 2026-11-25 00:03 UTC · original
tedin7:x2w-b3-f64-alu → main · +426 −0 · 4 files · 3 commits · closed without merging

Part of #1723

What this unblocks: shaders that use 64-bit float math (v_add_f64, v_mul_f64, v_fma_f64, v_cvt_f32_f64, v_cvt_f64_f32) no longer stop translation in gfx2hlsl.py.

A binary64 value is a VGPR/SGPR pair. The lowering reads both words into one HLSL double with asdouble(), computes, and writes both result words from one asuint(double, lo, hi) call, so an in-place destination keeps the original operands until the result is complete. Pair and inline-constant sources accept - and |abs|. Output modifiers (clamp, mul:, div:), op_sel, a destination that is not a VGPR pair, wrong operand counts and the binary32-only inline constant 0.15915494 are refused, not dropped. No opcode in this slice was on main or in an open PR.

Verification:

  • python3 -B tests/startup_gfx2hlsl_f64_alu_check.py: all checks passed on this branch; on origin/main it stops with Unsupported: v_add_f64.
  • for t in tests/startup_gfx2hlsl_*_check.py; do python3 -B $t; done: all pass.
  • Test registered in CMakeLists.txt as startup_gfx2hlsl_f64_alu.
  • Not run: Win2025 build and the CTest run. This was a Linux worktree and only the Python checks were executed.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-25 00:03 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2078) `tedin7:x2w-b3-f64-alu` → `main` · +426 −0 · 4 files · 3 commits · closed without merging Part of #1723 What this unblocks: shaders that use 64-bit float math (`v_add_f64`, `v_mul_f64`, `v_fma_f64`, `v_cvt_f32_f64`, `v_cvt_f64_f32`) no longer stop translation in `gfx2hlsl.py`. A binary64 value is a VGPR/SGPR pair. The lowering reads both words into one HLSL `double` with `asdouble()`, computes, and writes both result words from one `asuint(double, lo, hi)` call, so an in-place destination keeps the original operands until the result is complete. Pair and inline-constant sources accept `-` and `|abs|`. Output modifiers (`clamp`, `mul:`, `div:`), `op_sel`, a destination that is not a VGPR pair, wrong operand counts and the binary32-only inline constant `0.15915494` are refused, not dropped. No opcode in this slice was on main or in an open PR. Verification: - `python3 -B tests/startup_gfx2hlsl_f64_alu_check.py`: all checks passed on this branch; on `origin/main` it stops with `Unsupported: v_add_f64`. - `for t in tests/startup_gfx2hlsl_*_check.py; do python3 -B $t; done`: all pass. - Test registered in `CMakeLists.txt` as `startup_gfx2hlsl_f64_alu`. - Not run: Win2025 build and the CTest run. This was a Linux worktree and only the Python checks were executed. AI-assisted; commands listed were executed locally.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:54:41 +00:00
github-bot closed this pull request 2026-11-26 23:54:41 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-25 00:03 UTC · original · edited 2026-11-25 00:13 UTC

Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T00:13:01.961206Z ed782a1 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@⁠codex review" or "@⁠codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-25 00:03 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2078#issuecomment-7148091261) · edited 2026-11-25 00:13 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"ed782a1ab4262c16c42bda2034219e5945b7432b","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-25T00:13:01.961206Z">2026-11-25T00:13:01.961206Z</relative-time> | `ed782a1` | PR opened | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@⁠codex review" or "@⁠codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
@ -2697,0 +2769,4 @@
if len(ops) != 2:
raise Unsupported('v_cvt_f64_f32 with %d operands, expected 2' % len(ops))
lo, hi = self.f64_pair_destination('v_cvt_f64_f32', ops[0])
value = 'double(%s)' % self.f(ops[1])
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-25 00:12 UTC · original

P2 Badge Preserve NEG on inline integer inputs to the widening conversion

For gfx1013 bytecode encoding v_cvt_f64_f32_e64 v[2:3], neg(1), the decoder prints the source as -1, and this call emits double(F(0xffffffffu)), a NaN. The actual source bits after NEG are 0x80000001, representing a finite negative subnormal, not a NaN. Likewise, neg(0) decodes as -0 and emits double(0.0), losing the sign. Preserve these modifiers from the instruction encoding, as check_encoding() already does for ambiguous v_cndmask_b32_e64 immediates, or refuse the affected forms instead of silently widening a different value.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-25 00:12 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2078#discussion_r4688397657) **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Preserve NEG on inline integer inputs to the widening conversion** For gfx1013 bytecode encoding `v_cvt_f64_f32_e64 v[2:3], neg(1)`, the decoder prints the source as `-1`, and this call emits `double(F(0xffffffffu))`, a NaN. The actual source bits after NEG are `0x80000001`, representing a finite negative subnormal, not a NaN. Likewise, `neg(0)` decodes as `-0` and emits `double(0.0)`, losing the sign. Preserve these modifiers from the instruction encoding, as `check_encoding()` already does for ambiguous `v_cndmask_b32_e64` immediates, or refuse the affected forms instead of silently widening a different value. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-25 00:12 UTC · original

P2 Badge Make FP64 pair writes visible to the vertex fetch guard

For fetched vertex shaders, this block-shaped statement is rejected by Pipeline.hlsl_vs()'s definite-assignment guard, which recognizes writes only as lines starting with vN = ... and otherwise treats every VGPR name as a read. With a fetch defining v4/v5, v_add_f64 v[12:13], v[4:5], v[4:5] lowers here but subsequently raises Unsupported('vertex stage reads v12...') because its destination is mistaken for an uninitialized source. The same issue affects multiply, FMA, and the widening conversion. Make both destination writes visible to that guard while preserving evaluation before either write.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-25 00:12 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2078#discussion_r4688397665) **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Make FP64 pair writes visible to the vertex fetch guard** For fetched vertex shaders, this block-shaped statement is rejected by `Pipeline.hlsl_vs()`'s definite-assignment guard, which recognizes writes only as lines starting with `vN = ...` and otherwise treats every VGPR name as a read. With a fetch defining v4/v5, `v_add_f64 v[12:13], v[4:5], v[4:5]` lowers here but subsequently raises `Unsupported('vertex stage reads v12...')` because its destination is mistaken for an uninitialized source. The same issue affects multiply, FMA, and the widening conversion. Make both destination writes visible to that guard while preserving evaluation before either write. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
@ -2697,0 +2769,4 @@
if len(ops) != 2:
raise Unsupported('v_cvt_f64_f32 with %d operands, expected 2' % len(ops))
lo, hi = self.f64_pair_destination('v_cvt_f64_f32', ops[0])
value = 'double(%s)' % self.f(ops[1])
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 01:02 UTC · original

Fixed in 7e15003d (rebased on main, push pending): check_encoding now refuses NEG/ABS on an inline integer source of v_cvt_f64_f32_e64, so neg(1) and neg(0) are no longer widened as a different value. Test: tests/startup_gfx2hlsl_f64_alu_check.py. Ran locally: startup_gfx2hlsl_f64_alu_check.py, startup_gfx2hlsl_f64_alu_warp_check.py (controls), refusals/arity/cvt_alu checks. The Win2025 draw run is still pending.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-25 01:02 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2078#discussion_r4688767746) Fixed in 7e15003d (rebased on main, push pending): check_encoding now refuses NEG/ABS on an inline integer source of v_cvt_f64_f32_e64, so neg(1) and neg(0) are no longer widened as a different value. Test: tests/startup_gfx2hlsl_f64_alu_check.py. Ran locally: startup_gfx2hlsl_f64_alu_check.py, startup_gfx2hlsl_f64_alu_warp_check.py (controls), refusals/arity/cvt_alu checks. The Win2025 draw run is still pending. AI-assisted; commands listed were executed locally.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 01:02 UTC · original

Fixed in 7e15003d (rebased on main, push pending): the pair result is computed into temporaries first, then each half is its own vN = ... line, so the vertex fetch guard sees both writes and the operands are still evaluated before either write. Test added in tests/startup_gfx2hlsl_f64_alu_check.py; the WARP swap control was updated to the new shape. The Win2025 draw run is still pending.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-25 01:02 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2078#discussion_r4688767875) Fixed in 7e15003d (rebased on main, push pending): the pair result is computed into temporaries first, then each half is its own `vN = ...` line, so the vertex fetch guard sees both writes and the operands are still evaluated before either write. Test added in tests/startup_gfx2hlsl_f64_alu_check.py; the WARP swap control was updated to the new shape. The Win2025 draw run is still pending. AI-assisted; commands listed were executed locally.
Author
Owner

@⁠Makto94 on GitHub · 2026-11-25 10:43 UTC · original

First hardware run reported in this thread: startup_gfx2hlsl_f64_alu_hardware passes on head 9335d4a0 with both FXC and DXC.

.\tools\dev.ps1; ctest --preset dev --no-tests=error -j1 -R '^startup_gfx2hlsl_f64_alu_hardware$' -V

Environment: NVIDIA GeForce RTX 3070 Ti (10de:2482), driver 32.0.16.2101, Windows 11 build 26300.9974, Debug build, fxc 10.0.26100.9457, dxc 1.9.2602.17, D3D12 debug layer enabled, hardware run serial on an idle machine, 0 capability skips (77). The log has 30 fxc lines and 30 dxc lines (15 pixel rows and 15 "mutation: fails as expected" rows per compiler), and debug_errors=0 debug_warnings=0 on all 60 runs.
Same head, WARP and CPU checks: 100% tests passed, 0 tests failed out of 3 (startup_gfx2hlsl_f64_alu, startup_gfx2hlsl_f64_alu_controls, startup_gfx2hlsl_f64_alu_warp); the WARP test has 30 fxc lines, 30 dxc lines and debug_errors=0 debug_warnings=0 on all 60 runs.

**@⁠Makto94** on GitHub · 2026-11-25 10:43 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2078#issuecomment-7160084573) First hardware run reported in this thread: `startup_gfx2hlsl_f64_alu_hardware` passes on head 9335d4a0 with both FXC and DXC. ```powershell .\tools\dev.ps1; ctest --preset dev --no-tests=error -j1 -R '^startup_gfx2hlsl_f64_alu_hardware$' -V ``` Environment: NVIDIA GeForce RTX 3070 Ti (`10de:2482`), driver 32.0.16.2101, Windows 11 build 26300.9974, Debug build, fxc 10.0.26100.9457, dxc 1.9.2602.17, D3D12 debug layer enabled, hardware run serial on an idle machine, 0 capability skips (77). The log has 30 `fxc ` lines and 30 `dxc ` lines (15 pixel rows and 15 "mutation: fails as expected" rows per compiler), and `debug_errors=0 debug_warnings=0` on all 60 runs. Same head, WARP and CPU checks: `100% tests passed, 0 tests failed out of 3` (`startup_gfx2hlsl_f64_alu`, `startup_gfx2hlsl_f64_alu_controls`, `startup_gfx2hlsl_f64_alu_warp`); the WARP test has 30 `fxc ` lines, 30 `dxc ` lines and `debug_errors=0 debug_warnings=0` on all 60 runs.
Author
Owner

@⁠thepatrickworld on GitHub · 2026-11-25 11:54 UTC · original

Run on the AMD adapter, backend hardware, both compilers:

adapter=AMD Radeon RX 9070 XT vendor=1002 device=7550
driver=32.0.32029.2010

startup_gfx2hlsl_f64_alu_warp_check.py draw <dxc> <offscreen_check> hardware <fxc>. BODY_SOURCE has five operations (v_add_f64, v_mul_f64, v_fma_f64, v_cvt_f32_f64, v_cvt_f64_f32); the run gives 15 readbacks and 15 mutation runs per compiler, every readback matches its reference, and every mutation reads its mutated words.

Branch checked out at 9335d4a0; the log itself does not record the head.

One check is much looser than the others. In controls() all five operations are validated by looking for a substring of the translated text. For four of them that substring is the whole expected expression:

'v_add_f64': 'asdouble(v0, v1) + asdouble(v2, v3)',
'v_fma_f64': 'fma(asdouble(v0, v1), asdouble(v2, v3), asdouble(v4, v5))',
'v_cvt_f32_f64': 'asuint((float)asdouble(v0, v1))',
'v_cvt_f64_f32': 'double('

so for v_cvt_f64_f32 the assertion is "the text contains double(". Any lowering containing that substring satisfies it — a lowering that read the wrong register would too. I have not tested such a lowering; the point is that this control could not catch one. The other four pin the expression.

Limit. I ran the hardware backend; the warp backend named in the usage line is not covered by this run.

AI-assisted.

**@⁠thepatrickworld** on GitHub · 2026-11-25 11:54 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2078#issuecomment-7161664795) **Run on the AMD adapter, backend `hardware`, both compilers:** ``` adapter=AMD Radeon RX 9070 XT vendor=1002 device=7550 driver=32.0.32029.2010 ``` `startup_gfx2hlsl_f64_alu_warp_check.py draw <dxc> <offscreen_check> hardware <fxc>`. `BODY_SOURCE` has five operations (`v_add_f64`, `v_mul_f64`, `v_fma_f64`, `v_cvt_f32_f64`, `v_cvt_f64_f32`); the run gives 15 readbacks and 15 mutation runs per compiler, every readback matches its reference, and every mutation reads its mutated words. Branch checked out at `9335d4a0`; the log itself does not record the head. **One check is much looser than the others.** In `controls()` all five operations are validated by looking for a substring of the translated text. For four of them that substring is the whole expected expression: ```python 'v_add_f64': 'asdouble(v0, v1) + asdouble(v2, v3)', 'v_fma_f64': 'fma(asdouble(v0, v1), asdouble(v2, v3), asdouble(v4, v5))', 'v_cvt_f32_f64': 'asuint((float)asdouble(v0, v1))', 'v_cvt_f64_f32': 'double(' ``` so for `v_cvt_f64_f32` the assertion is "the text contains `double(`". Any lowering containing that substring satisfies it — a lowering that read the wrong register would too. I have not tested such a lowering; the point is that this control could not catch one. The other four pin the expression. **Limit.** I ran the `hardware` backend; the `warp` backend named in the usage line is not covered by this run. _AI-assisted._
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 11:54 UTC · original

Thank you @⁠Makto94 for the RTX 3070 Ti run at 9335d4a0: startup_gfx2hlsl_f64_alu_hardware passed with FXC and DXC, CPU/controls/WARP 3/3. Recorded as extra evidence for this PR.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-25 11:54 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2078#issuecomment-7161669861) Thank you @⁠Makto94 for the RTX 3070 Ti run at `9335d4a0`: `startup_gfx2hlsl_f64_alu_hardware` passed with FXC and DXC, CPU/controls/WARP 3/3. Recorded as extra evidence for this PR. AI-assisted; commands listed were executed locally.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 13:52 UTC · original

Closing this PR for now to keep the Windows test queue short. Nothing is wrong with it and the branch stays as it is.

We will reopen it once the queue is clear, re-run the Win2025 WARP checks at its head, and post the result here.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-25 13:52 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2078#issuecomment-7164408996) Closing this PR for now to keep the Windows test queue short. Nothing is wrong with it and the branch stays as it is. We will reopen it once the queue is clear, re-run the Win2025 WARP checks at its head, and post the result here. AI-assisted; commands listed were executed locally.
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-25 00:12 UTC · original · reviewed

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ed782a1ab4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@⁠codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@⁠codex address that feedback".

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-25 00:12 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2078#pullrequestreview-6049538178) · **reviewed** <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `ed782a1ab4` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@⁠codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@⁠codex address that feedback". </details>

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.