shader: lower compute v_ldexp_f32 #3882

Open
Leyukaka wants to merge 2 commits from upstream-pr/3882 into main
Leyukaka commented 2026-12-02 18:40:12 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-12-02T18:40:12Z.


Carries #1918 by @henriazz10 with their commits. Refs #721.

#1918 conflicts with main and has had no author update since 11-25. The author's commit is kept with its authorship and message (08620337b, a cherry-pick of 89b9aa85 onto current main); one commit on top adds the lane my review of 11-28 asked for. @henriazz10, if you would rather continue in #1918, say so and I will close this PR.

Change

From #1918 (see its description for the full design, the fixture and the review history):

  • tools/compute_store_aot.py lowers v_ldexp_f32 to f32_ldexp(S0, S1), only under the caller statement f32_mode="ieee-rne-denorm" (--f32-mode). With no statement, or any other mode, the instruction is refused.
  • compute_store_aot_ldexp_f32_{warp,hardware} compare 320 words with an independent bit-level Python model.

Conflicts with main are resolved inside the cherry-pick, the way pigalot's merge 90b39c31 resolved them:

  • CMakeLists.txt: main's compute_store_aot_alu_bfm_* block, then the ldexp_f32 block.
  • tools/compute_store_aot.py: main's wave64 docstring and its later wave_size check are kept; the branch's older wave_size not in (None, 32) check is dropped.

Added here, in e68698e83:

  • No fixture word reached a result exponent of exactly 0, so if (e <= 0) -> if (e < 0) in f32_ldexp survived the draw. Lanes 32..63 of word 0 now subtract 247 from S1 (three new fixture lines). Lane 32 scales 0x3fc00000 (1.5) by -127, and word 128 must read the denormal 0x00600000; the edit gives 0x00400000.
  • Lanes 0..31 are unchanged, so word 20 still separates preserved denormals from flush-to-zero. The six reference controls keep their first differing words (243, 1, 1, 42, 1, 256).
  • ldexp_f32_controls() asserts the model value at word 128.
  • ldexp_f32_draw adds the edit to its recompiled-HLSL mutations (six now).
  • docs/experiments.md describes the new lane and mutation.

Validation

Windows, MSVC, dev preset, head e68698e83.

cmake --build --preset dev --target offscreen_check
ctest --preset dev --no-tests=error -R "^compute_store_aot_ldexp_f32_(warp|hardware)$" -V

Result: both passed, on WARP and on a hardware adapter. The draw runs the six recompiled-HLSL mutations, and each must fail.

Known limits

Still open from other reviews of #1918, not covered here:

  • e >= 255 -> e > 255 changes no fixture word (pigalot, JohnConnorNPC). A lane with S0 0x3fffffff, S1 128, expecting 0x7f800000, would catch it.
  • Dropping the lower clamp (clamp(asint(b), -512, 512) -> min(asint(b), 512)) changes no fixture word (JohnConnorNPC). A lane with S0 0x00000001, S1 0x80000000, expecting 0x00000000, would catch it.
  • The comment above F32_HELPERS["ldexp"] still says the translator does not read MODE and does not mention the f32_mode gate.
  • akimfomin's negative underflow input next to the signed-zero boundary is not added.
  • R0Y00's change request on 226e0d59 (the mode gate) is answered by the author's commit, per pigalot and JohnConnorNPC, but still needs R0Y00's re-review.

