shader: lower v_ldexp_f32 in the direct compute path #3057

Manually merged
github merged 1 commit from github-bot/gh-3057 into gh-pr/3057/base 2026-11-27 14:42:07 +00:00 AGit
Owner

@⁠legacy-code-archaeologist on GitHub · 2026-11-27 12:48 UTC · original
legacy-code-archaeologist:shader/direct-ldexp → main · +286 −0 · 4 files · 1 commits · merged 2026-11-27 14:38 UTC

Change

src/gfx1013_direct_compute.inl lowers v_ldexp_f32 in the direct C++ compute path using integer bit operations only, matching tools/pixel_aot.py's ldexp32. Fixes #3013.

  • Semantics: exact binary32 scaling by 2^S1; zero, Inf and NaN (with payload) pass unchanged; denormal S0 normalized via five conditional shifts (16, 8, 4, 2, 1); S1 clamped to [-512, 512]; overflow to signed Inf; subnormal results rounded to nearest even; clamp saturates with integer comparisons (NaN / negative / -0 -> +0, >= 1.0 -> 1.0, denormals preserved).
  • Modifiers & refusals: abs/neg on S0 handled via bit operations; abs/neg on S1/S2, nonzero src2, omod, op_sel, SDWA and DPP are refused.
  • Fixture & docs: tests/native_ldexp_check.py, tests/cmake/native_ldexp.cmake, docs/experiments/native-direct-ldexp.md.

Verification

Commit 60c05adf on upstream/cpp-migration a0f67731, Windows 10.0.26100, dev preset:

  • cmake --build --preset dev --target compile_dxil native_store_replay: ok.
  • ctest --preset dev --no-tests=error -R '^native_ldexp_' -V: native_ldexp_controls passed (1.13 s); native_ldexp_hardware skipped (exit 77 — default adapter does not report shader model 6.6 with wave32, so readback is unmeasured).
  • python -B tests/docs_links_check.py: passed (66 Markdown files and 581 links).

AI-assisted.

**@⁠legacy-code-archaeologist** on GitHub · 2026-11-27 12:48 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3057) `legacy-code-archaeologist:shader/direct-ldexp` → `main` · +286 −0 · 4 files · 1 commits · merged 2026-11-27 14:38 UTC ## Change `src/gfx1013_direct_compute.inl` lowers `v_ldexp_f32` in the direct C++ compute path using integer bit operations only, matching `tools/pixel_aot.py`'s `ldexp32`. Fixes #3013. - **Semantics:** exact binary32 scaling by `2^S1`; zero, Inf and NaN (with payload) pass unchanged; denormal `S0` normalized via five conditional shifts (16, 8, 4, 2, 1); `S1` clamped to `[-512, 512]`; overflow to signed Inf; subnormal results rounded to nearest even; `clamp` saturates with integer comparisons (`NaN` / negative / `-0` -> `+0`, `>= 1.0` -> `1.0`, denormals preserved). - **Modifiers & refusals:** `abs`/`neg` on `S0` handled via bit operations; `abs`/`neg` on `S1`/`S2`, nonzero `src2`, `omod`, `op_sel`, SDWA and DPP are refused. - **Fixture & docs:** `tests/native_ldexp_check.py`, `tests/cmake/native_ldexp.cmake`, `docs/experiments/native-direct-ldexp.md`. ## Verification Commit `60c05adf` on `upstream/cpp-migration` `a0f67731`, Windows 10.0.26100, `dev` preset: - `cmake --build --preset dev --target compile_dxil native_store_replay`: ok. - `ctest --preset dev --no-tests=error -R '^native_ldexp_' -V`: `native_ldexp_controls` passed (1.13 s); `native_ldexp_hardware` skipped (exit 77 — default adapter does not report shader model 6.6 with wave32, so readback is **unmeasured**). - `python -B tests/docs_links_check.py`: passed (66 Markdown files and 581 links). AI-assisted.
Exact binary32 scaling after pixel_aot.py's ldexp32 with integer bit
operations only: zero, Inf and NaN unchanged, denormal inputs
normalized, denormal results rounded to nearest even, S1 clamped to
[-512, 512] and an integer saturate for clamp. Modifiers on S1/S2, a
src2 field, omod, op_sel, SDWA and DPP are refused.

Fixes #3013

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 12:58:25 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-27 13:07 UTC · original

Thanks for adding the v_ldexp_f32 coverage. New shader-lowering PRs target main. Retargeting this branch as it stands would also bring in the cpp-migration copies of #3034 and #3042. I checked that the single 60c05adf commit applies cleanly on main 801f4c3b. Could you replay just that commit onto current main and let us know when the PR is ready to retarget? If either heap change is needed for this fixture, please point to the dependency so we can order the reviews.

**@⁠R0Y00** on GitHub · 2026-11-27 13:07 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3057#issuecomment-7219093464) Thanks for adding the `v_ldexp_f32` coverage. New shader-lowering PRs target `main`. Retargeting this branch as it stands would also bring in the `cpp-migration` copies of #3034 and #3042. I checked that the single `60c05adf` commit applies cleanly on `main` `801f4c3b`. Could you replay just that commit onto current `main` and let us know when the PR is ready to retarget? If either heap change is needed for this fixture, please point to the dependency so we can order the reviews.
Author
Owner

@⁠RonLogic on GitHub · 2026-11-27 13:31 UTC · original

I tested the single 60c05adf00d4d04fce727b486e8ecdfa87ff3992 patch cherry-picked onto main ff04a75e58b5fb63e8638fa8cbdae8d98b06f48a (local a9b053f317dd38b144033c8395b4df6709b3bf0a). The four-file change applied cleanly. Neither of the two migration-only heap commits was needed for these fixtures.

Windows 11 26300.10075, MSVC 19.52, SDK 10.0.26100, DXC 1.9.2602.17, GeForce RTX 4070 (32.0.16.2124, default adapter, SM 6.6 / wave32, debug layer off for native replay).

foreach ($preset in 'release', 'dev') {
    cmake --build --preset $preset --target compile_dxil native_store_replay
    ctest --preset $preset --no-tests=error -j 1 -R '^native_(ldexp|absdiff|perm_lerp|cvt_pk16)_(controls|hardware)$' -V
}

Both presets passed 8/8 without skips. native_ldexp_hardware matched all 2,064 words per preset. The integer DXIL and operand-refusal controls passed.

As an independent Release check, I replayed 192 input/exponent pairs across 24 dispatches and compared all 49,536 readback words against math.ldexp in binary64, rounded once with struct.pack('<f', ...). This scaling is exact in binary64 for finite binary32 inputs in the allowed exponent range. The sweep included signed zero, adjacent subnormal/normal values, underflow ties, overflow, infinities, NaN payloads and both INT32 exponent extremes. All matched. The local WARP adapter advertises 4-lane waves, so the native replay does not apply to it.

**@⁠RonLogic** on GitHub · 2026-11-27 13:31 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3057#issuecomment-7219587082) I tested the single `60c05adf00d4d04fce727b486e8ecdfa87ff3992` patch cherry-picked onto `main` `ff04a75e58b5fb63e8638fa8cbdae8d98b06f48a` (local `a9b053f317dd38b144033c8395b4df6709b3bf0a`). The four-file change applied cleanly. Neither of the two migration-only heap commits was needed for these fixtures. Windows 11 `26300.10075`, MSVC 19.52, SDK 10.0.26100, DXC 1.9.2602.17, GeForce RTX 4070 (`32.0.16.2124`, default adapter, SM 6.6 / wave32, debug layer off for native replay). ```powershell foreach ($preset in 'release', 'dev') { cmake --build --preset $preset --target compile_dxil native_store_replay ctest --preset $preset --no-tests=error -j 1 -R '^native_(ldexp|absdiff|perm_lerp|cvt_pk16)_(controls|hardware)$' -V } ``` Both presets passed 8/8 without skips. `native_ldexp_hardware` matched all 2,064 words per preset. The integer DXIL and operand-refusal controls passed. As an independent Release check, I replayed 192 input/exponent pairs across 24 dispatches and compared all 49,536 readback words against `math.ldexp` in binary64, rounded once with `struct.pack('<f', ...)`. This scaling is exact in binary64 for finite binary32 inputs in the allowed exponent range. The sweep included signed zero, adjacent subnormal/normal values, underflow ties, overflow, infinities, NaN payloads and both `INT32` exponent extremes. All matched. The local WARP adapter advertises 4-lane waves, so the native replay does not apply to it.
github-bot changed target branch from cpp-migration to main 2026-11-27 13:46:16 +00:00
github-bot force-pushed github-bot/gh-3057 from 60c05adf00 to 35b43fac4a 2026-11-27 13:46:17 +00:00 Compare
Author
Owner

