shader: lower one-source binary32 math and rounding in the mesh entry translator #1195

Merged
tedin7 merged 5 commits from upstream-pr/1202 into main 2026-11-24 08:18:45 +00:00
tedin7 commented 2026-11-24 03:32:11 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T03:32:11Z.


Change

Lowers the one-source binary32 math and rounding forms v_rcp_f32, v_rsq_f32, v_sqrt_f32, v_floor_f32, v_trunc_f32, v_rndne_f32 and v_fract_f32 (_e32 and _e64) in the per-lane float forms of tools/mesh_entry_aot.py, to 1.0f / x, rsqrt, sqrt, floor, trunc, round (half to even) and frac. Source modifiers, clamp, output modifiers and a second source are refused. Same shape as the float and cvt/min/max draws already in the file.

Precision of reciprocal, reciprocal square root and square root is not claimed: the test uses only inputs with exact results (powers of two, 2.25, 0.5625) and the draw compares the depth word bit for bit. NaN, infinity, denormals, zero or negative operands of rsq and sqrt, and signed zero results are not exercised.

Verification

Commit 1e34566e, Linux, no GPU or Windows available here.

  • python3 -B tests/mesh_entry_check.py binary llvm-mc-19 llvm-objcopy-19 libLLVM-19.so: exit 0. The same with Debian LLVM 15.0.6 (llvm-mc-15, libLLVM-15.so.1): exit 0.
  • Negative control: the new test with tools/mesh_entry_aot.py of origin/main exits 1 (the translator rejects the first new opcode).
  • Mutations of the lowering that the binary mode catches (exit 1 each): reciprocal as 2.0f / x, rsq as 1.0f / sqrt, sqrt as rsqrt, floor as trunc, trunc as floor, round as floor(x + 0.5f), frac as x - trunc(x).
  • The binary mode also swaps each of the 14 encodings for its sibling opcode and requires a different depth, and refuses -v, |v|, clamp, mul:2, div:2 and a two-source form.
  • python3 -B tests/rdna2_tools_check.py (121 tests, OK, 13 skipped), docs_links_check.py and bidi_controls_check.py: pass.
  • Not run here: the Windows readback mesh_entry_unary_draw_* (new CTest entry, draw-unary). It compares the exported position words with the Python reference, then must report Mesh export trace mismatch for a depth one ulp off in the last vertex and for each of the 14 opcodes swapped for its sibling.

Evidence and follow-up

One program applies all fourteen encodings to exact inputs (rcp 4 and 0.125, rsq 16 and 0.0625, sqrt 2.25 and 0.5625, floor -2.5 and -7.75, trunc -2.5 and -6.75, rndne 3.5 and -2.5, fract -2.25 and 5.125) and adds the results to the depth. The reference is plain Python arithmetic (Python rounds ties to even) and shares no code with the lowering. e32 forms read a literal, e64 forms read a register. No store or address code changes; the existing export path is untouched.

Not claimed: ceil, exp, log, sin and cos forms, modifier forms, and the precision of the approximate math forms on any adapter.

