Recompiler: on NVIDIA the HLSL backend's v_cubetc_f32 flushes a denormal result to ±0; the direct backend keeps it #2347
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl#2347
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@Victorbriez on GitHub · 2026-11-25 16:13 UTC · original
What happens
v_cubetc_f32returns-S1for z- and x-major directions. WhenS1is 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:ff7fffff, 0000ffff, 54ed8ab50x800000000x8000ffff7fffffff, 00000001, 3c01bc000x800000000x8000000180010000, 0000007f, 38003bff0x800000000x8000007fffffffff, 8001fc00, 0ecf289d0x000000000x0001fc00All 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_tcin 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):With no
-denormoption the driver may flush the denormal of anfsub, and NVIDIA does. The direct backend lowers the same negation withfneg(crates/xcl/src/gpu/dxil/prelude.rs,cube), and that is alsofsub -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_scnegates 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 HLSLcube_sc/cube_tchelpers, an integer xor in the directcube), so the result does not depend on the driver's denormal handling. Add a GPU test with a denormalS1for both backends.One question first: XCL does not model the MODE denormal setting for f32 arithmetic (
s_denorm_modeis a no-op outsidefrexp), 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
e792e6bmerged locally intomain06c9f55cargo test -p xcl --lib valu_fuzz_backends_agree -- --ignored --nocapture --test-threads=1withXCL_FUZZ_DIRsetNot tested
S1is not measuredAI use