One work packet, landed as 7 commits (56d9d6332b..3fb626fab0 on archive/development-linear-2026-10-28), in order: * Accept the device's half NaN where a module widens halves natively Two tests still held a half NaN's bits on profiles whose modules now read a half from its bits by the device's widening (QuantizeForm::Converted, which records PrecisionNote::NativeHalfConversion, whose NaN encoding is the device's): - engine_access::every_leaf_path_is_exact_in_bounds_and_contained_out_of_bounds compared load_half_bytes byte for byte on moltenvk-m3; the pattern 0x7f62 came back 0x7e00. It now accepts any NaN for a NaN pattern where the compile records NativeHalfConversion, as narrow_units_are_exact_at_every_ bind_residual already does (same_halves); every other bit pattern stays exact. - engine_cross_class::accesses_through_another_class_are_the_native_words compared a half result's low 16 bits exactly on lavapipe; the word's low half 0xfcc0 came back 0x7e00. Where the cross-class compile records NativeHalfConversion (both profiles of the test), a NaN pattern need only come back a NaN. The product is unchanged; the reinterpret doc comment in lower/texture/emit.rs no longer claims a NaN's payload survives the cross read's widening. Verified: cargo nextest -p metal2vulkan --all-features over tests::engine_access and tests::engine_cross_class: 31 passed. * Expect the device's NaN notes in the float-call-notes tests The NaN and min/max deletion leaves every NaN Metal answers to the device, noted NativeNanEncoding where the profile is not measured to answer Metal's (NanEncoding::Native). Two tests still held the deleted policy's answer: - a_float_division_is_the_devices_arithmetic_unless_it_is_metals_precise_one asserted that no operator leaves its NaN to the device. It now expects NativeNanEncoding on a NanEncoding::Native profile for Metal's precise division, for the fast float division outside Metal's own fast-math entry, and for the operators Metal answers a canonical NaN for (float and half + - *, the float remainder), and on no other operator; still never DeviceNanEncoding. - exported_float_notes_are_the_ones_a_compile_records set aside only a half kernel's rounding note. Under the float controls (QuantizeForm::Controlled, both RADV classes) a half module that widens a half from its bits by the device records NativeNanEncoding for that widening (compile_kept), which no exported operation note carries: 124 half kernels a class failed so (fast_fabs, fast_sqrt, fmin, frem and the rest). The test now adds that note to the operation's where narrow::widens_bits finds the widening in the kernel's module, so the comparison stays exact. Product unchanged. Verified: cargo nextest -p metal2vulkan --all-features over tests::engine_float_call_notes: 4 passed. * Count one module, two translations, for a narrow-float sweep read as float The NaN deletion replaced the canonical NaN a 32-bit float read of a narrow-float vertex format selected after the device's widening with the note PrecisionNote::DeviceNanEncoding. VertexFetch::FixedFunction's narrow_float bit still keys the projection, since it decides that note, but it no longer changes an instruction, so the sweeps compile one module where they compiled two: - a_float_read_compiles_two_modules_for_the_whole_sweep, now a_float_read_compiles_one_module_for_the_whole_sweep: 2 projections, 1 module (was 2, 2). - a_constant_step_binding_compiles_two_modules_for_the_whole_sweep, now a_constant_step_binding_compiles_one_module_for_the_whole_sweep: (2, 1, 1, 1) where every format is fetched, (3, 2, 2, 2) with FloatRGB9E5 pulled on the Intel profiles (were (2, 2, 1, 1) and (3, 3, 2, 2)). - narrow_float_changes_no_instruction_of_a_half_read, now narrow_float_changes_no_instruction_but_a_float_reads_note: its float4 control asserted that the bit changes the words. It now asserts that the words are the same for both entries, that a half read's notes are the same, and that only a float read with the bit records DeviceNanEncoding, so the projection still keys what the artifact records. The module docs say so. Product unchanged: the second translation is what the per-pipeline note costs. Verified: cargo nextest -p metal2vulkan --all-features over tests::engine_vertex_variants: 8 passed. * Judge the rate-map decoder by the device's denormals, not Metal's flush The float-maths deletion leaves every float + - * and comparison's denormals to the device: Metal's where the profile takes MetalFloatDenormals (MoltenVK), the device's own elsewhere, noted DeviceDenormals. engine_rate_map::the_decoder_answers_as_the_map still ran the module of a profile stripped of that deviation, expecting it to flush denormals itself, and compared the CPU interpreter (which keeps denormals) with Metal's flushing shader decoder: identity layer 2 at (0, 0) answered -3.57e-43 where Metal answers 0. It also asserted that no profile records DeviceDenormals, which every profile but MoltenVK now records. The test now: - asserts no RasterizationRateMap note, DeviceDenormals exactly where denormal::device_flushes is false, and NativeNanEncoding exactly where the profile's NaN encoding is Native; - runs each profile's own module and compares the interpreter, bit for bit (a NaN any NaN), with kept(): rate_map_data's shader decoder with IEEE f32 arithmetic, no operand or result flushed; - checks that this equals Metal's shader decoder at every point of a map's own layers, differing only at layers past the map (their tables are other words read as floats, some denormal), and that both kinds of point occur. The profile helper loses its own_denormals arm. The decoder's docs in canon/rate_map.rs, canon/rate_map_data.rs and bind/rate_map.rs no longer say the module flushes denormals itself: the decoder answers Metal's on a device that reads denormals as Metal does, the device's elsewhere. No code changes. Verified: cargo nextest -p metal2vulkan --all-features over tests::engine_rate_map: 3 passed. * Give the helper-branch fixtures an optnone call the native half leaves The half rounding deletion removed the NoContraction barrier on the device's conversion pair, which SPIRV-Cross wrote as its optnone spvFAdd. That barrier was the only optnone call in the arms of the owned fixtures rch_helper_branch and rch_helper_tangle on moltenvk-m3 (QuantizeForm:: Converted), so the guard of spirv::helper_branches had nothing left to guard there: - helper_invocations_skip_an_optnone_branch_on_a_driver_that_drops_a_ simdgroups_stores: rch_helper_branch had 0 guards where 1 is expected; - a_tangled_instruction_reading_a_helper_call_keeps_the_note_away: rch_tangle_sample_before and rch_tangle_unread recorded no HelperBranchDropsSimdgroupStores (only quad_before kept one, from a kept addition). The product is right not to guard or note a branch with no optnone call; the fixtures lost their trigger. They now take it from mulhi in the same place (an OpUMulExtended, which SPIRV-Cross writes as its optnone spvMulExtended; checked with this host's spirv-cross on a hand-written module): rch_helper_branch's arms add the low bit of mulhi(i, k) to their mix, and rch_helper_tangle's arms take products(v, c), the high words of mulhi of the source's bits and the coverage's, scaled into [0, 1), which the tangled instruction reads in the after functions and does not read in the before ones. A covered pixel takes no arm, so its write, which the device lane runtime_lane::helper_tangle checks, is unchanged. Every expectation of both tests holds again unchanged; only their docs, the fixture comments and the lane's docs say mulhi instead of the half rounding. spirv::helper_branches no longer lists the half conversion barrier among the NoContraction users. Regenerated with scripts/regen-air-fixtures/regen-air-fixtures.sh rch_helper_branch rch_helper_tangle (Metal 32023.921, SDK 27.0, LLVM 21.1.8, the toolchain TOOLCHAIN already records for both), and their air_input goldens re-blessed with tests::air_input::bless_engine_goldens (no other golden changed). The golden hash tables are left for development's re-bless. Verified: - cargo nextest -p metal2vulkan --all-features over tests::engine_fragment, tests::air_input and tests::public_fixtures_engine: 69 passed (the fixture expectation table unchanged); - cargo nextest -p metal2vulkan-validation --all-features over the fixture tests: 28 passed. Not run: the device lane helper_tangle on an Apple GPU, which must show whether spvMulExtended triggers the store loss as spvFAdd did. * Re-pin the runtime sources at the landing tip The landed packet changed a runtime-sources input, so the committed digest no longer described the sources and `the_runtime_sources_are_the_committed_ones` would fail. Recomputed over the same inputs and committed by land-pkt.sh. * Re-bless the golden table after the native-arithmetic deletions Blessed on development at ea56fbb83d, after the six native-arithmetic lanes, the unread-fact and macOS 26.7 sweeps, the exact table's removal and the test fixes landed. The engine inventory and the fixture expectations table re-derive unchanged; golden_hashes.tsv moves where the deleted exact forms changed modules. The bless named no cell changed under an unchanged key. Verified: bless_engine_inventory, bless_golden_hashes and bless_engine_goldens each passed (exit 0).
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.
- Fast by default. Off Apple's GPUs, choices that trade exactness for speed take the device's native form; each has 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.