shader: lower binary16 rounding and transcendental ops in gfx2hlsl (Part of #1723) #2067

Closed
tedin7 wants to merge 8 commits from upstream-pr/2074 into main
tedin7 commented 2026-11-25 00:01:23 +00:00 (Migrated from github.com)

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


Part of #1723

What this unblocks: shaders that round, take roots or reciprocals, or use exp/log/sin/cos on 16-bit values now translate in gfx2hlsl instead of stopping on an unsupported opcode.

Lowers v_ceil_f16, v_floor_f16, v_trunc_f16, v_rndne_f16, v_fract_f16, v_rcp_f16, v_rsq_f16, v_sqrt_f16, v_sin_f16, v_cos_f16, v_exp_f16 and v_log_f16 (VOP1 and VOP3 without modifiers). The source is the low half of the operand; the result is computed in binary32, rounded to binary16 and written to the low half with the high half cleared (like v_cvt_f16_f32). v_fract_f16 stops at 0x3bff. Inline constants and neg/abs source modifiers work; clamp/omod/op_sel and wrong operand counts are refused.

Verification: (Win2025 was not used; commands run locally on Linux)

  • python3 -B tests/startup_gfx2hlsl_f16_trans_check.py -> f16 transcendental checks: 0 failed (same file on origin/main: 48 failed)
  • python3 -B tests/startup_gfx2hlsl_operand_count_check.py -> 0 failed
  • python3 -B tests/startup_gfx2hlsl_op_refusals_check.py -> 3 cases passed
  • python3 -B tests/startup_gfx2hlsl_capture_check.py -> passed
  • Registered as startup_gfx2hlsl_f16_trans in CMakeLists.txt.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6593956379 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2074). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T00:01:23Z. --- Part of #1723 What this unblocks: shaders that round, take roots or reciprocals, or use exp/log/sin/cos on 16-bit values now translate in gfx2hlsl instead of stopping on an unsupported opcode. Lowers `v_ceil_f16`, `v_floor_f16`, `v_trunc_f16`, `v_rndne_f16`, `v_fract_f16`, `v_rcp_f16`, `v_rsq_f16`, `v_sqrt_f16`, `v_sin_f16`, `v_cos_f16`, `v_exp_f16` and `v_log_f16` (VOP1 and VOP3 without modifiers). The source is the low half of the operand; the result is computed in binary32, rounded to binary16 and written to the low half with the high half cleared (like `v_cvt_f16_f32`). `v_fract_f16` stops at 0x3bff. Inline constants and neg/abs source modifiers work; clamp/omod/op_sel and wrong operand counts are refused. Verification: (Win2025 was not used; commands run locally on Linux) - `python3 -B tests/startup_gfx2hlsl_f16_trans_check.py` -> `f16 transcendental checks: 0 failed` (same file on origin/main: 48 failed) - `python3 -B tests/startup_gfx2hlsl_operand_count_check.py` -> 0 failed - `python3 -B tests/startup_gfx2hlsl_op_refusals_check.py` -> 3 cases passed - `python3 -B tests/startup_gfx2hlsl_capture_check.py` -> passed - Registered as `startup_gfx2hlsl_f16_trans` in CMakeLists.txt. AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot commented 2026-11-25 01:01:30 +00:00 (Migrated from github.com)

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

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 48dbc9bde3

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


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:21.113701Z 48dbc9b 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:7148054101 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2074#issuecomment-7148054101). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T00:01:33Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"48dbc9bde38b677e320033339617d0fb6326ed83","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:21.113701Z">2026-11-25T00:09:21.113701Z</relative-time> | `48dbc9b` | 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:18Z.

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

@@ -1824,6 +1855,15 @@ def declarations(self):
     'v_sin_f32': (1, 'sin({0} * 6.283185307)'), 'v_cos_f32': (1, 'cos({0} * 6.283185307)'),
     'v_med3_f32': (3, 'med3({0}, {1}, {2})'), 'v_min3_f32': (3, 'min({0}, min({1}, {2}))'), 'v_max3_f32': (3, 'max({0}, max({1}, {2}))'),
 }
+# binary16 one-source operations (VOP1, or VOP3 without modifiers): the source is the low half of the operand,
+# the result is rounded to binary16 and written to the low half with the high half cleared, as v_cvt_f16_f32 does.
+# v_fract_f16 stops at the largest binary16 below one; v_sin/cos take revolutions, as the binary32 forms do.
+VEC_H = {
+    'v_ceil_f16': 'ceil({0})', 'v_floor_f16': 'floor({0})', 'v_trunc_f16': 'trunc({0})', 'v_rndne_f16': 'round({0})',
+    'v_fract_f16': 'min(frac({0}), 0.99951171875)', 'v_rcp_f16': '1.0 / {0}', 'v_rsq_f16': 'rsqrt({0})',
+    'v_sqrt_f16': 'sqrt({0})', 'v_sin_f16': 'sin({0} * 6.283185307)', 'v_cos_f16': 'cos({0} * 6.283185307)',
+    'v_exp_f16': 'exp2({0})', 'v_log_f16': 'log2({0})',

P1 Badge Register the transcendental opcodes in the machine-code decoder

For real shader bytecode, the new rcp/rsq/sqrt/exp/log/sin/cos lowerings are unreachable: decode() delegates to disasm_rdna2.VOP1_OPS, and a repository-wide mnemonic search confirms that those decoder entries are absent. For example, the VOP1 bytes 02a9027e (v_rcp_f16 v1, v2) decode as v_vop1_54 and still raise Unsupported; VOP3 uses the same table. The new fixture bypasses decoding by calling Stage.one() with handwritten names, so its passing result hides this. Add the decoder mappings and binary-input coverage so these shaders can reach the new lowerings.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688370696 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2074#discussion_r4688370696). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T00:09:18Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 1865 ~~~~diff @@ -1824,6 +1855,15 @@ def declarations(self): 'v_sin_f32': (1, 'sin({0} * 6.283185307)'), 'v_cos_f32': (1, 'cos({0} * 6.283185307)'), 'v_med3_f32': (3, 'med3({0}, {1}, {2})'), 'v_min3_f32': (3, 'min({0}, min({1}, {2}))'), 'v_max3_f32': (3, 'max({0}, max({1}, {2}))'), } +# binary16 one-source operations (VOP1, or VOP3 without modifiers): the source is the low half of the operand, +# the result is rounded to binary16 and written to the low half with the high half cleared, as v_cvt_f16_f32 does. +# v_fract_f16 stops at the largest binary16 below one; v_sin/cos take revolutions, as the binary32 forms do. +VEC_H = { + 'v_ceil_f16': 'ceil({0})', 'v_floor_f16': 'floor({0})', 'v_trunc_f16': 'trunc({0})', 'v_rndne_f16': 'round({0})', + 'v_fract_f16': 'min(frac({0}), 0.99951171875)', 'v_rcp_f16': '1.0 / {0}', 'v_rsq_f16': 'rsqrt({0})', + 'v_sqrt_f16': 'sqrt({0})', 'v_sin_f16': 'sin({0} * 6.283185307)', 'v_cos_f16': 'cos({0} * 6.283185307)', + 'v_exp_f16': 'exp2({0})', 'v_log_f16': 'log2({0})', ~~~~ --- **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Register the transcendental opcodes in the machine-code decoder** For real shader bytecode, the new rcp/rsq/sqrt/exp/log/sin/cos lowerings are unreachable: `decode()` delegates to `disasm_rdna2.VOP1_OPS`, and a repository-wide mnemonic search confirms that those decoder entries are absent. For example, the VOP1 bytes `02a9027e` (`v_rcp_f16 v1, v2`) decode as `v_vop1_54` and still raise `Unsupported`; VOP3 uses the same table. The new fixture bypasses decoding by calling `Stage.one()` with handwritten names, so its passing result hides this. Add the decoder mappings and binary-input coverage so these shaders can reach the new lowerings. 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:09:18Z.

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

@@ -1532,6 +1534,35 @@ def op_v_fma_mixlo_f16(self, ops, mods):
     def op_v_fma_mixhi_f16(self, ops, mods):
         self.mix(ops, mods, True)
 
+    def half_src(self, tok):
+        """float expression for the binary16 value in the low half of a 32-bit operand."""
+        neg = tok.startswith('-') and not re.match(r'-[\d.]', tok)
+        if neg:
+            tok = tok[1:]

P2 Badge Apply FP16 source negation before interpreting literal bits

For a VOP3 NEG modifier on a literal, disasm_rdna2 prints, for example, -0x3800, but the digit check makes neg false and u() performs integer negation of the encoding. A decoded v_floor_f16_e64 v1, -0x3800 consequently reads half 0xc800 (-8.0) and returns -8.0, whereas negating half 0x3800 means -0.5 and should return -1.0 (0xbc00). Recognize literal source modifiers separately from signed inline constants before passing the bit pattern to u().

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688370703 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2074#discussion_r4688370703). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T00:09:18Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 1541 ~~~~diff @@ -1532,6 +1534,35 @@ def op_v_fma_mixlo_f16(self, ops, mods): def op_v_fma_mixhi_f16(self, ops, mods): self.mix(ops, mods, True) + def half_src(self, tok): + """float expression for the binary16 value in the low half of a 32-bit operand.""" + neg = tok.startswith('-') and not re.match(r'-[\d.]', tok) + if neg: + tok = tok[1:] ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Apply FP16 source negation before interpreting literal bits** For a VOP3 NEG modifier on a literal, `disasm_rdna2` prints, for example, `-0x3800`, but the digit check makes `neg` false and `u()` performs integer negation of the encoding. A decoded `v_floor_f16_e64 v1, -0x3800` consequently reads half `0xc800` (-8.0) and returns -8.0, whereas negating half `0x3800` means -0.5 and should return -1.0 (`0xbc00`). Recognize literal source modifiers separately from signed inline constants before passing the bit pattern to `u()`. 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:09:18Z.

Code review location: CMakeLists.txt; line 2182

@@ -2177,6 +2177,9 @@ if(EXISTS "${INTAKE_PYTHON}")
     # gfx2hlsl refuses a binary32 or integer vector operation with a source too few or too many.
     add_test(NAME startup_gfx2hlsl_operand_count COMMAND "${INTAKE_PYTHON}" -B
         "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_operand_count_check.py")
+    # gfx2hlsl lowers the binary16 rounding and transcendental operations (v_ceil_f16 ... v_log_f16).
+    add_test(NAME startup_gfx2hlsl_f16_trans COMMAND "${INTAKE_PYTHON}" -B
+        "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_f16_trans_check.py")

P1 Badge Document the new public translator capability

Root AGENTS.md requires updating “the relevant README row or docs/experiments.md when a public capability, build requirement or reproduction command changes,” but this commit adds supported half-precision forms and a new startup_gfx2hlsl_f16_trans check without updating either document. Add a public experiment entry covering the supported/refused forms and exact validation command/result so contributors can discover and reproduce the new capability through the documented workflow.

AGENTS.md reference: AGENTS.md:L211-L212

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688370711 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2074#discussion_r4688370711). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T00:09:18Z. **Code review location:** `CMakeLists.txt`; line 2182 ~~~~diff @@ -2177,6 +2177,9 @@ if(EXISTS "${INTAKE_PYTHON}") # gfx2hlsl refuses a binary32 or integer vector operation with a source too few or too many. add_test(NAME startup_gfx2hlsl_operand_count COMMAND "${INTAKE_PYTHON}" -B "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_operand_count_check.py") + # gfx2hlsl lowers the binary16 rounding and transcendental operations (v_ceil_f16 ... v_log_f16). + add_test(NAME startup_gfx2hlsl_f16_trans COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_f16_trans_check.py") ~~~~ --- **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Document the new public translator capability** Root `AGENTS.md` requires updating “the relevant README row or `docs/experiments.md` when a public capability, build requirement or reproduction command changes,” but this commit adds supported half-precision forms and a new `startup_gfx2hlsl_f16_trans` check without updating either document. Add a public experiment entry covering the supported/refused forms and exact validation command/result so contributors can discover and reproduce the new capability through the documented workflow. AGENTS.md reference: [AGENTS.md:L211-L212](https://github.com/R0Y00/Xbox2Windows/blob/48dbc9bde38b677e320033339617d0fb6326ed83/AGENTS.md#L211-L212) Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
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:41Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6049955079 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2074#pullrequestreview-6049955079). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T01:02:41Z. **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:43Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6049955287 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2074#pullrequestreview-6049955287). 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:38 +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:6049955469 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2074#pullrequestreview-6049955469). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T01:02:44Z. **Review:** COMMENTED --- _No description provided._
thepatrickworld commented 2026-11-25 02:02:07 +00:00 (Migrated from github.com)

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


Independent run on AMD, and the ISA's printed examples

Their check passes here: startup_gfx2hlsl_f16_trans_draw_check.py draw <dxc> <offscreen_check> hardware <fxc> exits 0 on an RX 9070 XT (driver 32.0.32029.2010), head 1bd402e7. So the positive half of this PR holds on a third adapter and both compilers.

What it does not reach is the set of literal cases the ISA prints for these instructions. INPUTS keeps sin/cos between -0.35 and 1.1, exp within ±10, and no operand is -0.0; the docstring says the inputs are chosen so that a binary32 intermediate and an exact one agree, which is exactly the property that stops the draw from seeing a divergence. I ran the printed pairs through the same fixture, with the expected words taken from the guide rather than from the model.

v_fract_f16, -0.0001 (0x868e). D.f16 = S0.f16 + -floor(S0.f16) gives 0.9999, which rounds to 1.0 (0x3c00). The translation returns 0x3bff, on both adapters and both compilers. The difference comes from the min(..., 0.99951171875) cap, and controls() states that cap as an expectation (fract stops below one) while the draw compares it against a lowering that applies the same cap, so no run of this fixture can report on it. If the cap is deliberate — the binary32 form in this translator caps too — then it is a deviation from the printed formula and should be called one where it is written, instead of being asserted as if measured.

Sign of zero, v_sin_f16 and v_fract_f16. For -0.0 the guide prints 0x8000 for both. On the card, under fxc and dxc, sin returns 0x0000 and fract returns 0x0000. WARP returns 0x8000 for sin. This is a sign-of-zero difference rather than a magnitude one, but it is a difference, and it is the one place where a translated shader and the guide disagree on a value that is not a NaN.

v_sqrt_f16(-0.0) under FXC. The guide prints 0x8000. FXC returns 0x8001, a binary16 denormal, on hardware and on WARP; DXC returns 0x8000 on the same adapter with the same translated source. Same shader, two compilers, two words. That is a property of FXC's sqrt sequence rather than of this lowering, but it means the two compiler paths of this check do not agree on the one input whose expected result is exactly representable.

For completeness, the other WARP differences I saw are NaN payloads — 0xffff where the guide prints 0xfe00 — which is a payload question, not a value one, and I do not read them as defects.

Suggestion. Add the guide's printed pairs as a small control block. They cost nothing, they come from outside the lowering, and they would have caught the three cases above before the review did. Where a case is accepted as-is, saying why in the check keeps the next reader from re-deriving it.

AI-assisted; runs executed on the machine above.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7149795587 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2074#issuecomment-7149795587). Originally posted by [thepatrickworld](https://github.com/thepatrickworld) on 2026-11-25T01:39:03Z. --- ### Independent run on AMD, and the ISA's printed examples Their check passes here: `startup_gfx2hlsl_f16_trans_draw_check.py draw <dxc> <offscreen_check> hardware <fxc>` exits 0 on an RX 9070 XT (driver 32.0.32029.2010), head `1bd402e7`. So the positive half of this PR holds on a third adapter and both compilers. What it does not reach is the set of literal cases the ISA prints for these instructions. `INPUTS` keeps `sin`/`cos` between -0.35 and 1.1, `exp` within ±10, and no operand is `-0.0`; the docstring says the inputs are chosen so that a binary32 intermediate and an exact one agree, which is exactly the property that stops the draw from seeing a divergence. I ran the printed pairs through the same fixture, with the expected words taken from the guide rather than from the model. **`v_fract_f16`, `-0.0001` (`0x868e`).** `D.f16 = S0.f16 + -floor(S0.f16)` gives `0.9999`, which rounds to `1.0` (`0x3c00`). The translation returns `0x3bff`, on both adapters and both compilers. The difference comes from the `min(..., 0.99951171875)` cap, and `controls()` states that cap as an expectation (`fract stops below one`) while the draw compares it against a lowering that applies the same cap, so no run of this fixture can report on it. If the cap is deliberate — the binary32 form in this translator caps too — then it is a deviation from the printed formula and should be called one where it is written, instead of being asserted as if measured. **Sign of zero, `v_sin_f16` and `v_fract_f16`.** For `-0.0` the guide prints `0x8000` for both. On the card, under fxc and dxc, `sin` returns `0x0000` and `fract` returns `0x0000`. WARP returns `0x8000` for `sin`. This is a sign-of-zero difference rather than a magnitude one, but it is a difference, and it is the one place where a translated shader and the guide disagree on a value that is not a NaN. **`v_sqrt_f16(-0.0)` under FXC.** The guide prints `0x8000`. FXC returns `0x8001`, a binary16 denormal, on hardware and on WARP; DXC returns `0x8000` on the same adapter with the same translated source. Same shader, two compilers, two words. That is a property of FXC's `sqrt` sequence rather than of this lowering, but it means the two compiler paths of this check do not agree on the one input whose expected result is exactly representable. For completeness, the other WARP differences I saw are NaN payloads — `0xffff` where the guide prints `0xfe00` — which is a payload question, not a value one, and I do not read them as defects. **Suggestion.** Add the guide's printed pairs as a small control block. They cost nothing, they come from outside the lowering, and they would have caught the three cases above before the review did. Where a case is accepted as-is, saying why in the check keeps the next reader from re-deriving it. _AI-assisted; runs executed on the machine above._
tedin7 commented 2026-11-25 02:02:11 +00:00 (Migrated from github.com)

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

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

@@ -1824,6 +1855,15 @@ def declarations(self):
     'v_sin_f32': (1, 'sin({0} * 6.283185307)'), 'v_cos_f32': (1, 'cos({0} * 6.283185307)'),
     'v_med3_f32': (3, 'med3({0}, {1}, {2})'), 'v_min3_f32': (3, 'min({0}, min({1}, {2}))'), 'v_max3_f32': (3, 'max({0}, max({1}, {2}))'),
 }
