shader: lower binary16 arithmetic and integer conversions in gfx2hlsl (Part of #1723) #2066

Merged
tedin7 merged 8 commits from upstream-pr/2073 into main 2026-11-25 22:55:52 +00:00
tedin7 commented 2026-11-25 00:01:19 +00:00 (Migrated from github.com)

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


Part of #1723

What this unblocks: shaders that use 16-bit vector arithmetic (add, sub, mul, min, max, fma forms and i16/u16 conversions) now translate in gfx2hlsl instead of being refused.

Verification:

  • python3 -B tests/startup_gfx2hlsl_f16_alu_check.py on origin/main: fails with Unsupported: v_add_f16.
  • python3 -B tests/startup_gfx2hlsl_f16_alu_check.py on this branch: passes (value checks as bits, clamp, and refusals for op_sel, omod and wrong operand counts).
  • python3 -B tests/startup_gfx2hlsl_{opsel,op_refusals,operand_count,cvt_alu,refusals}_check.py: all exit 0.
  • Test registered as startup_gfx2hlsl_f16_alu in CMakeLists.txt.
  • Not run: Win2025 build and CTest (no Windows host in this session).

Notes:

  • New: v_add/sub/subrev/mul/min/max/fmac/fmamk/fmaak_f16, v_cvt_f16_i16, v_cvt_f16_u16, v_cvt_i16_f16, v_cvt_u16_f16. None existed on origin/main or in open PRs.
  • Operands are the low 16 bits. The result fills the low 16 bits and zeroes the upper half. Math runs in binary32 and rounds to binary16 (fma is not single-rounded).
  • op_sel, omod and SDWA forms are refused. clamp is accepted on binary16 results only.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6593955239 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2073). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T00:01:19Z. --- Part of #1723 What this unblocks: shaders that use 16-bit vector arithmetic (add, sub, mul, min, max, fma forms and i16/u16 conversions) now translate in gfx2hlsl instead of being refused. Verification: - `python3 -B tests/startup_gfx2hlsl_f16_alu_check.py` on origin/main: fails with `Unsupported: v_add_f16`. - `python3 -B tests/startup_gfx2hlsl_f16_alu_check.py` on this branch: passes (value checks as bits, clamp, and refusals for op_sel, omod and wrong operand counts). - `python3 -B tests/startup_gfx2hlsl_{opsel,op_refusals,operand_count,cvt_alu,refusals}_check.py`: all exit 0. - Test registered as `startup_gfx2hlsl_f16_alu` in CMakeLists.txt. - Not run: Win2025 build and CTest (no Windows host in this session). Notes: - New: v_add/sub/subrev/mul/min/max/fmac/fmamk/fmaak_f16, v_cvt_f16_i16, v_cvt_f16_u16, v_cvt_i16_f16, v_cvt_u16_f16. None existed on origin/main or in open PRs. - Operands are the low 16 bits. The result fills the low 16 bits and zeroes the upper half. Math runs in binary32 and rounds to binary16 (fma is not single-rounded). - op_sel, omod and SDWA forms are refused. clamp is accepted on binary16 results only. AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot commented 2026-11-25 01:01:29 +00:00 (Migrated from github.com)

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

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6653af27c5

ℹ️ 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:6049507441 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2073#pullrequestreview-6049507441). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T00:09:16Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `6653af27c5` <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:02 +00:00 (Migrated from github.com)

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


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:09:19.245239Z 6653af2 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:7148052244 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2073#issuecomment-7148052244). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T00:01:27Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"6653af27c57f8d7b18b72c8eb14a924c2199a6e2","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:09:19.245239Z">2026-11-25T00:09:19.245239Z</relative-time> | `6653af2` | 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:14 +00:00 (Migrated from github.com)

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

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

@@ -712,6 +714,45 @@ def lower(self, base, asm, ops, mods):
             raise Unsupported('%s requires descriptor FORMAT and DST_SEL' % base)
         raise Unsupported(base)
 
+    def half_operand(self, tok, kind):
+        """Float expression for a 16-bit operand: the low half of the register, or an inline constant."""
+        if kind == 'i16':
+            return 'float(((int(%s) & 0xffff) ^ 0x8000) - 0x8000)' % self.u(tok)
+        if kind == 'u16':
+            return 'float(%s & 0xffffu)' % self.u(tok)

P2 Badge Decode inline floating constants at the integer operand width

