DXIL: fix negative preserved denormal qNaN in rm_sqrt and route rm_mad via by_mode #2524
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2534"
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 ivall/xcl. Originally posted by Decodere on 2026-11-25T21:48:39Z.
Part of #675
Part of #1833
What is in it
Fixes two direct-DXIL directed f32 rounding bugs in
crates/xcl/src/gpu/dxil/lower_round.rsand expands test coverage incrates/xcl/src/gpu/dxil/round_tests.rs:Lw::rm_sqrt: Previously,rm_sqrtfell back tonative(dx.op.unary.f32(Sqrt, fa)) for nonzero special values (negv || infnan). Under D3D12 / SM 6.x, native f32Sqrtflushes f32 denormals to zero, so a negative preserved denormal (MODE[4] == 1) produced-0.0(0x8000_0000) instead ofqNaN, and static directed modes kept an unused nativeSqrtcall live.rm_sqrtnow computes the special-case result directly from theMODE[4]-filtered bitsu(±0->±0,+inf->+inf, negative nonzero values including preserved denormals and-infand all NaNs -> canonicalqNaN0x7FC0_0000), removing thenativedependency from the directed path so DCE eliminates the dead nativeSqrtin static directed modes.Lw::rm_madthroughLw::by_mode: Replaces the nestedrm_mul+rm_add+ outeris_neselect with a singleself.by_mode(native, mode, ...)(ext_exact->fmul->round_exact->ext_exact->round_sum), matchingrm_add,rm_mul, andrm_fma. ConstantRNEnow folds directly tonative(mad_nf) with zero f64 instructions, and dynamic mode emits only a singlenativemad_nfinstead of duplicate deadfmul float/fadd floatops.crates/xcl/src/gpu/dxil/round_tests.rs):ref_sqrtto returnSome(0x7FC0_0000)for negative nonzero inputs (instead of skipping them withNone) and updateddirected_reference_basicswith preserved/flushed negative-denormalref_sqrtassertions and host NaN comparison.direct_f32_round_sqrt_specials_and_mad_dxil_validate(pure-CPU/WARP0-skip DXC 1.9 validation + disassembly check verifying a singledx.op.unary.f32(i32 24, ...)under static directedv_sqrt_f32, singlefmul float/fadd floatunder dynamicv_mad_f32, and zerofmul doubleunder constant RNEv_mad_f32).gpu_direct_f32_round_sqrt_negative_denormals_and_specialscovering±denorm,±0,-1.0,±inf,±qNaN,±sNaN, andv_mad_f32(+denorm, +inf, 1.0)under boths_denorm_mode 3(preserve) ands_denorm_mode 0(flush) acrossrm in [1, 2, 3](cleanly skipped on WARP/CI viagpu_ready()).Tested
origin/main(lower_round.rsunchanged) with the new tests:direct_f32_round_sqrt_specials_and_mad_dxil_validate): panicked atround_tests.rs:574(expected 1 Sqrt (dead native eliminated): left: 2, right: 1).gpu_direct_f32_round_sqrt_negative_denormals_and_specials): panicked atround_tests.rs:639(rm=1 keep=true lane=0 in=0x80000001: got=0x80000000 want=0x7fc00000).1.9.2609.5,0compiler warnings inlower_round.rsandround_tests.rs):cargo test --release -p xcl --lib gpu::dxil::round_tests -- --test-threads=1 --nocapture:10 passed; 0 failed; 0 ignored(0skipped).XCL_ADAPTER=warp):cargo test --release -p xcl --lib gpu::dxil::round_tests -- --test-threads=1 --nocapture:10 passed; 0 failed; 0 ignored(all 4 CPU/DXC tests ran with0skips; all 6gpu_*tests cleanly reportedSKIPPED: no wave64).cargo test --release --workspace --no-fail-fast -- --test-threads=4 --nocapture):37test binaries:1425 passed; 0 failed; 46 ignored.29pre-existing runtimeSKIPPEDmessages (21no wave64on wave32-only RTX 4060,3per-lane form: refused,3no D3D12 debug layer/no d3d12SDKLayers.dll,1cannot disable the driver cache,1no heap windows).Regression run
Before (
origin/maine1d84b7d9153f86a97d2ec5d209d196046fc0bea):After (
fix-dxil-round-sqrt-denorm-madb3fced11b79fe70204212a03ec78e60dca110eb9):Both 60 s runs reach steady
60presents per 2 s (60 61 60vs60 60 60) with0device removals,0crashes,1593vs1556frames shown (102.4%), and14004 MBvs14015 MBpeak commit.Not tested
direct_kerneltests ran on the split-wave64 path;round_testslowering is wave-width independent).d3d12SDKLayers.dllis not installed on this machine).AI use
Written and verified with Google Antigravity (Gemini 4 Neon). All code changes, CPU/DXIL and RTX 4060 failing-first reproductions, targeted RTX 4060 and WARP test runs, the full release workspace suite, and both paired 60 s GPU smoke runs were executed and checked locally.
Imported from ivall/xcl. Originally posted by DarkPanda69 on 2026-11-25T22:00:46Z.
Native wave64 run (listed as untested) on AMD RDNA4, plus an RTX 3060: both new tests pass on both cards, and nothing else changes.
Head
b3fced1applied onmaine1d84b7, debug, Windows 11 Pro 26200,XCL_DIRECT_DXIL=1 cargo test -p xcl --lib -- gpu:: --test-threads=4onmainand with the PR, card chosen withXCL_ADAPTER:maindirect_kernel_full(.., true)runs native wave64 here)On both cards, the only result changes against
mainare the newgpu_direct_f32_round_sqrt_negative_denormals_and_specialsanddirect_f32_round_sqrt_specials_and_mad_dxil_validate, both ok, with no new skips. The 2 RX 9070 XT failures are the AMD fuzz seeds tracked in #2115, the same onmain. So the expected denormal and NaN results hold on both vendors' hardware, with denormals kept and flushed, for round modes 1–3.Not tested: the D3D12 debug-layer tests (no
d3d12SDKLayers.dllhere either; they skip), RDNA2/3, a title.AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T22:08:32Z.
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!
Imported from ivall/xcl. Originally posted by xpatfussy69x on 2026-11-25T22:09:19Z.
Test run on exact head
b3fced1(b3fced11b79fe70204212a03ec78e60dca110eb9, on its basee1d84b7), clean tree.Tested
cargo test --workspace -- --test-threads=4: 1425 passed, 0 failed, 46 ignoredV_MUL_F16/V_PK_MUL_F16/V_CVT_F16_F32(onmaintoo)cargo test -p xcl --lib round: 36 passed, 0 faileddirect_f32_round_sqrt_specials_and_mad_dxil_validate: ok, not skippedgpu_direct_f32_round_sqrt_negative_denormals_and_specials: ok, not skippedRegression run (60 s, default settings)
main:
this PR:
No crash or device removal; frames 101 % of
main's, peak commit 100 %.Not tested
XCL_DIRECT_DXIL=1, and no directed rounding mode: a regression check onlymain(tested on its own base; it merges intoe1d84b7without conflicts)AI use
Imported from ivall/xcl. Originally posted by emirduran707 on 2026-11-25T22:10:18Z.
Independent AMD RDNA4 (native wave64) test report on exact head
b3fced11b79fe70204212a03ec78e60dca110eb9(clean detached checkout, no local changes).Tested
stable-x86_64-pc-windows-msvc), DXC 1.9.2602.17; tests debug, smoke release.cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4: 1423 passed, 2 failed, 46 ignored; 8 SKIPPED (6 inlower_dxil::tests::{f16,f32}_programs_on_the_gpurefused by per-lane form;heap_window_out_of_memory_falls_back_to_the_switch_form;pso_measurement_compiles_an_exact_synthetic_record). All native wave64 GPU tests ran and passed.gpu::dxil::round_tests::direct_f32_round_sqrt_specials_and_mad_dxil_validateandgpu_direct_f32_round_sqrt_negative_denormals_and_specials.gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1seed 722 andfuzz_validate_and_gpu_3seed 1599) are pre-existing on unmodifiedmainon this GPU.Regression run (60 s retail-title smoke,
XCL_NETWORK=0, release)(Matched
main68a284abaseline on the same machine today: 1573 frames, 14420 MB peak, 0 device removals, 0 crashes.)Not tested
AI use
Imported from ivall/xcl. Originally posted by SlopTart on 2026-11-25T23:07:58Z.
Tested: current PR head merged onto current
origin/main(clean), Linux (Arch, kernel 7.2.15), Mesa 26.2.5 RADV, Radeon RX 7900 XT (NAVI31), cargo targetx86_64-pc-windows-gnurun under wine-11.0 (Proton), rustc 1.94.0, vkd3d-proton 3.1 with the XCL patch, official MS DXC (binaries 2026-09-29).gpu_suite (cold cache): 165 passed / 3 failed, no crashes. The three are the known baseline on this lane (seed-1003 fuzz, mad/mac contraction, promoted-UAV-clear driver gap, PR #2490); none caused by this PR.Targeted run of the rm_sqrt/rm_mad qNaN/denormal tests: the three matching new-behavior tests passed; the one failure in the same filter is the pre-existing baseline
gpu_nonfused_mad_and_mac_prevent_fma_contraction, which stays red on this lane with this PR (unchanged from main). Flagging that explicitly since this PR touches that machinery.Not tested: retail titles (no title data on this lane, counts only).
AI use: Hermes agent (local Qwen-class) ran both machines and drafted this; I checked it before posting.
Imported from ivall/xcl. Originally posted by luckyteagirl on 2026-11-25T23:31:01Z.
RX 6800M focused validation on exact PR head
b3fced11b79fe70204212a03ec78e60dca110eb9(Windows 11 build 26200, Radeon RX 6800M driver30.0.13002.13003, Rust 1.99.0 MSVC, DXC/DXIL 1.8.2502.11):XCL_ADAPTER=6800M XCL_REQUIRE_GPU=1 XCL_DIRECT_DXIL=1 cargo test --locked -p xcl --lib -j 1 gpu_direct_f32_round_sqrt_negative_denormals_and_specials -- --test-threads=1 --show-outputpassed on an isolated target directory: 1 passed, 0 failed, 0 ignored, 0 SKIPPED (1,325 filtered out). The fixture ran on native RDNA2 hardware, exercising the new negative-denormal/special-value cases in direct DXIL. The memory guard did not stop this completed run.A prior cold compile stopped at the memory guard before testing. A later attempt with a target directory shared across worktrees incorrectly reused another PR's test binary and selected zero tests; I detected that in the libtest summary, discarded it, and rebuilt in the isolated target for the result above. Neither earlier attempt is counted as a pass.
Not tested: full GPU workspace suite, release binary, paired title smoke, other adapters/drivers, or a full title path through these instructions. No game data was uploaded.
AI use: OpenAI Codex (GPT-6; exact variant unavailable) ran the guarded exact-head test, checked the binary/test selection and logs, and drafted this report.
Imported from ivall/xcl. Originally posted by throny on 2026-11-27T20:17:48Z.
merge-check claim
head:
b3fced11b7Imported from ivall/xcl. Originally posted by throny on 2026-11-27T20:32:08Z.
merge-check
base:
6089122ahead:
b3fced11b7merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 1467 passed, 0 failed, 47 ignored (26 SKIPPED lines); base alone: 1465 passed, 0 failed, 47 ignored
review: no defect. rm_sqrt: signed zero and +inf pass through, negatives (preserved denormals and -inf included) and NaN give the quiet NaN; the old code fell back to the native square root, which flushes denormals. rm_mad is an equivalent by_mode form. The three new tests fail on main by reading the code (not run there). Not verified: NaN inputs lose their payload; whether the hardware keeps denormals in the mad product, which one expectation assumes.
performance: direct DXIL only, fewer instructions under directed rounding; only XCL_DIRECT_DXIL users re-translate (reasoned).
verdict: safe to merge
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).
Imported from ivall/xcl. Originally posted by KOLESNiii on 2026-11-28T00:18:51Z.
merge-check claim
head:
b3fced11b7Imported from ivall/xcl. Originally posted by KOLESNiii on 2026-11-28T01:10:53Z.
merge-check
base:
2c717a043chead:
b3fced11b7merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 1468 passed, 0 failed, 47 ignored, 25 SKIPPED: 21 no wave64, 3 per-lane f16/f32 forms refused (#1426 semantics), 1 no heap windows; failing: none. The suite ran on this PC at the same time as 5 other PRs' suites, in one queued job.
review: none. Whole diff read (lower_round.rs rm_mad via by_mode, rm_sqrt special values; round_tests.rs reference + 2 tests). Under a directed round mode v_sqrt_f32 now returns canonical qNaN for negative inputs (also preserved denormals) and NaN, +inf for +inf, and +/-0 for zeros instead of falling back to the native Sqrt (which flushes denormals); v_mad_f32 goes through by_mode, so a constant RNE mode folds to the native mad.
performance: reasoned, not measured: shaders in the default round mode are unchanged (constant RNE folds to native); shaders that set the round mode at run time get the exact f64 path for v_mad_f32 in their directed branch.
verdict: safe to merge
hardware / tool and model: Windows 11 build 26300.9974, NVIDIA GeForce RTX 2070 SUPER 8 GB (driver 621.40, wave32 only), AMD Ryzen 5 3600XT; rustc 1.100.1 (20ddd0171 2026-11-25) x86_64-pc-windows-msvc, debug test profile; trial merge 5b9e2cdcf0db1cf50908586880d65c2bb0bc7454 (local, not pushed). Claude Code: Claude Opus 5.5 (coordination, full-diff review, draft).
Imported from ivall/xcl. Originally posted by Gevroska on 2026-11-28T02:04:30Z.
I found no change in finite
MADresults between basee1d84b7dand headb3fced11on an RTX 3080 using direct DXIL. I ran the same fixture on both revisions. It dispatched the shader and read back the GPU registers for three directed rounding settings, each with subnormal flushing and preservation. All six base/head readbacks matched bit for bit.MADwith a subnormal inputMULwith a positive subnormal productMULwith a negative subnormal product0x3f8000000x000000000x800000000x3f8000010x004000000x80400000In the first column, the shader computes
1 + 2⁻¹⁴⁹ × 2¹²⁶. Preserving the input adds exactly one FP32 ULP to1.0. Across all four lanes, including the normal control,MADalso matched a separateMULfollowed byADDon both revisions.The focused test passed once per revision with zero failures or skips (Windows, NVIDIA driver
32.0.16.1692, DXC1.9.2609.5). These inputs have exact arithmetic results, so they don’t distinguish the three rounding directions. The readbacks establish XCL’s behavior on this GPU; the console opcode’s behavior remains unverified.I used OpenAI Codex with GPT-6.2 Sol to write and run the fixture. A separate GPT-6.2 Sol agent verified the arithmetic and saved readbacks. GPT-6.1 Terra checked for overlapping upstream reports. GPT-6.2 Astra drafted this comment.
I reviewed and approved this comment before posting.