Other limits:

  • The LLVM 15 binary round trip was not rerun with the three new fixture lines.
  • The denormal, NaN and infinity cases check the helper against its own model on desktop adapters, as #1918 states.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5612563329 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3882). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-12-02T18:40:12Z. --- Carries #1918 by @henriazz10 with their commits. Refs #721. #1918 conflicts with `main` and has had no author update since 11-25. The author's commit is kept with its authorship and message (`08620337b`, a cherry-pick of `89b9aa85` onto current `main`); one commit on top adds the lane my review of 11-28 asked for. @henriazz10, if you would rather continue in #1918, say so and I will close this PR. ## Change From #1918 (see its description for the full design, the fixture and the review history): - `tools/compute_store_aot.py` lowers `v_ldexp_f32` to `f32_ldexp(S0, S1)`, only under the caller statement `f32_mode="ieee-rne-denorm"` (`--f32-mode`). With no statement, or any other mode, the instruction is refused. - `compute_store_aot_ldexp_f32_{warp,hardware}` compare 320 words with an independent bit-level Python model. Conflicts with `main` are resolved inside the cherry-pick, the way pigalot's merge `90b39c31` resolved them: - `CMakeLists.txt`: `main`'s `compute_store_aot_alu_bfm_*` block, then the `ldexp_f32` block. - `tools/compute_store_aot.py`: `main`'s wave64 docstring and its later `wave_size` check are kept; the branch's older `wave_size not in (None, 32)` check is dropped. Added here, in `e68698e83`: - No fixture word reached a result exponent of exactly 0, so `if (e <= 0)` -> `if (e < 0)` in `f32_ldexp` survived the draw. Lanes 32..63 of word 0 now subtract 247 from S1 (three new fixture lines). Lane 32 scales `0x3fc00000` (1.5) by -127, and word 128 must read the denormal `0x00600000`; the edit gives `0x00400000`. - Lanes 0..31 are unchanged, so word 20 still separates preserved denormals from flush-to-zero. The six reference controls keep their first differing words (243, 1, 1, 42, 1, 256). - `ldexp_f32_controls()` asserts the model value at word 128. - `ldexp_f32_draw` adds the edit to its recompiled-HLSL mutations (six now). - `docs/experiments.md` describes the new lane and mutation. ## Validation Windows, MSVC, dev preset, head `e68698e83`. ```powershell cmake --build --preset dev --target offscreen_check ctest --preset dev --no-tests=error -R "^compute_store_aot_ldexp_f32_(warp|hardware)$" -V ``` Result: both passed, on WARP and on a hardware adapter. The draw runs the six recompiled-HLSL mutations, and each must fail. ## Known limits Still open from other reviews of #1918, not covered here: - `e >= 255` -> `e > 255` changes no fixture word (pigalot, JohnConnorNPC). A lane with S0 `0x3fffffff`, S1 `128`, expecting `0x7f800000`, would catch it. - Dropping the lower clamp (`clamp(asint(b), -512, 512)` -> `min(asint(b), 512)`) changes no fixture word (JohnConnorNPC). A lane with S0 `0x00000001`, S1 `0x80000000`, expecting `0x00000000`, would catch it. - The comment above `F32_HELPERS["ldexp"]` still says the translator does not read MODE and does not mention the `f32_mode` gate. - akimfomin's negative underflow input next to the signed-zero boundary is not added. - R0Y00's change request on `226e0d59` (the mode gate) is answered by the author's commit, per pigalot and JohnConnorNPC, but still needs R0Y00's re-review. Other limits: - The LLVM 15 `binary` round trip was not rerun with the three new fixture lines. - The denormal, NaN and infinity cases check the helper against its own model on desktop adapters, as #1918 states.
R0Y00 commented 2026-12-02 19:06:18 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T19:06:18Z.

Review: COMMENTED


I checked e68698e8 against the f32_mode request on #1918. The offline lowerer and CLI require the explicit IEEE RNE mode with denormals preserved, and the new lane reaches the exact zero-exponent boundary. Independent MSVC Debug ctest --preset dev --no-tests=error -V -j 1 -R '^compute_store_aot_ldexp_f32_(warp|hardware)$' passed 2/2, including all six HLSL mutation controls, on Windows 11 build 26300, WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656 with the debug layer on. Please coordinate the landing branch with @henriazz10, as offered on #1918. The same evidence can carry to the original PR if it takes the boundary fixture.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6157073641 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3882#pullrequestreview-6157073641). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T19:06:18Z. **Review:** COMMENTED --- I checked e68698e8 against the `f32_mode` request on #1918. The offline lowerer and CLI require the explicit IEEE RNE mode with denormals preserved, and the new lane reaches the exact zero-exponent boundary. Independent MSVC Debug `ctest --preset dev --no-tests=error -V -j 1 -R '^compute_store_aot_ldexp_f32_(warp|hardware)$'` passed 2/2, including all six HLSL mutation controls, on Windows 11 build 26300, WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656 with the debug layer on. Please coordinate the landing branch with @henriazz10, as offered on #1918. The same evidence can carry to the original PR if it takes the boundary fixture.
R0Y00 commented 2026-12-03 03:52:39 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-03T03:52:39Z.

Review: COMMENTED


I followed up on the two open #1918 boundary controls at e68698e8 (clean trial merge with main 41a83a9a). ldexp_f32_controls() and both existing tests/compute_store_check.py draw-ldexp_f32 <dxc> <offscreen_check> <warp|hardware> runs passed, including the existing controls. The original fixture also passed both adapters with either e >= 255 changed to e > 255 or clamp(asint(b), -512, 512) changed to min(asint(b), 512).

