Skip to content

gfx2hlsl: the v_fma_mix lowering is not precise, so RDNA 1 drops the sign of a -0 product (startup_gfx2hlsl_fma_mix_dispatch_hardware) #2729

Done

Description

@ColorMeBoom

Commit or build

2215c26 (main)

Reproduction

ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_fma_mix_dispatch_(warp|hardware)$' -V

Expected behavior

negated inline 0 addend keeps a -0 product reads back 80000000, as on WARP. The case runs v1 = U(F(v2) * f16tof32(v3 >> 16) + (-0.0)); with v2 = 0x80000000 and a high half of 4.0. Stage.mix() already prints (-0.0) for this operand because "f() would print +0.0, which changes a -0 product".

Observed behavior

WARP passes. The RX 5700 XT fails two checks:

hardware: negated inline 0 addend keeps a -0 product readback: MISMATCH
  expected 80000000, got 00000000
hardware: control without the high-half shift reads the low half in all 4 high-half cases: MISMATCH

The second check is the same case: with the shift removed, the low-half reference is also -0 and the card returns +0.

A standalone DXC cs_6_0 probe isolates it. Inputs are read from the UAV at run time, through offscreen_check --raw-uav-dump:

Expression (v2 = -0, high half = 4.0) RX 5700 XT WARP
F(v2) * f16tof32(v3 >> 16) + (-0.0) (the translated line) 00000000 80000000
F(v2) * f16tof32(v3 >> 16) 00000000 80000000
F(v2) * f16tof32(v3 & 0xffffu) + (-0.0) (low half) 00000000 80000000
mad(F(v2), f16tof32(v3 >> 16), -0.0) 00000000 80000000
F(v2) * F(v3) + (-0.0), v3 = 4.0 as binary32 80000000 80000000
precise float p = F(v2) * f16tof32(v3 >> 16) + (-0.0); 80000000 80000000
precise float p = mad(F(v2), f16tof32(v3 >> 16), -0.0); 80000000 80000000

The sign is lost only when a widened binary16 operand feeds a non-precise multiply. Non-precise HLSL arithmetic does not guarantee signed zeros, and WARP takes the same freedom elsewhere: F(v2) * f16tof32(v3 >> 16) + 0.0 returns 80000000 on WARP and 00000000 on the RX 5700 XT.

mad32() in the same translator already computes its product and sum as precise. For mix() there is a choice. precise float r = a * b + c; keeps -0 but forbids contraction, so every adapter rounds the product before the add. The comment in mix() already accepts 1 ULP from rounding the product, but this would make it certain. precise float r = mad(a, b, c); also keeps -0 on both adapters here. DXC emits it as FMad, which a driver may still fuse. On this card it runs unfused either way: mad(4097, 4097, -16785408) returns 0, with or without precise. Either form would need the startup shader cache revision to advance. I can send the change as a PR once you pick the form.

Environment

Windows 11 Home build 26200.9974, VS 2022 Build Tools (MSVC 19.44.35230), Windows SDK 10.0.26100.0, DXC 1.9.2602.17 (SDK). AMD Radeon RX 5700 XT (RDNA 1, 1002:731f), driver 32.0.21045.29003, hardware backend; WARP 10.0.26100.9818. Debug layer unavailable.

AI-assisted with Claude Code (Claude Opus 5.5).

Checklist

  • I reproduced this on a source-built input.
  • I did not include game files, dumps, distribution links or credentials.

