Repository navigation
Description
What happens
v_cubetc_f32 returns -S1 for z- and x-major directions. When S1 is a denormal, the two backends disagree on NVIDIA: the HLSL backend returns a signed zero, the direct DXIL backend returns the negated denormal.
Measured with the VALU fuzzer of #2169 (valu_fuzz_backends_agree, default four rounds, 256 inputs) on an RTX 3070. Of 341 instructions, 333 compared on both backends and this is the only one that differs: 58 of 256. Examples:
| sources (S0, S1, S2) | HLSL | direct |
|---|---|---|
ff7fffff, 0000ffff, 54ed8ab5 |
0x80000000 |
0x8000ffff |
7fffffff, 00000001, 3c01bc00 |
0x80000000 |
0x80000001 |
80010000, 0000007f, 38003bff |
0x80000000 |
0x8000007f |
ffffffff, 8001fc00, 0ecf289d |
0x00000000 |
0x0001fc00 |
All 58 are a zero on HLSL against a denormal on direct. The same 58 showed up on an RTX 3060 (same driver) in DarkPanda69's run on #2169. On the RX 9070 XT in that run, the HLSL result keeps the denormal, so this is the NVIDIA driver, not the translation.
Why
cube_tc in the HLSL prelude (crates/xcl/src/gpu/recomp/emit.rs) writes the negation as -y. DXC compiles that to an arithmetic subtraction (checked with the SDK's DXC 1.9.2602.17, -T cs_6_6 -HV 2021 -O1):
%21 = fsub fast float -0.000000e+00, %8
With no -denorm option the driver may flush the denormal of an fsub, and NVIDIA does. The direct backend lowers the same negation with fneg (crates/xcl/src/gpu/dxil/prelude.rs, cube), and that is also fsub -0.0, x (crates/xcl/src/gpu/dxil/lower.rs, fneg), not a sign-bit flip as this issue first said. NVIDIA keeps the denormal there; RADV under vkd3d-proton flushes it (reported on #2348).
cube_sc negates the same way (-x, -z) but did not differ in this run.
Plan
Negate by flipping the sign bit on both backends (asfloat(asuint(v) ^ 0x80000000u) in the HLSL cube_sc / cube_tc helpers, an integer xor in the direct cube), so the result does not depend on the driver's denormal handling. Add a GPU test with a denormal S1 for both backends.
One question first: XCL does not model the MODE denormal setting for f32 arithmetic (s_denorm_mode is a no-op outside frexp), so elsewhere f32 denormals follow the host driver. If agreeing with the direct backend here is not wanted, or if this should rather go with the fast-math work in #2168, I will leave it.
Tested
- NVIDIA GeForce RTX 3070 8 GB, driver 621.24 (32.0.16.2124); AMD Ryzen 7 5800X; Windows 11 Pro 10.0.26300; Rust 1.100.0 msvc; debug; DXC 1.9.2602.17 (Windows SDK 10.0.26100.0)
- Tests: a cross-backend and cross-device VALU fuzzer (ignored by default) #2169's head e792e6b merged locally into
main06c9f55 cargo test -p xcl --lib valu_fuzz_backends_agree -- --ignored --nocapture --test-threads=1withXCL_FUZZ_DIRset
Not tested
- RDNA2 hardware, so what the console returns for a denormal
S1is not measured - AMD on this build; a title
AI use
- Claude Code (Claude Opus 5.5) ran the fuzzer, read DXC's output and wrote this issue; the runs are on my machine.
Activity