A fragment function's half color output is declared 16-bit where the device enables storageInputOutput16 and shaderFloat16, so the device blends the half Metal's attachment receives (the M3's 52 half-blend rows no longer diverge). SEMANTICS 1909, ARTIFACT 476. One work packet, landed as 6 commit(s) (9e8b40289e..f5e9c26fe3 on archive/development-linear-2026-10-28-evening), in order: * Declare a half color output 16-bit where the device enables storageInputOutput16 What: a fragment function's `half` color output through a variable of its own type (not an extended-range or word attachment's raw texel, not an attachment held with its channels rotated) is declared with 16-bit float lanes on a profile that enables `storageInputOutput16` and `shaderFloat16`, and stored by one OpFConvert of the f32 that holds the half (exact: the value is a half). The module then requires StorageInputOutput16 (derived from the Output pointer as before). `StageIo::half_outputs` lists the keys so link's contract check holds the module to the 16-bit declaration (`io_type_matches` takes the float width); the artifact codec carries the field. Every other interface variable stays 32-bit, and a device without the feature (lavapipe, NVIDIA's 615.71.09) keeps the half widened to float. Why: the widening hid the output's type from the device. With the half declared as a half, the device blends and converts the value Metal's attachment receives as its own half output: on MoltenVK that is Metal's compiler handling Metal's own output type. No Metal arithmetic is emulated and no note changes (HalfOutputPrecision and HalfOutputFastMathBlend fire as before; a computed fast-math output may still differ). Verified: - M3 Max, MoltenVK 1.4.2, macOS 27.0.1: `conformance replay` of the six `half-output-blends-*` cases: every value exact (verdict `announced`, the case's declared notice only); the 52 M3 rows of known-gaps.tsv (17, 17, 18 sites of r16f, rg16f, rgba16f) all read "no longer diverges", so they are removed. The 32-bit float formats stay exact. A replay of the 40 cases whose recorded fragment functions return half (half-output-blends-*, xr-*, rgb10a2-srgb-stores-h, render-then-sample-magnified-*, fragment-imageblock-reflection): 39 announced, 1 exact, no other ledger difference. - New unit test `a_half_color_output_is_declared_16_bit_where_the_device_enables_it` (moltenvk-m3 and amd-rdna3-radv 16-bit, lavapipe 32-bit; a float output and a rotated attachment 32-bit everywhere; L3 on each module). * Bump the cache versions for 16-bit half color outputs SEMANTICS_VERSION 1907 -> 1908: a fragment function's half color output is declared 16-bit on a profile that enables storageInputOutput16 and shaderFloat16, so its module's words and requirements change under an unchanged key (golden_hashes reports 657 cells changed; the table is re-blessed on the lane branch, not here). ARTIFACT_FORMAT_VERSION 475 -> 476: StageIo gains `half_outputs`, which the artifact codec encodes. Verified: cargo check; the version constants alone moved. * Regenerate the conformance coverage document for the 52 removed M3 rows What: docs/CONFORMANCE-COVERAGE.md, written by `python3 -I scripts/conformance-coverage/coverage.py`. Its ledger count goes from 1129 to 1077 rows and its ledger table loses the 52 Apple M3 Max rows of `half-output-blends-r16f`, `-rg16f` and `-rgba16f`, which the 16-bit half output commit removed from known-gaps.tsv (they read "no longer diverges" on the M3 replay). Why: the document is derived from the ledger, and `conformance_coverage::the_conformance_coverage_document_is_what_the_sources_derive` failed on the stale copy. Verified: the diff is those 52 lines and the count, nothing else. * Record the M3's safe-math half blends under the 16-bit half output What: PrecisionNote::HalfOutputPrecision's documentation said MoltenVK on the M3 Max stores Metal's bytes in every draw of the safe-math sweep. It now states what the lane measures with the output declared 16-bit, and that the NVIDIA, RADV, ANV and lavapipe bounds were measured with the output widened to float (RADV and ANV, which enable storageInputOutput16, now take the 16-bit form and are not re-measured: host away). Measured on the M3 Max, MoltenVK 1.4.2, macOS 27.0.1, with `runtime_lane::half_output_blends::half_output_blends_against_metals_rule` under --cfg m2v_gpu (the measurement prints HALF-BLEND-SUMMARY lines): - at this branch (16-bit output): R16Float, RG16Float, RGBA16Float 28 of 28 measured blend draws Metal's rule's value in every channel, largest distance 0; R32Float 28, RG32Float 28, RGBA32Float 26 of 28 (zero-1msa k0 and k4: one channel of 262,144 off by a zero's sign, distance 0); - at0db5825a60(float output; a lean snapshot built in a seeded target): 6 of 28 in each 16-bit float format, up to 2 half ulps apart at the operands' magnitude; the 32-bit formats identical to the above, the same two draws included. So the 16-bit output moves the 16-bit float formats to Metal's rule and leaves the 32-bit ones as they were. Both runs: the five runtime_lane::color_writes tests pass too. * Give the 16-bit half output its own SEMANTICS_VERSION, 1909 The half16 commits were written on0db5825a60and bumped SEMANTICS_VERSION 1907 -> 1908. On the release base b8f5007845, 1908 is already the serializer's element-by-element array copy (8b7a8aa2d8), so the rebase took that hunk as already applied and two different changes of translated words shared one version. A cache filled at the release would then serve the 32-bit half outputs to this lane under an unchanged key. 1909 separates them. ARTIFACT_FORMAT_VERSION 476 (StageIo::half_outputs) stays: the release did not move it. Verified: the constant alone moved. * Re-bless the golden hashes for the 16-bit half output on the native lane 73 rows of golden_hashes.tsv move: the fragment entry points whose half color outputs are now declared 16-bit on profiles that enable storageInputOutput16 and shaderFloat16 (SEMANTICS_VERSION 1909). The engine inventory and the engine golden printouts blessed with no change. Verified: bless_engine_inventory, bless_golden_hashes, bless_engine_goldens pass on macOS at fc8e43eff0; clippy --workspace --all-targets --all-features -D warnings clean.
metal2vulkan
metal2vulkan runs Metal shaders and Metal programs on Vulkan. It reads Metal AIR (a metallib, or AIR bitcode) and compiles it into Vulkan pipelines, and it offers the Metal API itself on top of a Vulkan device.
Beta. The API, the command line, the pipeline JSON and the emitted SPIR-V may change during the
0.xseries. Version your cached outputs.
The crates
| Crate | Directory | What it is |
|---|---|---|
metal2vulkan |
crates/metal2vulkan |
The translator. A Metal-shaped API (device, library, pipeline descriptors, binding plans) that compiles compute, render, tessellation, tile and mesh pipelines for a described Vulkan device: SPIR-V per stage, one pipeline layout, fixed-function state, and per-draw descriptor writes and push constants. The cli feature builds the metal2vulkan command. |
metal2vulkan-runtime |
crates/metal2vulkan-runtime |
The Metal API on Vulkan: devices, command queues and buffers, encoders, buffers, textures, heaps, pipeline states and events, run on a Vulkan device through ash. It uses only the translator's public API. |
metal2vulkan-air |
crates/metal2vulkan-air |
The AIR front end: the metallib container, the bitcode reader, a typed IR, AIR's metadata ABI, intrinsics and canonicalization. For tools that read AIR without translating it. |
metal2vulkan-validation |
crates/metal2vulkan-validation |
Not published. Authored cases run on Metal and on Vulkan and compared, and bounded audits over a private corpus. |
metal2vulkan-devtools |
crates/metal2vulkan-devtools |
Not published. The external-tool runner and fixture assemblers the tests share. |
The three published crates share one version and are released together; metal2vulkan pins
metal2vulkan-air exactly.
What the translator promises:
- Typed refusals. Input the device cannot run exactly fails with an error that names the Metal feature and what would make it work. It never returns a module that computes something else.
- Recorded differences. Where a pipeline gives a near-equivalent of Metal's answer, its artifact records a precision note, and the runtime announces it once with a stable code.
- The GPU's native arithmetic. Where the device has a native form (its maths, rounding, conversions and sampler), that form gives the answer, its difference from Metal's recorded; the runtime's speed-for-accuracy choices default to the fast form, each with an opt-in exact switch (docs/FAST-PATHS.md).
- Bounded work. Every compile runs under a deadline, a cancellation token and deterministic work and memory caps.
Install
0.2.0 is not on crates.io yet (crates.io has 0.1.0, an unrelated earlier design). Depend on a git revision:
[dependencies]
metal2vulkan = { git = "https://github.com/steelbrain/metal2vulkan", rev = "<sha>" }
# For the Metal API on Vulkan:
metal2vulkan-runtime = { git = "https://github.com/steelbrain/metal2vulkan", rev = "<sha>" }
Features of metal2vulkan, none needed by the library:
serde: serialization of the API's plain-data values.ash: conversions to and fromash::vk, andDeviceDescription::query, which reads a physical device.cli: themetal2vulkancommand (enablesserde).
Requirements: Rust 1.98 or newer. The libraries run no external tool. The runtime opens the Vulkan loader at run time and needs a Vulkan 1.2 device.
Command line
cargo install --git https://github.com/steelbrain/metal2vulkan metal2vulkan --features cli
The command compiles one pipeline of a metallib, an AIR bitcode module or an LLVM text module
(.ll) for the device a Khronos profiles JSON describes, and writes its SPIR-V:
# A kernel: one module.
metal2vulkan library.metallib kernel.spv --profile device.json --function my_kernel
# A render pipeline: one module per stage (pipeline.vert.spv, pipeline.frag.spv).
metal2vulkan shaders.air pipeline.spv --profile device.json \
--function vertex_main --fragment fragment_main --vertex-descriptor vertex.json \
--color-format 0:BGRA8Unorm --depth-format Depth32Float
# The pipeline's layout, interface, dependencies and stages as JSON.
metal2vulkan kernel.ll kernel.spv --profile device.json --emit-meta kernel.json
--profileis required: the crate ships no device description. Any Khronos profiles JSON works;crates/metal2vulkan-validation/profiles/has examples, from a bare Vulkan 1.2 device to desktop GPUs and MoltenVK.- Without
--functionit compiles the library's only kernel or vertex function. A kernel with--color-formatcompiles as a tile pipeline. A post-tessellation vertex function adds.tesc.spvand.tese.spvmodules on a device withtessellationShader; on one without, it is the.vert.spvmodule itself, which draws the tessellator's triangles. - A compile that needs a pipeline input fails naming it and the option that supplies it:
--constant ID:TYPE:VALUEfor a function constant,--stage-input FILEor--vertex-descriptor FILEfor a stage-input or vertex descriptor (as JSON). - A
.llinput is assembled withllvm-as(LLVM 21 or newer). Each module written is checked withspirv-valwhen it is found, under the environments the library states for the device;--no-spirv-valskips it. Both tools come fromPATH, or fromMETAL2VULKAN_LLVM_ASandMETAL2VULKAN_SPIRV_VAL. - Success prints a line with
PASSand exits 0. Failure printsmetal2vulkan: FALLBACK (<why>), writes nothing, and exits 2; a failure after the inputs are read also writes a repro bundle under$TMPDIR/metal2vulkan-repros(orMETAL2VULKAN_REPRO_DIR). metal2vulkan --helplists every option.
Library
The flow follows Metal's object lifecycle: describe the device, parse a library, compile a pipeline, then plan and instantiate each dispatch or draw.
use metal2vulkan::device::{Device, DeviceDescription, DevicePolicy};
use metal2vulkan::library::Library;
use metal2vulkan::pipeline::{ComputePipelineDescriptor, FunctionDescriptor, StageSource};
use metal2vulkan::Budget;
let description = DeviceDescription::from_khronos_json(&profile_json, None)?;
let device = Device::new(description, DevicePolicy::default())?;
let library = Library::parse(&metallib_bytes)?;
let kernel = FunctionDescriptor::new(library.function("my_kernel")?);
let descriptor = ComputePipelineDescriptor::new(StageSource::Function(kernel));
let pipeline = device.compile_compute_pipeline(&descriptor, &Budget::standard())?;
// pipeline.stage.spirv, pipeline.layout, pipeline.interface: create the Vulkan objects from these,
// then pipeline.plan(...) and plan.instantiate_dispatch(...) per dispatch.
docs/API.md walks the whole flow on a runnable example,
examples/api_preview.rs:
cargo run -p metal2vulkan --example api_preview # needs llvm-as on PATH
For the runtime, start at its README.
Documentation
| Document | Read it when |
|---|---|
| docs/API.md | You use the translator's API: devices, libraries, pipelines, binding, caching, errors; and the runtime's degrade notices |
| Runtime README | You use the Metal API on Vulkan |
| docs/HOWTO.md | You integrate: tools, caching, failures, isolation, the runtime's shader cache |
| docs/RUNTIME-PORTING.md | You port Metal calls (Objective-C or metal-rs) to the runtime |
| docs/FAST-PATHS.md | You need every speed-for-accuracy default and its exact switch |
| docs/METAL-COVERAGE.md | You ask whether a Metal API item is covered |
| docs/REFUSALS.md | You ask what Metal accepts that the code refuses |
| docs/ARCHITECTURE.md | You change the translator |
| docs/VALIDATION.md | You check behavior against Metal |
| CONTRIBUTING.md | You build and test the repository |
The rustdoc of each crate (cargo doc --workspace --all-features --open) documents every public
item; each runtime item names its Metal counterpart.
Shaders in this repository
The repository ships no third-party shaders. Tests use synthetic fixtures written for it. Passing
spirv-val shows a module is valid, not that it computes what Metal computes; that claim needs the
authored validation cases (docs/VALIDATION.md).
License
metal2vulkan is dual-licensed: you can redistribute it and/or modify it under the terms of either of these licenses, at your choice (LICENSE):
- the GNU General Public License, version 2, or (at your option) any later version;
- the GNU Lesser General Public License, version 3, or (at your option) any later version. It incorporates the terms of the GNU General Public License, version 3.
As an SPDX expression: GPL-2.0-or-later OR LGPL-3.0-or-later. Each published crate carries the
notice and the three texts.
Metal is a trademark of Apple Inc. metal2vulkan is an independent project and is not affiliated with, sponsored by, or endorsed by Apple Inc.