Files
metal2vulkan/docs
Anees Iqbal d77bd86377 Compute half + - * and fma in 16 bits under the 16-bit float controls
On a device whose half roundings take the 16-bit float controls (RoundingModeRTE, DenormPreserve
and SignedZeroInfNanPreserve for 16 bits with shaderFloat16: ANV and RADV among the committed
profiles), a half + - * is now the device's 16-bit OpFAdd, OpFSub or Fma(a, b, -0.0), kept apart,
between exact conversions (ops::f16_binary, the form the measured MoltenVK fact already takes).
Where shaderFmaFloat16 is enabled too, a half fused multiply-add is OpFmaKHR on 16 bits (new
fma::Route::F16Khr), under either policy. Elsewhere the f32 operation and its rounding pair, the
round-to-odd routine and native device maths' Fma stay as they were.

Exact: Vulkan's precision table lists OpFAdd, OpFSub and OpFMul for half precision, and OpFmaKHR,
as correctly rounded, to nearest even under RoundingModeRTE, with denormals kept under
DenormPreserve and zero signs under SignedZeroInfNanPreserve, the modes the entry declares where it
computes in 16 bits (narrow::computes_in_16_bits). That is Metal's half arithmetic and Metal's
half fma, which the round-to-odd routine emulated. A NaN's bits are the device's, as the
controlled rounding's already are; Metal's NaN is selected around the instruction where the
profile asks for it. The half fma under native device maths no longer records NativeFma there.

Why: the device's compiler spent most of a large half fragment function's making on the f32 ->
f16 -> f32 rounding pairs, most of which follow a + - * or a fused multiply-add. On ANV a
consumer's largest fragment library made in about 4 s, and about 2.2 s without its rounding pairs.

New: VkFeature::ShaderFmaFloat16 (the Khronos table, enables, the ash and runtime feature chains,
derivation, the codec), OpFmaKHR's feature by its operands' width, the builder's OpFmaKHR on 16-bit
floats, and the owned fixture engine/hfb_filter_bank (a 32-case switch of runtime-sampler tap
loops and half arithmetic chains) with its engine inventory rows. The validation engine's enable
list enables shaderFmaFloat16 from VkPhysicalDeviceShaderFmaFeaturesKHR beside shaderFmaFloat32,
and the opened-chains pin records it for the profiles that list it. Docs: docs/FAST-PATHS.md's half
rounding row, and the NativeFma notice in artifact.rs and docs/API.md.

Verified, as the commits state:
- On the UHD 770 (ANV, Mesa 26.2.4) the fixture's fragment library made in 1.74-1.89 s against
  4.64-5.26 s before (3 alternating rounds, no driver caches), SIMD8 instructions 25,902 ->
  18,736, translation 0.17 s release; driver_deviations::half_arithmetic_answers_as_metal passes
  there.
- On the UHD 770 in the release m2v_gpu build, the groups that failed before the engine enabled
  the feature pass: candidate engine runs, platform enables and device, engine_render,
  engine_compute, engine_textures, acceptance_pipelines, the runtime lanes kernel_textures,
  sparse_textures, renders, argument_buffers and runtime_probe, and the half and fma driver
  deviations.
- Debug translator tests: engine_arith, lower::arith, the fma, derivation, device, ash_interop,
  cache and fast_paths tests, and the engine inventory's llvm_as parts; engine_native_half
  (counting the 16-bit operations and their exact conversions) and engine_spirv_cross_forms (no
  NativeFma where the half fma route is F16Khr), with fused and engine_arith, 213 passed.
- clippy of metal2vulkan.
2026-10-19 00:16:00 +03:00
..