Repository navigation
Translator: --fma khr emits OpFmaKHR, the only correctly rounded FMA in Vulkan SPIR-V (GLSL Fma may round twice); runtime enables VK_KHR_shader_fma - #1364
Conversation
GLSL.std.450 Fma may be split into two roundings by a driver (Vulkan environment: inherited from OpFMul followed by OpFAdd); RDNA2 v_fma_* round once. --fma khr (default stays glsl) emits OpFmaKHR with capability FMAKHR and SPV_KHR_fma and lists shaderFmaFloat32 in the index. Runtime device creation and the vk_* test programs enable VK_KHR_shader_fma when present; cs_fma_fused tests single rounding; the mini interpreter learns OpFmaKHR. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cks VK_KHR_shader_fma test_fma_khr put tools/ on the path only through support, so it failed when run alone; it now inserts TOOLS_DIR itself like test_f16_fma_rounding. The standalone device no longer prints on every start when the feature is missing (the tools refuse an FMAKHR module where it matters). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Tested d630dd7 on Windows 11 x64 (Python 3.14.6, CPU only): pass
Verified that |
…thout VK_KHR_shader_fma The Linux CI's Vulkan headers predate VK_KHR_shader_fma, where ShaderFma has no features member; the other tools chain it through link_after, which is already guarded. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # runtime/test/vk_test_device.h
|
Tested on Windows 11 with two GPUs on one machine (runtime built from this PR's head, MSVC 14.51, llvm-mc 23.1.6): no regression. |
|
Tested
With The two cases with distinct operands (out[1], out[6]) stay
So No game files. AI-assisted (Claude Code). |
|
Tested
Two notes for the author:
AI-assisted (ZCode agent): builds and runs executed by a coding agent on this machine. |
Claimed in #1218. It came out of web research and needs no game files.
What and why
RDNA2's
v_fma_*round once. The f32 hardware oracle confirmed this in #1248, where all 72cancelprobes came out fused. The translator emitsGLSL.std.450 Fmafor them, but the Vulkan SPIR-V environment givesfma()the precision "Inherited from OpFMul followed by OpFAdd", so a driver may round twice. OnlyOpFmaKHRfromVK_KHR_shader_fma/SPV_KHR_fmais specified as "Correctly rounded". DXC (#8330) and Slang (#13773) track the same gap.VK_KHR_shader_fmais available on the AMD Windows driver since 26.3.1, on NVIDIA 617 and on RADV from Mesa 26.2. On both GPUs hereshaderFmaFloat16/32/64are all true.Translator:
tools/rdna2spirv.py --fma glsl|khr. Withkhrit emitsOpFmaKHR(capabilityFMAKHR, extensionSPV_KHR_fma) for every fused f32 multiply-add:v_fma_f32,v_fmac_f32,v_fmaak_f32,v_fmamk_f32andv_fma_mix*;Fmacalls infma_mix_odd, which need the exact product error.The shader index lists capability
FMAKHRand featureshaderFmaFloat32. The default staysglsl, so a runtime without the extension never meets an unknown capability. Default output is byte-identical tomainfor all 114 test shaders, and shaders without an FMA are identical underkhrtoo.f16:
v_fma_f16,v_fmac_f16andv_pk_fma_f16already use round-to-odd built fromOpFMul/OpFAdd. They are correct either way, so they are unchanged.Runtime: the standalone device,
vk_test_device.hand thevk_*test programs enableVK_KHR_shader_fmaandshaderFmaFloat32when the device offers them.vk_shader_fma.hmakesvk_compute_test,vk_store_testandvk_harnessexit 77 on a module that needsFMAKHRwhen the device lacks the feature.vk_pipeline_checkreports the missing feature per shader.Interpreter and fuzzer:
spirv_mini_interp.pyexecutesOpFmaKHRwith exact single rounding, andf32_fuzz.pygains--fma.Tested
runtime/test/shaders/cs_fma_fused.asm: 7 f32 single-vs-double-rounding discriminators and one f16 case, with the expected words derived in the header. The operands arrive through user SGPRs, so no driver can fold them.--fma glsland with--fma khron the Radeon 880M (26.11.2) and the RTX 5070 (617.42).Fmatoday. The guarantee matters for other or future drivers and compilers, not as an observed bug here.REPO=… run_gpu_lab.sh both: each GPU gives the same result with both options.cs_barrier_loopfails. That failure also happens withmain's SPIR-V and the shader contains no FMA.f32_fuzz --oracle translator,hw --fma khr --programs 1000on gfx1150:pytest tests --ignore=tests/semantic: 3126 passed. The semantic suite: 1157 passed.tests/semantic/test_fma_khr.pyis new.ctestpasses 61/61 on AMD withLEONIDA_VK_VALIDATION=1.-j2while other GPU jobs ran, and passed when re-run alone.The docs are updated:
docs/design.md(the floating-point row, the optional device features and the metadata index),docs/testing.mdandtests/semantic/README.md.An independent review checked:
mainand from this branch give identical.spv.spirv-valaccepts theOpFmaKHRmodules at vulkan1.2, 1.3 and 1.4.cs_fma_fused's expected words were re-derived by hand.Its small findings are fixed:
test_fma_khrnow runs on its own, and there is no start-up log line. One finding is still open:vk_harnesschecks only the fragment shader forFMAKHR, which is enough because only the fragment shader is translated today.AI-assisted (Claude Code).
Checklist
docs/design.md, with how it was confirmed.🤖 Generated with Claude Code