AI-assisted (Codex).

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6573991642 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1202). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T03:32:11Z. --- ## Change Lowers the one-source binary32 math and rounding forms `v_rcp_f32`, `v_rsq_f32`, `v_sqrt_f32`, `v_floor_f32`, `v_trunc_f32`, `v_rndne_f32` and `v_fract_f32` (`_e32` and `_e64`) in the per-lane float forms of `tools/mesh_entry_aot.py`, to `1.0f / x`, `rsqrt`, `sqrt`, `floor`, `trunc`, `round` (half to even) and `frac`. Source modifiers, `clamp`, output modifiers and a second source are refused. Same shape as the float and cvt/min/max draws already in the file. Precision of reciprocal, reciprocal square root and square root is not claimed: the test uses only inputs with exact results (powers of two, 2.25, 0.5625) and the draw compares the depth word bit for bit. NaN, infinity, denormals, zero or negative operands of rsq and sqrt, and signed zero results are not exercised. ## Verification Commit 1e34566e, Linux, no GPU or Windows available here. - `python3 -B tests/mesh_entry_check.py binary llvm-mc-19 llvm-objcopy-19 libLLVM-19.so`: exit 0. The same with Debian LLVM 15.0.6 (`llvm-mc-15`, `libLLVM-15.so.1`): exit 0. - Negative control: the new test with `tools/mesh_entry_aot.py` of `origin/main` exits 1 (the translator rejects the first new opcode). - Mutations of the lowering that the binary mode catches (exit 1 each): reciprocal as `2.0f / x`, rsq as `1.0f / sqrt`, sqrt as `rsqrt`, floor as `trunc`, trunc as `floor`, round as `floor(x + 0.5f)`, frac as `x - trunc(x)`. - The binary mode also swaps each of the 14 encodings for its sibling opcode and requires a different depth, and refuses `-v`, `|v|`, `clamp`, `mul:2`, `div:2` and a two-source form. - `python3 -B tests/rdna2_tools_check.py` (121 tests, OK, 13 skipped), `docs_links_check.py` and `bidi_controls_check.py`: pass. - Not run here: the Windows readback `mesh_entry_unary_draw_*` (new CTest entry, `draw-unary`). It compares the exported position words with the Python reference, then must report `Mesh export trace mismatch` for a depth one ulp off in the last vertex and for each of the 14 opcodes swapped for its sibling. ## Evidence and follow-up One program applies all fourteen encodings to exact inputs (rcp 4 and 0.125, rsq 16 and 0.0625, sqrt 2.25 and 0.5625, floor -2.5 and -7.75, trunc -2.5 and -6.75, rndne 3.5 and -2.5, fract -2.25 and 5.125) and adds the results to the depth. The reference is plain Python arithmetic (Python rounds ties to even) and shares no code with the lowering. e32 forms read a literal, e64 forms read a register. No store or address code changes; the existing export path is untouched. Not claimed: ceil, exp, log, sin and cos forms, modifier forms, and the precision of the approximate math forms on any adapter. AI-assisted (Codex). ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets.
chatgpt-codex-connector[bot commented 2026-11-24 06:46:52 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T03:52:11Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1e34566e7f

ℹ️ 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:6033393090 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1202#pullrequestreview-6033393090). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T03:52:11Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `1e34566e7f` <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>
tedin7 commented 2026-11-24 06:46:52 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T03:54:44Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6033410773 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1202#pullrequestreview-6033410773). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T03:54:44Z. **Review:** COMMENTED --- _No description provided._
chatgpt-codex-connector[bot commented 2026-11-24 06:46:52 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T05:00:28Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c59161c392

ℹ️ 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:6033920013 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1202#pullrequestreview-6033920013). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T05:00:28Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `c59161c392` <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>
tedin7 commented 2026-11-24 06:46:52 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:05:34Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6033983919 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1202#pullrequestreview-6033983919). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T05:05:34Z. **Review:** COMMENTED --- _No description provided._
chatgpt-codex-connector[bot commented 2026-11-24 06:46:52 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T05:13:29Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bd558d6400

ℹ️ 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:6034054675 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1202#pullrequestreview-6034054675). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T05:13:29Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `bd558d6400` <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>
tedin7 commented 2026-11-24 06:46:52 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:17:50Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6034086480 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1202#pullrequestreview-6034086480). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T05:17:50Z. **Review:** COMMENTED --- _No description provided._
tedin7 commented 2026-11-24 06:50:16 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T03:54:47Z.


AI-assisted follow-up in e9d79b70: the unary draw program now ends at an exact depth of 0.625 (two inputs changed, every opcode still exercised, siblings still differ), and unary_reference() asserts the depth is inside [0, 1] so depth clipping cannot hide the triangle. mesh_entry_check.py binary passes with LLVM 19; the draw cases need a mesh-capable adapter and were not run here.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7121535373 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1202#issuecomment-7121535373). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T03:54:47Z. --- AI-assisted follow-up in e9d79b70: the unary draw program now ends at an exact depth of 0.625 (two inputs changed, every opcode still exercised, siblings still differ), and unary_reference() asserts the depth is inside [0, 1] so depth clipping cannot hide the triangle. mesh_entry_check.py binary passes with LLVM 19; the draw cases need a mesh-capable adapter and were not run here.
tedin7 commented 2026-11-24 06:50:19 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T04:28:30Z.


@codex review

AI-assisted: the depth-clip finding is fixed in e9d79b70 and answered in its thread; please re-read the current head.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7122052763 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1202#issuecomment-7122052763). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T04:28:30Z. --- @codex review AI-assisted: the depth-clip finding is fixed in e9d79b70 and answered in its thread; please re-read the current head.
chatgpt-codex-connector[bot commented 2026-11-24 06:50:20 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T04:32:01Z.


Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: e9d79b7070

ℹ️ 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:comment:7122105679 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1202#issuecomment-7122105679). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T04:32:01Z. --- <!-- codex-review-receipt:v1 --> Codex Review: Didn't find any major issues. Can't wait for the next one! **Reviewed commit:** `e9d79b7070` <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>
tedin7 commented 2026-11-24 06:50:22 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T04:54:23Z.


AI-assisted change (c59161c3), test and docs only.

Why: on a Windows Server 2025 node with WARP, mesh_entry_draw_warp, mesh_entry_float_draw_warp and mesh_entry_cvt_minmax_draw_warp passed, but mesh_entry_unary_draw_warp failed with Draw reference mismatch: pixels=1024 mismatches=1024, so the whole triangle was missing. The export trace was not the failing check, which points at the shader compiled without trace exports.

What changed in tests/mesh_entry_check.py (the translator is untouched):

  • Every input now reaches its opcode through a register that holds an added zero the compiler cannot prove (the point and matrix value minus itself). Before, all inputs were literals, so the compiler could fold floor, round, frac and the others itself and the draw did not check what the hardware computes.
  • Reciprocal, reciprocal square root and square root are approximate in D3D and are no longer compared bit for bit. Each result is rounded to the nearest integer (add 0.5, floor) before it is summed, on inputs whose exact result is an integer, so any result within 0.5 gives the same depth. The sibling opcode gives a different integer in every case.
  • Floor, trunc, round half to even (-2.5, -0.5) and frac stay exact and are compared directly.
  • A fixed bias of -4.25 brings the final depth to 0.625. The reference still asserts 0 <= z <= 1 and is computed independently in Python.
  • Binary mode on Linux also checks that scaling the three approximate results by 1 +/- 2^-10 leaves the depth unchanged, and every opcode swapped for its sibling still changes it.
  • docs/experiments.md updated; precision of the approximate operations is still not claimed.

Linux: python3 -B tests/mesh_entry_check.py binary llvm-mc-19 llvm-objcopy-19 libLLVM.so.19.1 passes. The draw cannot run here.

To rerun on the Windows node (WARP): ctest -R mesh_entry_unary_draw_warp, and then ctest -R '^mesh_entry_.*_warp$'. If it still fails with every pixel missing, the cause is not folding or approximation; run the draw with the traced pass only and print the exported depth word.

@codex review

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7122444730 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1202#issuecomment-7122444730). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T04:54:23Z. --- AI-assisted change (c59161c3), test and docs only. Why: on a Windows Server 2025 node with WARP, `mesh_entry_draw_warp`, `mesh_entry_float_draw_warp` and `mesh_entry_cvt_minmax_draw_warp` passed, but `mesh_entry_unary_draw_warp` failed with `Draw reference mismatch: pixels=1024 mismatches=1024`, so the whole triangle was missing. The export trace was not the failing check, which points at the shader compiled without trace exports. What changed in `tests/mesh_entry_check.py` (the translator is untouched): - Every input now reaches its opcode through a register that holds an added zero the compiler cannot prove (the point and matrix value minus itself). Before, all inputs were literals, so the compiler could fold `floor`, `round`, `frac` and the others itself and the draw did not check what the hardware computes. - Reciprocal, reciprocal square root and square root are approximate in D3D and are no longer compared bit for bit. Each result is rounded to the nearest integer (add 0.5, floor) before it is summed, on inputs whose exact result is an integer, so any result within 0.5 gives the same depth. The sibling opcode gives a different integer in every case. - Floor, trunc, round half to even (-2.5, -0.5) and frac stay exact and are compared directly. - A fixed bias of -4.25 brings the final depth to 0.625. The reference still asserts 0 <= z <= 1 and is computed independently in Python. - Binary mode on Linux also checks that scaling the three approximate results by 1 +/- 2^-10 leaves the depth unchanged, and every opcode swapped for its sibling still changes it. - docs/experiments.md updated; precision of the approximate operations is still not claimed. Linux: `python3 -B tests/mesh_entry_check.py binary llvm-mc-19 llvm-objcopy-19 libLLVM.so.19.1` passes. The draw cannot run here. To rerun on the Windows node (WARP): `ctest -R mesh_entry_unary_draw_warp`, and then `ctest -R '^mesh_entry_.*_warp$'`. If it still fails with every pixel missing, the cause is not folding or approximation; run the draw with the traced pass only and print the exported depth word. @codex review
tedin7 commented 2026-11-24 06:50:23 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:04:26Z.


Re-verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit c59161c3:

  • Debug (--preset dev):
    • Build: cmake --preset dev && cmake --build out/build/dev -j 6 --target offscreen_check
    • Test: ctest --test-dir out/build/dev -R "^mesh_entry_.*_warp$" --output-on-failure -> 4/4 passed (6.37s total: mesh_entry_draw_warp 1.25s, mesh_entry_float_draw_warp 1.36s, mesh_entry_cvt_minmax_draw_warp 1.52s, mesh_entry_unary_draw_warp 2.20s)
  • Release /O2 (--preset release):
    • Build: cmake --preset release && cmake --build out/build/release -j 6 --target offscreen_check
    • Test: ctest --test-dir out/build/release -R "^mesh_entry_.*_warp$" --output-on-failure -> 4/4 passed (5.73s total: mesh_entry_draw_warp 1.21s, mesh_entry_float_draw_warp 1.22s, mesh_entry_cvt_minmax_draw_warp 1.41s, mesh_entry_unary_draw_warp 1.85s)
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7122598906 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1202#issuecomment-7122598906). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T05:04:26Z. --- Re-verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `c59161c3`: - **Debug (`--preset dev`)**: - Build: `cmake --preset dev && cmake --build out/build/dev -j 6 --target offscreen_check` - Test: `ctest --test-dir out/build/dev -R "^mesh_entry_.*_warp$" --output-on-failure` -> **4/4 passed** (`6.37s` total: `mesh_entry_draw_warp` `1.25s`, `mesh_entry_float_draw_warp` `1.36s`, `mesh_entry_cvt_minmax_draw_warp` `1.52s`, `mesh_entry_unary_draw_warp` `2.20s`) - **Release `/O2` (`--preset release`)**: - Build: `cmake --preset release && cmake --build out/build/release -j 6 --target offscreen_check` - Test: `ctest --test-dir out/build/release -R "^mesh_entry_.*_warp$" --output-on-failure` -> **4/4 passed** (`5.73s` total: `mesh_entry_draw_warp` `1.21s`, `mesh_entry_float_draw_warp` `1.22s`, `mesh_entry_cvt_minmax_draw_warp` `1.41s`, `mesh_entry_unary_draw_warp` `1.85s`)
tedin7 commented 2026-11-24 06:50:23 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:05:36Z.


AI-assisted update for the P2 finding on tools/mesh_entry_aot.py: v_fract_f32 now lowers to min(frac(x), asfloat(0x3f7fffffu)), as in the pixel and dispatch translators. The binary check feeds -2^-30 (e32) and -2^-28 (e64) and compares with the binary32 rule fract(x) = min(x - floor(x), 0x3f7fffff); dropping the cap from either encoding changes the depth and fails. The unary draw program is unchanged, so its depth stays 0.625.

@codex review

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7122616409 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1202#issuecomment-7122616409). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T05:05:36Z. --- AI-assisted update for the P2 finding on `tools/mesh_entry_aot.py`: `v_fract_f32` now lowers to `min(frac(x), asfloat(0x3f7fffffu))`, as in the pixel and dispatch translators. The binary check feeds -2^-30 (e32) and -2^-28 (e64) and compares with the binary32 rule fract(x) = min(x - floor(x), 0x3f7fffff); dropping the cap from either encoding changes the depth and fails. The unary draw program is unchanged, so its depth stays 0.625. @codex review
tedin7 commented 2026-11-24 06:50:25 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:17:52Z.


AI-assisted: the NaN-preserving cap for v_fract_f32 in the mesh entry translator is now a comparison (frac(x) >= 1.0f ? asfloat(0x3f7fffffu) : frac(x)), as in the pixel translator, so a NaN input stays a NaN. The test covers both encodings with a NaN input and checks that the old min form loses it.

@codex review

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7122814958 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1202#issuecomment-7122814958). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T05:17:52Z. --- AI-assisted: the NaN-preserving cap for `v_fract_f32` in the mesh entry translator is now a comparison (`frac(x) >= 1.0f ? asfloat(0x3f7fffffu) : frac(x)`), as in the pixel translator, so a NaN input stays a NaN. The test covers both encodings with a NaN input and checks that the old `min` form loses it. @codex review
tedin7 commented 2026-11-24 06:50:25 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:19:32Z.


Re-verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit 372408ad8decda72f21498cadddf3422f503478a:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target offscreen_check -- -j 6): 26s (configure 1.87s)
    • Test (ctest --preset dev -R '^mesh_entry_.*_warp$' --parallel 4 --no-tests=error --output-on-failure): 4/4 passed (3.19s: mesh_entry_draw_warp 2.16s, mesh_entry_float_draw_warp 2.31s, mesh_entry_cvt_minmax_draw_warp 2.35s, mesh_entry_unary_draw_warp 3.12s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target offscreen_check -- -j 6): 28.17s (configure 1.79s)
    • Test (ctest --preset release -R '^mesh_entry_.*_warp$' --parallel 4 --no-tests=error --output-on-failure): 4/4 passed (2.99s: mesh_entry_draw_warp 2.03s, mesh_entry_float_draw_warp 2.03s, mesh_entry_cvt_minmax_draw_warp 2.12s, mesh_entry_unary_draw_warp 2.92s)
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7122841192 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1202#issuecomment-7122841192). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T05:19:32Z. --- Re-verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `372408ad8decda72f21498cadddf3422f503478a`: - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev --target offscreen_check -- -j 6`): `26s` (configure `1.87s`) - Test (`ctest --preset dev -R '^mesh_entry_.*_warp$' --parallel 4 --no-tests=error --output-on-failure`): **4/4 passed** (`3.19s`: `mesh_entry_draw_warp` `2.16s`, `mesh_entry_float_draw_warp` `2.31s`, `mesh_entry_cvt_minmax_draw_warp` `2.35s`, `mesh_entry_unary_draw_warp` `3.12s`) - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release --target offscreen_check -- -j 6`): `28.17s` (configure `1.79s`) - Test (`ctest --preset release -R '^mesh_entry_.*_warp$' --parallel 4 --no-tests=error --output-on-failure`): **4/4 passed** (`2.99s`: `mesh_entry_draw_warp` `2.03s`, `mesh_entry_float_draw_warp` `2.03s`, `mesh_entry_cvt_minmax_draw_warp` `2.12s`, `mesh_entry_unary_draw_warp` `2.92s`)
chatgpt-codex-connector[bot commented 2026-11-24 06:50:26 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T05:22:32Z.


Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 372408ad8d

ℹ️ 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:comment:7122887882 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1202#issuecomment-7122887882). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T05:22:32Z. --- <!-- codex-review-receipt:v1 --> Codex Review: Didn't find any major issues. Breezy! **Reviewed commit:** `372408ad8d` <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-24 06:50:26 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T03:47:58Z.


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-24T05:22:33.549572Z 372408a Manual request
ℹ️ 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:7121432663 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1202#issuecomment-7121432663). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T03:47:58Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"372408ad8decda72f21498cadddf3422f503478a","has_any_findings":false,"has_unresolved_findings":false,"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-24T05:22:33.549572Z">2026-11-24T05:22:33.549572Z</relative-time> | `372408a` | Manual request | <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-24 06:50:40 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T03:52:12Z.

Code review location: tests/mesh_entry_check.py; line 625

@@ -544,6 +557,119 @@ def cvt_minmax_binary(tmp, tools):
         raise AssertionError(line)
 
 
+# One-source binary32 math. Every input has an exact result, and the sibling opcode gives a different one: a
+# reciprocal and a reciprocal square root of different powers of two, floor and truncation of negative fractions,
+# a tie rounded to even (3.5 and -2.5; floor of -2.5 is -3, round half away is -3 too), and a fractional part.
+UNARY_CASES = [
+    ("v_rcp_f32_e32", 4.0, "v_rsq_f32_e32"),
+    ("v_rsq_f32_e32", 16.0, "v_rcp_f32_e32"),
+    ("v_sqrt_f32_e32", 2.25, "v_rsq_f32_e32"),
+    ("v_floor_f32_e32", -2.5, "v_trunc_f32_e32"),
+    ("v_trunc_f32_e32", -2.5, "v_floor_f32_e32"),
+    ("v_rndne_f32_e32", 3.5, "v_floor_f32_e32"),
+    ("v_fract_f32_e32", -2.25, "v_floor_f32_e32"),
+    ("v_rcp_f32_e64", 0.125, "v_rsq_f32_e64"),
+    ("v_rsq_f32_e64", 0.0625, "v_rcp_f32_e64"),
+    ("v_sqrt_f32_e64", 0.5625, "v_rsq_f32_e64"),
+    ("v_floor_f32_e64", -7.75, "v_trunc_f32_e64"),
+    ("v_trunc_f32_e64", -6.75, "v_floor_f32_e64"),
+    ("v_rndne_f32_e64", -2.5, "v_floor_f32_e64"),
+    ("v_fract_f32_e64", 5.125, "v_floor_f32_e64"),
+]
+
+
+def fword(x):
+    return struct.unpack("<I", struct.pack("<f", x))[0]
+
+
+def unary_program(swap=None, line=None):
+    # The e32 forms read a literal; the e64 forms read a register. A swap replaces one case's opcode with its sibling.
+    program = PROGRAM.copy()
+    body = []
+    for i, (op, x, sibling) in enumerate(UNARY_CASES):
+        op = sibling if op == swap else op
+        out = f"v{20 + i}"
+        if op.endswith("_e32"):
+            body.append(f"{op} {out}, 0x{fword(x):08x}")
+        else:
+            body += [f"v_mov_b32_e32 v{40 + i}, 0x{fword(x):08x}", f"{op} {out}, v{40 + i}"]
+        body.append(f"v_add_f32_e32 v3, {out}, v3")
+    program[-2:-2] = body
+    if line:
+        program.insert(-2, line)
+    return program
+
+
+def unary_reference():
+    # Independent of the lowering: Python arithmetic on exact values, in the order the program runs. Python rounds
+    # a tie to even, which is what v_rndne_f32 does.
+    exact = {
+        "v_rcp": lambda x: 1 / x,
+        "v_rsq": lambda x: 1 / math.sqrt(x),
+        "v_sqrt": math.sqrt,
+        "v_floor": math.floor,
+        "v_trunc": math.trunc,
+        "v_rndne": round,
+        "v_fract": lambda x: x - math.floor(x),
+    }
+    z = 0.125 + 0.375  # pointData y plus the matrix value
+    for op, x, _ in UNARY_CASES:
+        z += exact[op.rsplit("_f32", 1)[0]](x)
+    return z
+
+
+def unary_draw(program=None):
+    depth = unary_reference()
+    positions = [(x, y, depth, w) for x, y, _, w in TRIANGLE]
+    program = unary_program() if program is None else program
+    return lower(enumerate_pcs(program), [4099], (3, 1)), [(triangle_inputs(), positions, True)]

P1 Badge Keep the unary draw triangle inside the depth clip range

On a mesh-capable Windows adapter, this positive draw will fail even with correct lowering: unary_reference() and the emitted expressions both produce -0.875, giving every vertex z < 0 with w = 1. The harness enables depth clipping (tests/mesh_entry_draw.cpp:207), so the entire triangle is clipped, but visible=True makes fixture() expect 1,024 green pixels. Consequently, mesh_entry_unary_draw_* fails with Draw reference mismatch in its first, untraced draw and never reaches the export checks or mutation controls. Adjust the program and reference to produce an in-range depth, or expect the clipped raster.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4675295475 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1202#discussion_r4675295475). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T03:52:12Z. **Code review location:** `tests/mesh_entry_check.py`; line 625 ~~~~diff @@ -544,6 +557,119 @@ def cvt_minmax_binary(tmp, tools): raise AssertionError(line) +# One-source binary32 math. Every input has an exact result, and the sibling opcode gives a different one: a +# reciprocal and a reciprocal square root of different powers of two, floor and truncation of negative fractions, +# a tie rounded to even (3.5 and -2.5; floor of -2.5 is -3, round half away is -3 too), and a fractional part. +UNARY_CASES = [ + ("v_rcp_f32_e32", 4.0, "v_rsq_f32_e32"), + ("v_rsq_f32_e32", 16.0, "v_rcp_f32_e32"), + ("v_sqrt_f32_e32", 2.25, "v_rsq_f32_e32"), + ("v_floor_f32_e32", -2.5, "v_trunc_f32_e32"), + ("v_trunc_f32_e32", -2.5, "v_floor_f32_e32"), + ("v_rndne_f32_e32", 3.5, "v_floor_f32_e32"), + ("v_fract_f32_e32", -2.25, "v_floor_f32_e32"), + ("v_rcp_f32_e64", 0.125, "v_rsq_f32_e64"), + ("v_rsq_f32_e64", 0.0625, "v_rcp_f32_e64"), + ("v_sqrt_f32_e64", 0.5625, "v_rsq_f32_e64"), + ("v_floor_f32_e64", -7.75, "v_trunc_f32_e64"), + ("v_trunc_f32_e64", -6.75, "v_floor_f32_e64"), + ("v_rndne_f32_e64", -2.5, "v_floor_f32_e64"), + ("v_fract_f32_e64", 5.125, "v_floor_f32_e64"), +] + + +def fword(x): + return struct.unpack("<I", struct.pack("<f", x))[0] + + +def unary_program(swap=None, line=None): + # The e32 forms read a literal; the e64 forms read a register. A swap replaces one case's opcode with its sibling. + program = PROGRAM.copy() + body = [] + for i, (op, x, sibling) in enumerate(UNARY_CASES): + op = sibling if op == swap else op + out = f"v{20 + i}" + if op.endswith("_e32"): + body.append(f"{op} {out}, 0x{fword(x):08x}") + else: + body += [f"v_mov_b32_e32 v{40 + i}, 0x{fword(x):08x}", f"{op} {out}, v{40 + i}"] + body.append(f"v_add_f32_e32 v3, {out}, v3") + program[-2:-2] = body + if line: + program.insert(-2, line) + return program + + +def unary_reference(): + # Independent of the lowering: Python arithmetic on exact values, in the order the program runs. Python rounds + # a tie to even, which is what v_rndne_f32 does. + exact = { + "v_rcp": lambda x: 1 / x, + "v_rsq": lambda x: 1 / math.sqrt(x), + "v_sqrt": math.sqrt, + "v_floor": math.floor, + "v_trunc": math.trunc, + "v_rndne": round, + "v_fract": lambda x: x - math.floor(x), + } + z = 0.125 + 0.375 # pointData y plus the matrix value + for op, x, _ in UNARY_CASES: + z += exact[op.rsplit("_f32", 1)[0]](x) + return z + + +def unary_draw(program=None): + depth = unary_reference() + positions = [(x, y, depth, w) for x, y, _, w in TRIANGLE] + program = unary_program() if program is None else program + return lower(enumerate_pcs(program), [4099], (3, 1)), [(triangle_inputs(), positions, True)] ~~~~ --- **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Keep the unary draw triangle inside the depth clip range** On a mesh-capable Windows adapter, this positive draw will fail even with correct lowering: `unary_reference()` and the emitted expressions both produce `-0.875`, giving every vertex `z < 0` with `w = 1`. The harness enables depth clipping (`tests/mesh_entry_draw.cpp:207`), so the entire triangle is clipped, but `visible=True` makes `fixture()` expect 1,024 green pixels. Consequently, `mesh_entry_unary_draw_*` fails with `Draw reference mismatch` in its first, untraced draw and never reaches the export checks or mutation controls. Adjust the program and reference to produce an in-range depth, or expect the clipped raster. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
tedin7 commented 2026-11-24 06:50:40 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T03:54:44Z.

Code review location: tests/mesh_entry_check.py; line 625

@@ -544,6 +557,119 @@ def cvt_minmax_binary(tmp, tools):
         raise AssertionError(line)
 
 
+# One-source binary32 math. Every input has an exact result, and the sibling opcode gives a different one: a
+# reciprocal and a reciprocal square root of different powers of two, floor and truncation of negative fractions,
+# a tie rounded to even (3.5 and -2.5; floor of -2.5 is -3, round half away is -3 too), and a fractional part.
+UNARY_CASES = [
+    ("v_rcp_f32_e32", 4.0, "v_rsq_f32_e32"),
+    ("v_rsq_f32_e32", 16.0, "v_rcp_f32_e32"),
+    ("v_sqrt_f32_e32", 2.25, "v_rsq_f32_e32"),
+    ("v_floor_f32_e32", -2.5, "v_trunc_f32_e32"),
+    ("v_trunc_f32_e32", -2.5, "v_floor_f32_e32"),
+    ("v_rndne_f32_e32", 3.5, "v_floor_f32_e32"),
+    ("v_fract_f32_e32", -2.25, "v_floor_f32_e32"),
+    ("v_rcp_f32_e64", 0.125, "v_rsq_f32_e64"),
+    ("v_rsq_f32_e64", 0.0625, "v_rcp_f32_e64"),
+    ("v_sqrt_f32_e64", 0.5625, "v_rsq_f32_e64"),
+    ("v_floor_f32_e64", -7.75, "v_trunc_f32_e64"),
+    ("v_trunc_f32_e64", -6.75, "v_floor_f32_e64"),
+    ("v_rndne_f32_e64", -2.5, "v_floor_f32_e64"),
+    ("v_fract_f32_e64", 5.125, "v_floor_f32_e64"),
+]
+
+
+def fword(x):
+    return struct.unpack("<I", struct.pack("<f", x))[0]
+
+
+def unary_program(swap=None, line=None):
+    # The e32 forms read a literal; the e64 forms read a register. A swap replaces one case's opcode with its sibling.
+    program = PROGRAM.copy()
+    body = []
+    for i, (op, x, sibling) in enumerate(UNARY_CASES):
+        op = sibling if op == swap else op
+        out = f"v{20 + i}"
+        if op.endswith("_e32"):
+            body.append(f"{op} {out}, 0x{fword(x):08x}")
+        else:
+            body += [f"v_mov_b32_e32 v{40 + i}, 0x{fword(x):08x}", f"{op} {out}, v{40 + i}"]
+        body.append(f"v_add_f32_e32 v3, {out}, v3")
+    program[-2:-2] = body
+    if line:
+        program.insert(-2, line)
+    return program
+
+
+def unary_reference():
+    # Independent of the lowering: Python arithmetic on exact values, in the order the program runs. Python rounds
+    # a tie to even, which is what v_rndne_f32 does.
+    exact = {
+        "v_rcp": lambda x: 1 / x,
+        "v_rsq": lambda x: 1 / math.sqrt(x),
+        "v_sqrt": math.sqrt,
+        "v_floor": math.floor,
+        "v_trunc": math.trunc,
+        "v_rndne": round,
+        "v_fract": lambda x: x - math.floor(x),
+    }
+    z = 0.125 + 0.375  # pointData y plus the matrix value
+    for op, x, _ in UNARY_CASES:
+        z += exact[op.rsplit("_f32", 1)[0]](x)
+    return z
+
+
+def unary_draw(program=None):
+    depth = unary_reference()
+    positions = [(x, y, depth, w) for x, y, _, w in TRIANGLE]
+    program = unary_program() if program is None else program
+    return lower(enumerate_pcs(program), [4099], (3, 1)), [(triangle_inputs(), positions, True)]

Fixed in e9d79b70.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4675310508 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1202#discussion_r4675310508). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T03:54:44Z. **Code review location:** `tests/mesh_entry_check.py`; line 625 ~~~~diff @@ -544,6 +557,119 @@ def cvt_minmax_binary(tmp, tools): raise AssertionError(line) +# One-source binary32 math. Every input has an exact result, and the sibling opcode gives a different one: a +# reciprocal and a reciprocal square root of different powers of two, floor and truncation of negative fractions, +# a tie rounded to even (3.5 and -2.5; floor of -2.5 is -3, round half away is -3 too), and a fractional part. +UNARY_CASES = [ + ("v_rcp_f32_e32", 4.0, "v_rsq_f32_e32"), + ("v_rsq_f32_e32", 16.0, "v_rcp_f32_e32"), + ("v_sqrt_f32_e32", 2.25, "v_rsq_f32_e32"), + ("v_floor_f32_e32", -2.5, "v_trunc_f32_e32"), + ("v_trunc_f32_e32", -2.5, "v_floor_f32_e32"), + ("v_rndne_f32_e32", 3.5, "v_floor_f32_e32"), + ("v_fract_f32_e32", -2.25, "v_floor_f32_e32"), + ("v_rcp_f32_e64", 0.125, "v_rsq_f32_e64"), + ("v_rsq_f32_e64", 0.0625, "v_rcp_f32_e64"), + ("v_sqrt_f32_e64", 0.5625, "v_rsq_f32_e64"), + ("v_floor_f32_e64", -7.75, "v_trunc_f32_e64"), + ("v_trunc_f32_e64", -6.75, "v_floor_f32_e64"), + ("v_rndne_f32_e64", -2.5, "v_floor_f32_e64"), + ("v_fract_f32_e64", 5.125, "v_floor_f32_e64"), +] + + +def fword(x): + return struct.unpack("<I", struct.pack("<f", x))[0] + + +def unary_program(swap=None, line=None): + # The e32 forms read a literal; the e64 forms read a register. A swap replaces one case's opcode with its sibling. + program = PROGRAM.copy() + body = [] + for i, (op, x, sibling) in enumerate(UNARY_CASES): + op = sibling if op == swap else op + out = f"v{20 + i}" + if op.endswith("_e32"): + body.append(f"{op} {out}, 0x{fword(x):08x}") + else: + body += [f"v_mov_b32_e32 v{40 + i}, 0x{fword(x):08x}", f"{op} {out}, v{40 + i}"] + body.append(f"v_add_f32_e32 v3, {out}, v3") + program[-2:-2] = body + if line: + program.insert(-2, line) + return program + + +def unary_reference(): + # Independent of the lowering: Python arithmetic on exact values, in the order the program runs. Python rounds + # a tie to even, which is what v_rndne_f32 does. + exact = { + "v_rcp": lambda x: 1 / x, + "v_rsq": lambda x: 1 / math.sqrt(x), + "v_sqrt": math.sqrt, + "v_floor": math.floor, + "v_trunc": math.trunc, + "v_rndne": round, + "v_fract": lambda x: x - math.floor(x), + } + z = 0.125 + 0.375 # pointData y plus the matrix value + for op, x, _ in UNARY_CASES: + z += exact[op.rsplit("_f32", 1)[0]](x) + return z + + +def unary_draw(program=None): + depth = unary_reference() + positions = [(x, y, depth, w) for x, y, _, w in TRIANGLE] + program = unary_program() if program is None else program + return lower(enumerate_pcs(program), [4099], (3, 1)), [(triangle_inputs(), positions, True)] ~~~~ --- Fixed in e9d79b70.
chatgpt-codex-connector[bot commented 2026-11-24 06:50:42 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T05:00:28Z.

Code review location: tools/mesh_entry_aot.py; line 36

@@ -24,6 +24,20 @@ def span(token):
     return range(int(m[1]), int(m[2]) + 1)
 
 
+# One-source binary32 forms and their HLSL lowering. round is round-half-even, like v_rndne_f32. The result of
+# rcp, rsq and sqrt is whatever the host computes; callers must only rely on inputs whose result is exact.
+UNARY_F32_EXPR = {
+    "v_rcp_f32": "(1.0f / {x})",
+    "v_rsq_f32": "rsqrt({x})",
+    "v_sqrt_f32": "sqrt({x})",
+    "v_floor_f32": "floor({x})",
+    "v_trunc_f32": "trunc({x})",
+    "v_rndne_f32": "round({x})",
+    "v_fract_f32": "frac({x})",

P2 Badge Clamp the fractional result below one

For a small negative normal input such as -2**-30, bare HLSL frac can return 1.0f, whereas gfx1013 v_fract_f32 clamps the result to asfloat(0x3f7fffff). docs/experiments.md:4217 records this exact mismatch on RTX 4070 Ti, and both the pixel translator's fract32 helper and the depth translator already apply the clamp. This new mesh mapping accepts those inputs without restriction, so translated positions or attributes can differ from the native program on physical adapters even though the current exact-fraction cases pass. Apply the same clamp here and add a tiny-negative regression case.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4675714048 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1202#discussion_r4675714048). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T05:00:28Z. **Code review location:** `tools/mesh_entry_aot.py`; line 36 ~~~~diff @@ -24,6 +24,20 @@ def span(token): return range(int(m[1]), int(m[2]) + 1) +# One-source binary32 forms and their HLSL lowering. round is round-half-even, like v_rndne_f32. The result of +# rcp, rsq and sqrt is whatever the host computes; callers must only rely on inputs whose result is exact. +UNARY_F32_EXPR = { + "v_rcp_f32": "(1.0f / {x})", + "v_rsq_f32": "rsqrt({x})", + "v_sqrt_f32": "sqrt({x})", + "v_floor_f32": "floor({x})", + "v_trunc_f32": "trunc({x})", + "v_rndne_f32": "round({x})", + "v_fract_f32": "frac({x})", ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Clamp the fractional result below one** For a small negative normal input such as `-2**-30`, bare HLSL `frac` can return `1.0f`, whereas gfx1013 `v_fract_f32` clamps the result to `asfloat(0x3f7fffff)`. `docs/experiments.md:4217` records this exact mismatch on RTX 4070 Ti, and both the pixel translator's `fract32` helper and the depth translator already apply the clamp. This new mesh mapping accepts those inputs without restriction, so translated positions or attributes can differ from the native program on physical adapters even though the current exact-fraction cases pass. Apply the same clamp here and add a tiny-negative regression case. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
tedin7 commented 2026-11-24 06:50:42 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:05:34Z.

Code review location: tools/mesh_entry_aot.py; line 36

@@ -24,6 +24,20 @@ def span(token):
     return range(int(m[1]), int(m[2]) + 1)
 
 
+# One-source binary32 forms and their HLSL lowering. round is round-half-even, like v_rndne_f32. The result of
+# rcp, rsq and sqrt is whatever the host computes; callers must only rely on inputs whose result is exact.
+UNARY_F32_EXPR = {
+    "v_rcp_f32": "(1.0f / {x})",
+    "v_rsq_f32": "rsqrt({x})",
+    "v_sqrt_f32": "sqrt({x})",
+    "v_floor_f32": "floor({x})",
+    "v_trunc_f32": "trunc({x})",
+    "v_rndne_f32": "round({x})",
+    "v_fract_f32": "frac({x})",

Fixed in bd558d64.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4675750558 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1202#discussion_r4675750558). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T05:05:34Z. **Code review location:** `tools/mesh_entry_aot.py`; line 36 ~~~~diff @@ -24,6 +24,20 @@ def span(token): return range(int(m[1]), int(m[2]) + 1) +# One-source binary32 forms and their HLSL lowering. round is round-half-even, like v_rndne_f32. The result of +# rcp, rsq and sqrt is whatever the host computes; callers must only rely on inputs whose result is exact. +UNARY_F32_EXPR = { + "v_rcp_f32": "(1.0f / {x})", + "v_rsq_f32": "rsqrt({x})", + "v_sqrt_f32": "sqrt({x})", + "v_floor_f32": "floor({x})", + "v_trunc_f32": "trunc({x})", + "v_rndne_f32": "round({x})", + "v_fract_f32": "frac({x})", ~~~~ --- Fixed in bd558d64.
chatgpt-codex-connector[bot commented 2026-11-24 06:50:42 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T05:13:29Z.

Code review location: tools/mesh_entry_aot.py; line 37

@@ -24,6 +24,21 @@ def span(token):
     return range(int(m[1]), int(m[2]) + 1)
 
 
+# One-source binary32 forms and their HLSL lowering. round is round-half-even, like v_rndne_f32. The result of
+# rcp, rsq and sqrt is whatever the host computes; callers must only rely on inputs whose result is exact.
+UNARY_F32_EXPR = {
+    "v_rcp_f32": "(1.0f / {x})",
+    "v_rsq_f32": "rsqrt({x})",
+    "v_sqrt_f32": "sqrt({x})",
+    "v_floor_f32": "floor({x})",
+    "v_trunc_f32": "trunc({x})",
+    "v_rndne_f32": "round({x})",
+    # v_fract_f32 is x - floor(x) clamped to 0x3f7fffff: a tiny negative input must not round up to 1.0.
+    "v_fract_f32": "min(frac({x}), asfloat(0x3f7fffffu))",

P2 Badge Preserve NaNs when capping the fractional result

For a NaN source, frac produces NaN, but D3D's min returns its other, non-NaN operand. Both encodings therefore return the finite value asfloat(0x3f7fffff) instead of propagating NaN as gfx1013 does. This differs from the pixel translator's fract32 in tools/pixel_aot.py:319-321, whose comparison-based cap deliberately preserves NaN. Reuse that comparison-based cap and add a NaN regression so the tiny-negative fix does not silently turn NaN positions or attributes into finite values.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4675800137 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1202#discussion_r4675800137). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T05:13:29Z. **Code review location:** `tools/mesh_entry_aot.py`; line 37 ~~~~diff @@ -24,6 +24,21 @@ def span(token): return range(int(m[1]), int(m[2]) + 1) +# One-source binary32 forms and their HLSL lowering. round is round-half-even, like v_rndne_f32. The result of +# rcp, rsq and sqrt is whatever the host computes; callers must only rely on inputs whose result is exact. +UNARY_F32_EXPR = { + "v_rcp_f32": "(1.0f / {x})", + "v_rsq_f32": "rsqrt({x})", + "v_sqrt_f32": "sqrt({x})", + "v_floor_f32": "floor({x})", + "v_trunc_f32": "trunc({x})", + "v_rndne_f32": "round({x})", + # v_fract_f32 is x - floor(x) clamped to 0x3f7fffff: a tiny negative input must not round up to 1.0. + "v_fract_f32": "min(frac({x}), asfloat(0x3f7fffffu))", ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Preserve NaNs when capping the fractional result** For a NaN source, `frac` produces NaN, but D3D's `min` returns its other, non-NaN operand. Both encodings therefore return the finite value `asfloat(0x3f7fffff)` instead of propagating NaN as gfx1013 does. This differs from the pixel translator's `fract32` in `tools/pixel_aot.py:319-321`, whose comparison-based cap deliberately preserves NaN. Reuse that comparison-based cap and add a NaN regression so the tiny-negative fix does not silently turn NaN positions or attributes into finite values. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
tedin7 commented 2026-11-24 06:50:42 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:17:50Z.

Code review location: tools/mesh_entry_aot.py; line 37

@@ -24,6 +24,21 @@ def span(token):
     return range(int(m[1]), int(m[2]) + 1)
 
 
+# One-source binary32 forms and their HLSL lowering. round is round-half-even, like v_rndne_f32. The result of
+# rcp, rsq and sqrt is whatever the host computes; callers must only rely on inputs whose result is exact.
+UNARY_F32_EXPR = {
+    "v_rcp_f32": "(1.0f / {x})",
+    "v_rsq_f32": "rsqrt({x})",
+    "v_sqrt_f32": "sqrt({x})",
+    "v_floor_f32": "floor({x})",
+    "v_trunc_f32": "trunc({x})",
+    "v_rndne_f32": "round({x})",
+    # v_fract_f32 is x - floor(x) clamped to 0x3f7fffff: a tiny negative input must not round up to 1.0.
+    "v_fract_f32": "min(frac({x}), asfloat(0x3f7fffffu))",

Fixed in 372408ad.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4675827740 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1202#discussion_r4675827740). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T05:17:50Z. **Code review location:** `tools/mesh_entry_aot.py`; line 37 ~~~~diff @@ -24,6 +24,21 @@ def span(token): return range(int(m[1]), int(m[2]) + 1) +# One-source binary32 forms and their HLSL lowering. round is round-half-even, like v_rndne_f32. The result of +# rcp, rsq and sqrt is whatever the host computes; callers must only rely on inputs whose result is exact. +UNARY_F32_EXPR = { + "v_rcp_f32": "(1.0f / {x})", + "v_rsq_f32": "rsqrt({x})", + "v_sqrt_f32": "sqrt({x})", + "v_floor_f32": "floor({x})", + "v_trunc_f32": "trunc({x})", + "v_rndne_f32": "round({x})", + # v_fract_f32 is x - floor(x) clamped to 0x3f7fffff: a tiny negative input must not round up to 1.0. + "v_fract_f32": "min(frac({x}), asfloat(0x3f7fffffu))", ~~~~ --- Fixed in 372408ad.
upstream-sync closed this pull request 2026-11-24 09:04:20 +00:00
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!1195
No description provided.