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

Closed
tedin7 wants to merge 3 commits from upstream-pr/2078 into main
tedin7 commented 2026-11-25 00:03:20 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T00:03:20Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6593982450 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2078). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T00:03:20Z. --- 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.
chatgpt-codex-connector[bot commented 2026-11-25 01:01:31 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T00:12:59Z.

Review: COMMENTED


💡 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".

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6049538178 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2078#pullrequestreview-6049538178). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T00:12:59Z. **Review:** COMMENTED --- <!-- 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>
chatgpt-codex-connector[bot commented 2026-11-25 01:02:03 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T00:03:32Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7148091261 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2078#issuecomment-7148091261). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T00:03:32Z. --- <!-- 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>
chatgpt-codex-connector[bot commented 2026-11-25 01:02:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T00:12:59Z.

Code review location: tools/startup/gfx2hlsl.py; line 1646

@@ -1576,6 +1576,81 @@ def op_v_lshrrev_b64(self, ops, mods):
 
     def op_v_ashrrev_i64(self, ops, mods):
         self.shift64(ops, mods, 'shr64i')
+    def f64_source(self, tok):
+        """double expression of a 64-bit float source: a VGPR/SGPR pair or an inline constant, with neg/abs."""
+        neg = tok.startswith('-') and not re.match(r'-[\d.]', tok)
+        if neg:
+            tok = tok[1:]
+        absolute = tok.startswith('|') and tok.endswith('|') and len(tok) > 2
+        if absolute:
+            tok = tok[1:-1]
+        pair = reg_range(tok)
+        if pair:
+            low, high = self.i64_words(tok)
+            text = 'asdouble(%s, %s)' % (low, high)
+        elif tok in FLOATS and tok != '0.15915494':
+            text = repr(float(FLOATS[tok]))
+        elif tok == '0':
+            text = '0.0'
+        else:
+            raise Unsupported('64-bit float source %s' % tok)
+        if absolute:
+            text = 'abs(%s)' % text
+        return '(-%s)' % text if neg else text
+
+    def f64_pair_destination(self, name, tok):
+        dst = reg_range(tok)
+        if not dst or dst[0] != 'v' or dst[2] != dst[1] + 1 or dst[2] > 255:
+            raise Unsupported('%s destination %s' % (name, tok))
+        return dst[1], dst[2]
+
+    def f64_op(self, name, ops, mods, arity, text):
+        if mods:
+            raise Unsupported('%s with %s' % (name, mods))
+        if len(ops) != arity + 1:
+            raise Unsupported('%s with %d operands, expected %d' % (name, len(ops), arity + 1))
+        lo, hi = self.f64_pair_destination(name, ops[0])
+        value = text.format(*[self.f64_source(o) for o in ops[1:]])
+        if hasattr(self, 'uniform_v'):
+            self.uniform_v.discard(lo)
+            self.uniform_v.discard(hi)
+        self.used_v.update((lo, hi))
+        body = '{ uint lo, hi; asuint(%s, lo, hi); v%d = lo; v%d = hi; }' % (value, lo, hi)
+        self.emit(body if self.exec_known else 'if (exec & 1) ' + body)
+
+    def op_v_add_f64(self, ops, mods):
+        self.f64_op('v_add_f64', ops, mods, 2, '{0} + {1}')
+
+    def op_v_mul_f64(self, ops, mods):
+        self.f64_op('v_mul_f64', ops, mods, 2, '{0} * {1}')
+
+    def op_v_fma_f64(self, ops, mods):
+        self.f64_op('v_fma_f64', ops, mods, 3, 'fma({0}, {1}, {2})')
+
+    def op_v_cvt_f32_f64(self, ops, mods):
+        if mods:
+            raise Unsupported('v_cvt_f32_f64 with %s' % (mods,))
+        if len(ops) != 2:
+            raise Unsupported('v_cvt_f32_f64 with %d operands, expected 2' % len(ops))
+        dst = reg_range(ops[0])
+        if not dst or dst[0] != 'v' or dst[1] != dst[2] or dst[1] > 255:
+            raise Unsupported('v_cvt_f32_f64 destination %s' % ops[0])
+        self.set_v(dst[1], 'asuint((float)%s)' % self.f64_source(ops[1]))
+
+    def op_v_cvt_f64_f32(self, ops, mods):
+        if mods:
+            raise Unsupported('v_cvt_f64_f32 with %s' % (mods,))
+        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])

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 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688397657 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2078#discussion_r4688397657). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T00:12:59Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 1646 ~~~~diff @@ -1576,6 +1576,81 @@ def op_v_lshrrev_b64(self, ops, mods): def op_v_ashrrev_i64(self, ops, mods): self.shift64(ops, mods, 'shr64i') + def f64_source(self, tok): + """double expression of a 64-bit float source: a VGPR/SGPR pair or an inline constant, with neg/abs.""" + neg = tok.startswith('-') and not re.match(r'-[\d.]', tok) + if neg: + tok = tok[1:] + absolute = tok.startswith('|') and tok.endswith('|') and len(tok) > 2 + if absolute: + tok = tok[1:-1] + pair = reg_range(tok) + if pair: + low, high = self.i64_words(tok) + text = 'asdouble(%s, %s)' % (low, high) + elif tok in FLOATS and tok != '0.15915494': + text = repr(float(FLOATS[tok])) + elif tok == '0': + text = '0.0' + else: + raise Unsupported('64-bit float source %s' % tok) + if absolute: + text = 'abs(%s)' % text + return '(-%s)' % text if neg else text + + def f64_pair_destination(self, name, tok): + dst = reg_range(tok) + if not dst or dst[0] != 'v' or dst[2] != dst[1] + 1 or dst[2] > 255: + raise Unsupported('%s destination %s' % (name, tok)) + return dst[1], dst[2] + + def f64_op(self, name, ops, mods, arity, text): + if mods: + raise Unsupported('%s with %s' % (name, mods)) + if len(ops) != arity + 1: + raise Unsupported('%s with %d operands, expected %d' % (name, len(ops), arity + 1)) + lo, hi = self.f64_pair_destination(name, ops[0]) + value = text.format(*[self.f64_source(o) for o in ops[1:]]) + if hasattr(self, 'uniform_v'): + self.uniform_v.discard(lo) + self.uniform_v.discard(hi) + self.used_v.update((lo, hi)) + body = '{ uint lo, hi; asuint(%s, lo, hi); v%d = lo; v%d = hi; }' % (value, lo, hi) + self.emit(body if self.exec_known else 'if (exec & 1) ' + body) + + def op_v_add_f64(self, ops, mods): + self.f64_op('v_add_f64', ops, mods, 2, '{0} + {1}') + + def op_v_mul_f64(self, ops, mods): + self.f64_op('v_mul_f64', ops, mods, 2, '{0} * {1}') + + def op_v_fma_f64(self, ops, mods): + self.f64_op('v_fma_f64', ops, mods, 3, 'fma({0}, {1}, {2})') + + def op_v_cvt_f32_f64(self, ops, mods): + if mods: + raise Unsupported('v_cvt_f32_f64 with %s' % (mods,)) + if len(ops) != 2: + raise Unsupported('v_cvt_f32_f64 with %d operands, expected 2' % len(ops)) + dst = reg_range(ops[0]) + if not dst or dst[0] != 'v' or dst[1] != dst[2] or dst[1] > 255: + raise Unsupported('v_cvt_f32_f64 destination %s' % ops[0]) + self.set_v(dst[1], 'asuint((float)%s)' % self.f64_source(ops[1])) + + def op_v_cvt_f64_f32(self, ops, mods): + if mods: + raise Unsupported('v_cvt_f64_f32 with %s' % (mods,)) + 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]) ~~~~ --- **<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 -->
chatgpt-codex-connector[bot commented 2026-11-25 01:02:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T00:12:59Z.

Code review location: tools/startup/gfx2hlsl.py; line 1619

@@ -1576,6 +1576,81 @@ def op_v_lshrrev_b64(self, ops, mods):
 
     def op_v_ashrrev_i64(self, ops, mods):
         self.shift64(ops, mods, 'shr64i')
+    def f64_source(self, tok):
+        """double expression of a 64-bit float source: a VGPR/SGPR pair or an inline constant, with neg/abs."""
+        neg = tok.startswith('-') and not re.match(r'-[\d.]', tok)
+        if neg:
+            tok = tok[1:]
+        absolute = tok.startswith('|') and tok.endswith('|') and len(tok) > 2
+        if absolute:
+            tok = tok[1:-1]
+        pair = reg_range(tok)
+        if pair:
+            low, high = self.i64_words(tok)
+            text = 'asdouble(%s, %s)' % (low, high)
+        elif tok in FLOATS and tok != '0.15915494':
+            text = repr(float(FLOATS[tok]))
+        elif tok == '0':
+            text = '0.0'
+        else:
+            raise Unsupported('64-bit float source %s' % tok)
+        if absolute:
+            text = 'abs(%s)' % text
+        return '(-%s)' % text if neg else text
+
+    def f64_pair_destination(self, name, tok):
+        dst = reg_range(tok)
+        if not dst or dst[0] != 'v' or dst[2] != dst[1] + 1 or dst[2] > 255:
+            raise Unsupported('%s destination %s' % (name, tok))
+        return dst[1], dst[2]
+
+    def f64_op(self, name, ops, mods, arity, text):
+        if mods:
+            raise Unsupported('%s with %s' % (name, mods))
+        if len(ops) != arity + 1:
+            raise Unsupported('%s with %d operands, expected %d' % (name, len(ops), arity + 1))
+        lo, hi = self.f64_pair_destination(name, ops[0])
+        value = text.format(*[self.f64_source(o) for o in ops[1:]])
+        if hasattr(self, 'uniform_v'):
+            self.uniform_v.discard(lo)
+            self.uniform_v.discard(hi)
+        self.used_v.update((lo, hi))
+        body = '{ uint lo, hi; asuint(%s, lo, hi); v%d = lo; v%d = hi; }' % (value, lo, hi)
+        self.emit(body if self.exec_known else 'if (exec & 1) ' + body)

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 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688397665 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2078#discussion_r4688397665). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T00:12:59Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 1619 ~~~~diff @@ -1576,6 +1576,81 @@ def op_v_lshrrev_b64(self, ops, mods): def op_v_ashrrev_i64(self, ops, mods): self.shift64(ops, mods, 'shr64i') + def f64_source(self, tok): + """double expression of a 64-bit float source: a VGPR/SGPR pair or an inline constant, with neg/abs.""" + neg = tok.startswith('-') and not re.match(r'-[\d.]', tok) + if neg: + tok = tok[1:] + absolute = tok.startswith('|') and tok.endswith('|') and len(tok) > 2 + if absolute: + tok = tok[1:-1] + pair = reg_range(tok) + if pair: + low, high = self.i64_words(tok) + text = 'asdouble(%s, %s)' % (low, high) + elif tok in FLOATS and tok != '0.15915494': + text = repr(float(FLOATS[tok])) + elif tok == '0': + text = '0.0' + else: + raise Unsupported('64-bit float source %s' % tok) + if absolute: + text = 'abs(%s)' % text + return '(-%s)' % text if neg else text + + def f64_pair_destination(self, name, tok): + dst = reg_range(tok) + if not dst or dst[0] != 'v' or dst[2] != dst[1] + 1 or dst[2] > 255: + raise Unsupported('%s destination %s' % (name, tok)) + return dst[1], dst[2] + + def f64_op(self, name, ops, mods, arity, text): + if mods: + raise Unsupported('%s with %s' % (name, mods)) + if len(ops) != arity + 1: + raise Unsupported('%s with %d operands, expected %d' % (name, len(ops), arity + 1)) + lo, hi = self.f64_pair_destination(name, ops[0]) + value = text.format(*[self.f64_source(o) for o in ops[1:]]) + if hasattr(self, 'uniform_v'): + self.uniform_v.discard(lo) + self.uniform_v.discard(hi) + self.used_v.update((lo, hi)) + body = '{ uint lo, hi; asuint(%s, lo, hi); v%d = lo; v%d = hi; }' % (value, lo, hi) + self.emit(body if self.exec_known else 'if (exec & 1) ' + body) ~~~~ --- **<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 -->
tedin7 commented 2026-11-25 02:01:40 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T01:02:43Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6049955323 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2078#pullrequestreview-6049955323). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T01:02:43Z. **Review:** COMMENTED --- _No description provided._
tedin7 commented 2026-11-25 02:01:40 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T01:02:44Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6049955487 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2078#pullrequestreview-6049955487). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T01:02:44Z. **Review:** COMMENTED --- _No description provided._
tedin7 commented 2026-11-25 02:02:12 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T01:02:43Z.

Code review location: tools/startup/gfx2hlsl.py; line 1646

@@ -1576,6 +1576,81 @@ def op_v_lshrrev_b64(self, ops, mods):
 
     def op_v_ashrrev_i64(self, ops, mods):
         self.shift64(ops, mods, 'shr64i')
+    def f64_source(self, tok):
+        """double expression of a 64-bit float source: a VGPR/SGPR pair or an inline constant, with neg/abs."""
+        neg = tok.startswith('-') and not re.match(r'-[\d.]', tok)
+        if neg:
+            tok = tok[1:]
+        absolute = tok.startswith('|') and tok.endswith('|') and len(tok) > 2
+        if absolute:
+            tok = tok[1:-1]
+        pair = reg_range(tok)
+        if pair:
+            low, high = self.i64_words(tok)
+            text = 'asdouble(%s, %s)' % (low, high)
+        elif tok in FLOATS and tok != '0.15915494':
+            text = repr(float(FLOATS[tok]))
+        elif tok == '0':
+            text = '0.0'
+        else:
+            raise Unsupported('64-bit float source %s' % tok)
+        if absolute:
+            text = 'abs(%s)' % text
+        return '(-%s)' % text if neg else text
+
+    def f64_pair_destination(self, name, tok):
+        dst = reg_range(tok)
+        if not dst or dst[0] != 'v' or dst[2] != dst[1] + 1 or dst[2] > 255:
+            raise Unsupported('%s destination %s' % (name, tok))
+        return dst[1], dst[2]
+
+    def f64_op(self, name, ops, mods, arity, text):
+        if mods:
+            raise Unsupported('%s with %s' % (name, mods))
+        if len(ops) != arity + 1:
+            raise Unsupported('%s with %d operands, expected %d' % (name, len(ops), arity + 1))
+        lo, hi = self.f64_pair_destination(name, ops[0])
+        value = text.format(*[self.f64_source(o) for o in ops[1:]])
+        if hasattr(self, 'uniform_v'):
+            self.uniform_v.discard(lo)
+            self.uniform_v.discard(hi)
+        self.used_v.update((lo, hi))
+        body = '{ uint lo, hi; asuint(%s, lo, hi); v%d = lo; v%d = hi; }' % (value, lo, hi)
+        self.emit(body if self.exec_known else 'if (exec & 1) ' + body)
+
+    def op_v_add_f64(self, ops, mods):
+        self.f64_op('v_add_f64', ops, mods, 2, '{0} + {1}')
+
+    def op_v_mul_f64(self, ops, mods):
+        self.f64_op('v_mul_f64', ops, mods, 2, '{0} * {1}')
+
+    def op_v_fma_f64(self, ops, mods):
+        self.f64_op('v_fma_f64', ops, mods, 3, 'fma({0}, {1}, {2})')
+
+    def op_v_cvt_f32_f64(self, ops, mods):
+        if mods:
+            raise Unsupported('v_cvt_f32_f64 with %s' % (mods,))
+        if len(ops) != 2:
+            raise Unsupported('v_cvt_f32_f64 with %d operands, expected 2' % len(ops))
+        dst = reg_range(ops[0])
+        if not dst or dst[0] != 'v' or dst[1] != dst[2] or dst[1] > 255:
+            raise Unsupported('v_cvt_f32_f64 destination %s' % ops[0])
+        self.set_v(dst[1], 'asuint((float)%s)' % self.f64_source(ops[1]))
+
+    def op_v_cvt_f64_f32(self, ops, mods):
+        if mods:
+            raise Unsupported('v_cvt_f64_f32 with %s' % (mods,))
+        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])

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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688767746 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2078#discussion_r4688767746). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T01:02:43Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 1646 ~~~~diff @@ -1576,6 +1576,81 @@ def op_v_lshrrev_b64(self, ops, mods): def op_v_ashrrev_i64(self, ops, mods): self.shift64(ops, mods, 'shr64i') + def f64_source(self, tok): + """double expression of a 64-bit float source: a VGPR/SGPR pair or an inline constant, with neg/abs.""" + neg = tok.startswith('-') and not re.match(r'-[\d.]', tok) + if neg: + tok = tok[1:] + absolute = tok.startswith('|') and tok.endswith('|') and len(tok) > 2 + if absolute: + tok = tok[1:-1] + pair = reg_range(tok) + if pair: + low, high = self.i64_words(tok) + text = 'asdouble(%s, %s)' % (low, high) + elif tok in FLOATS and tok != '0.15915494': + text = repr(float(FLOATS[tok])) + elif tok == '0': + text = '0.0' + else: + raise Unsupported('64-bit float source %s' % tok) + if absolute: + text = 'abs(%s)' % text + return '(-%s)' % text if neg else text + + def f64_pair_destination(self, name, tok): + dst = reg_range(tok) + if not dst or dst[0] != 'v' or dst[2] != dst[1] + 1 or dst[2] > 255: + raise Unsupported('%s destination %s' % (name, tok)) + return dst[1], dst[2] + + def f64_op(self, name, ops, mods, arity, text): + if mods: + raise Unsupported('%s with %s' % (name, mods)) + if len(ops) != arity + 1: + raise Unsupported('%s with %d operands, expected %d' % (name, len(ops), arity + 1)) + lo, hi = self.f64_pair_destination(name, ops[0]) + value = text.format(*[self.f64_source(o) for o in ops[1:]]) + if hasattr(self, 'uniform_v'): + self.uniform_v.discard(lo) + self.uniform_v.discard(hi) + self.used_v.update((lo, hi)) + body = '{ uint lo, hi; asuint(%s, lo, hi); v%d = lo; v%d = hi; }' % (value, lo, hi) + self.emit(body if self.exec_known else 'if (exec & 1) ' + body) + + def op_v_add_f64(self, ops, mods): + self.f64_op('v_add_f64', ops, mods, 2, '{0} + {1}') + + def op_v_mul_f64(self, ops, mods): + self.f64_op('v_mul_f64', ops, mods, 2, '{0} * {1}') + + def op_v_fma_f64(self, ops, mods): + self.f64_op('v_fma_f64', ops, mods, 3, 'fma({0}, {1}, {2})') + + def op_v_cvt_f32_f64(self, ops, mods): + if mods: + raise Unsupported('v_cvt_f32_f64 with %s' % (mods,)) + if len(ops) != 2: + raise Unsupported('v_cvt_f32_f64 with %d operands, expected 2' % len(ops)) + dst = reg_range(ops[0]) + if not dst or dst[0] != 'v' or dst[1] != dst[2] or dst[1] > 255: + raise Unsupported('v_cvt_f32_f64 destination %s' % ops[0]) + self.set_v(dst[1], 'asuint((float)%s)' % self.f64_source(ops[1])) + + def op_v_cvt_f64_f32(self, ops, mods): + if mods: + raise Unsupported('v_cvt_f64_f32 with %s' % (mods,)) + 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]) ~~~~ --- 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 commented 2026-11-25 02:02:12 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T01:02:44Z.

Code review location: tools/startup/gfx2hlsl.py; line 1619

@@ -1576,6 +1576,81 @@ def op_v_lshrrev_b64(self, ops, mods):
 
     def op_v_ashrrev_i64(self, ops, mods):
         self.shift64(ops, mods, 'shr64i')
+    def f64_source(self, tok):
+        """double expression of a 64-bit float source: a VGPR/SGPR pair or an inline constant, with neg/abs."""
+        neg = tok.startswith('-') and not re.match(r'-[\d.]', tok)
+        if neg:
+            tok = tok[1:]
+        absolute = tok.startswith('|') and tok.endswith('|') and len(tok) > 2
+        if absolute:
+            tok = tok[1:-1]
+        pair = reg_range(tok)
+        if pair:
+            low, high = self.i64_words(tok)
+            text = 'asdouble(%s, %s)' % (low, high)
+        elif tok in FLOATS and tok != '0.15915494':
+            text = repr(float(FLOATS[tok]))
+        elif tok == '0':
+            text = '0.0'
+        else:
+            raise Unsupported('64-bit float source %s' % tok)
+        if absolute:
+            text = 'abs(%s)' % text
+        return '(-%s)' % text if neg else text
+
+    def f64_pair_destination(self, name, tok):
+        dst = reg_range(tok)
+        if not dst or dst[0] != 'v' or dst[2] != dst[1] + 1 or dst[2] > 255:
+            raise Unsupported('%s destination %s' % (name, tok))
+        return dst[1], dst[2]
+
+    def f64_op(self, name, ops, mods, arity, text):
+        if mods:
+            raise Unsupported('%s with %s' % (name, mods))
+        if len(ops) != arity + 1:
+            raise Unsupported('%s with %d operands, expected %d' % (name, len(ops), arity + 1))
+        lo, hi = self.f64_pair_destination(name, ops[0])
+        value = text.format(*[self.f64_source(o) for o in ops[1:]])
+        if hasattr(self, 'uniform_v'):
+            self.uniform_v.discard(lo)
+            self.uniform_v.discard(hi)
+        self.used_v.update((lo, hi))
+        body = '{ uint lo, hi; asuint(%s, lo, hi); v%d = lo; v%d = hi; }' % (value, lo, hi)
+        self.emit(body if self.exec_known else 'if (exec & 1) ' + body)

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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688767875 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2078#discussion_r4688767875). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T01:02:44Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 1619 ~~~~diff @@ -1576,6 +1576,81 @@ def op_v_lshrrev_b64(self, ops, mods): def op_v_ashrrev_i64(self, ops, mods): self.shift64(ops, mods, 'shr64i') + def f64_source(self, tok): + """double expression of a 64-bit float source: a VGPR/SGPR pair or an inline constant, with neg/abs.""" + neg = tok.startswith('-') and not re.match(r'-[\d.]', tok) + if neg: + tok = tok[1:] + absolute = tok.startswith('|') and tok.endswith('|') and len(tok) > 2 + if absolute: + tok = tok[1:-1] + pair = reg_range(tok) + if pair: + low, high = self.i64_words(tok) + text = 'asdouble(%s, %s)' % (low, high) + elif tok in FLOATS and tok != '0.15915494': + text = repr(float(FLOATS[tok])) + elif tok == '0': + text = '0.0' + else: + raise Unsupported('64-bit float source %s' % tok) + if absolute: + text = 'abs(%s)' % text + return '(-%s)' % text if neg else text + + def f64_pair_destination(self, name, tok): + dst = reg_range(tok) + if not dst or dst[0] != 'v' or dst[2] != dst[1] + 1 or dst[2] > 255: + raise Unsupported('%s destination %s' % (name, tok)) + return dst[1], dst[2] + + def f64_op(self, name, ops, mods, arity, text): + if mods: + raise Unsupported('%s with %s' % (name, mods)) + if len(ops) != arity + 1: + raise Unsupported('%s with %d operands, expected %d' % (name, len(ops), arity + 1)) + lo, hi = self.f64_pair_destination(name, ops[0]) + value = text.format(*[self.f64_source(o) for o in ops[1:]]) + if hasattr(self, 'uniform_v'): + self.uniform_v.discard(lo) + self.uniform_v.discard(hi) + self.used_v.update((lo, hi)) + body = '{ uint lo, hi; asuint(%s, lo, hi); v%d = lo; v%d = hi; }' % (value, lo, hi) + self.emit(body if self.exec_known else 'if (exec & 1) ' + body) ~~~~ --- 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.
Makto94 commented 2026-11-25 11:02:31 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Makto94 on 2026-11-25T10:43:23Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7160084573 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2078#issuecomment-7160084573). Originally posted by [Makto94](https://github.com/Makto94) on 2026-11-25T10:43:23Z. --- 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.
thepatrickworld commented 2026-11-25 12:01:55 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-25T11:54:32Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7161664795 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2078#issuecomment-7161664795). Originally posted by [thepatrickworld](https://github.com/thepatrickworld) on 2026-11-25T11:54:32Z. --- **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._
tedin7 commented 2026-11-25 12:01:55 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T11:54:45Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7161669861 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2078#issuecomment-7161669861). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T11:54:45Z. --- 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.
upstream-sync closed this pull request 2026-11-25 14:04:38 +00:00
tedin7 commented 2026-11-25 14:05:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T13:52:12Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7164408996 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2078#issuecomment-7164408996). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T13:52:12Z. --- 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.

Pull request closed

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!2071
No description provided.