v_fma_mix_* are not fused; using tb_fma removes the WARP device (0x887a0005) #40

Closed
opened 2026-11-26 06:08:10 +00:00 by github-bot · 1 comment
Owner

@⁠artareias on GitHub · 2026-11-21 18:57 UTC · original

tombox-xshader emits v_fma_mix_f32 / v_fma_mixlo_f16 / v_fma_mixhi_f16 as a * b + c, which is not fused. The RDNA 2 ISA guide (p. 173) describes them as fused multiply-add. One vop3_basic case shows it: (1 + 2^-23) * (1 - 2^-24) - 1 expects 0x337ffffe (single rounding) and the emitter returns 0.

Hardware adapter vs WARP

Changing the emitter to use the existing tb_fma helper (mad(a, b, c), the same one v_fma_f32 uses) at hlsl.rs, in the v_fma_mix branch:

-            let e = format!("{} * {} + {}", v[0], v[1], v[2]);
+            let e = format!("tb_fma({}, {}, {})", v[0], v[1], v[2]);

gives, for vop::basic::vop3_basic (Windows 10 19045, rustc 1.100.0):

Adapter failing cases before after
AMD Radeon RX 7600 (TOMBOX_EXEC_HW=1), driver 32.0.32015.7029 37 18 (only v_bfe_i32, see #33): the fused case passes
WARP 37 443: the first v_fma_mix_f32 case reports device removed 0x887a0005 and every later case fails with CreateGraphicsPipelineState hr=0x887a0005

The first case is harmless: 1.0 * 1.0 + (-0.5), all three sources f16-low (opsel_hi = 7, opsel = 0). v_fma_f32 with the same tb_fma does not remove the device on WARP.

What I compared

Compiling only (no execution) with dxc 1.8 (Windows SDK 10.0.26100, -T ps_6_0), the two shapes differ only in where the operands come from. Both lower to FMad (op 46); no half types or min-precision appear.

float tb_fma(float a, float b, float c) { return mad(a, b, c); }
uint4 main(nointerpolation uint4 v : TEXCOORD0) : SV_Target {
    float r = tb_fma(f16tof32(v.x & 0xffffu), f16tof32(v.y & 0xffffu), f16tof32(v.z & 0xffffu));
    return uint4(asuint(r), 0u, 0u, 0u);
}

DXIL: three LegacyF16ToF32 (op 131) feeding one FMad. The v_fma_f32 shape (asfloat operands) has just the FMad. So the trigger looks like WARP executing FMad on LegacyF16ToF32 results, but I did not run this minimal shader on WARP in isolation; I only saw it through vop3_basic.

Why it is not a PR

The fused form fixes one case on the RX 7600 but turns a 37-case failure into a device removal in the default WARP mode. I did not include it in #39 (which only fixes the mixhi expectation). If someone knows a fused form WARP accepts, or can confirm the WARP crash in isolation, the emitter change is one line.

**@⁠artareias** on GitHub · 2026-11-21 18:57 UTC · [original](https://github.com/omonkeyz/xbox-emulator/issues/40) `tombox-xshader` emits `v_fma_mix_f32` / `v_fma_mixlo_f16` / `v_fma_mixhi_f16` as `a * b + c`, which is not fused. The RDNA 2 ISA guide (p. 173) describes them as fused multiply-add. One `vop3_basic` case shows it: `(1 + 2^-23) * (1 - 2^-24) - 1` expects `0x337ffffe` (single rounding) and the emitter returns `0`. ## Hardware adapter vs WARP Changing the emitter to use the existing `tb_fma` helper (`mad(a, b, c)`, the same one `v_fma_f32` uses) at `hlsl.rs`, in the `v_fma_mix` branch: ```diff - let e = format!("{} * {} + {}", v[0], v[1], v[2]); + let e = format!("tb_fma({}, {}, {})", v[0], v[1], v[2]); ``` gives, for `vop::basic::vop3_basic` (Windows 10 19045, rustc 1.100.0): | Adapter | failing cases before | after | |---|---|---| | AMD Radeon RX 7600 (`TOMBOX_EXEC_HW=1`), driver 32.0.32015.7029 | 37 | 18 (only `v_bfe_i32`, see #33): the fused case passes | | WARP | 37 | 443: the first `v_fma_mix_f32` case reports `device removed 0x887a0005` and every later case fails with `CreateGraphicsPipelineState hr=0x887a0005` | The first case is harmless: `1.0 * 1.0 + (-0.5)`, all three sources f16-low (`opsel_hi = 7`, `opsel = 0`). `v_fma_f32` with the same `tb_fma` does not remove the device on WARP. ## What I compared Compiling only (no execution) with dxc 1.8 (Windows SDK 10.0.26100, `-T ps_6_0`), the two shapes differ only in where the operands come from. Both lower to `FMad` (op 46); no half types or min-precision appear. ```hlsl float tb_fma(float a, float b, float c) { return mad(a, b, c); } uint4 main(nointerpolation uint4 v : TEXCOORD0) : SV_Target { float r = tb_fma(f16tof32(v.x & 0xffffu), f16tof32(v.y & 0xffffu), f16tof32(v.z & 0xffffu)); return uint4(asuint(r), 0u, 0u, 0u); } ``` DXIL: three `LegacyF16ToF32` (op 131) feeding one `FMad`. The `v_fma_f32` shape (`asfloat` operands) has just the `FMad`. So the trigger looks like WARP executing `FMad` on `LegacyF16ToF32` results, but I did not run this minimal shader on WARP in isolation; I only saw it through `vop3_basic`. ## Why it is not a PR The fused form fixes one case on the RX 7600 but turns a 37-case failure into a device removal in the default WARP mode. I did not include it in #39 (which only fixes the `mixhi` expectation). If someone knows a fused form WARP accepts, or can confirm the WARP crash in isolation, the emitter change is one line.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:08:11 +00:00
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-22 13:20 UTC · original

Fixed on main in b72625c: v_fma_mix* now use a single-rounding fused path (tb_fma_rto / exact_mix16) instead of a*b+c. Thanks!

**@⁠omonkeyz** on GitHub · 2026-11-22 13:20 UTC · [original](https://github.com/omonkeyz/xbox-emulator/issues/40#issuecomment-7079737711) Fixed on main in b72625c: v_fma_mix* now use a single-rounding fused path (tb_fma_rto / exact_mix16) instead of a*b+c. Thanks!
This discussion has been locked. Commenting is limited to contributors.
No description provided.