Repository navigation
feat(agc): use native f16 arithmetic on Apple GPUs - #234
Merged
utkuhalis merged 1 commit intoDec 4, 2026
Merged
Conversation
MoltenVK reports no f16 denormal preserve mode, so every f16 instruction was emulated with 32-bit arithmetic there. Apple GPUs keep f16 denormals and round correctly, so the driver now uses native f16 on them. MoltenVK lowers an exact multiply to a fused multiply-add of +0, which loses the sign of a zero product, so f16 multiplies add -0 through GLSL Fma, as f32 ones already do there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
|
Thanks, a big win for that shader. I checked how the gate holds up:
I'll merge once CI is green; I'll rerun the macOS job if it's cancelled for lack of a runner. |
Collaborator
|
Merged, thanks! Native f16 now runs on Apple GPUs under MoltenVK. |
12 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
On macOS, every f16 instruction is emulated with 32-bit arithmetic. The driver only uses native f16 when
shaderDenormPreserveFloat16is reported, and MoltenVK doesn't report it. In Grand Theft Auto V, one full-screen compute shader with a lot of f16 maths grows to 1.4 million SPIR-V words.Apple GPUs do keep f16 denormals. On an M5 Pro, Metal's
halfadd, subtract, multiply,fmaand conversions returned the correctly rounded result for about 16 million random inputs each, denormals included.VulkanDeviceenables native f16 on MoltenVK with an Apple GPU. No denormal preserve mode is declared for it, since the device doesn't report one.fma(a, b, +0), which turns a -0 product into +0. OnfusedExactArithmetictargets, f16 multiplies now use GLSLFmawith -0, as f32 multiplies already do.agc_driver_float16_nativeandagc_driver_packed_float16_nativerun on MoltenVK instead of skipping.Tested
macOS 27.2.1, Apple M5 Pro, MoltenVK 1.4.2, x86-64 build under Rosetta 2 (AppleClang 21.0.0, Release):
mainand on this branch, withANYPS5_REQUIRE_VULKAN=1andANYPS5_NO_SHADER_CACHE=1. The only differences are the two tests above, which go from skipped to passed. 352 pass, 22 skip, andagc_driver_f32_denormal_flushandagc_driver_pixel_exec_interpolationfail on both.python3 tools/debt_fold.py --checkandpython3 tools/check_conventions.py --base origin/mainpass.tools/trace_digest.pysummaries of it.VK_LAYER_KHRONOS_validationcomparison from AGENTS.md, because no validation layer is installed on this Mac. Other Apple GPUs weren't tested.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code