shader: lower binary32 add, subtract and multiply in the compute store profile #1162
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1169"
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-24T02:22:37Z.
Change
Lowers four binary32 vector ALU forms in
tools/compute_store_aot.pybetween a guarded t0 read and the u0 store:v_add_f32_e32,v_sub_f32_e32,v_subrev_f32_e32andv_mul_f32_e32. Each is a small HLSL helper over the word bit pattern whose result isprecise, so a multiply followed by an add is not contracted. A result is again a word, so it can feed the integer forms already supported.Fused multiply-add (
v_fma_f32,v_fmac_f32_e32,v_mac_f32_e32) stays refused, because DXIL has no binary32 form with a guaranteed single rounding. NaN, infinity and denormal constants are refused (Unverified float operand). A word read from memory is not known statically, so the caller must keep operands and results finite and normal; the docs say so.Refs #721 (claim: https://github.com/R0Y00/Xbox2Windows/issues/721#issuecomment-7120064357). It touches the same files as #1118 (vector shifts and subtract); the code is separate (own table, helper, test case, CTest entry) and this branch starts from current
origin/main. Expect a mechanical merge intests/compute_store_check.py,CMakeLists.txtanddocs/experiments.md.Verification
Commit
062b3c5e, Linux, no GPU available here.python3 -B tests/compute_store_check.py binary llvm-mc-15 llvm-objcopy-15 libLLVM-15.so.1(Debian LLVM 15.0.6): exit 0. The same with LLVM 19: exit 0.tools/andtests/oforigin/mainexits 1 atUnsupported compute instruction: v_add_f32_e32 v4, v2, v3.python3 -B tests/rdna2_tools_check.pywith LLVM 15: 109 tests OK.docs_links_checkandbidi_controls_checkpass.subrevlowered assub, the multiply lowered as an add,precisedropped, the NaN refusal dropped, the denormal refusal dropped.compute_store_aot_f32_warpand_hardware, new CTest entries,draw-f32mode). I ran the samedrawflow against a Python stand-in for the compiler and renderer that evaluates the lowered HLSL with numpy binary32: all runs, five wrong references, two sentinel changes and eight HLSL mutants behaved as expected. That is a check of the test logic, not of WARP or a GPU. The same evaluation of the lowered expression on all 167 active lanes of the three dispatches matches the CPU model.Evidence and follow-up
The fixture is a guarded read-compute-write kernel built from source and assembled with LLVM 15 for gfx1013. The source word gives
xin [1.5, 2) andyin [3, 4) with integer operations, and the chain isa = x + y,b = cap - a,c = b - pi,d = x * c,e = 1.0 + d,out = e - (-4.0)withcap = 20.0. It uses every form, an SGPR, a literal and two inline constants as sources, and every operand and result is finite and normal (asserted). The exponent constants are chosen so LLVM does not print them as inline floats in the integer forms.The readback compares all 320 words on three dispatches (no lane passes, a split wave, five groups with 150 active lanes), so words past the bound must stay at their sentinel. The CPU model is separate Python that rounds each step to binary32; it shares no code with the lowering. Each of these must fail at its own word: five references with one operation swapped, a changed sentinel word at the bound and at word 319, and recompiled HLSL with add as subtract, exchanged subtract operands, multiply as add, the cap read from the next constant, a literal off by one bit, a flipped inline sign,
1.0replaced by2.0, and a guard that lets lane 150 write. No store or address code changes, so alignment and window handling are those of the existing guard.Not claimed: NaN payloads, infinities, denormals, fused multiply-add,
_e64and modifier forms,v_min_f32andv_max_f32. Anyone can pick up the fused forms if a binary32 construction with one rounding is found.AI-assisted (Codex).
Checklist
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T03:30:20Z.
Review: COMMENTED
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
044b39c82fℹ️ 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:33:51Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T02:45:48Z.
AI-assisted. Merged current main into this branch. The conflicts in the compute store lowerer and its check kept both sides: the binary32 add, subtract and multiply case, and the new shift and subtract case. compute_store_check.py binary (llvm 19) passes after the merge.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T03:19:34Z.
AI-assisted. Merged main again. The only conflict was in CMakeLists.txt, where both new compute store tests (binary32 and the 32-bit typed buffer load) are kept. compute_store_check.py binary (llvm 19) exits 0 after the merge.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T03:28:27Z.
AI-assisted. Merged main again. The only conflict was the draw mode table in tests/compute_store_check.py, where the binary32 mode and the new typed buffer store mode are both kept. compute_store_check.py binary (llvm 19) exits 0 after the merge. Merge commit
e56af416.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T03:34:44Z.
AI-assisted. Fixed the inline P2 in
d12a6b96: float helpers are now selected from the final body, including the LDS statements. The new case in f32_controls fails without the change (f32_mul called but not defined) and passes with it; tests/compute_store_check.py passes locally with LLVM 19.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T04:06:06Z.
@codex review
AI-assisted: the inline findings are fixed and answered in their threads; please re-read the current head.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T04:11:17Z.
Codex Review: Didn't find any major issues. Already looking forward to the next diff.
Reviewed commit:
d12a6b96e9ℹ️ 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:23:42Z.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
d12a6b9ℹ️ 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 tedin7 on 2026-11-24T04:47:34Z.
Windows Server 2025 verification (
d12a6b96) — PASS (Debug + Release/O2, WARP)--preset dev) (35.17s build+test):cmake --build --preset dev -j 6 --target offscreen_checkctest --test-dir out\build\dev -R "^compute_store_aot_(f32_)?warp$" --output-on-failure-> 2/2 passed (0 skipped, 15.14s:compute_store_aot_warp9.39s,compute_store_aot_f32_warp5.71s)/O2(--preset release) (42.24s configure+build+test):cmake --preset release && cmake --build --preset release -j 6 --target offscreen_checkctest --test-dir out\build\release -R "^compute_store_aot_(f32_)?warp$" --output-on-failure-> 2/2 passed (0 skipped, 14.51s:compute_store_aot_warp9.35s,compute_store_aot_f32_warp5.11s)Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T03:30:21Z.
Code review location:
tools/compute_store_aot.py; line 1154For gfx1030 kernels that feed a float ALU result into a materialized LDS operation, the helper call can appear only in
ds_steps, which is prepended after this scan. Addingv_mul_f32_e32 v7, 2.0, v7immediately beforeds_add_f32 v5, v7in the existinglds_f32_program("ds_add_f32")fixture reproduces this through the LLVM 20 assembly/CLI round trip: translation succeeds, but the generatedds_f32_0statement callsf32_mulwithout emitting its definition. This leaves an accepted, finite-normal kernel with uncompilable HLSL. Select helpers from the final body, including the LDS statements.Useful? React with 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T03:33:51Z.
Code review location:
tools/compute_store_aot.py; line 1154Fixed in
d12a6b96(AI-assisted): float helpers are now selected from the final body, DS steps included. New control lowers the LDS f32 fixture with a v_mul before ds_add_f32; it fails on the previous lowering (f32_mul called without its definition) and passes now. compute_store_check.py binary (llvm 19) exits 0.