I tried both suggested inputs in a temporary source fixture, varying the exponent delta per lane so DXC still compiled the branch. With both guards intact the entire 320-word readback matched on each adapter. With the first edit, lane 0 with S0 0x3fffffff, S1 128 read back 0x7fffffff instead of 0x7f800000 at word 0. With the second edit, lane 0 with S0 0x00000001, S1 0x80000000 read back 0x7f800000 instead of zero at word 1. Both failures were identical on WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656 (Windows build 26300, SDK DXC, debug layer enabled, no skips). These inputs distinguish the two mutations independently and can be carried into whichever PR the original author chooses.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6163412689 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3882#pullrequestreview-6163412689). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-03T03:52:39Z. **Review:** COMMENTED --- I followed up on the two open #1918 boundary controls at `e68698e8` (clean trial merge with `main` `41a83a9a`). `ldexp_f32_controls()` and both existing `tests/compute_store_check.py draw-ldexp_f32 <dxc> <offscreen_check> <warp|hardware>` runs passed, including the existing controls. The original fixture also passed both adapters with either `e >= 255` changed to `e > 255` or `clamp(asint(b), -512, 512)` changed to `min(asint(b), 512)`. I tried both suggested inputs in a temporary source fixture, varying the exponent delta per lane so DXC still compiled the branch. With both guards intact the entire 320-word readback matched on each adapter. With the first edit, lane 0 with S0 `0x3fffffff`, S1 `128` read back `0x7fffffff` instead of `0x7f800000` at word 0. With the second edit, lane 0 with S0 `0x00000001`, S1 `0x80000000` read back `0x7f800000` instead of zero at word 1. Both failures were identical on WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656 (Windows build 26300, SDK DXC, debug layer enabled, no skips). These inputs distinguish the two mutations independently and can be carried into whichever PR the original author chooses.
R0Y00 commented 2026-12-03 07:36:06 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-03T07:36:06Z.


Independent check of e68698e8: the existing compute_store_aot_ldexp_f32_(warp|hardware) fixture passed 2/2 on Windows 11 build 26300, SDK DXC, WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656, with the debug layer on and no skips. I also verified the two outstanding boundary suggestions from #1918 by replacing the first result in the existing source-built program:

  • v_ldexp_f32 of 0x3fffffff and 128 produced 0x7f800000. Changing e >= 255 to e > 255 produced 0x7fffffff on both adapters.
  • Form subnormal bits with v_add_nc_u32_e32 v10, 1, v3 and use exponent 0x80000000. The original produced positive zero. Replacing the exponent clamp with min(asint(b), 512) produced 0x7f800000 on both adapters. Computing the source word from the lane lets this exercise the normal translator path; a literal subnormal as the float source is refused.

Both original cases matched 320/320 words per adapter; each mutation mismatched 64/320. Please include these as regression rows and mention the explicit f32 mode gate in the helper comment. This checks desktop readback against the bit model.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7371194962 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3882#issuecomment-7371194962). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-03T07:36:06Z. --- Independent check of `e68698e8`: the existing `compute_store_aot_ldexp_f32_(warp|hardware)` fixture passed 2/2 on Windows 11 build 26300, SDK DXC, WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656, with the debug layer on and no skips. I also verified the two outstanding boundary suggestions from #1918 by replacing the first result in the existing source-built program: - `v_ldexp_f32` of `0x3fffffff` and `128` produced `0x7f800000`. Changing `e >= 255` to `e > 255` produced `0x7fffffff` on both adapters. - Form subnormal bits with `v_add_nc_u32_e32 v10, 1, v3` and use exponent `0x80000000`. The original produced positive zero. Replacing the exponent clamp with `min(asint(b), 512)` produced `0x7f800000` on both adapters. Computing the source word from the lane lets this exercise the normal translator path; a literal subnormal as the float source is refused. Both original cases matched 320/320 words per adapter; each mutation mismatched 64/320. Please include these as regression rows and mention the explicit f32 mode gate in the helper comment. This checks desktop readback against the bit model.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3882:upstream-pr/3882'
git switch 'upstream-pr/3882'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3882'
git switch 'upstream-pr/3882'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3882'
git switch 'upstream-pr/3882'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3882'
git switch 'main'
git merge --squash 'upstream-pr/3882'
git switch 'main'
git merge --ff-only 'upstream-pr/3882'
git switch 'main'
git merge 'upstream-pr/3882'
git push origin 'main'
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!3882
No description provided.