For a native v_cvt_f16_i16 or v_cvt_f16_u16 using inline source encoding 242, the shared disassembler prints 1.0, but self.u() supplies the binary32 word 0x3f800000 instead of the binary16 word 0x3c00. Masking its low half therefore converts zero rather than integer 15360. For example, synthetic encoding f2a2067e produces 0x0000 instead of 0x7380. Decode inline constants according to the 16-bit source width before interpreting them as signed or unsigned integers, or refuse these encodings.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688370411 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2073#discussion_r4688370411). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T00:09:16Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 722 ~~~~diff @@ -712,6 +714,45 @@ def lower(self, base, asm, ops, mods): raise Unsupported('%s requires descriptor FORMAT and DST_SEL' % base) raise Unsupported(base) + def half_operand(self, tok, kind): + """Float expression for a 16-bit operand: the low half of the register, or an inline constant.""" + if kind == 'i16': + return 'float(((int(%s) & 0xffff) ^ 0x8000) - 0x8000)' % self.u(tok) + if kind == 'u16': + return 'float(%s & 0xffffu)' % self.u(tok) ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Decode inline floating constants at the integer operand width** For a native `v_cvt_f16_i16` or `v_cvt_f16_u16` using inline source encoding 242, the shared disassembler prints `1.0`, but `self.u()` supplies the binary32 word `0x3f800000` instead of the binary16 word `0x3c00`. Masking its low half therefore converts zero rather than integer 15360. For example, synthetic encoding `f2a2067e` produces `0x0000` instead of `0x7380`. Decode inline constants according to the 16-bit source width before interpreting them as signed or unsigned integers, or refuse these encodings. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
chatgpt-codex-connector[bot commented 2026-11-25 01:02:14 +00:00 (Migrated from github.com)

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

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

@@ -712,6 +714,45 @@ def lower(self, base, asm, ops, mods):
             raise Unsupported('%s requires descriptor FORMAT and DST_SEL' % base)
         raise Unsupported(base)
 
+    def half_operand(self, tok, kind):
+        """Float expression for a 16-bit operand: the low half of the register, or an inline constant."""
+        if kind == 'i16':
+            return 'float(((int(%s) & 0xffff) ^ 0x8000) - 0x8000)' % self.u(tok)
+        if kind == 'u16':
+            return 'float(%s & 0xffffu)' % self.u(tok)
+        neg = False
+        if tok.startswith('-') and not re.match(r'-[\d.]', tok):
+            neg, tok = True, tok[1:]

P2 Badge Apply literal NEG modifiers separately from integer negation

For an e64 half instruction with NEG set on a hexadecimal literal, the shared decoder emits a token such as -0x3c01. This condition does not recognize the modifier because the token starts with -0, so self.u() instead performs two's-complement integer negation. A decoded v_add_f16_e64 v3, neg(0x3c01), v1 with v1 = 0 consequently produces 0xc3ff (-3.998046875) rather than 0xbc01 (-1.0009765625). Preserve the encoded NEG as a floating sign flip, or reject the encoding instead of silently changing the operand.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688370415 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2073#discussion_r4688370415). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T00:09:16Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 725 ~~~~diff @@ -712,6 +714,45 @@ def lower(self, base, asm, ops, mods): raise Unsupported('%s requires descriptor FORMAT and DST_SEL' % base) raise Unsupported(base) + def half_operand(self, tok, kind): + """Float expression for a 16-bit operand: the low half of the register, or an inline constant.""" + if kind == 'i16': + return 'float(((int(%s) & 0xffff) ^ 0x8000) - 0x8000)' % self.u(tok) + if kind == 'u16': + return 'float(%s & 0xffffu)' % self.u(tok) + neg = False + if tok.startswith('-') and not re.match(r'-[\d.]', tok): + neg, tok = True, tok[1:] ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Apply literal NEG modifiers separately from integer negation** For an e64 half instruction with NEG set on a hexadecimal literal, the shared decoder emits a token such as `-0x3c01`. This condition does not recognize the modifier because the token starts with `-0`, so `self.u()` instead performs two's-complement integer negation. A decoded `v_add_f16_e64 v3, neg(0x3c01), v1` with `v1 = 0` consequently produces `0xc3ff` (-3.998046875) rather than `0xbc01` (-1.0009765625). Preserve the encoded NEG as a floating sign flip, or reject the encoding instead of silently changing the operand. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
chatgpt-codex-connector[bot commented 2026-11-25 01:02:14 +00:00 (Migrated from github.com)

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

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

@@ -712,6 +714,45 @@ def lower(self, base, asm, ops, mods):
             raise Unsupported('%s requires descriptor FORMAT and DST_SEL' % base)
         raise Unsupported(base)
 
+    def half_operand(self, tok, kind):
+        """Float expression for a 16-bit operand: the low half of the register, or an inline constant."""
+        if kind == 'i16':
+            return 'float(((int(%s) & 0xffff) ^ 0x8000) - 0x8000)' % self.u(tok)
+        if kind == 'u16':
+            return 'float(%s & 0xffffu)' % self.u(tok)
+        neg = False
+        if tok.startswith('-') and not re.match(r'-[\d.]', tok):
+            neg, tok = True, tok[1:]
+        absolute = tok.startswith('|') and tok.endswith('|')
+        if absolute:
+            tok = tok[1:-1]
+        if tok in FLOATS:
+            text = repr(FLOATS[tok])

P2 Badge Quantize inline half constants before performing arithmetic

For inline source encoding 248 (0.15915494), emitting the binary32 value from FLOATS does not reproduce the native binary16 operand, which is 0x3118 (0.1591796875), as already recorded in pixel_aot.INLINE_F16. For example, v_mul_f16_e32 v3, 0.15915494, v1 with v1 = 0x3002 should produce 0x251b, but this lowering produces 0x251a. Widen the binary16 inline-constant value before applying arithmetic; rounding only the final result is not equivalent.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688370422 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2073#discussion_r4688370422). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T00:09:16Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 730 ~~~~diff @@ -712,6 +714,45 @@ def lower(self, base, asm, ops, mods): raise Unsupported('%s requires descriptor FORMAT and DST_SEL' % base) raise Unsupported(base) + def half_operand(self, tok, kind): + """Float expression for a 16-bit operand: the low half of the register, or an inline constant.""" + if kind == 'i16': + return 'float(((int(%s) & 0xffff) ^ 0x8000) - 0x8000)' % self.u(tok) + if kind == 'u16': + return 'float(%s & 0xffffu)' % self.u(tok) + neg = False + if tok.startswith('-') and not re.match(r'-[\d.]', tok): + neg, tok = True, tok[1:] + absolute = tok.startswith('|') and tok.endswith('|') + if absolute: + tok = tok[1:-1] + if tok in FLOATS: + text = repr(FLOATS[tok]) ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Quantize inline half constants before performing arithmetic** For inline source encoding 248 (`0.15915494`), emitting the binary32 value from `FLOATS` does not reproduce the native binary16 operand, which is `0x3118` (0.1591796875), as already recorded in `pixel_aot.INLINE_F16`. For example, `v_mul_f16_e32 v3, 0.15915494, v1` with `v1 = 0x3002` should produce `0x251b`, but this lowering produces `0x251a`. Widen the binary16 inline-constant value before applying arithmetic; rounding only the final result is not equivalent. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
tedin7 commented 2026-11-25 01:02:21 +00:00 (Migrated from github.com)

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

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

@@ -712,6 +714,45 @@ def lower(self, base, asm, ops, mods):
             raise Unsupported('%s requires descriptor FORMAT and DST_SEL' % base)
         raise Unsupported(base)
 
+    def half_operand(self, tok, kind):
+        """Float expression for a 16-bit operand: the low half of the register, or an inline constant."""
+        if kind == 'i16':
+            return 'float(((int(%s) & 0xffff) ^ 0x8000) - 0x8000)' % self.u(tok)
+        if kind == 'u16':
+            return 'float(%s & 0xffffu)' % self.u(tok)

Fixed in 098a0c49 (rebased on main; pending host push): inline float constants at i16/u16 width are now binary16 words, a negated hex literal is a float sign flip, and 0.15915494 widens from binary16 before the arithmetic. Covered by new cases in tests/startup_gfx2hlsl_f16_alu_check.py (ran locally, passes).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688764034 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2073#discussion_r4688764034). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T01:02:11Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 722 ~~~~diff @@ -712,6 +714,45 @@ def lower(self, base, asm, ops, mods): raise Unsupported('%s requires descriptor FORMAT and DST_SEL' % base) raise Unsupported(base) + def half_operand(self, tok, kind): + """Float expression for a 16-bit operand: the low half of the register, or an inline constant.""" + if kind == 'i16': + return 'float(((int(%s) & 0xffff) ^ 0x8000) - 0x8000)' % self.u(tok) + if kind == 'u16': + return 'float(%s & 0xffffu)' % self.u(tok) ~~~~ --- Fixed in 098a0c49 (rebased on main; pending host push): inline float constants at i16/u16 width are now binary16 words, a negated hex literal is a float sign flip, and 0.15915494 widens from binary16 before the arithmetic. Covered by new cases in tests/startup_gfx2hlsl_f16_alu_check.py (ran locally, passes). AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 01:02:21 +00:00 (Migrated from github.com)

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

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

@@ -712,6 +714,45 @@ def lower(self, base, asm, ops, mods):
             raise Unsupported('%s requires descriptor FORMAT and DST_SEL' % base)
         raise Unsupported(base)
 
+    def half_operand(self, tok, kind):
+        """Float expression for a 16-bit operand: the low half of the register, or an inline constant."""
+        if kind == 'i16':
+            return 'float(((int(%s) & 0xffff) ^ 0x8000) - 0x8000)' % self.u(tok)
+        if kind == 'u16':
+            return 'float(%s & 0xffffu)' % self.u(tok)
+        neg = False
+        if tok.startswith('-') and not re.match(r'-[\d.]', tok):
+            neg, tok = True, tok[1:]

Fixed in 098a0c49 (rebased on main; pending host push): inline float constants at i16/u16 width are now binary16 words, a negated hex literal is a float sign flip, and 0.15915494 widens from binary16 before the arithmetic. Covered by new cases in tests/startup_gfx2hlsl_f16_alu_check.py (ran locally, passes).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688764228 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2073#discussion_r4688764228). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T01:02:13Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 725 ~~~~diff @@ -712,6 +714,45 @@ def lower(self, base, asm, ops, mods): raise Unsupported('%s requires descriptor FORMAT and DST_SEL' % base) raise Unsupported(base) + def half_operand(self, tok, kind): + """Float expression for a 16-bit operand: the low half of the register, or an inline constant.""" + if kind == 'i16': + return 'float(((int(%s) & 0xffff) ^ 0x8000) - 0x8000)' % self.u(tok) + if kind == 'u16': + return 'float(%s & 0xffffu)' % self.u(tok) + neg = False + if tok.startswith('-') and not re.match(r'-[\d.]', tok): + neg, tok = True, tok[1:] ~~~~ --- Fixed in 098a0c49 (rebased on main; pending host push): inline float constants at i16/u16 width are now binary16 words, a negated hex literal is a float sign flip, and 0.15915494 widens from binary16 before the arithmetic. Covered by new cases in tests/startup_gfx2hlsl_f16_alu_check.py (ran locally, passes). AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 01:02:21 +00:00 (Migrated from github.com)

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

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

@@ -712,6 +714,45 @@ def lower(self, base, asm, ops, mods):
             raise Unsupported('%s requires descriptor FORMAT and DST_SEL' % base)
         raise Unsupported(base)
 
+    def half_operand(self, tok, kind):
+        """Float expression for a 16-bit operand: the low half of the register, or an inline constant."""
+        if kind == 'i16':
+            return 'float(((int(%s) & 0xffff) ^ 0x8000) - 0x8000)' % self.u(tok)
+        if kind == 'u16':
+            return 'float(%s & 0xffffu)' % self.u(tok)
+        neg = False
+        if tok.startswith('-') and not re.match(r'-[\d.]', tok):
+            neg, tok = True, tok[1:]
+        absolute = tok.startswith('|') and tok.endswith('|')
+        if absolute:
+            tok = tok[1:-1]
+        if tok in FLOATS:
+            text = repr(FLOATS[tok])

Fixed in 098a0c49 (rebased on main; pending host push): inline float constants at i16/u16 width are now binary16 words, a negated hex literal is a float sign flip, and 0.15915494 widens from binary16 before the arithmetic. Covered by new cases in tests/startup_gfx2hlsl_f16_alu_check.py (ran locally, passes).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688764395 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2073#discussion_r4688764395). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T01:02:14Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 730 ~~~~diff @@ -712,6 +714,45 @@ def lower(self, base, asm, ops, mods): raise Unsupported('%s requires descriptor FORMAT and DST_SEL' % base) raise Unsupported(base) + def half_operand(self, tok, kind): + """Float expression for a 16-bit operand: the low half of the register, or an inline constant.""" + if kind == 'i16': + return 'float(((int(%s) & 0xffff) ^ 0x8000) - 0x8000)' % self.u(tok) + if kind == 'u16': + return 'float(%s & 0xffffu)' % self.u(tok) + neg = False + if tok.startswith('-') and not re.match(r'-[\d.]', tok): + neg, tok = True, tok[1:] + absolute = tok.startswith('|') and tok.endswith('|') + if absolute: + tok = tok[1:-1] + if tok in FLOATS: + text = repr(FLOATS[tok]) ~~~~ --- Fixed in 098a0c49 (rebased on main; pending host push): inline float constants at i16/u16 width are now binary16 words, a negated hex literal is a float sign flip, and 0.15915494 widens from binary16 before the arithmetic. Covered by new cases in tests/startup_gfx2hlsl_f16_alu_check.py (ran locally, passes). AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 02:01:38 +00:00 (Migrated from github.com)

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

Review: COMMENTED


No description provided.

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

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

Review: COMMENTED


No description provided.

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

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

Review: COMMENTED


No description provided.

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

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


Independent run on AMD, and one divergence the fixture cannot reach

Their draw passes here: startup_gfx2hlsl_f16_alu_draw_check.py draw … hardware … exits 0 on the AMD Radeon RX 9070 XT (1002:7550, driver 32.0.32029.2010), with FXC and DXC, head 61447651. So the positive half holds on a third adapter, integer conversions included — that is where I expected trouble and there was none.

v_fmac_f16 is emitted as f16rn(a*b + c). The product of two binary16 values is exact in binary32, but the sum is not: it can need more than 24 bits, so the binary32 result is rounded and then rounded again into binary16. The guide describes V_FMAC_F16 as fused, 0.5 ULP precision, which is one rounding. Where the two disagree, the translation is one binary16 unit off.

Measured on the card and on WARP, under FXC and DXC, all four lanes:

a b c exact, one rounding translation
4a54 1ef4 4e2d 0x4e33 0x4e32
51ea bf3e 1d5f 0xd55b 0xd55a
2bd5 be83 4528 0x450f 0x450e
3915 387a 4b71 0x4b9f 0x4b9e

The expected column is this PR's own reference, the exact rational model, so the disagreement is between the model and the lowering rather than between two opinions of mine. A one-bit corruption of the expected word is rejected by the same harness, so it does discriminate.

The triples are not exotic: nine in 400 000 random binary16 triples, about 2e-5. The fixture does not reach them because ARITH and ACC only combine values where the exact sum and the binary32 sum agree (1*2+1, 100*1000+100, …), so the exact model and the lowering never conflict on any input it draws. v_fmamk_f16 and v_fmaak_f16 share the same template and V_FMA_F16 is described the same way; I did not measure those two.

What could be done is a design choice, so I am only listing it. A compensated sum in binary32 (TwoSum over a*b and c) recovers the exact sum and lets the single rounding be done explicitly; the alternative is to state the 1-ULP divergence as a known limit of the lowering instead of claiming the fused accuracy. Either way a control carrying a triple from this class would save the next reader the trouble of finding it again.

Limits. AMD and WARP only, no NVIDIA here; and the native v_fmac_f16 cannot be executed from a desktop shader, so the "one rounding" side rests on the guide's wording rather than on a run, exactly as the reference model does.

AI-assisted; runs executed on the machine above.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7150083825 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2073#issuecomment-7150083825). Originally posted by [thepatrickworld](https://github.com/thepatrickworld) on 2026-11-25T01:53:44Z. --- **Independent run on AMD, and one divergence the fixture cannot reach** Their draw passes here: `startup_gfx2hlsl_f16_alu_draw_check.py draw … hardware …` exits 0 on the AMD Radeon RX 9070 XT (`1002:7550`, driver `32.0.32029.2010`), with FXC and DXC, head `61447651`. So the positive half holds on a third adapter, integer conversions included — that is where I expected trouble and there was none. **`v_fmac_f16` is emitted as `f16rn(a*b + c)`.** The product of two binary16 values is exact in binary32, but the sum is not: it can need more than 24 bits, so the binary32 result is rounded and then rounded again into binary16. The guide describes `V_FMAC_F16` as fused, 0.5 ULP precision, which is one rounding. Where the two disagree, the translation is one binary16 unit off. Measured on the card and on WARP, under FXC and DXC, all four lanes: | a | b | c | exact, one rounding | translation | |---|---|---|---|---| | `4a54` | `1ef4` | `4e2d` | `0x4e33` | `0x4e32` | | `51ea` | `bf3e` | `1d5f` | `0xd55b` | `0xd55a` | | `2bd5` | `be83` | `4528` | `0x450f` | `0x450e` | | `3915` | `387a` | `4b71` | `0x4b9f` | `0x4b9e` | The expected column is this PR's own reference, the exact rational model, so the disagreement is between the model and the lowering rather than between two opinions of mine. A one-bit corruption of the expected word is rejected by the same harness, so it does discriminate. The triples are not exotic: nine in 400 000 random binary16 triples, about 2e-5. The fixture does not reach them because `ARITH` and `ACC` only combine values where the exact sum and the binary32 sum agree (`1*2+1`, `100*1000+100`, …), so the exact model and the lowering never conflict on any input it draws. `v_fmamk_f16` and `v_fmaak_f16` share the same template and `V_FMA_F16` is described the same way; I did not measure those two. **What could be done** is a design choice, so I am only listing it. A compensated sum in binary32 (TwoSum over `a*b` and `c`) recovers the exact sum and lets the single rounding be done explicitly; the alternative is to state the 1-ULP divergence as a known limit of the lowering instead of claiming the fused accuracy. Either way a control carrying a triple from this class would save the next reader the trouble of finding it again. **Limits.** AMD and WARP only, no NVIDIA here; and the native `v_fmac_f16` cannot be executed from a desktop shader, so the "one rounding" side rests on the guide's wording rather than on a run, exactly as the reference model does. _AI-assisted; runs executed on the machine above._
thepatrickworld commented 2026-11-25 03:01:21 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-25T02:10:41Z.


Measured the new head 08c5844f with the same four triples: they now agree.

f16rn(a*b + c) gave 4e32, d55a, 450e, 4b9e here; with fma16o the same four lanes come back

startup_flat_param words=00004e33,0000d55b,0000450f,00004b9f

which is the exact model's value, under FXC and DXC, on hardware and on WARP. The one-bit corruption control still fails, so the harness is still discriminating — the change is in the value, not in the check.

TwoSum plus round-to-odd is the right shape for this: p is exact, so the SumErr of s = p + c recovers what binary32 dropped, and moving an inexact even result to its odd neighbour toward the true value means the f16rn that follows is the only rounding left. The precise qualifiers matter as much as the algebra — without them a compiler is free to reassociate the compensation away, and FXC is allowed to contract.

One suggestion. The fixture still does not contain a triple of this class: ARITH/ACC only combine values where the exact sum and the binary32 sum agree, so reverting fma16o to f16rn(a*b + c) would leave every draw in this PR green. The four triples above are free to add and they are the only thing in the file that would notice. v_fmamk_f16 and v_fmaak_f16 now share the helper, which covers them by construction; they are still unmeasured on hardware, since the fixture drives v_fmac_f16 only.

Limits. AMD and WARP, no NVIDIA here; and v_fmac_f16 itself is never executed by these draws, so what passes is the value the translated shader produces.

AI-assisted; runs executed on the machine above.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7150408271 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2073#issuecomment-7150408271). Originally posted by [thepatrickworld](https://github.com/thepatrickworld) on 2026-11-25T02:10:41Z. --- **Measured the new head `08c5844f` with the same four triples: they now agree.** `f16rn(a*b + c)` gave `4e32, d55a, 450e, 4b9e` here; with `fma16o` the same four lanes come back ``` startup_flat_param words=00004e33,0000d55b,0000450f,00004b9f ``` which is the exact model's value, under FXC and DXC, on hardware and on WARP. The one-bit corruption control still fails, so the harness is still discriminating — the change is in the value, not in the check. TwoSum plus round-to-odd is the right shape for this: `p` is exact, so the SumErr of `s = p + c` recovers what binary32 dropped, and moving an inexact even result to its odd neighbour toward the true value means the `f16rn` that follows is the only rounding left. The `precise` qualifiers matter as much as the algebra — without them a compiler is free to reassociate the compensation away, and FXC is allowed to contract. **One suggestion.** The fixture still does not contain a triple of this class: `ARITH`/`ACC` only combine values where the exact sum and the binary32 sum agree, so reverting `fma16o` to `f16rn(a*b + c)` would leave every draw in this PR green. The four triples above are free to add and they are the only thing in the file that would notice. `v_fmamk_f16` and `v_fmaak_f16` now share the helper, which covers them by construction; they are still unmeasured on hardware, since the fixture drives `v_fmac_f16` only. **Limits.** AMD and WARP, no NVIDIA here; and `v_fmac_f16` itself is never executed by these draws, so what passes is the value the translated shader produces. _AI-assisted; runs executed on the machine above._
tedin7 commented 2026-11-25 03:01:23 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T02:42:39Z.


Thank you for the independent AMD run and the four measured triples. You were right.

Fixed in 08c5844f: v_fmac_f16, v_fmamk_f16 and v_fmaak_f16 now go through a small helper. It takes the exact binary32 product, recovers the sum error with TwoSum, and moves an inexact even result to its odd neighbour (round to odd). The single f16rn that follows is then the only rounding that can change the result.

Counterexamples added (4a54*1ef4+4e2d, 51ea*bf3e+1d5f, 2bd5*be83+4528, 3915*387a+4b71, expected 4e33, d55b, 450f, 4b9f):

  • tests/startup_gfx2hlsl_f16_alu_check.py: the four triples run through the emitted statement with a model of the helper.
  • tests/startup_gfx2hlsl_f16_alu_draw_check.py: they replace four of the eight v_fmac_f16 lanes in the real draw, plus model and lane-coverage controls.

Verification on Win2025 (WARP, FXC and DXC):

  • x2w_pipe.py win2025 2073 --force --targets offscreen_check --regex 'startup_gfx2hlsl_f16_alu_draw_(controls|warp)|startup_translator': dev 3/3 passed, release 3/3 passed.
  • Linux: startup_gfx2hlsl_f16_alu_check.py, startup_gfx2hlsl_f16_alu_draw_check.py, startup_translator_check.py, docs_links_check.py all pass.
  • The default full-scope run overflows the Windows command-line limit, so I used focused targets.
  • I have no AMD hardware here. If you re-run the draw on the RX 9070 XT, that would confirm the hardware side.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7151078242 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2073#issuecomment-7151078242). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T02:42:39Z. --- Thank you for the independent AMD run and the four measured triples. You were right. Fixed in `08c5844f`: `v_fmac_f16`, `v_fmamk_f16` and `v_fmaak_f16` now go through a small helper. It takes the exact binary32 product, recovers the sum error with TwoSum, and moves an inexact even result to its odd neighbour (round to odd). The single `f16rn` that follows is then the only rounding that can change the result. Counterexamples added (`4a54*1ef4+4e2d`, `51ea*bf3e+1d5f`, `2bd5*be83+4528`, `3915*387a+4b71`, expected `4e33`, `d55b`, `450f`, `4b9f`): - `tests/startup_gfx2hlsl_f16_alu_check.py`: the four triples run through the emitted statement with a model of the helper. - `tests/startup_gfx2hlsl_f16_alu_draw_check.py`: they replace four of the eight `v_fmac_f16` lanes in the real draw, plus model and lane-coverage controls. Verification on Win2025 (WARP, FXC and DXC): - `x2w_pipe.py win2025 2073 --force --targets offscreen_check --regex 'startup_gfx2hlsl_f16_alu_draw_(controls|warp)|startup_translator'`: dev 3/3 passed, release 3/3 passed. - Linux: `startup_gfx2hlsl_f16_alu_check.py`, `startup_gfx2hlsl_f16_alu_draw_check.py`, `startup_translator_check.py`, `docs_links_check.py` all pass. - The default full-scope run overflows the Windows command-line limit, so I used focused targets. - I have no AMD hardware here. If you re-run the draw on the RX 9070 XT, that would confirm the hardware side. AI-assisted; commands listed were executed locally.
Makto94 commented 2026-11-25 13:00:57 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Makto94 on 2026-11-25T12:02:56Z.


NVIDIA run at 37b610ca: startup_gfx2hlsl_f16_alu_draw_hardware fails on one draw, fxc v_fmac_f16 set 0

I ran the current head on an NVIDIA GeForce RTX 3070 Ti. This is the first NVIDIA run in this thread. @thepatrickworld's run of the fma16o form (AMD and WARP, 02:10Z) was on 08c5844f; the fma16o helper text is identical at 08c5844f and 37b610ca.

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

Two runs gave the same result. Only fxc v_fmac_f16 set 0 fails:

fxc v_fmac_f16 set 0 MISMATCH inputs [(2882357844, 1515855604, 3735899693), (1515868650, 3735928638, 305405279), (3735890901, 305446531, 2882356520), (305412373, 2882353274, 1515866993)]
startup_flat_param mismatch expected=00004e33,0000d55b,0000450f,00004b9f actual=00004e32,0000d55a,0000450e,00004b9e
AssertionError: draw mismatches: fxc v_fmac_f16 set 0

Every other draw passes in both runs: 26 per run (13 ops, 2 sets each) for FXC and 26 for DXC, minus this one. That includes v_fmamk_f16 and v_fmaak_f16, sets 0 and 1, with FXC and with DXC. They call the same helper; I did not check whether their inputs reach the correction. debug_errors=0 debug_warnings=0 on all 52 draws in each run.

Controls

  • DXC on the same card passes this draw: dxc v_fmac_f16 set 0: 00004e33,0000d55b,0000450f,00004b9f.
  • FXC on WARP reads the expected words: fxc v_fmac_f16 set 0: 00004e33,0000d55b,0000450f,00004b9f (startup_gfx2hlsl_f16_alu_draw_warp). The check uses the same HLSL and the same fxc command line for warp and hardware.
  • The CPU test and the draw controls also pass (startup_gfx2hlsl_f16_alu, startup_gfx2hlsl_f16_alu_draw_controls, startup_gfx2hlsl_f16_alu_draw_warp: 3/3).

What FXC emits

fxc /nologo /T ps_5_1 /E main keeps the seven float steps of the fma16o helper separate, each marked [precise]:

mul [precise] r0.xyzw, r0.xyzw, r1.xyzw
add [precise] r1.xyzw, r2.xyzw, r0.xyzw
add [precise] r3.xyzw, -r0.xyzw, r1.xyzw
add [precise] r4.xyzw, r1.xyzw, -r3.xyzw
add [precise] r0.xyzw, r0.xyzw, -r4.xyzw
add [precise] r2.xyzw, r2.xyzw, -r3.xyzw
add [precise] r0.xyzw, r0.xyzw, r2.xyzw

I also compiled the same shader with /Gis and drew it on the RTX. I drew the default build the same way. Both give 00004e32,0000d55a,0000450e,00004b9e, so /Gis makes no difference here. The seven steps are [precise] in both builds.

Thread

The failing words match what thepatrickworld reported for the previous form: "f16rn(a*b + c) gave 4e32, d55a, 450e, 4b9e here" (02:10Z comment).

Hypothesis, not measured: on this card the correction term does not seem to have any effect. I have not isolated the cause and I do not propose a change.

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. Both ctest runs were serial on an idle machine. 0 capability skips (77). One card and one driver; AMD and Intel are not measured by me at this head.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7161849301 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2073#issuecomment-7161849301). Originally posted by [Makto94](https://github.com/Makto94) on 2026-11-25T12:02:56Z. --- **NVIDIA run at `37b610ca`: `startup_gfx2hlsl_f16_alu_draw_hardware` fails on one draw, `fxc v_fmac_f16 set 0`** I ran the current head on an NVIDIA GeForce RTX 3070 Ti. This is the first NVIDIA run in this thread. @thepatrickworld's run of the `fma16o` form (AMD and WARP, 02:10Z) was on `08c5844f`; the `fma16o` helper text is identical at `08c5844f` and `37b610ca`. ``` .\tools\dev.ps1; ctest --preset dev --no-tests=error -j1 -R '^startup_gfx2hlsl_f16_alu_draw_hardware$' -V ``` Two runs gave the same result. Only `fxc v_fmac_f16 set 0` fails: ``` fxc v_fmac_f16 set 0 MISMATCH inputs [(2882357844, 1515855604, 3735899693), (1515868650, 3735928638, 305405279), (3735890901, 305446531, 2882356520), (305412373, 2882353274, 1515866993)] startup_flat_param mismatch expected=00004e33,0000d55b,0000450f,00004b9f actual=00004e32,0000d55a,0000450e,00004b9e AssertionError: draw mismatches: fxc v_fmac_f16 set 0 ``` Every other draw passes in both runs: 26 per run (13 ops, 2 sets each) for FXC and 26 for DXC, minus this one. That includes `v_fmamk_f16` and `v_fmaak_f16`, sets 0 and 1, with FXC and with DXC. They call the same helper; I did not check whether their inputs reach the correction. `debug_errors=0 debug_warnings=0` on all 52 draws in each run. **Controls** - DXC on the same card passes this draw: `dxc v_fmac_f16 set 0: 00004e33,0000d55b,0000450f,00004b9f`. - FXC on WARP reads the expected words: `fxc v_fmac_f16 set 0: 00004e33,0000d55b,0000450f,00004b9f` (`startup_gfx2hlsl_f16_alu_draw_warp`). The check uses the same HLSL and the same fxc command line for `warp` and `hardware`. - The CPU test and the draw controls also pass (`startup_gfx2hlsl_f16_alu`, `startup_gfx2hlsl_f16_alu_draw_controls`, `startup_gfx2hlsl_f16_alu_draw_warp`: 3/3). **What FXC emits** `fxc /nologo /T ps_5_1 /E main` keeps the seven float steps of the `fma16o` helper separate, each marked `[precise]`: ``` mul [precise] r0.xyzw, r0.xyzw, r1.xyzw add [precise] r1.xyzw, r2.xyzw, r0.xyzw add [precise] r3.xyzw, -r0.xyzw, r1.xyzw add [precise] r4.xyzw, r1.xyzw, -r3.xyzw add [precise] r0.xyzw, r0.xyzw, -r4.xyzw add [precise] r2.xyzw, r2.xyzw, -r3.xyzw add [precise] r0.xyzw, r0.xyzw, r2.xyzw ``` I also compiled the same shader with `/Gis` and drew it on the RTX. I drew the default build the same way. Both give `00004e32,0000d55a,0000450e,00004b9e`, so `/Gis` makes no difference here. The seven steps are `[precise]` in both builds. **Thread** The failing words match what thepatrickworld reported for the previous form: "`f16rn(a*b + c)` gave `4e32, d55a, 450e, 4b9e` here" (02:10Z comment). **Hypothesis, not measured:** on this card the correction term does not seem to have any effect. I have not isolated the cause and I do not propose a change. **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. Both ctest runs were serial on an idle machine. 0 capability skips (77). One card and one driver; AMD and Intel are not measured by me at this head.
Makto94 commented 2026-11-25 13:00:58 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Makto94 on 2026-11-25T12:15:35Z.


Follow-up to my NVIDIA report: where the fxc v_fmac_f16 set 0 difference appears to start

I drew the same v_fmac_f16 set 0 inputs with a probe that exports one intermediate of the fma16o helper instead of the final binary16 word. The probe replaces the four lines v12..v15 (vN = f16rn(fma16o(...))) with vN = asuint(probe16(...)). probe16 has the same four precise lines as fma16o and returns p, s or e by variant:

float probe16(float a, float b, float c) {
    precise float p = a * b;
    precise float s = p + c;
    precise float t = s - p;
    precise float e = (p - (s - t)) + (c - t);
    return e;   // or s, or p
}

Compiled as in my previous comment: fxc /nologo /T ps_5_1 /E main (no /Gis). In the e variant fxc keeps the four precise lines as separate [precise] mul/add instructions (seven in total, as for fma16o).

Words exported for set 0, lanes 0 to 3. "WARP read" equals the CPU value in each case:

var expected (CPU) / WARP read RTX 3070 Ti read
p 3db00040,c2ab52b0,bdcbfffc,3eb60010 same
s 41c65000,c2ab5000,40a1d000,4173d000 same
e 35000000,b6800000,33000000,35000000 00000000,00000000,00000000,00000000

With e == 0 the helper returns s. Each s word is exactly halfway between two consecutive binary16 values, and round-to-nearest-even on those four s words gives 4e32,d55a,450e,4b9e, which are exactly the words the test read on the RTX. The expected 4e33,d55b,450f,4b9f need the correction e to move s off the tie.

My hypothesis, not a diagnosis: on this card the error term seems to be simplified to zero in this shader. I am not claiming a cause or proposing a change.

Limits: one draw per variant on the RTX; the RTX draws were on an idle machine. Only FXC without /Gis was probed. DXC was not probed. I did not measure t, nor the two halves of e separately. The WARP column is one draw per variant, with debug_errors=0. Each variant is a separate shader, so p and s were not read from the shader that reads e. Environment as in the linked report (RTX 3070 Ti, driver 32.0.16.2101, head 37b610ca); debug_errors=0 in every RTX probe draw.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7162131372 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2073#issuecomment-7162131372). Originally posted by [Makto94](https://github.com/Makto94) on 2026-11-25T12:15:35Z. --- **Follow-up to my [NVIDIA report](https://github.com/R0Y00/Xbox2Windows/pull/2073#issuecomment-7161849301): where the `fxc v_fmac_f16 set 0` difference appears to start** I drew the same `v_fmac_f16` set 0 inputs with a probe that exports one intermediate of the `fma16o` helper instead of the final binary16 word. The probe replaces the four lines `v12`..`v15` (`vN = f16rn(fma16o(...))`) with `vN = asuint(probe16(...))`. `probe16` has the same four `precise` lines as `fma16o` and returns `p`, `s` or `e` by variant: ```hlsl float probe16(float a, float b, float c) { precise float p = a * b; precise float s = p + c; precise float t = s - p; precise float e = (p - (s - t)) + (c - t); return e; // or s, or p } ``` Compiled as in my previous comment: `fxc /nologo /T ps_5_1 /E main` (no `/Gis`). In the `e` variant fxc keeps the four `precise` lines as separate `[precise]` `mul`/`add` instructions (seven in total, as for `fma16o`). Words exported for set 0, lanes 0 to 3. "WARP read" equals the CPU value in each case: | var | expected (CPU) / WARP read | RTX 3070 Ti read | |---|---|---| | p | `3db00040,c2ab52b0,bdcbfffc,3eb60010` | same | | s | `41c65000,c2ab5000,40a1d000,4173d000` | same | | e | `35000000,b6800000,33000000,35000000` | `00000000,00000000,00000000,00000000` | With `e == 0` the helper returns `s`. Each `s` word is exactly halfway between two consecutive binary16 values, and round-to-nearest-even on those four `s` words gives `4e32,d55a,450e,4b9e`, which are exactly the words the test read on the RTX. The expected `4e33,d55b,450f,4b9f` need the correction `e` to move `s` off the tie. My hypothesis, not a diagnosis: on this card the error term seems to be simplified to zero in this shader. I am not claiming a cause or proposing a change. Limits: one draw per variant on the RTX; the RTX draws were on an idle machine. Only FXC without `/Gis` was probed. DXC was not probed. I did not measure `t`, nor the two halves of `e` separately. The WARP column is one draw per variant, with `debug_errors=0`. Each variant is a separate shader, so `p` and `s` were not read from the shader that reads `e`. Environment as in the linked report (RTX 3070 Ti, driver 32.0.16.2101, head `37b610ca`); `debug_errors=0` in every RTX probe draw.
tedin7 commented 2026-11-25 13:01:03 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T12:58:18Z.


Thanks for the two measurements. They pin it down: on the RTX the error term e of the float TwoSum comes back 0, so the helper returns s, which sits on a binary16 tie and rounds to even (4e32,d55a,450e,4b9e). WARP and DXC keep the term. So the float TwoSum in fma16o is not safe on a driver that rewrites floating-point algebra, even with precise on every line.

Change at b87b5ae6fd: fma16o no longer uses floats for the correction. For finite operands it calls the existing integer fma16_rne (the helper pixel_aot.py already uses for packed fma), which does a*b+c with a single round-to-nearest-even on the binary16 encodings in 32-bit integer arithmetic. Infinity and NaN operands keep the binary32 path. The call sites (v_fmac_f16, v_fmamk_f16, v_fmaak_f16) and the startup_gfx2hlsl_f16_alu_draw_hardware / _warp readback tests are unchanged.

What I could not do: Linux has no GPU, so I did not reproduce the NVIDIA mismatch here, and I have not run the draw tests. The hardware run on your card at b87b5ae6fd is the check that decides this. The Python model in startup_gfx2hlsl_f16_alu_check.py now models the contract (one rounding, ties to even, exact rational reference) and still holds the four #2073 words 4e33,d55b,450f,4b9f.

Commands run locally:

  • python3 -I tests/startup_gfx2hlsl_f16_alu_check.py (ok)
  • python3 -I tests/startup_gfx2hlsl_f16_alu_draw_check.py (ok)
  • python3 -I tests/startup_gfx2hlsl_cmp_class_f16_check.py (ok)
  • python3 -I tests/startup_gfx2hlsl_compute_check.py (ok)
  • 200000 random finite binary16 triples: model vs exact rational reference, 0 differences

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7163109037 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2073#issuecomment-7163109037). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T12:58:18Z. --- Thanks for the two measurements. They pin it down: on the RTX the error term `e` of the float TwoSum comes back 0, so the helper returns `s`, which sits on a binary16 tie and rounds to even (`4e32,d55a,450e,4b9e`). WARP and DXC keep the term. So the float TwoSum in `fma16o` is not safe on a driver that rewrites floating-point algebra, even with `precise` on every line. Change at b87b5ae6fd: `fma16o` no longer uses floats for the correction. For finite operands it calls the existing integer `fma16_rne` (the helper `pixel_aot.py` already uses for packed fma), which does a*b+c with a single round-to-nearest-even on the binary16 encodings in 32-bit integer arithmetic. Infinity and NaN operands keep the binary32 path. The call sites (`v_fmac_f16`, `v_fmamk_f16`, `v_fmaak_f16`) and the `startup_gfx2hlsl_f16_alu_draw_hardware` / `_warp` readback tests are unchanged. What I could not do: Linux has no GPU, so I did not reproduce the NVIDIA mismatch here, and I have not run the draw tests. The hardware run on your card at b87b5ae6fd is the check that decides this. The Python model in `startup_gfx2hlsl_f16_alu_check.py` now models the contract (one rounding, ties to even, exact rational reference) and still holds the four #2073 words `4e33,d55b,450f,4b9f`. Commands run locally: - `python3 -I tests/startup_gfx2hlsl_f16_alu_check.py` (ok) - `python3 -I tests/startup_gfx2hlsl_f16_alu_draw_check.py` (ok) - `python3 -I tests/startup_gfx2hlsl_cmp_class_f16_check.py` (ok) - `python3 -I tests/startup_gfx2hlsl_compute_check.py` (ok) - 200000 random finite binary16 triples: model vs exact rational reference, 0 differences AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-25 14:04:36 +00:00
Makto94 commented 2026-11-25 14:05:09 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Makto94 on 2026-11-25T13:24:00Z.


RTX 3070 Ti run at b87b5ae6, as you asked: startup_gfx2hlsl_f16_alu_draw_hardware passes. The fxc v_fmac_f16 set 0 mismatch from my run at 37b610ca does not reproduce in this run:

fxc v_fmac_f16 set 0: 00004e33,0000d55b,0000450f,00004b9f
dxc v_fmac_f16 set 0: 00004e33,0000d55b,0000450f,00004b9f
.\tools\dev.ps1; ctest --preset dev --no-tests=error -j1 -R '^startup_gfx2hlsl_f16_alu_draw_hardware$' -V

The log has 26 fxc and 26 dxc result lines (13 ops x 2 sets), including v_fmamk_f16 and v_fmaak_f16; no debug_errors= line has a nonzero value. CPU, control and WARP tests (ctest --preset dev --no-tests=error -j1 -R 'f16_alu' -E '_hardware$' -V): 100% tests passed, 0 tests failed out of 3.

The C++ binaries were built at 37b610ca; between 37b610ca and b87b5ae6 only tools/startup/gfx2hlsl.py and tests/startup_gfx2hlsl_f16_alu_check.py change, so I did not rebuild. One hardware run, one card and one driver. The drawn inputs have no Inf or NaN operand, so the binary32 path of the new fma16o was not drawn.

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; the hardware run was serial on an idle machine; 0 capability skips (77).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7163720909 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2073#issuecomment-7163720909). Originally posted by [Makto94](https://github.com/Makto94) on 2026-11-25T13:24:00Z. --- RTX 3070 Ti run at `b87b5ae6`, as you asked: `startup_gfx2hlsl_f16_alu_draw_hardware` passes. The `fxc v_fmac_f16 set 0` mismatch from [my run at `37b610ca`](https://github.com/R0Y00/Xbox2Windows/pull/2073#issuecomment-7161849301) does not reproduce in this run: ``` fxc v_fmac_f16 set 0: 00004e33,0000d55b,0000450f,00004b9f dxc v_fmac_f16 set 0: 00004e33,0000d55b,0000450f,00004b9f ``` ``` .\tools\dev.ps1; ctest --preset dev --no-tests=error -j1 -R '^startup_gfx2hlsl_f16_alu_draw_hardware$' -V ``` The log has 26 `fxc` and 26 `dxc` result lines (13 ops x 2 sets), including `v_fmamk_f16` and `v_fmaak_f16`; no `debug_errors=` line has a nonzero value. CPU, control and WARP tests (`ctest --preset dev --no-tests=error -j1 -R 'f16_alu' -E '_hardware$' -V`): `100% tests passed, 0 tests failed out of 3`. The C++ binaries were built at `37b610ca`; between `37b610ca` and `b87b5ae6` only `tools/startup/gfx2hlsl.py` and `tests/startup_gfx2hlsl_f16_alu_check.py` change, so I did not rebuild. One hardware run, one card and one driver. The drawn inputs have no Inf or NaN operand, so the binary32 path of the new `fma16o` was not drawn. 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; the hardware run was serial on an idle machine; 0 capability skips (77).
tedin7 commented 2026-11-25 14:05:11 +00:00 (Migrated from github.com)

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


Thanks for the RTX 3070 Ti run.

Result: at b87b5ae6 (which is the current head) startup_gfx2hlsl_f16_alu_draw_hardware passes. The fxc v_fmac_f16 set 0 mismatch seen at 37b610ca is gone: fxc and dxc both read 4e33,d55b,450f,4b9f. All 26 fxc and 26 dxc lines are present, debug_errors is 0, and the CPU/control/WARP tests pass 3 of 3.

What this means for the PR: the integer fma16_rne correction in fma16o fixes the NVIDIA case. No further code change is needed from this comment.

Still not covered, as you noted: one card, one driver, and no Inf/NaN operand drawn, so the binary32 path of fma16o is not exercised on hardware. Your point about not rebuilding the C++ binaries is fine, since only gfx2hlsl.py and the Python check changed between the two heads.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7164238822 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2073#issuecomment-7164238822). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T13:45:13Z. --- Thanks for the RTX 3070 Ti run. Result: at `b87b5ae6` (which is the current head) `startup_gfx2hlsl_f16_alu_draw_hardware` passes. The `fxc v_fmac_f16 set 0` mismatch seen at `37b610ca` is gone: fxc and dxc both read `4e33,d55b,450f,4b9f`. All 26 fxc and 26 dxc lines are present, `debug_errors` is 0, and the CPU/control/WARP tests pass 3 of 3. What this means for the PR: the integer `fma16_rne` correction in `fma16o` fixes the NVIDIA case. No further code change is needed from this comment. Still not covered, as you noted: one card, one driver, and no Inf/NaN operand drawn, so the binary32 path of `fma16o` is not exercised on hardware. Your point about not rebuilding the C++ binaries is fine, since only `gfx2hlsl.py` and the Python check changed between the two heads. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 14:05:12 +00:00 (Migrated from github.com)

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


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:7164377742 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2073#issuecomment-7164377742). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T13:50:54Z. --- 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.
ChazY11 commented 2026-11-25 23:02:08 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T22:58:07Z.


Post-merge audit of f03cf16f: seven mutations across the binary16 operand path, five caught

python -B tests/startup_gfx2hlsl_f16_alu_check.py         → f16 alu ok
python -B tests/startup_gfx2hlsl_cvt_alu_check.py         → refused forms stay refused: ok
python -B tests/startup_gfx2hlsl_f16_alu_draw_check.py    → v_cvt_u16_f16: translates to four lane results: ok

Three fixtures, one of them a draw-level check that the conversion really produces four lane results, so this PR is not
only text comparison.

mutation in half_operand / the VEC_H dispatch caught by
i16 sign extension replaced by zero extension f16_alu
u16 mask dropped (float(src) instead of float(src & 0xffffu)) f16_alu
the VEC_H dispatch removed (half ops stop going through half_alu) f16_alu
neg initialised True (every operand treated as negated) f16_alu
the half operand no longer goes through f16tof32(src & 0xffffu) f16_alu
abs(…) wrapping dropped survived
the final negation dropped (return '(-%s)' % text if neg else text → return text) survived

The five catches are the ones that change numbers: sign extension, the low-half mask, the dispatch, the negation
predicate, and reading the half through f16tof32 rather than reinterpreting the bits as float.

Why the two survivors are worth naming

They are the two halves of the same modifier handling, and each is only reachable through a specific operand spelling:

  • abs — absolute = tok.startswith('|') and tok.endswith('|'). No fixture passes an operand spelled |s0|, so
    wrapping in abs(…) is unconstrained. Dropping it means an absolute-value modifier is silently ignored, and the result
    is wrong by a sign with nothing to show for it.
  • the negation itself — neg = True is caught (the predicate), but applying it is not. So the fixture never has an
    operand that is both non-inline and negated: for an inline constant the code goes down the tok in FLOATS branch and
    returns before line 3240, and for a plain register the fixture apparently never writes -s[N].

Together those two mean the modifier application at the end of half_operand — abs then - — has no case where
either actually runs on a register operand. One case with -|s0| (negated absolute, exercising both in the documented
order) would pin both at once.

Note on my own anchors

Four of my first attempts missed on indentation: I copied leading spaces out of a git diff excerpt, where the + prefix
shifts the column, and once I quoted a line I had already mutated in the previous pass. Anchors taken as $l[N-1] from
Get-Content — the actual file line — all hit. In a 6 000-line file with nested expressions that is the only reliable way.

AI-assisted; pure Python, Windows 11 build 26300, no DXC or GPU for the rows above.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7176993779 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2073#issuecomment-7176993779). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-25T22:58:07Z. --- ## Post-merge audit of `f03cf16f`: seven mutations across the binary16 operand path, five caught ```text python -B tests/startup_gfx2hlsl_f16_alu_check.py → f16 alu ok python -B tests/startup_gfx2hlsl_cvt_alu_check.py → refused forms stay refused: ok python -B tests/startup_gfx2hlsl_f16_alu_draw_check.py → v_cvt_u16_f16: translates to four lane results: ok ``` Three fixtures, one of them a draw-level check that the conversion really produces four lane results, so this PR is not only text comparison. | mutation in `half_operand` / the `VEC_H` dispatch | caught by | |---|---| | `i16` sign extension replaced by zero extension | f16_alu | | `u16` mask dropped (`float(src)` instead of `float(src & 0xffffu)`) | f16_alu | | the `VEC_H` dispatch removed (half ops stop going through `half_alu`) | f16_alu | | `neg` initialised `True` (every operand treated as negated) | f16_alu | | the half operand no longer goes through `f16tof32(src & 0xffffu)` | f16_alu | | `abs(…)` wrapping dropped | survived | | the final negation dropped (`return '(-%s)' % text if neg else text` → `return text`) | survived | The five catches are the ones that change numbers: sign extension, the low-half mask, the dispatch, the negation *predicate*, and reading the half through `f16tof32` rather than reinterpreting the bits as `float`. ### Why the two survivors are worth naming They are the two halves of the same modifier handling, and each is only reachable through a specific operand spelling: - **`abs`** — `absolute = tok.startswith('|') and tok.endswith('|')`. No fixture passes an operand spelled `|s0|`, so wrapping in `abs(…)` is unconstrained. Dropping it means an absolute-value modifier is silently ignored, and the result is wrong by a sign with nothing to show for it. - **the negation itself** — `neg = True` is caught (the predicate), but *applying* it is not. So the fixture never has an operand that is both non-inline and negated: for an inline constant the code goes down the `tok in FLOATS` branch and returns before line 3240, and for a plain register the fixture apparently never writes `-s[N]`. Together those two mean the **modifier application** at the end of `half_operand` — `abs` then `-` — has no case where either actually runs on a register operand. One case with `-|s0|` (negated absolute, exercising both in the documented order) would pin both at once. ### Note on my own anchors Four of my first attempts missed on indentation: I copied leading spaces out of a `git diff` excerpt, where the `+` prefix shifts the column, and once I quoted a line I had already mutated in the previous pass. Anchors taken as `$l[N-1]` from `Get-Content` — the actual file line — all hit. In a 6 000-line file with nested expressions that is the only reliable way. AI-assisted; pure Python, Windows 11 build 26300, no DXC or GPU for the rows above.
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!2066
No description provided.