Repository navigation
Backlog
Description
On AMD's RDNA1 Windows driver, the fused FP32 ops are translated to mad(), which DXIL lets the driver evaluate unfused, and this driver does. So v_fma_f32 (and presumably the rest of the fused family) rounds twice where the console rounds once. gpu::recomp::tests::gpu_nonfused_mad_and_mac_prevent_fma_contraction fails here on its fused control:
assertion `left == right` failed: v_fma_f32 overflow control should stay fused
left: 2139095040 (0x7F800000, +inf: unfused)
right: 1946157055 (0x73FFFFFF: fused)
The non-fused half of the test passes: mad_nf with precise works as #73 intended. Only the fused side depends on the driver.
Where
crates/xcl/src/gpu/recomp/emit.rs:"v_fma_f32" => fr(format!("mad({}, {}, {})", ...)), and the samemad(...)forv_fmac_f32,v_fmamk_f32,v_fmaak_f32,v_fma_f16,v_fmac_f16,v_pk_fma_f16and the others. HLSL has no fused FP32 intrinsic, somad()is fused only if the driver chooses to fuse it.
Measured
- RX 5700 XT (RDNA1), driver 32.0.21045.29003, Windows 11 22631,
main2997c9a. This is the one failing test ofcargo test --workspace --no-fail-fast -- --test-threads=4on this adapter (675 passed, 1 failed, 41 ignored, with D3D12.X: map a one-slice title texture's packed mips where D3D12 addresses them #470 applied; the same failure onmain). - I tried one option locally.
float fma_f32(float a, float b, float c) { return (float)fma((double)a, (double)b, (double)c); }used forv_fma_f32only makes the test pass, and all 182gpu::recomptests pass with it. I'm not proposing it as is:- fp64 is required: every shader with
v_fma_f32then needs double-precision shader ops. Some GPUs report none (Intel Arc), and their pipelines would fail. - Cost: RDNA1/2 consumer parts run fp64 at 1/16 rate, and
v_fma_f32is one of the most common instructions. - Not exact: the product is exact in double, but the double result is then rounded again to float. In rare cases that double rounding still differs from a true fp32 FMA.
- Scope: it covers
v_fma_f32only, not the rest of the fused family.
- fp64 is required: every shader with
Options I can see (not tested beyond the above)
- Probe at device creation whether
madfuses (this test's two vectors in one dispatch). Only on a driver that does not fuse, and only with fp64, use a fused path (double, or an exact FP32 emulation). Make that part of the translation cache key. - Leave
mad()and mark the test as SKIPPED on a driver that does not fuse it (the console behaviour is then not reproduced there).
Which one fits XCL is your call; I can test whichever you prefer on this RDNA1 card.
Found with Claude Code (Claude Opus 5.5), which also wrote this report; I ran the tests on my machine.
Metadata
Metadata
Assignees
Labels
No labels
Activity
PHeitor1 commentedon Nov 24, 2026
NVIDIA data point:
gpu::recomp::tests::gpu_nonfused_mad_and_mac_prevent_fma_contractionpasses, fused control included, on an RTX 5060 Ti 8 GB (Blackwell), NVIDIA 621.24, Windows 11 Pro 26300, debug. It passed in the full-suite runs of 12 PRs, each merged ontomain3516080(5) or2997c9a(7). (Edited: the first version also claimed runs of thosemaincommits by themselves, which I did not make.) So this driver fusesmad(), and a device-creation probe (option 1) would take the existing path here.Written with Claude Code (Claude Opus 5.5).
Tjabooo commentedon Nov 24, 2026
Another adapter where the fused control fails, and how it happens on Linux: RADV through vkd3d-proton, AMD RX 9070 XT (RDNA4, GFX1201), Mesa 26.2.6, Wine 11.21, vkd3d-proton v3.1 (with #257's patch),
maindd2ae9across-built forx86_64-pc-windows-gnu, DXC 2026_09_29.It's the same failure as on the RDNA1 Windows driver. This one is the only failure of
cargo test -p xcl --libthere once #530 is applied (649 passed, 1 failed, 0 GPU tests skipped).Why RADV runs it unfused. vkd3d-proton turns DXIL into SPIR-V with dxil-spirv, and
emit_fmad_instruction(opcodes/opcodes_dxil_builtins.cpp, dxil-spirv8b48f0e0, the one in vkd3d-proton v3.1) decides it:dx.op.fmadbecomesGLSL.std.450 Fma, which RADV runs fused;fmadthat carriesdx.precisemetadata (orforce_precise), unless vkd3d-proton'sprecise_fmaquirk is set, is split on purpose intoOpFMul+OpFAdd, bothNoContraction, so it is unfused. The comment there says Big Navi splits a no-contract fma into mul + add anyway.So on this stack the fused
mad()only stays fused if DXC doesn't mark it precise.emit.rsdoesn't mark it itself, butprecisein HLSL also applies to every operation that feeds a precise value. If the test's fusedv_fma_f32result reaches amad_nf(precise float p = a * b; precise float r = p + c;) or another precise value, DXC would putdx.preciseon thefmadtoo. That's a hypothesis: I haven't looked at the DXIL of the test shader. If it holds, keeping the fused result out of precise data flow would fix RADV without fp64, and a disassembly of that one shader would show whether itsfmadhas!dx.precise.I'm happy to run any candidate fix on this RADV / RDNA4 setup. No game files used. AI-assisted (Claude); the results above are from runs on this machine.
Tjabooo commentedon Nov 24, 2026
Correction to my comment above: the hypothesis is wrong. I compiled the test's HLSL (from
gpu_nonfused_mad_and_mac_prevent_fma_contractionatmaindd2ae9a) with DXC 2026_09_29 (-T cs_6_6 -E main -HV 2021 -Fc). The fused controlv16 = mad(v0, v1, v2)is one plainFMad, with no!dx.precise:The
mad_nflines are separatefmul/faddwithout fast-math flags, as intended, and nothing spreads to theFMad. vkd3d-proton v3.1 doesn't set dxil-spirv'sforce_preciseeither (PRECISE_FMAis only a per-application quirk indevice_workarounds.c). So dxil-spirv should emitGLSL.std.450 Fmafor it, and the double rounding happens below that, in RADV / ACO, not in XCL's HLSL or DXC. I'll check the SPIR-V and the RADV side next. Sorry for the noise.Tjabooo commentedon Nov 24, 2026
Found the RADV side: the SPIR-V vkd3d-proton gives RADV has a real
Fma, but RADV's NIR folds the fma'sv0 * v1into the identical exact products of the test'smad_nflines in the same program, so it is rounded twice. A lonev_fma_f32is fused on RADV (both lanes pass). Details and a test-only fix (the control runs as its own program) in #676. Whether this is also what happens on the RDNA1 Windows driver is open: that needs a run of #676 there.joeypercia commentedon Nov 24, 2026
Data point for the open question of whether the RDNA1 Windows failure is the driver version: on an RDNA2 iGPU (Ryzen 7 7800X3D,
AMD Radeon(TM) Graphics) with the same Windows driver, 32.0.21045.29003,gpu::recomp::tests::gpu_nonfused_mad_and_mac_prevent_fma_contractionpasses, fused control included, in three full-suite runs today (maincb868b2, anddd2ae9awith #672 applied), not skipped. Windows 11 Pro 26200, DXC 1.8.2502.11, Rust 1.100.0 MSVC, debug,XCL_ADAPTER=radeon. It passes on an RTX 4070 Ti (616.56) in the same runs too.So with this driver release the combined program is fused on RDNA2 and not on RDNA1, which points at the RDNA1 compiler path rather than the release, consistent with @Tjabooo's contraction finding on RADV. I haven't run #676 here; on this adapter its control would pass either way.
Run and report by Claude Code (Claude Opus 5.5).
LAEGGYMODZ commentedon Nov 24, 2026
Measurements on WARP for this issue. They confirm and extend what Marvisak/VIctory#284 reported: its description and two comments show WARP returning the unfused result for two vectors through an FMad-based lowering.
Configuration — the conclusions below apply only to this:
1414:008C);d3d10warp.dllandd3d12.dll10.0.26100.9818.dxc.exeSHA-256aa7965b3763d9c710baaa5a28cedcc633449962a75d1391d161a85304a41b3e2), with-T cs_6_0 -E main -HV 2021 -O3 -WX.Kernels: four standalone kernels, nothing else in each program,
numthreads(64,1,1), raw f32 bits in (t0..t2) and out (u0).mad(a, b, c)FMad687a78242b67c13fee41ed3540506697b03e5311e358988aab96f33da32013ad4dc6393a83eda93df5a31e7e496c131637f1027ca9d89ebec13372191836e958mad(a,b,c)andprecise p = a*b; precise r = p + cFMad+ plainfmul/fadd75bc62dbb961994bf0d6c744f08ce8faf9c9c5f9831f3e5259d65c95b58faee903c5d797c88fa0cc24ee34cd48e056d3a9aac5ac1884cb7f61cb22c076b6bf80precise p = a*b; precise r = p + cfmul/fadd5ab8d699a47da893132eaf2c76215e799abc699fb5206cb59e711ea4e8ac4d358e2bebb656f8b04ed18dd5b6e83d36f5785825add3b28373c78e39de49ab9274a*b + c(noprecise)fmul fast/fadd fast6db05ec7fb713bab4d523ed0714187b5d97dcafeac10f4c679a08237925eff9c1cc60e3113f9b0411fcdc149f06f89e32dc7f39f4602a3f84dca14121bc44f02Vectors: 8 batches × 4,096 = 32,768 per kernel. In every batch:
a = 18631·2^60,b = 1801·2^43,c = −2^104(fused0x7F7FFFFE, unfused0x7F800000);0x7F7FFFFF, 0x3F800001, 0xFF7FFFFF(fused0x73FFFFFF, unfused0x7F800000).That makes 16 control instances plus 32,752 generated vectors. Every generated triple is kept only if the fused result (one rounding) and the unfused result (two roundings) differ in bits and are both finite. Each output was compared bit for bit with both. The fused reference is Rust's
f32::mul_add.Results
madmad/precisetwinpreciseOn this issue's control, all four kernels return
0x7F800000(the RX 5700 XT's value). Without the 16 controls: 32,752 / 32,752 generated vectors match the unfused result in each kernel.What this suggests for option 1 (an inference; I have not built or run XCL):
XCL_ADAPTER=warp.gpu_nonfused_mad_and_mac_prevent_fma_contractionto fail underXCL_ADAPTER=warp.a*b + cis not contracted here either, so on WARP you can't see thepreciseinmad_nfmattering (Floating-point modes: the non-fused MAD/MAC family needsprecise, and thes_round_modeNOOPs are not free #73); that needs a fusing driver.P1 kernel
Vector generator (Python 3, standard library, exact arithmetic) — regenerates the 24 input buffers byte for byte
SHA-256 of the 24 input buffers (batch.in0 = a, in1 = b, in2 = c)
The test harness, kernels, generator, measurements and this text were produced with Claude Code (Claude Opus 5.5) on my machine, under my direction. I reviewed the comment before posting.
Diskuss commentedon Nov 24, 2026
Native RDNA4 Windows data point: the fused control passes here. AMD Radeon RX 9070 XT (RDNA4), driver 32.0.32015.7029; Windows 11 Pro 26300; DXC 1.9.2602.17; Rust 1.100.0 MSVC; debug;
mainc160d86ef2efe3a07e4dfb473e4fa72eafb413c0.Results
cargo test -p xcl --lib gpu_nonfused_mad_and_mac_prevent_fma_contraction -- --test-threads=1: 6/6 passed (HLSL/DXC path), fused control included (0x73FFFFFFand0x28800000); themad_nflines stay unfused.XCL_DIRECT_DXIL=1(direct DXIL backend,dxil/lower_valu.rsv_fma_f32->fmad): 3/3 passed.DXIL of the test's HLSL (dumped from
t.hlsl, compiled with-T cs_6_6 -E main -HV 2021 -Fc), same as @Tjabooo found with DXC 2026_09_29:No
dx.preciseand no fast-math flags anywhere in the module (0!dx.precise), so DXC is not what splits themad().emit.rs:3367("v_fma_f32" => mad(...)) gives oneFMad, which this driver fuses even with the identicalfmul %40, %39in the same program.What this means
FMad".Investigation by Claude Code (Claude Opus 5.5) on this machine.