shader: lower one-source binary32 math and rounding in the mesh entry translator #1195
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1202"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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_f32andv_fract_f32(_e32and_e64) in the per-lane float forms oftools/mesh_entry_aot.py, to1.0f / x,rsqrt,sqrt,floor,trunc,round(half to even) andfrac. 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.tools/mesh_entry_aot.pyoforigin/mainexits 1 (the translator rejects the first new opcode).2.0f / x, rsq as1.0f / sqrt, sqrt asrsqrt, floor astrunc, trunc asfloor, round asfloor(x + 0.5f), frac asx - trunc(x).-v,|v|,clamp,mul:2,div:2and a two-source form.python3 -B tests/rdna2_tools_check.py(121 tests, OK, 13 skipped),docs_links_check.pyandbidi_controls_check.py: pass.mesh_entry_unary_draw_*(new CTest entry,draw-unary). It compares the exported position words with the Python reference, then must reportMesh export trace mismatchfor 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
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
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".
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T03:54:44Z.
Review: COMMENTED
No description provided.
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
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".
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:05:34Z.
Review: COMMENTED
No description provided.
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
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".
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:17:50Z.
Review: COMMENTED
No description provided.
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.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
e9d79b70and answered in its thread; please re-read the current head.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
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".
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_warpandmesh_entry_cvt_minmax_draw_warppassed, butmesh_entry_unary_draw_warpfailed withDraw 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):floor,round,fracand the others itself and the draw did not check what the hardware computes.Linux:
python3 -B tests/mesh_entry_check.py binary llvm-mc-19 llvm-objcopy-19 libLLVM.so.19.1passes. The draw cannot run here.To rerun on the Windows node (WARP):
ctest -R mesh_entry_unary_draw_warp, and thenctest -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
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:--preset dev):cmake --preset dev && cmake --build out/build/dev -j 6 --target offscreen_checkctest --test-dir out/build/dev -R "^mesh_entry_.*_warp$" --output-on-failure-> 4/4 passed (6.37stotal:mesh_entry_draw_warp1.25s,mesh_entry_float_draw_warp1.36s,mesh_entry_cvt_minmax_draw_warp1.52s,mesh_entry_unary_draw_warp2.20s)/O2(--preset release):cmake --preset release && cmake --build out/build/release -j 6 --target offscreen_checkctest --test-dir out/build/release -R "^mesh_entry_.*_warp$" --output-on-failure-> 4/4 passed (5.73stotal:mesh_entry_draw_warp1.21s,mesh_entry_float_draw_warp1.22s,mesh_entry_cvt_minmax_draw_warp1.41s,mesh_entry_unary_draw_warp1.85s)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_f32now lowers tomin(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
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:17:52Z.
AI-assisted: the NaN-preserving cap for
v_fract_f32in 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 oldminform loses it.@codex review
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:--preset dev):cmake --build --preset dev --target offscreen_check -- -j 6):26s(configure1.87s)ctest --preset dev -R '^mesh_entry_.*_warp$' --parallel 4 --no-tests=error --output-on-failure): 4/4 passed (3.19s:mesh_entry_draw_warp2.16s,mesh_entry_float_draw_warp2.31s,mesh_entry_cvt_minmax_draw_warp2.35s,mesh_entry_unary_draw_warp3.12s)/O2(--preset release):cmake --build --preset release --target offscreen_check -- -j 6):28.17s(configure1.79s)ctest --preset release -R '^mesh_entry_.*_warp$' --parallel 4 --no-tests=error --output-on-failure): 4/4 passed (2.99s:mesh_entry_draw_warp2.03s,mesh_entry_float_draw_warp2.03s,mesh_entry_cvt_minmax_draw_warp2.12s,mesh_entry_unary_draw_warp2.92s)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
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".
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.
372408aℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
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 625On 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 vertexz < 0withw = 1. The harness enables depth clipping (tests/mesh_entry_draw.cpp:207), so the entire triangle is clipped, butvisible=Truemakesfixture()expect 1,024 green pixels. Consequently,mesh_entry_unary_draw_*fails withDraw reference mismatchin 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 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T03:54:44Z.
Code review location:
tests/mesh_entry_check.py; line 625Fixed in
e9d79b70.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 36For a small negative normal input such as
-2**-30, bare HLSLfraccan return1.0f, whereas gfx1013v_fract_f32clamps the result toasfloat(0x3f7fffff).docs/experiments.md:4217records this exact mismatch on RTX 4070 Ti, and both the pixel translator'sfract32helper 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 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:05:34Z.
Code review location:
tools/mesh_entry_aot.py; line 36Fixed in
bd558d64.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 37For a NaN source,
fracproduces NaN, but D3D'sminreturns its other, non-NaN operand. Both encodings therefore return the finite valueasfloat(0x3f7fffff)instead of propagating NaN as gfx1013 does. This differs from the pixel translator'sfract32intools/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 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:17:50Z.
Code review location:
tools/mesh_entry_aot.py; line 37Fixed in
372408ad.