@⁠legacy-code-archaeologist on GitHub · 2026-11-27 13:52 UTC · original

@⁠R0Y00 Replayed just the single v_ldexp_f32 commit onto main (36d2cbeb -> 35b43fac, updating the base SHA in docs/experiments/native-direct-ldexp.md) and retargeted PR #3057 to main. Confirmed neither #3034 nor #3042 is needed for this change or its fixtures.

Thanks @⁠RonLogic for the independent RTX 4070 and 192-case math.ldexp verification.

Re-verified locally on 35b43fac (dev preset):

  • cmake --build --preset dev --target compile_dxil native_store_replay: ok
  • ctest --preset dev --no-tests=error -R '^native_ldexp_' -V: native_ldexp_controls passed (1.03 s); native_ldexp_hardware skipped (77, Quadro M1000M does not support shader model 6.6 with wave32 — readback unmeasured locally)
  • python -B tests/docs_links_check.py: passed (75 Markdown files and 585 links)

AI-assisted.

**@⁠legacy-code-archaeologist** on GitHub · 2026-11-27 13:52 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3057#issuecomment-7220049798) @⁠R0Y00 Replayed just the single `v_ldexp_f32` commit onto `main` (`36d2cbeb` -> `35b43fac`, updating the base SHA in `docs/experiments/native-direct-ldexp.md`) and retargeted PR #3057 to `main`. Confirmed neither #3034 nor #3042 is needed for this change or its fixtures. Thanks @⁠RonLogic for the independent RTX 4070 and 192-case `math.ldexp` verification. Re-verified locally on `35b43fac` (`dev` preset): - `cmake --build --preset dev --target compile_dxil native_store_replay`: ok - `ctest --preset dev --no-tests=error -R '^native_ldexp_' -V`: `native_ldexp_controls` passed (`1.03 s`); `native_ldexp_hardware` skipped (`77`, Quadro M1000M does not support shader model 6.6 with wave32 — readback unmeasured locally) - `python -B tests/docs_links_check.py`: passed (75 Markdown files and 585 links) AI-assisted.
github-bot changed target branch from main to gh-pr/3057/base 2026-11-27 14:42:06 +00:00
github manually merged commit 35b43fac4a into gh-pr/3057/base 2026-11-27 14:42:07 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-27 14:37 UTC · original · approved these changes

Reviewed 35b43fac integrated with main 2a4bbff5 (tree 2974b781d9a265c74a68df1d282c5053456a5b5d). The retargeted diff contains only the four v_ldexp_f32 files. The lowering bounds shifts even on discarded lanes, retains special values without clamp, and rounds subnormal results using the retained significand bit. Built compile_dxil native_store_replay and ran ctest --test-dir <build> --no-tests=error -j 1 -V -R '^native_(ldexp|absdiff|perm_lerp|cvt_pk16)_(controls|hardware)$' in Debug and Release /O2. Both passed 8/8 with zero skips, and v_ldexp_f32 matched all 2,064 words on RTX. The compile and incorrect-reference controls passed. Windows 11 build 26200.9974, RTX 4060 Laptop driver 32.0.16.1656, SDK DXC 10.0.26100, native replay debug layer off. The native fixture requires wave32 and has no local WARP coverage.

**@⁠R0Y00** on GitHub · 2026-11-27 14:37 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3057#pullrequestreview-6089746527) · **approved these changes** Reviewed `35b43fac` integrated with `main` `2a4bbff5` (tree `2974b781d9a265c74a68df1d282c5053456a5b5d`). The retargeted diff contains only the four `v_ldexp_f32` files. The lowering bounds shifts even on discarded lanes, retains special values without clamp, and rounds subnormal results using the retained significand bit. Built `compile_dxil native_store_replay` and ran `ctest --test-dir <build> --no-tests=error -j 1 -V -R '^native_(ldexp|absdiff|perm_lerp|cvt_pk16)_(controls|hardware)$'` in Debug and Release `/O2`. Both passed 8/8 with zero skips, and `v_ldexp_f32` matched all 2,064 words on RTX. The compile and incorrect-reference controls passed. Windows 11 build 26200.9974, RTX 4060 Laptop driver 32.0.16.1656, SDK DXC 10.0.26100, native replay debug layer off. The native fixture requires wave32 and has no local WARP coverage.
This discussion has been locked. Commenting is limited to contributors.
No description provided.