Activity

  1. added
    bug
    on Nov 26, 2026
  2. RonLogic commented on Nov 26, 2026

    @RonLogic
    Contributor

    Windows x64 Release comparison against 2215c26d using DXC 1.9.2602.17. I used the #2728 build after verifying its only differences from that base were GPU package tooling and CMake registration for the package recorder. Both adapter paths ran, with no skips. WARP driver 10.0.26100.10068; physical NVIDIA RTX 4070 driver 32.0.16.2124. Both startup_gfx2hlsl_fma_mix_dispatch tests passed. The widened binary16 signed-zero case kept 80000000, the high-half control passed, and the D3D12 debug layer reported zero errors or warnings. This provides a comparison point for the reported RDNA 1 result.

  3. R0Y00 commented on Nov 26, 2026

    @R0Y00
    Owner

    Please send a focused fix using a precise result of mad(a, b, c) for the existing v_fma_mix_f32 lowering. The RX 5700 XT probe distinguishes the signed-zero regression. mad still allows fused or unfused execution on a given backend, so record the cancellation discriminator separately and keep the documented approximation. Please bump the shader cache revision, preserve the half-selection and modifier order, and rerun the raw-bit signed-zero and wrong-half controls on RDNA 1 and WARP. RonLogic's RTX 4070 result is a useful baseline for a retest. HLSL mad · AMD RDNA 2 ISA

  4. thepatrickworld commented on Nov 26, 2026

    @thepatrickworld
    Contributor

    RDNA 4 datum for the fix requested here (b457f7ff, RX 9070 XT, driver 32.0.32029.2010, Windows 26200.9974).

    • The precise form keeps the sign: precise float p = F(v2) * f16tof32(v3 >> 16) + (-0.0); returns 80000000 on the card and on WARP, while the same row without it returns 00000000 on the card.
    • The fix has to cover the mad row too, not only the multiply-add: in the same shader tertiary.f32 = FMad(F(v2), f16tof32(v3 >> 16), -0.0) loses the sign as well, and it is not a fmul fast.
    • What the failing rows share is a multiply whose operand is widened out of binary16; a fmul fast with a binary32 operand keeps -0 on this adapter.

    Raw words, both shaders and the DXIL mapping are in the #2746 comment: #2746 (comment)

    AI-assisted.

  5. Not-Saii commented on Nov 26, 2026

    @Not-Saii
    Contributor

    I'm the fixture author from #2055. Here are notes on the precise mad form requested above, for whoever sends the PR. I have a local candidate but have not opened one. @ColorMeBoom, if your PR is in progress, send yours and I'll review it against these notes.

    Form. I tried one helper in Pipeline.common(), next to mul16 from #2779, and changed mix() to call it. All three forms now emit mix32(a, b, c). Operand order, half selection and modifiers stay the same, and saturate stays outside the call:

    float mix32(float a, float b, float c) { precise float result = mad(a, b, c); return result; }

    DXC 1.9.2602.17, cs_6_0, on v1 = U(mix32(F(v2), f16tof32(v3 >> 16), (-0.0)));:

    %7 = call float @dx.op.legacyF16ToF32(i32 131, i32 %6), !dx.precise !10
    %9 = call float @dx.op.tertiary.f32(i32 46, float %8, float %7, float -0.000000e+00), !dx.precise !10  ; FMad
    

    So the helper form keeps !dx.precise on both the FMad and the widening, the two places #2746 says lost the sign.

    Test notes (tests/startup_gfx2hlsl_fma_mix_check.py)

    • The FXC and dispatch shaders define only F and U, so they need the helper text. A module constant in gfx2hlsl.py, used by both common() and the test, keeps the two copies from drifting apart.
    • Stripping precise is not a useful negative control: WARP keeps -0 without it. A second dispatch shader whose helper returns asfloat(asuint(result) == 0x80000000u ? 0u : asuint(result)) must fail exactly the -0 case. It does on both adapters below.
    • The ' >> 16)' wrong-half control still matches the new text, and still changes 3 of 4 high-half results.
    • To record the cancellation discriminator without a pass/fail check, mix32(4097, 4097, -16785408) can go in one extra row, loaded through the UAV fill like the other inputs, with the word printed per adapter.

    Cache revision. main is at x2w-startup-shader-27 since #2778, so this would be 28. The revision is pinned in 11 files, including tests/startup_packed_position_provenance_check.py and tests/startup_resource_retire_title.cpp. Known answers at revision 28, computed with a standalone FNV-1a and checked against the revision 27 values first:

    • pipeline_key(b"\x00VS\xff", b"PS\x00\x80", b"RTS0\x00") = 0xe4791179bf7096b3; with layout b"ia\x00\xfe" = 0xf6cb7f56c2985cfb
    • tests/startup_compute_request_offline_check.py framed key at 28cs = 0x39e7422f5da15950

    Measured on 79410a80 plus the change, preset dev, Windows 11 26300.9974, DXC 1.9.2602.17 (SDK 10.0.26100.0), debug layer on with 0 errors and 0 warnings:

    adapter readback -0 case sign-clearing control wrong-half control mad(4097, 4097, -16785408)
    WARP 1414:008c, 10.0.26100.9818 17/17 80000000 fails only the -0 case 4/4, changes 3 00000000 (unfused)
    RTX 4090 10de:2684, 32.0.16.1088 17/17 80000000 fails only the -0 case 4/4, changes 3 3f800000 (fused)

    The RTX 4090 also passes on unmodified main, so neither row shows the fix on RDNA. That still needs the RX 5700 XT retest here and the RX 9070 XT retest offered in #2746.

    ctest --preset dev --no-tests=error -j1 -R '^startup_gfx2hlsl_fma_mix(_fxc|_dispatch_(warp|hardware))?$' -V

    AI-assisted with Claude Code (Claude Opus 5.5); commands listed were executed locally.

  6. Not-Saii commented on Nov 26, 2026

    @Not-Saii
    Contributor

    The precise mad lowering from this thread is on main as of 02075500 (#2818). All three v_fma_mix* forms now emit mix32(a, b, c), which is precise float result = mad(a, b, c); return result;. The cache revision moves to x2w-startup-shader-28.

    On WARP and an RTX 4090, all 17 words match, the -0 case reads 80000000, and a control helper that clears a -0 result fails only that case. The RTX 4090 also passed before the change, though, so this does not yet show the fix on RDNA 1.

    @ColorMeBoom, could you rerun on the RX 5700 XT at 02075500 or later?

    ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_fma_mix_dispatch_(warp|hardware)$' -V

    The useful lines are:

    • hardware: negated inline 0 addend keeps a -0 product readback;
    • hardware: control that clears a -0 result fails only the -0 product case;
    • the mad(4097, 4097, -16785408) line, which tells us whether the card fuses.

    Please include the driver and whether the debug layer was on. If it passes, this issue can close.

    AI-assisted with Claude Code (Claude Opus 5.5).

  7. ColorMeBoom commented on Nov 26, 2026

    @ColorMeBoom
    ContributorAuthor

    @Not-Saii: the fix passes on the RX 5700 XT at 22aa7bf9 (current main, contains 02075500).

    Environment:

    • Windows 11 Home build 26200.9974, preset dev.
    • DXC 1.9.2602.17 (SDK 10.0.26100.0).
    • AMD Radeon RX 5700 XT (RDNA 1, 1002:731f), driver 32.0.21045.29003.
    • WARP 10.0.26100.9818.
    • Debug layer unavailable on both.
    ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_fma_mix(_fxc|_dispatch_(warp|hardware))?$' -V

    All 4 tests passed: startup_gfx2hlsl_fma_mix, _fxc, _dispatch_warp and _dispatch_hardware.

    Line RX 5700 XT WARP
    negated inline 0 addend keeps a -0 product readback ok ok
    control that clears a -0 result fails only the -0 product case ok ok
    mad(4097, 4097, -16785408) 00000000 (unfused) 00000000 (unfused)

    Removing precise brings the failure back on this card. I edited only MIX32 in tools/startup/gfx2hlsl.py to float result = mad(a, b, c); and reran the two dispatch tests. WARP still passes. The RX 5700 XT fails:

    hardware: negated inline 0 addend keeps a -0 product readback: MISMATCH
      expected 80000000, got 00000000
    hardware: control without the high-half shift reads the low half in all 4 high-half cases: MISMATCH
    

    So on this adapter the precise keyword is what restores the sign, which the WARP and RTX 4090 runs could not show. The wrong-half control also fails without precise. I did not look into why. The edit was reverted afterwards.

    From my side as the reporter, this resolves the issue. I'll leave closing it to the maintainers.

    AI-assisted with Claude Code (Claude Opus 5.5); the commands listed were run locally.

  8. Not-Saii commented on Nov 26, 2026

    @Not-Saii
    Contributor

    Thanks @ColorMeBoom, and especially for the run without precise. That is the before/after on RDNA 1 that the WARP and RTX 4090 runs couldn't give.

    Taken with the RX 9070 XT runs in #2746, the precise mad lowering (#2818) is now confirmed on both AMD architectures that failed. Without it the RX 5700 XT reads 00000000 for the -0 case. With it, all four fma-mix tests pass at 22aa7bf9.

    Agreed that this can be closed from my side too.

    AI-assisted with Claude Code (Claude Opus 5.5).

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions