Direct DXIL: truncate s instead of returning native on special values in round_exact #1898

Manually merged
github merged 1 commit from gh-pr/1898/head into gh-pr/1898/base 2026-11-26 05:08:41 +00:00
Owner

@⁠emirduran707 on GitHub · 2026-11-24 22:39 UTC · original
emirduran707:dxil-round-denorm-inf-nan → main · +37 −17 · 2 files · 1 commits · merged 2026-11-24 23:55 UTC

In directed f32 rounding (crates/xcl/src/gpu/dxil/lower_round.rs, #1679), round_exact returned the native D3D12 f32 result (native) whenever the f64 value s was ±inf or NaN (ex == 0x7FF). Because native is computed with D3D12's default f32 denormal behaviour rather than MODE's input denormal control (ext_exact), v_mul_f32(denormal, +inf) and v_fma_f32(denormal, +inf, 1.0) returned NaN (0xffc00000) instead of +inf (0x7f800000) when input denormals are preserved (MODE_INIT), and can similarly disagree when input denormals are flushed.

s already holds the exact f64 ±inf/NaN computed from the MODE-aware inputs: round_exact now truncates s directly with FPTrunc on the special path, and the unused native parameter is removed from round_exact and round_sum.

What is in it

  • crates/xcl/src/gpu/dxil/lower_round.rs: truncate s via FPTrunc on ex == 0x7FF in round_exact instead of returning native; drop unused native parameter from round_exact and round_sum.
  • crates/xcl/src/gpu/dxil/round_tests.rs: GPU test gpu_direct_f32_round_preserved_denormal_times_inf_is_inf checking v_mul_f32(0x0000_0001, +inf) and v_fma_f32(0x0000_0001, +inf, 1.0) under directed rounding with preserved denormals.

Tested

  • AMD Radeon RX 9060 XT (driver 32.0.31044.16), Ryzen 5 5600, Windows 11 Pro 26300, Rust 1.100.0; tests debug, smoke release
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on e1217e7: 974 passed, 2 failed, 45 ignored; 8 SKIPPED (6 in lower_dxil::tests::{f16,f32}_programs_on_the_gpu; heap_window_out_of_memory_falls_back_to_the_switch_form; pso_measurement_compiles_an_exact_synthetic_record)
    • The 2 failures (gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 seed 722 and fuzz_validate_and_gpu_3 seed 1599) fail identically on unmodified main 689f2db on this GPU.
  • cargo test -p xcl --lib round_tests -- --test-threads=4: 5 passed, 0 failed
  • gpu_direct_f32_round_preserved_denormal_times_inf_is_inf before the change failed (v_mul_f32(denorm, +inf) with preserve = 0xffc00000, expected +inf); passes after

Regression run

main:

xcl-smoke v1
commit: c4d37bec1bb4286eb373aea963404a23f13401fa
gpu: AMD Radeon RX 9060 XT
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1539 (PresentX 1539)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14791 MB

this PR:

xcl-smoke v1
commit: e1217e762c3fa064dd2d3bceb44e640cc2a5d7eb
gpu: AMD Radeon RX 9060 XT
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1613 (PresentX 1613)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14652 MB

Not tested

  • NVIDIA and Intel GPUs.
  • The smoke title's run is a regression check only.

AI use

  • Antigravity with Gemini 4 Neon: found the bug, wrote the fix, GPU test and this description, and ran the test suite and smoke runs above.
**@⁠emirduran707** on GitHub · 2026-11-24 22:39 UTC · [original](https://github.com/xcl-dev/xcl/pull/1898) `emirduran707:dxil-round-denorm-inf-nan` → `main` · +37 −17 · 2 files · 1 commits · merged 2026-11-24 23:55 UTC In directed f32 rounding (`crates/xcl/src/gpu/dxil/lower_round.rs`, #1679), `round_exact` returned the native D3D12 f32 result (`native`) whenever the f64 value `s` was `±inf` or `NaN` (`ex == 0x7FF`). Because `native` is computed with D3D12's default f32 denormal behaviour rather than `MODE`'s input denormal control (`ext_exact`), `v_mul_f32(denormal, +inf)` and `v_fma_f32(denormal, +inf, 1.0)` returned `NaN` (`0xffc00000`) instead of `+inf` (`0x7f800000`) when input denormals are preserved (`MODE_INIT`), and can similarly disagree when input denormals are flushed. `s` already holds the exact f64 `±inf`/`NaN` computed from the `MODE`-aware inputs: `round_exact` now truncates `s` directly with `FPTrunc` on the `special` path, and the unused `native` parameter is removed from `round_exact` and `round_sum`. **What is in it** - `crates/xcl/src/gpu/dxil/lower_round.rs`: truncate `s` via `FPTrunc` on `ex == 0x7FF` in `round_exact` instead of returning `native`; drop unused `native` parameter from `round_exact` and `round_sum`. - `crates/xcl/src/gpu/dxil/round_tests.rs`: GPU test `gpu_direct_f32_round_preserved_denormal_times_inf_is_inf` checking `v_mul_f32(0x0000_0001, +inf)` and `v_fma_f32(0x0000_0001, +inf, 1.0)` under directed rounding with preserved denormals. **Tested** - AMD Radeon RX 9060 XT (driver 32.0.31044.16), Ryzen 5 5600, Windows 11 Pro 26300, Rust 1.100.0; tests debug, smoke release - `cargo test --workspace --no-fail-fast -- --test-threads=4` on e1217e7: 974 passed, 2 failed, 45 ignored; 8 SKIPPED (6 in `lower_dxil::tests::{f16,f32}_programs_on_the_gpu`; `heap_window_out_of_memory_falls_back_to_the_switch_form`; `pso_measurement_compiles_an_exact_synthetic_record`) - The 2 failures (`gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1` seed 722 and `fuzz_validate_and_gpu_3` seed 1599) fail identically on unmodified `main` `689f2db` on this GPU. - `cargo test -p xcl --lib round_tests -- --test-threads=4`: 5 passed, 0 failed - `gpu_direct_f32_round_preserved_denormal_times_inf_is_inf` before the change failed (`v_mul_f32(denorm, +inf) with preserve = 0xffc00000, expected +inf`); passes after **Regression run** main: ``` xcl-smoke v1 commit: c4d37bec1bb4286eb373aea963404a23f13401fa gpu: AMD Radeon RX 9060 XT title: 21222967 seconds: 60 exit: 0x0 frames shown: 1539 (PresentX 1539) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14791 MB ``` this PR: ``` xcl-smoke v1 commit: e1217e762c3fa064dd2d3bceb44e640cc2a5d7eb gpu: AMD Radeon RX 9060 XT title: 21222967 seconds: 60 exit: 0x0 frames shown: 1613 (PresentX 1613) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14652 MB ``` **Not tested** - NVIDIA and Intel GPUs. - The smoke title's run is a regression check only. **AI use** - Antigravity with Gemini 4 Neon: found the bug, wrote the fix, GPU test and this description, and ran the test suite and smoke runs above.
In directed f32 rounding (`dxil/lower_round.rs`, #1679), `round_exact`
returned the native D3D12 f32 result (`native`) whenever the f64 value `s`
was `±inf` or `NaN` (`ex == 0x7FF`). Because `native` is computed with
D3D12's default f32 denormal behaviour rather than `MODE`'s input denormal
control (`ext_exact`), `denormal * +inf` and `fma(denormal, +inf, 1.0)`
returned `NaN` (`0xffc00000`) instead of `+inf` (`0x7f800000`) when input
denormals are preserved (`MODE_INIT`), and could similarly disagree when
input denormals are flushed.

`s` already holds the exact f64 `±inf`/`NaN` computed from the `MODE`-aware
inputs: truncate `s` directly with `FPTrunc` on the `special` path and remove
the unused `native` parameter from `round_exact` and `round_sum`.

Assisted-by: Antigravity (Gemini 4 Neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:08:39 +00:00
github manually merged commit e1217e762c into gh-pr/1898/base 2026-11-26 05:08:41 +00:00
Author
Owner

@⁠upipibi on GitHub · 2026-11-24 22:41 UTC · original

NVIDIA counterpart to the Radeon run: RTX 3070 8 GB, driver 616.56, Windows 11, debug, e1217e7 on main 689f2db.

  • gpu_direct_f32_round_preserved_denormal_times_inf_is_inf: passes, 2 of 2 runs.
  • Tests matching round: 29 passed, 0 failed.

AI-assisted (Claude Code). Synthetic tests only.

**@⁠upipibi** on GitHub · 2026-11-24 22:41 UTC · [original](https://github.com/xcl-dev/xcl/pull/1898#issuecomment-7146539972) NVIDIA counterpart to the Radeon run: RTX 3070 8 GB, driver 616.56, Windows 11, debug, `e1217e7` on `main` `689f2db`. - `gpu_direct_f32_round_preserved_denormal_times_inf_is_inf`: passes, 2 of 2 runs. - Tests matching `round`: 29 passed, 0 failed. AI-assisted (Claude Code). Synthetic tests only.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 02:07 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-25 02:07 UTC · [original](https://github.com/xcl-dev/xcl/pull/1898#issuecomment-7150342596) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
This discussion has been locked. Commenting is limited to contributors.
No description provided.