The Mac triage work packet: what MoltenVK on the M3 Max reports, counted and expected as it is.
Count a pipeline found in its cache where every stage says so, as MoltenVK reports it:
The shader cache's driver_pipeline_hits counted a making as found in its cache only where the whole
pipeline's VkPipelineCreationFeedback said APPLICATION_PIPELINE_CACHE_HIT. MoltenVK 1.4.1 never sets
that bit for the whole pipeline: it sets it on a stage's feedback alone, where it found the stage's
converted Metal function in the pipeline cache (MVKPipelineCache::getShaderLibraryImpl), and leaves
the whole pipeline's feedback VALID (MVKGraphicsPipeline, MVKComputePipeline; read in MoltenVK
v1.4.1's MVKPipeline.mm and MVKShaderModule.mm). The runtime chained no stage feedback, so on
MoltenVK every making from a record counted as a miss, and the statistics' doc ("On every driver,
MoltenVK's included") was false there. The specification allows either form: the bit "specifies
that a readily usable pipeline or pipeline stage was found in the pipelineCache", and "when an
implementation sets this bit for the entire pipeline, it may leave it unset for any stage".
A making now chains each stage's feedback too (a graphics pipeline's where it has at most five
stages, VUID-...-06594; a compute pipeline's one, VUID-...-06566), and shader_cache::found_in_cache
counts a hit where the whole pipeline's feedback is valid and says the hit, or where every stage's
is valid and says it; a miss where the whole pipeline's is valid otherwise; nothing where it is not
valid. A driver that sets the bit for the whole pipeline counts as before. No MoltenVK check: only
what the feedback structures say. The ShaderCacheStatistics docs state the rule.
RUNTIME_VERSION 1190 (a making chains more feedback; the statistic changes on MoltenVK).
Verified on the M3 Max (macOS 27.0.1, MoltenVK 1.4.1), release --cfg m2v_gpu:
- shader_cache::found_in_cache's unit test (whole hit; whole valid and every stage a hit; mixed;
no stages; not valid) passes, with the runtime's other shader_cache tests (18 of 18).
- runtime_lane::pipeline_records, at the round's first composed tree plus this branch: all three tests that
failed at 61a2efc7d3 and fd22785008 ("the driver reported (0, 1), not (1, 0)") pass; the second
device now counts pipeline_hits=1 pipeline_misses=0 at creation and 2/0 after its draw, from
MoltenVK's stage feedback. The module's other tests pass.
- the_runtime_sources_are_the_committed_ones passes with the new pin.
- By source, the count is unchanged where drivers set the whole pipeline's bit: RADV sets it on the
whole pipeline alone (radv_pipeline_graphics.c, radv_pipeline_compute.c), Mesa's common
vk_pipeline.c (ANV and others) sets it exactly when every stage hit, lavapipe on neither. Not run
here on NVIDIA, RADV or ANV.
Expect a MoltenVK device's kept-cache message in the creation sink lane:
degrade_notices::a_creation_s_notices_and_messages_reach_the_sink_on_the_asking_thread failed on the
M3 Max (MoltenVK 1.4.1) at 61a2efc7d3 and at fd22785008 alike: as a device is made on a driver
that keeps its internal pipeline cache and that cache is Metal's own (device/create.rs,
kept_cache_is_metals), the runtime sends the informational message
metal2vulkan-driver-pipeline-cache-kept, which creation_heard_checked did not expect (it expected
metal2vulkan-unmeasured-driver alone).
creation_heard_checked now expects that message, after the unmeasured-driver one, exactly where the
lane reads from the driver that it keeps its cache (driver_keeps_pipeline_cache: no
VK_KHR_pipeline_binary, no VK_KHR_maintenance5, or no internal cache control) and the cache is
Metal's (the runtime's own predicate, kept_cache_is_metals, which creation_kinds now shares). The
message must name the device and end in its id name. Test only.
Verified on the M3 Max (macOS 27.0.1, MoltenVK 1.4.1), release --cfg m2v_gpu:
- the test fails at 61a2efc7d3 and passes at the round's first composed tree plus this branch, with every
other degrade_notices test that passed before (passes_degrade_once_per_kind still fails on macOS
27's missing 8-sample textures, as before).
Expect the GPU-time reads' notice in the mesh object lane:
mesh_draws::object_draws_store_metals_words failed on the M3 Max at 61a2efc7d3 and fd22785008 alike:
each pass the lane runs reads its command buffer's GPU times for its timing line, and on MoltenVK
1.4.1 (DriverFact::TimestampsWaitForEveryQueue) that read announces gpu-times-from-host, which the
lane's exact list of kinds left out. It now adds gpu_times::read_kinds, as first_use does for its
own reads. Test only.
Verified on the M3 Max (macOS 27.0.1, MoltenVK 1.4.1), release --cfg m2v_gpu:
- the test fails at 61a2efc7d3 and passes at the round's first composed tree plus this branch, with the
module's other tests.
Let the layer's clear message about a Metal-texture image pass as its known gap:
window_surfaces::programmable_blends_over_host_pages failed on the M3 Max at 61a2efc7d3 and
fd22785008 alike on VUID-vkCmdClearColorImage-image-00003: the pass clears a color its first
instance leaves out before the pass (render.rs, Clears), and that color's image is an imported
Metal texture, which Vulkan treats as bound but Vulkan-ValidationLayers 1.4.357 does not model (the
gap metal_import_gap.rs already lets pass for barriers, views, framebuffers, descriptors and copy
sources). The clear's message joins the list, with its text in the shape tests; still only for an
image the runtime named as a Metal texture, and only on the layer release read. Test only.
Verified on the M3 Max (macOS 27.0.1, MoltenVK 1.4.1, layer 1.4.357), release --cfg m2v_gpu:
- the test fails at 61a2efc7d3 and passes at the round's first composed tree plus this branch, with the
module's other tests; metal_import_gap's four shape tests pass with the new message.
Write the CPU-write lanes' rows where no tile a draw reaches holds them:
linear_attachments::a_cpu_write_at_an_undrawn_pixel_survives_{a_loaded_pass,a_pass_apart} failed on
the M3 Max at 61a2efc7d3 and fd22785008 alike, always "4142 of 16384 bytes kept". The lanes wrote
the last 8 rows while the pass ran and took Metal to keep them. Metal does so only by timing: it
stores each tile a draw reaches whole, those rows too. Measured through Metal alone on the M3 Max,
macOS 27.0.1 (26A434), with the lane's pass (512x256 BGRA8Unorm over a no-copy buffer, Load and
Store, the zwd_panel blend, the scissor, the shared event) at 6000 panels: with 8 rows left out, a
write late in the pass kept 5163, 11282, 13322 and 11282 of 16384 bytes (and 5163, 11281 beside a
stencil attachment); with 64 rows left out, every byte at each of 11 delays across the pass (7
beside the stencil). Metal stores no tile no draw reaches. The runtime's pass on MoltenVK is that
Metal pass (a MoltenVK call trace shows nothing else touching the image meanwhile), slower per draw,
so its write landed inside the bottom tiles' window.
The lanes now leave out the last 64 rows, which no tile a draw reaches holds, where Metal's answer
does not depend on timing; a copy back of the area by the merge would still be caught. Test only.
Verified on the M3 Max (macOS 27.0.1, MoltenVK 1.4.1), release --cfg m2v_gpu:
- both tests fail at 61a2efc7d3 and pass at the round's first composed tree plus this branch, with every
other linear_attachments test. The Metal readings: a probe program of the lane's pass in Swift
over Metal alone, its CPU write at delays from 0 to 11 ms.
Versions: RUNTIME_VERSION 1199 -> 1200. RUNTIME_VERSION moves: how a pipeline found in its cache is
counted on MoltenVK changes. crates/metal2vulkan-validation/runtime-sources.sha256 holds
d495df50a3dff8090fad17ec55742a34374aa6c32544cacd63fd9c497e64d0b1, the hash of this tree's runtime
inputs (runtime-pin.py, which reproduces build.rs's). Version numbers quoted above are the values
the work's branch built with. Each part's Verified lines name the tree it ran at.
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.
Alpha. 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. - 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.