Skip to content

Recompiler: on NVIDIA the HLSL backend's v_cubetc_f32 flushes a denormal result to ±0; the direct backend keeps it #2347

Backlog

Description

@Victorbriez

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

Not tested

  • RDNA2 hardware, so what the console returns for a denormal S1 is 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions