microsoft / microsoft/DirectXShaderCompiler

[SPIR-V] `fma` emits `GLSL.std.450 Fma` instead of `OpFmaKHR`

Open
#8,330 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug needs-triage spirv
Dominant language
C++
Stars
3.7k
Forks
900
Avg merge
2d 11h
Merged PRs (30d)
44

Description

Description
When compiling the HLSL fma intrinsic to SPIR-V, DXC emits the GLSL.std.450 Fma instruction. According to the Vulkan spec, this instruction is not guaranteed to be implemented in hardware as a fused operation. HLSL's fma intrinsic specifically requires fused semantics, so emitting this GLSL instruction does not seem correct. This also appears to be the root cause of this issue in the offload-test-suite. On Intel Vulkan, the driver gives the non-fused output for one of the precision sensitive constant-folding cases (though the buffer equivalent case produces the fused/correct result).

The fix for this would be to emit OpFmaKHR from SPV_KHR_fma instead, which guarantees a fused operation. This is also what Clang currently does.

Repro
https://godbolt.org/z/ezEexaGMa

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Godbolt repro and trace how HLSL’s fma intrinsic is lowered to SPIR-V, comparing the current GLSL.std.450 Fma path with Clang’s existing handling. The fix is complete when the generated SPIR-V uses OpFmaKHR from SPV_KHR_fma and the precision-sensitive repro produces fused results.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.