The RTX 5080 samples A1BGR5Unorm, ABGR4Unorm (and every other 16-bit packed order), R8Unorm_sRGB,
RG8Unorm_sRGB and RGB9E5Float but renders none of them, and lavapipe renders neither 8-bit sRGB
format. A render target, clear or draw of such a texture was refused as the device lacking the
format, which ends the guest of any app that renders to one. They now render through an R8_UINT,
R16_UINT or R32_UINT view of the same bits, the fragment function writing Metal's word.
What changes:
- metal::format::WordAttachment (public, with WordField): a format's fields in its word (packed
16-bit layouts named from the least significant bit, Srgb8, Rgb9e5). WordAttachment::of holds
where the device samples the format (or its UNORM twin), does not render it, and renders the
word's integer format: derived from format features alone, on every driver.
- Translator: LoweringInputs::word_colors names such attachments. The fragment output to one is
declared as a uint and each return stores Metal's word: a packed channel h(x) to nearest even,
NaN 0, clamped to [0, 1], times the maximum code, rounded to even; an sRGB channel through
Metal's twelve-bit table; RGB9E5 by the truncating kernel-write rule (shared with the storage
write, lower::texture::rgb9e5_word). The cache codec carries the new fields.
- Partial write masks and blends:
- in the pixel interlock (where the device orders fetch through it alone), a packed 16-bit or
8-bit sRGB word's partial mask merges the kept fields from the word read first;
- a packed 16-bit word's blend other than One/Zero decodes each code as Metal's blend reads
it, h(c / m), blends in half as the 8-bit unorm blend does and encodes Metal's word. Metal's
tile holds a pass's earlier result finer than the codes, so this is a near-equivalent within
one code, recorded as PrecisionNote::DeviceColorConversion and announced; the exact form (the
extended-range half shadow taken by word attachments) is a FAST-PATHS "not built yet" row;
- where fetch reads rasterization-order input attachments (lavapipe), an 8-bit sRGB word's
partial mask merges over its input attachment (new RuntimeFact::WordInputMerge), per sample in
a multisampled pipeline.
- Runtime: the texture's image keeps its own format, sampled and blitted natively, made mutable
with extended usage and the word view listed; the pass's attachment is the view; a pass clear
writes the word of Metal's clear.
- New degradation kind shared-exponent-kept (Precision): Metal's tile store normalizes a loaded
RGB9E5 word whose largest mantissa is below 256 in each tile a draw reaches, which a Vulkan pass
keeps; announced at each such draw, with a FAST-PATHS row.
- DeviceColorConversion's rustdoc states that Metal blends a packed 16-bit attachment against its
tile's finer values within a pass.
- Still refused, recorded as FAST-PATHS known gaps: colour inputs and resolves of word
attachments, blended or fetched sRGB words, an output of fewer than four lanes for a blended
packed word, RGB9E5 half outputs, blends, masks, inputs and resolves.
- New owned fixture engine/wm_samples and runtime_lane::word_samples for the multisampled merge.
Why: these formats are Metal render targets the guest uses, and the device holds and samples them;
only rendering them directly is missing.
Metal's rules, measured with plain Metal on the M3 Max under macOS 27.0.1: 65,536 float4 and half4
outputs and 4,096 clear colours per packed format, 0 texels off the rule; a One/Zero blend stores
the same bytes; the blend sweep (2,891 states, 8,192 random pixels, four packed formats, half and
float, fast and safe maths) gave Metal's code in every channel without fast maths and within one
code under it; within a pass Metal's tile holds a packed attachment finer than its codes (blends
in one pass follow the unrounded value, across two passes the stored codes); RGB9E5 draws and
clears 65,536 of each, 0 off.
Verified:
- Translator and runtime unit filters on gem10: 162 of 162 and 258 of 258 (word attachments),
394 (partial masks in the interlock), 370 and 422 (blends, including 864 words the M3 stored
checked on the interpreter), 538 (sRGB and RGB9E5 words), 38 and 108 (input-attachment merge).
- On lavapipe: runtime_lane::color_writes 5 passed, RG8UnormSRGB under the red mask 0 of 107,814
channels off where it was refused before; word_samples, 64 texels of 4 samples merged, the edge
texels keeping both greens; public_fixtures_engine with the new rows.
- clippy -D warnings (plain, m2v_gpu, m2v_cpu_icd) and rustdoc.
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.