You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Recompiler: the HLSL backend's fast-math loses -0 in f16 results and changes v_sin/v_cos on AMD #2168
The HLSL backend and the direct-DXIL backend give different results for the same instruction on six instructions. The results agree bit for bit on an RX 9070 (RDNA4) and on a gfx1036 iGPU (RDNA2). Compiling the HLSL kernels with DXC's -Gis (IEEE strictness) removes all six differences. So the cause looks like DXC's default fast-math flags (nsz, etc.) on the HLSL path, which the AMD driver then uses. XCL's dxc::compile passes no -Gis.
Found with a cross-backend / cross-device VALU fuzzer: one VOP3/VOP3P instruction per wave64 kernel, 256 edge and random inputs. A PR is coming; it is test-only.
instruction
differ (of 256)
example sources
HLSL
direct DXIL
v_mul_f16
26
0x0001 × 0x8000 (+denorm × -0)
0x0000
0x8000
v_pk_mul_f16
49
hi 0x8000 × 0x0001
0x0000…
0x8000…
v_ldexp_f16
19
ldexp(0x8000, 1)
0x0000
0x8000
v_sin_f16
4
sin(0x8000)
0x0000
0x8000
v_sin_f32
7
0x7f7fffff (FLT_MAX)
0x00000000
0xffc00000
v_cos_f32
8
0x47bcfc00 (96760.0)
0x3f800000
0x3f7fb10e
f16: IEEE gives -0 for every f16 example (a product or ldexp of -0, sin(-0)). The direct backend keeps it; the HLSL backend returns +0. This is not the rounding difference that DIFFERS_ON_1426 in recomp/lower.rs lists for V_MUL_F16 / V_PK_MUL_F16 (RTZ vs RNE). It is the sign of zero, and it shows up on the default (HLSL) path.
sin/cos: both backends emit sin(x * 2π) / cos(x * 2π). Without -Gis the AMD driver seems to compile the HLSL one differently: it gives 1.0 for cos of a whole number of turns and 0 for sin(FLT_MAX), where the direct backend gives the radian result and NaN. These inputs are outside the [-256, 256] input range the RDNA ISA gives for v_sin/v_cos, so what the console returns there is worth checking separately.
Separately, v_dot2_f32_f16 differs between the two GPUs on both backends: 7 of 256 results, mostly 1-3 ulp, plus a denormal result that RDNA4 keeps (0x00000001) and RDNA2 flushes (0x00000000). The console is RDNA2, so the iGPU's results are presumably the console's.
Reproduce: the fuzzer PR adds valu_fuzz_backends_agree (ignored). Run cargo test -p xcl --lib valu_fuzz -- --ignored --nocapture --test-threads=1, and again with XCL_FUZZ_DXC_GIS=1.
Not tested: NVIDIA, the cost of -Gis on real shaders, and a retail title (I have no title here).
AI use: found, analysed and written with Claude Code (Claude Opus 5.5). The runs above are real runs on the hardware named, on mainf5c5bdf.
NVIDIA data point (listed as untested here): on an RTX 3060 (driver 32.0.16.1088, Windows, so the split wave64 form), valu_fuzz_backends_agree from #2169 finds none of these six differences. HLSL and direct DXIL agree on v_mul_f16, v_pk_mul_f16, v_ldexp_f16, v_sin_f16, v_sin_f32 and v_cos_f32 for all 256 inputs. On an RX 9070 XT in the same run the six reproduce with the counts above. So the HLSL fast-math difference shows up through the AMD driver only.
The 3060 has one difference of its own, v_cubetc_f32 (58 of 256): the HLSL result is a signed zero where the direct result keeps an f32 denormal, which looks like the same fast-math family (denormal flush instead of the sign of zero). Details and the cross-GPU comparison are in the run on #2169.
Head e792e6b on main568e7db, debug. AI use: Claude Code (Claude Opus 5.5) ran the fuzzer on this machine and wrote this comment.
RX 6800M (RDNA2) follow-up on #2169's exact head e792e6b: I reproduced this issue's six default-HLSL differences with the same 8/19/26/49/4/7 counts (of 256 inputs per instruction). XCL_FUZZ_DXC_GIS=1 removed all six, but introduced differences in eight FMA-family instructions that matched without -Gis: V_DIV_FMAS_F32 (2), V_FMAC_F32 (2), V_FMAC_LEGACY_F32 (4), V_FMA_F16 (6), V_FMA_F32 (1), V_FMA_MIXHI_F16 (7), V_FMA_MIXLO_F16 (6), and V_PK_FMA_F16 (14), each out of 256. A focused rerun of those eight gave 0 differing instructions by default and 8 with -Gis, with identical per-instruction counts.
Linux status for this one, stated plainly: the cross-backend check cannot run here, so this is "not applicable", not a confirmation.
The comparison is done by executing the generated HLSL and the direct-DXIL form on a device (runner::run in crates/xcl/src/gpu/recomp/lower_dxil.rs, and runner::wave32_supported() gating in fuzz_tests.rs). On Linux our XCL builds are x86_64-pc-windows-gnu and there is no D3D12 device in the path - Wine has no WARP, and vkd3d-proton would be the "device", which is not what the test measures. So runner::wave32_supported() is false and the GPU half of these tests is skipped.
What I could do and did not, to be explicit: compile the same kernels with and without -Gis through DXC and diff the DXIL bytes. That would show whether the flag changes the module, but it would not answer your question - the difference you measured is in the executed result (-0 in f16, v_sin/v_cos), which needs the card.
If a Windows host is available to you, the useful extra data point would be the same fuzzer on RDNA3 natively: your data is RDNA4 (9070) and RDNA2 (gfx1036), and RDNA3 is the generation in between.
Correction to this issue, with thanks to @luckyteagirl for the full-run data: -Gis is not the fix. My -Gis check covered only the six differing instructions. The whole run on the RX 9070, at #2169's head e792e6b on 568e7db, shows the same as the RX 6800M:
-Gis makes HLSL's mad an unfused multiply-add, so it trades the sign-of-zero differences for rounding ones in every fused op. A narrower direction would leave fusion alone: precise only on the f16 multiply / ldexp / sin results (or only where a zero can come out), so nsz cannot drop their sign. I have not measured that yet. The NVIDIA data above (no default-build differences on an RTX 3060) suggests the sign drop comes from AMD's compiler using nsz.
AI use: Claude Code (Claude Opus 5.5) ran both fuzzer builds on this machine and wrote this comment.
Measured the narrower direction from my last comment: precise only on the affected HLSL expressions, no -Gis. With it, the HLSL and direct-DXIL backends agree on every instruction on both AMD GPUs, and the FMA-family ops stay fused.
valu_fuzz_backends_agree from #2169 at e792e6b on 568e7db: 341 instructions, 333 compared, 8 refused by both. cargo test --workspace -- --test-threads=4 with the change (RX 9070): 1152 passed, 2 failed (seeds 722 / 1599, as on main), 48 ignored.
The change: four small helpers whose result is precise (so nsz / reassociation cannot touch it), used by v_mul_f16, v_pk_mul_f16, v_ldexp_f16 and v_sin / v_cos (f16 and f32):
It touches recomp/emit.rs, so a PR needs a smoke run on a real title, which I cannot do here. Anyone with a title is welcome to take it, or I can open it once someone runs scripts/smoke.ps1 on it. Not tested: NVIDIA (the RTX 3060 run above already had no default-build differences), and the shader-size or performance cost of precise on real shaders.
AI use: Claude Code (Claude Opus 5.5) wrote the change, ran both fuzzer builds and the suite on this machine, and wrote this comment.
Activity
DarkPanda69 commentedon Nov 25, 2026
NVIDIA data point (listed as untested here): on an RTX 3060 (driver 32.0.16.1088, Windows, so the split wave64 form),
valu_fuzz_backends_agreefrom #2169 finds none of these six differences. HLSL and direct DXIL agree onv_mul_f16,v_pk_mul_f16,v_ldexp_f16,v_sin_f16,v_sin_f32andv_cos_f32for all 256 inputs. On an RX 9070 XT in the same run the six reproduce with the counts above. So the HLSL fast-math difference shows up through the AMD driver only.The 3060 has one difference of its own,
v_cubetc_f32(58 of 256): the HLSL result is a signed zero where the direct result keeps an f32 denormal, which looks like the same fast-math family (denormal flush instead of the sign of zero). Details and the cross-GPU comparison are in the run on #2169.Head
e792e6bonmain568e7db, debug. AI use: Claude Code (Claude Opus 5.5) ran the fuzzer on this machine and wrote this comment.luckyteagirl commentedon Nov 25, 2026
RX 6800M (RDNA2) follow-up on #2169's exact head
e792e6b: I reproduced this issue's six default-HLSL differences with the same 8/19/26/49/4/7 counts (of 256 inputs per instruction).XCL_FUZZ_DXC_GIS=1removed all six, but introduced differences in eight FMA-family instructions that matched without-Gis:V_DIV_FMAS_F32(2),V_FMAC_F32(2),V_FMAC_LEGACY_F32(4),V_FMA_F16(6),V_FMA_F32(1),V_FMA_MIXHI_F16(7),V_FMA_MIXLO_F16(6), andV_PK_FMA_F16(14), each out of 256. A focused rerun of those eight gave 0 differing instructions by default and 8 with-Gis, with identical per-instruction counts.So
-Gisis not a complete cross-backend parity fix on this GPU. The fuzzer compares HLSL with direct DXIL; this run did not check console reference results for the FMA cases. Full setup, logs summary, and limitations are in the #2169 report.AI use: OpenAI Codex ran and repeated the tests and prepared this note.
YaBulochka commentedon Nov 25, 2026
Linux status for this one, stated plainly: the cross-backend check cannot run here, so this is "not applicable", not a confirmation.
The comparison is done by executing the generated HLSL and the direct-DXIL form on a device (
runner::runincrates/xcl/src/gpu/recomp/lower_dxil.rs, andrunner::wave32_supported()gating infuzz_tests.rs). On Linux our XCL builds arex86_64-pc-windows-gnuand there is no D3D12 device in the path - Wine has no WARP, and vkd3d-proton would be the "device", which is not what the test measures. Sorunner::wave32_supported()is false and the GPU half of these tests is skipped.What I could do and did not, to be explicit: compile the same kernels with and without
-Gisthrough DXC and diff the DXIL bytes. That would show whether the flag changes the module, but it would not answer your question - the difference you measured is in the executed result (-0in f16, v_sin/v_cos), which needs the card.If a Windows host is available to you, the useful extra data point would be the same fuzzer on RDNA3 natively: your data is RDNA4 (9070) and RDNA2 (gfx1036), and RDNA3 is the generation in between.
alexdeliu commentedon Nov 25, 2026
Correction to this issue, with thanks to @luckyteagirl for the full-run data:
-Gisis not the fix. My-Gischeck covered only the six differing instructions. The whole run on the RX 9070, at #2169's heade792e6bon568e7db, shows the same as the RX 6800M:v_cos_f328,v_ldexp_f1619,v_mul_f1626,v_pk_mul_f1649,v_sin_f164,v_sin_f327-Gisv_fma_f321,v_fmac_f322,v_fmac_legacy_f324,v_div_fmas_f322,v_fma_f166,v_pk_fma_f1614,v_fma_mixlo_f166,v_fma_mixhi_f167,v_dot2_f32_f167-Gismakes HLSL'smadan unfused multiply-add, so it trades the sign-of-zero differences for rounding ones in every fused op. A narrower direction would leave fusion alone:preciseonly on the f16 multiply /ldexp/sinresults (or only where a zero can come out), sonszcannot drop their sign. I have not measured that yet. The NVIDIA data above (no default-build differences on an RTX 3060) suggests the sign drop comes from AMD's compiler usingnsz.AI use: Claude Code (Claude Opus 5.5) ran both fuzzer builds on this machine and wrote this comment.
alexdeliu commentedon Nov 25, 2026
Measured the narrower direction from my last comment:
preciseonly on the affected HLSL expressions, no-Gis. With it, the HLSL and direct-DXIL backends agree on every instruction on both AMD GPUs, and the FMA-family ops stay fused.-Gisprecisehelpers belowvalu_fuzz_backends_agreefrom #2169 ate792e6bon568e7db: 341 instructions, 333 compared, 8 refused by both.cargo test --workspace -- --test-threads=4with the change (RX 9070): 1152 passed, 2 failed (seeds 722 / 1599, as onmain), 48 ignored.The change: four small helpers whose result is
precise(sonsz/ reassociation cannot touch it), used byv_mul_f16,v_pk_mul_f16,v_ldexp_f16andv_sin/v_cos(f16 and f32):It touches
recomp/emit.rs, so a PR needs a smoke run on a real title, which I cannot do here. Anyone with a title is welcome to take it, or I can open it once someone runsscripts/smoke.ps1on it. Not tested: NVIDIA (the RTX 3060 run above already had no default-build differences), and the shader-size or performance cost ofpreciseon real shaders.AI use: Claude Code (Claude Opus 5.5) wrote the change, ran both fuzzer builds and the suite on this machine, and wrote this comment.