+# binary16 one-source operations (VOP1, or VOP3 without modifiers): the source is the low half of the operand,
+# the result is rounded to binary16 and written to the low half with the high half cleared, as v_cvt_f16_f32 does.
+# v_fract_f16 stops at the largest binary16 below one; v_sin/cos take revolutions, as the binary32 forms do.
+VEC_H = {
+    'v_ceil_f16': 'ceil({0})', 'v_floor_f16': 'floor({0})', 'v_trunc_f16': 'trunc({0})', 'v_rndne_f16': 'round({0})',
+    'v_fract_f16': 'min(frac({0}), 0.99951171875)', 'v_rcp_f16': '1.0 / {0}', 'v_rsq_f16': 'rsqrt({0})',
+    'v_sqrt_f16': 'sqrt({0})', 'v_sin_f16': 'sin({0} * 6.283185307)', 'v_cos_f16': 'cos({0} * 6.283185307)',
+    'v_exp_f16': 'exp2({0})', 'v_log_f16': 'log2({0})',

Rebased on main: the decoder already maps the VOP1/VOP3 f16 transcendental opcodes there. 1bd402e7 adds machine-code tests (VOP1 and VOP3 words through decode) for all 12 operations.

AI-assisted; commands listed were executed locally: python3 -B tests/startup_gfx2hlsl_f16_trans_check.py (0 failed), python3 -B tests/startup_gfx2hlsl_f16_trans_draw_check.py.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688767550 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2074#discussion_r4688767550). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T01:02:41Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 1865 ~~~~diff @@ -1824,6 +1855,15 @@ def declarations(self): 'v_sin_f32': (1, 'sin({0} * 6.283185307)'), 'v_cos_f32': (1, 'cos({0} * 6.283185307)'), 'v_med3_f32': (3, 'med3({0}, {1}, {2})'), 'v_min3_f32': (3, 'min({0}, min({1}, {2}))'), 'v_max3_f32': (3, 'max({0}, max({1}, {2}))'), } +# binary16 one-source operations (VOP1, or VOP3 without modifiers): the source is the low half of the operand, +# the result is rounded to binary16 and written to the low half with the high half cleared, as v_cvt_f16_f32 does. +# v_fract_f16 stops at the largest binary16 below one; v_sin/cos take revolutions, as the binary32 forms do. +VEC_H = { + 'v_ceil_f16': 'ceil({0})', 'v_floor_f16': 'floor({0})', 'v_trunc_f16': 'trunc({0})', 'v_rndne_f16': 'round({0})', + 'v_fract_f16': 'min(frac({0}), 0.99951171875)', 'v_rcp_f16': '1.0 / {0}', 'v_rsq_f16': 'rsqrt({0})', + 'v_sqrt_f16': 'sqrt({0})', 'v_sin_f16': 'sin({0} * 6.283185307)', 'v_cos_f16': 'cos({0} * 6.283185307)', + 'v_exp_f16': 'exp2({0})', 'v_log_f16': 'log2({0})', ~~~~ --- Rebased on main: the decoder already maps the VOP1/VOP3 f16 transcendental opcodes there. 1bd402e7 adds machine-code tests (VOP1 and VOP3 words through decode) for all 12 operations. AI-assisted; commands listed were executed locally: python3 -B tests/startup_gfx2hlsl_f16_trans_check.py (0 failed), python3 -B tests/startup_gfx2hlsl_f16_trans_draw_check.py.
tedin7 commented 2026-11-25 02:02:11 +00:00 (Migrated from github.com)

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

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

@@ -1532,6 +1534,35 @@ def op_v_fma_mixlo_f16(self, ops, mods):
     def op_v_fma_mixhi_f16(self, ops, mods):
         self.mix(ops, mods, True)
 
+    def half_src(self, tok):
+        """float expression for the binary16 value in the low half of a 32-bit operand."""
+        neg = tok.startswith('-') and not re.match(r'-[\d.]', tok)
+        if neg:
+            tok = tok[1:]

Fixed in 1bd402e7: -0x3800 is now read as the neg modifier on the half literal (result -0.5 path), with a machine-code test.

AI-assisted; commands listed were executed locally: python3 -B tests/startup_gfx2hlsl_f16_trans_check.py (0 failed), python3 -B tests/startup_gfx2hlsl_f16_trans_draw_check.py.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688767715 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2074#discussion_r4688767715). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T01:02:42Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 1541 ~~~~diff @@ -1532,6 +1534,35 @@ def op_v_fma_mixlo_f16(self, ops, mods): def op_v_fma_mixhi_f16(self, ops, mods): self.mix(ops, mods, True) + def half_src(self, tok): + """float expression for the binary16 value in the low half of a 32-bit operand.""" + neg = tok.startswith('-') and not re.match(r'-[\d.]', tok) + if neg: + tok = tok[1:] ~~~~ --- Fixed in 1bd402e7: -0x3800 is now read as the neg modifier on the half literal (result -0.5 path), with a machine-code test. AI-assisted; commands listed were executed locally: python3 -B tests/startup_gfx2hlsl_f16_trans_check.py (0 failed), python3 -B tests/startup_gfx2hlsl_f16_trans_draw_check.py.
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: CMakeLists.txt; line 2182

@@ -2177,6 +2177,9 @@ if(EXISTS "${INTAKE_PYTHON}")
     # gfx2hlsl refuses a binary32 or integer vector operation with a source too few or too many.
     add_test(NAME startup_gfx2hlsl_operand_count COMMAND "${INTAKE_PYTHON}" -B
         "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_operand_count_check.py")
+    # gfx2hlsl lowers the binary16 rounding and transcendental operations (v_ceil_f16 ... v_log_f16).
+    add_test(NAME startup_gfx2hlsl_f16_trans COMMAND "${INTAKE_PYTHON}" -B
+        "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_f16_trans_check.py")

Fixed in 1bd402e7: new docs/experiments.md section lists supported/refused forms, the ctest command and the WARP result.

AI-assisted; commands listed were executed locally: python3 -B tests/startup_gfx2hlsl_f16_trans_check.py (0 failed), python3 -B tests/startup_gfx2hlsl_f16_trans_draw_check.py.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688767851 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2074#discussion_r4688767851). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T01:02:44Z. **Code review location:** `CMakeLists.txt`; line 2182 ~~~~diff @@ -2177,6 +2177,9 @@ if(EXISTS "${INTAKE_PYTHON}") # gfx2hlsl refuses a binary32 or integer vector operation with a source too few or too many. add_test(NAME startup_gfx2hlsl_operand_count COMMAND "${INTAKE_PYTHON}" -B "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_operand_count_check.py") + # gfx2hlsl lowers the binary16 rounding and transcendental operations (v_ceil_f16 ... v_log_f16). + add_test(NAME startup_gfx2hlsl_f16_trans COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_f16_trans_check.py") ~~~~ --- Fixed in 1bd402e7: new docs/experiments.md section lists supported/refused forms, the ctest command and the WARP result. AI-assisted; commands listed were executed locally: python3 -B tests/startup_gfx2hlsl_f16_trans_check.py (0 failed), python3 -B tests/startup_gfx2hlsl_f16_trans_draw_check.py.
tedin7 commented 2026-11-25 11:02:08 +00:00 (Migrated from github.com)

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

Review: COMMENTED


No description provided.

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

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T10:55:56Z.


@thepatrickworld thank you for the AMD run and for the printed-case comparison. Pushed 20fd34f4 (docs and a comment only, no lowering change).

  • v_fract_f16(-0.0001): the min(..., 0.99951171875) cap is deliberate and follows the binary32 form of this translator, so it differs from the printed S0 + -floor(S0) (which rounds to 1.0). docs/experiments.md and the fract stops below one check now say it is a lowering choice, not a measurement.
  • Signed zero for v_sin_f16 / v_fract_f16 and v_sqrt_f16(-0.0) (FXC 0x8001, DXC 0x8000): the draw inputs avoid these on purpose, so they are not covered. The docs now list them as uncovered instead of implying coverage. Adding the guide's printed pairs as a control block is a fair follow-up and is not in this PR.

AI-assisted; commands listed were executed locally: python3 -B tests/startup_gfx2hlsl_f16_trans_check.py (0 failed), python3 -B tests/docs_links_check.py (419 links), git diff --check.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7160364508 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2074#issuecomment-7160364508). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T10:55:56Z. --- @thepatrickworld thank you for the AMD run and for the printed-case comparison. Pushed 20fd34f4 (docs and a comment only, no lowering change). - `v_fract_f16(-0.0001)`: the `min(..., 0.99951171875)` cap is deliberate and follows the binary32 form of this translator, so it differs from the printed `S0 + -floor(S0)` (which rounds to 1.0). `docs/experiments.md` and the `fract stops below one` check now say it is a lowering choice, not a measurement. - Signed zero for `v_sin_f16` / `v_fract_f16` and `v_sqrt_f16(-0.0)` (FXC `0x8001`, DXC `0x8000`): the draw inputs avoid these on purpose, so they are not covered. The docs now list them as uncovered instead of implying coverage. Adding the guide's printed pairs as a control block is a fair follow-up and is not in this PR. AI-assisted; commands listed were executed locally: `python3 -B tests/startup_gfx2hlsl_f16_trans_check.py` (0 failed), `python3 -B tests/docs_links_check.py` (419 links), `git diff --check`.
tedin7 commented 2026-11-25 11:02:38 +00:00 (Migrated from github.com)

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

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

@@ -1824,6 +1855,15 @@ def declarations(self):
     'v_sin_f32': (1, 'sin({0} * 6.283185307)'), 'v_cos_f32': (1, 'cos({0} * 6.283185307)'),
     'v_med3_f32': (3, 'med3({0}, {1}, {2})'), 'v_min3_f32': (3, 'min({0}, min({1}, {2}))'), 'v_max3_f32': (3, 'max({0}, max({1}, {2}))'),
 }
