DriverDeviation::MetalSampler, CubeGradientRoute and GraphicsCubeGradientTangents, with VkProperty::MetalSampler and its codec tag, were never taken: Device::from_queries enables no Metal* property and always inserts VkProperty::DeviceSampling, and no committed profile carries a Metal* property. ProfileFields::cube_gradients, with CubeGradients and CubeGradientRoute, had one reachable value (Vulkan's rule for both stages), so it goes too. The forms only they reached go with them: - Cube gradients: CubeFootprint::Metal and ::Projected (MoltenVK's gradientcube and its graphics fixup); a cube's explicit gradients take Length, Face or Word by the sampler's anisotropy alone, and CubeGradientFootprint is raised wherever the shader does not take Metal's level and taps itself. - The sampler requirement: SamplerFamily::metal_sampler merges into device_sampling. Every sample, gather and LOD query, the hoisted no-bias samples and BiasReach::Metal's included, requires VkProperty::DeviceSampling and records DeviceSampling, as on every real device. - The half-texel routine (lower/texture/half.rs) and everything only it read: HalfClass, half_class and heap_half_class, TexelLanes and TexelOrigin, the texel argument of texel_value and held_value, sample_lanes and word_reads_one, Sampling::one_texel's word forms (one_texel now answers whether an access may read one texel, which float_texel_notes reads) and half_texel, SamplerSlot::texels, SlotPlan::half_format and unmeasured, TexturePlan::heap_half, the declarations half_format, half_routine and plain_half, the module's table of heap texel classes (AccessPlan::heap_class, declare_heap_classes, heap_texel_class, HEAP_CLASS_WORDS, and texel_format::heap_classes, whose tests now read the layout itself), texel_round::f32_to_half_from_even, NoteOn::Unmeasured, SpecKey::UnmeasuredTexels and PlainHalfTexels with their plan answers, TexelFormat::YCBCR_8192, MEASURED_ON_METAL_SAMPLER, unmeasured_on_metal_sampler and plain_on_metal_sampler, and the identity-domain refusal of a heap half sample that only a Metal-sampler profile met. - The Metal sampler's YCbCr filter note (linear::filter_note and metal_filtered_ycbcr), with NoteOn::HeapYCbCr and ArgumentSamplers, SpecKey::HeapYCbCrTextures and FilteringArgumentSampler, their plan answers and TexelFormat::two_plane_ycbcr. - The anisotropic not-mipmapped clamp [0, 0] (vk_sampler's own_anisotropic) and its note's source (anisotropic::own_not_mipmapped); PrecisionNote::NotMipmappedAnisotropicFilter, its codec tag, conformance Degradation and validation allowance go with its only source. - The rest: device_texels, device_decode's and fragment/color.rs's Metal decode, bind::plan::resources' swizzled_packed profile test, and border_read's metal_sampler (and device_opaque_black's format argument, which nothing then read). Rule 1, per note the commits stop raising: every one is case (b), no difference goes silent. - filter_note's HalfSampleFilter and FloatSampleFilter (slot clauses on a bound two-plane YCbCr format and the bound sampler word, heap clauses on HeapYCbCrTextures and FilteringArgumentSampler): raised only on a profile with VkProperty::MetalSampler, so on no real device. Such a filtered sample goes to the device's own sampler, and every sample, gather and LOD query sets device_sampling, so the stage records DeviceSampling, whose entry covers the device's filter of a two-plane texture. The in-place Y'CbCr model's HalfSampleFilter and FloatSampleFilter stay as they were. - NotMipmappedAnisotropicFilter: raised only under own_not_mipmapped, which needed MetalSampler. An anisotropic sample on a device with samplerAnisotropy goes to the device's sampler (DeviceSampling, its not-mipmapped clamp [0, 0.25] the device's footprint), and one without it keeps AnisotropicFilter or DeviceAnisotropicFilter, as on every real device. - The rest only widen: HalfTexelConversion (now outright at every half read, sample and gather, where the Metal-sampler profile tested the bound class), DeviceTexelConversion, SrgbTexelDecode and CubeGradientFootprint, each withheld only on a Metal-sampler or Metal-route profile. The precision-note catalogue loses NotMipmappedAnisotropicFilter alone; the docs of GradFromBias, HalfTexelConversion, HalfSampleFilter, SrgbTexelDecode, FloatSampleFilter, DeviceSampling and DeviceTexelConversion lose their Metal-sampler clauses (docs/API.md's entries already stated the one rule). Validation: comparison.rs's allowance list loses NotMipmappedAnisotropicFilter (unbounded), which no device raised; its HalfSampleFilter and FloatSampleFilter reasons now name the in-place model, their class unchanged (unbounded). No validation file names a deleted DriverDeviation. Also, from the planner: the citation of VUID-RuntimeSpirv-NonUniform-06274, which spec 1.4.366 no longer has, becomes VUID-RuntimeSpirv-None-10148 and VUID-RuntimeSpirv-subgroupSize-10149 in spirv/builder/ops/memory.rs, spirv/ir/module.rs (twice), spirv/serialize/mod.rs and the doc of non_uniform_elements_are_decorated_through_what_carries_them. Comments only. Tests: each deleted form's tests go with it: lower/arith/tests/half_texel.rs (the routine, its plain arm, and the steps that bounded the Metal-sampler note) with arith/tests.rs' quantize_flush_of, which only it read, f32_to_half_from_even_is_exact_on_every_tie, the projected-footprint test and the swizzle helper of face/tests/anisotropic.rs, texel_format's ycbcr_8192, wide16 and metal_sampler_s_read_bits tests, the format version 326 round trip, and the routes' asserts in engine_handles, engine_heap_binder and engine_sampler_unk. The rest assert the device's sampler on every profile: half_reads_round_their_texel_to_nearest_even (was half_reads_convert_by_the_bound_format), heap_half_texels_round_the_device_s_texel (was heap_half_texels_convert_by_the_handle_s_class), heap_linear_samples_are_the_device_s (no FloatSampleFilter, outright or specialized), engine_sample_coordinates' requires_the_sampler, engine_bias_reach, engine_graphics_binder's border test, engine_srgb_decode, engine_sampler, the routines test, the merged-members round trip, and metal/sampler.rs' and format/tests.rs' opaque-black calls. SEMANTICS_VERSION 2239, ARTIFACT_FORMAT_VERSION 577 (placeholders; main renumbers). SEMANTICS: the profile's fingerprint and the notes of the same input change form. ARTIFACT: the codec loses the VkProperty, the PrecisionNote and four SpecKey tags. RUNTIME_VERSION stays: the pinned sources' edits (device/, bind/plan/resources.rs and slots.rs, metal/sampler.rs, cache/codec.rs) remove forms and keys no profile reached, so no run changes; runtime-sources.sha256 takes the new hash. api_signatures is blessed; docs/REFUSALS.md and the coverage are unchanged. Consumer check (consumer-uses.sh, consumer development 2040502291, 62 refs): CubeGradientRoute, GraphicsCubeGradientTangents, CubeGradients, cube_gradients, FilteringArgumentSampler, HeapYCbCrTextures, PlainHalfTexels and UnmeasuredTexels 0 hits (code). MetalSampler and NotMipmappedAnisotropicFilter: 0 hits on development (its answer.rs names neither, and it has no gpu/rgbx.rs); named in crates/reims-vgpu-vulkan/src/answer.rs and gpu/rgbx.rs on 36 of the consumer's steelbrain/* branches younger than a day. Verified: m3-max-61441 (msi-laptop, this tree): fmt, clippy (all features, --cfg m2v_gpu, --cfg m2v_cpu_icd), Rustdoc green; tests 5861 of 5863 passed. The two failures: golden_hashes_match_the_table, every one of its 29536 cells under a changed profile fingerprint (re-blessed on development at a named pin), and the_old_render_descriptor_key_keeps_its_value, left unpinned until the next named pin. Rebased onto developmentd10a14d5af: the SEMANTICS placeholder is one above its 2235 in stack order (ARTIFACT_FORMAT_VERSION is already above its 574). The checks above ran at the old base acc706ca47; the rebased stack's tip is checked by m3-max-61756 (msi-laptop), at the stack rebased ond6d56b8a7c(tip 5c74fad38d, whose diff from its base is this stack's diff fromd10a14d5af): fmt, clippy (all features, --cfg m2v_gpu, --cfg m2v_cpu_icd) and Rustdoc green; nextest of metal2vulkan, metal2vulkan-validation, metal2vulkan-conformance and metal2vulkan-runtime ran 5877 tests, 5870 passed. Of the 7 failures, the old render descriptor key's test is unpinned; golden_hashes and engine inventory parts 4, 5, 7 and 8 are bless due (the profiles' fingerprints changed); and metal::state's encoder_raster_state_needs_its_features fails the same way at developmentd10a14d5afitself (m3-max-61802, where runtime-floor gained depthBiasClamp ina529fb658e), as inventory parts 3, 4, 5 and 8 do there. The stack as rebased on72e1754218(tip 090d544208: the same product changes, without the test-only push sweep fix) played 36 distinct streams over 61 runs on five nodes with 0 refused (player m3-max-61537; plays m3-max-61548, 61549, 61550, 61559 and 61569).
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, with one path for every device: devices, memory blocks and buffers, textures, sampler states, command queues, command buffers and events, encoders and pipeline states, 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, and metal2vulkan-runtime pins metal2vulkan 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.
- 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.3 device with what its README's Floor lists.
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. A profile compiles with the default domains (DevicePolicy::UNTRUSTED).--device FILEtakes its place with a device description and policy as JSON ({"description": ..., "policy": ...}), which is how a runtime's compile device is reproduced: metal2vulkan-runtime's is the description restricted to the features it enables, with the identity pointer and handle domains.- 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 withouttessellationShaderit answersFALLBACK, naming the feature. - A vertex function that returns no value, with no
--fragment, compiles with rasterization disabled, the one pipeline Metal makes of it. - 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), whoserepro.shreplays it. 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::from_queries(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 precision notes |
| Runtime README | You use the Metal API on Vulkan |
| docs/HOWTO.md | You integrate: tools, caching, failures, isolation, the runtime's shader cache |
| docs/RESOURCE-ID.md | You compute a texture's or sampler's gpuResourceID on the guest's side |
| 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.