shader: lower v_ldexp_f32 in the direct compute path #3057

Merged
legacy-code-archaeologist merged 1 commit from upstream-pr/3057 into main 2026-11-27 14:38:04 +00:00
legacy-code-archaeologist commented 2026-11-27 12:48:48 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-27T12:48:48Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5526897178 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3057). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-27T12:48:48Z. --- ## 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.
R0Y00 commented 2026-11-27 13:07:47 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-27T13:07:47Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7219093464 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3057#issuecomment-7219093464). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-27T13:07:47Z. --- 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.
RonLogic commented 2026-11-27 13:31:31 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RonLogic on 2026-11-27T13:31:31Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7219587082 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3057#issuecomment-7219587082). Originally posted by [RonLogic](https://github.com/RonLogic) on 2026-11-27T13:31:31Z. --- 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.
legacy-code-archaeologist commented 2026-11-27 13:52:26 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-27T13:52:26Z.


@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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7220049798 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3057#issuecomment-7220049798). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-27T13:52:26Z. --- @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.
R0Y00 commented 2026-11-27 14:37:51 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-27T14:37:51Z.

Review: APPROVED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6089746527 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3057#pullrequestreview-6089746527). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-27T14:37:51Z. **Review:** APPROVED --- 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.
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!3057
No description provided.