+# binary16 one-source operations (VOP1, or VOP3 without modifiers): the source is the low half of the operand,
+# the result is rounded to binary16 and written to the low half with the high half cleared, as v_cvt_f16_f32 does.
+# v_fract_f16 stops at the largest binary16 below one; v_sin/cos take revolutions, as the binary32 forms do.
+VEC_H = {
+    'v_ceil_f16': 'ceil({0})', 'v_floor_f16': 'floor({0})', 'v_trunc_f16': 'trunc({0})', 'v_rndne_f16': 'round({0})',
+    'v_fract_f16': 'min(frac({0}), 0.99951171875)', 'v_rcp_f16': '1.0 / {0}', 'v_rsq_f16': 'rsqrt({0})',
+    'v_sqrt_f16': 'sqrt({0})', 'v_sin_f16': 'sin({0} * 6.283185307)', 'v_cos_f16': 'cos({0} * 6.283185307)',
+    'v_exp_f16': 'exp2({0})', 'v_log_f16': 'log2({0})',

Re-checked on current head 20fd34f4: the f16 transcendental opcodes are registered and decoded, literal negation is handled, and docs are updated. Resolving. AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4693922161 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2074#discussion_r4693922161). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T11:01:51Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 1865 ~~~~diff @@ -1824,6 +1855,15 @@ def declarations(self): 'v_sin_f32': (1, 'sin({0} * 6.283185307)'), 'v_cos_f32': (1, 'cos({0} * 6.283185307)'), 'v_med3_f32': (3, 'med3({0}, {1}, {2})'), 'v_min3_f32': (3, 'min({0}, min({1}, {2}))'), 'v_max3_f32': (3, 'max({0}, max({1}, {2}))'), } +# binary16 one-source operations (VOP1, or VOP3 without modifiers): the source is the low half of the operand, +# the result is rounded to binary16 and written to the low half with the high half cleared, as v_cvt_f16_f32 does. +# v_fract_f16 stops at the largest binary16 below one; v_sin/cos take revolutions, as the binary32 forms do. +VEC_H = { + 'v_ceil_f16': 'ceil({0})', 'v_floor_f16': 'floor({0})', 'v_trunc_f16': 'trunc({0})', 'v_rndne_f16': 'round({0})', + 'v_fract_f16': 'min(frac({0}), 0.99951171875)', 'v_rcp_f16': '1.0 / {0}', 'v_rsq_f16': 'rsqrt({0})', + 'v_sqrt_f16': 'sqrt({0})', 'v_sin_f16': 'sin({0} * 6.283185307)', 'v_cos_f16': 'cos({0} * 6.283185307)', + 'v_exp_f16': 'exp2({0})', 'v_log_f16': 'log2({0})', ~~~~ --- Re-checked on current head 20fd34f4: the f16 transcendental opcodes are registered and decoded, literal negation is handled, and docs are updated. Resolving. AI-assisted; commands listed were executed locally.
Makto94 commented 2026-11-25 12:01:53 +00:00 (Migrated from github.com)

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


First hardware run on 20fd34f4 (NVIDIA). The only other hardware run in this thread is thepatrickworld's AMD run (RX 9070 XT), which was on 1bd402e7.

.\tools\dev.ps1; ctest --preset dev --no-tests=error -j1 -R '^startup_gfx2hlsl_f16_trans_draw_hardware$' -V passes. The log has 36 fxc lines and 36 dxc lines, 3 for each of the 12 ops (v_ceil_f16, v_cos_f16, v_exp_f16, v_floor_f16, v_fract_f16, v_log_f16, v_rcp_f16, v_rndne_f16, v_rsq_f16, v_sin_f16, v_sqrt_f16, v_trunc_f16). All 72 debug_errors= lines read debug_errors=0, and there were 0 capability skips (77).

CPU, control and WARP tests (startup_gfx2hlsl_f16_trans, _draw_controls, _draw_warp): 100% tests passed, 0 tests failed out of 3.

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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7161004374 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2074#issuecomment-7161004374). Originally posted by [Makto94](https://github.com/Makto94) on 2026-11-25T11:24:25Z. --- First hardware run on `20fd34f4` (NVIDIA). The only other hardware run in this thread is thepatrickworld's AMD run (RX 9070 XT), which was on `1bd402e7`. `.\tools\dev.ps1; ctest --preset dev --no-tests=error -j1 -R '^startup_gfx2hlsl_f16_trans_draw_hardware$' -V` passes. The log has 36 `fxc` lines and 36 `dxc` lines, 3 for each of the 12 ops (`v_ceil_f16`, `v_cos_f16`, `v_exp_f16`, `v_floor_f16`, `v_fract_f16`, `v_log_f16`, `v_rcp_f16`, `v_rndne_f16`, `v_rsq_f16`, `v_sin_f16`, `v_sqrt_f16`, `v_trunc_f16`). All 72 `debug_errors=` lines read `debug_errors=0`, and there were 0 capability skips (77). CPU, control and WARP tests (`startup_gfx2hlsl_f16_trans`, `_draw_controls`, `_draw_warp`): `100% tests passed, 0 tests failed out of 3`. 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.
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:44Z.


Thank you @Makto94 for the NVIDIA RTX 3070 Ti run at 20fd34f4: startup_gfx2hlsl_f16_trans_draw_hardware passed (36 fxc + 36 dxc lines, 12 ops), CPU/controls/WARP 3/3. Recorded as extra evidence for this PR.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7161669277 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2074#issuecomment-7161669277). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T11:54:44Z. --- Thank you @Makto94 for the NVIDIA RTX 3070 Ti run at `20fd34f4`: `startup_gfx2hlsl_f16_trans_draw_hardware` passed (36 fxc + 36 dxc lines, 12 ops), 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:36 +00:00
tedin7 commented 2026-11-25 14:05:14 +00:00 (Migrated from github.com)

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


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:7164405499 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2074#issuecomment-7164405499). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T13:52:03Z. --- 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!2067
No description provided.