Anees Iqbal 1f7b797e2e Runtime README: the host-seen event value is stated in the events contract
The sentence saying that an event's value the host sees, where a GPU signal raised it, is one a
host wait with a timeout of 0 confirmed states how events behave; it is not a gap. It moves from
"Known gaps" (the timestamp-pool bullet, restored to its text before the fix) to the `Event` and
`SharedEvent` bullet of "Queues, command buffers and events", in the present tense. No code
changes.

The record of the fix's cost (58158f96a9, with the doc commit 4ab995b621 on it): the harness's
two_queues row (`harness --runtime new --only two_queues`), before = d50eeb3522, after =
4ab995b621, 5 pairs alternated in one exclusive job per card, the arm order swapped each pair.
Times in us (b_done_p50 in ms: B committed to completed in the signalling part). spr is an arm's
max / min - 1.

RTX 2080, job m3-max-76839: every event key within 1%, base spreads at most 4.0%.
run       wait_p50 wait_p90 a_gap_p50 a_gap_p90  a_per_cb b_done_p50
before 1    19.840   20.192    41.376    42.336 20250.718    161.700
after  1    19.840   20.352    41.600    42.528 20263.368    161.800
after  2    19.872   20.128    41.312    42.176 20255.721    161.800
before 2    19.808   20.448    41.350    42.432 20251.343    161.800
before 3    19.872   20.480    41.120    42.144 20255.964    161.800
after  3    19.904   21.472    41.472    44.416 20255.081    161.800
after  4    20.000   20.416    41.344    43.040 20256.101    161.800
before 4    19.904   20.896    41.333    42.976 20258.708    161.800
before 5    19.904   20.992    41.440    43.776 20254.411    161.800
after  5    19.904   21.088    41.472    42.469 20252.510    161.800
before p50  19.872   20.480    41.350    42.432 20254.411    161.800
before spr    0.5%     4.0%      0.8%      3.9%      0.0%       0.1%
after p50   19.904   20.416    41.472    42.528 20255.721    161.800
after spr     0.8%     6.7%      0.7%      5.3%      0.1%       0.0%
after/before 1.002    0.997     1.003     1.002     1.000      1.000

Iris Xe (RPL-P), job m3-max-76844: every event key within 1%, base spreads at most 1.7%.
run       wait_p50 wait_p90 a_gap_p50 a_gap_p90  a_per_cb b_done_p50
before 1     9.012    9.167    38.803    46.503 22598.215    180.500
after  1     9.063    9.324    38.854    46.564 22597.641    180.500
after  2     9.220    9.636    38.959    46.826 22609.295    180.500
before 2     9.064    9.271    38.855    46.663 22597.349    180.500
before 3     9.115    9.272    38.855    46.353 22610.056    180.500
after  3     9.115    9.272    38.856    46.625 22642.170    180.600
after  4     9.114    9.271    38.803    46.498 22597.597    180.400
before 4     9.115    9.271    38.855    46.410 22625.471    180.500
before 5     9.167    9.323    38.804    46.567 22606.507    180.400
after  5     9.115    9.272    38.855    46.574 22618.163    180.500
before p50   9.115    9.271    38.855    46.503 22606.507    180.500
before spr    1.7%     1.7%      0.1%      0.7%      0.1%       0.1%
after p50    9.115    9.272    38.855    46.574 22609.295    180.500
after spr     1.7%     3.9%      0.4%      0.7%      0.2%       0.1%
after/before 1.000    1.000     1.000     1.002     1.000      1.000

RX 7900 XTX (RADV), job m3-max-76837: every event key within 1%, base spreads at most 4.5%.
run       wait_p50 wait_p90 a_gap_p50 a_gap_p90  a_per_cb b_done_p50
before 1    23.480   23.720   664.250   690.220 20664.500    165.100
after  1    23.560   23.800   665.520   685.240 20546.559    164.200
after  2    23.520   23.680   665.530   735.111 20645.568    165.000
before 2    23.520   23.680   663.780   697.990 20594.544    164.700
before 3    23.440   23.680   654.693   677.460 20495.322    164.300
after  3    23.480   23.680   665.810   670.200 20624.176    164.800
after  4    23.560   23.720   665.800   681.720 20659.588    165.100
before 4    23.560   23.720   661.400   688.170 20614.650    164.500
before 5    23.600   23.720   661.600   668.007 20625.205    164.700
after  5    23.520   23.720   665.078   697.190 20629.603    164.800
before p50  23.520   23.720   661.600   688.170 20614.650    164.700
before spr    0.7%     0.2%      1.5%      4.5%      0.8%       0.5%
after p50   23.520   23.720   665.530   685.240 20629.603    164.800
after spr     0.3%     0.5%      0.1%      9.7%      0.6%       0.5%
after/before 1.000    1.000     1.006     0.996     1.001      1.001

RTX 5080 Laptop, job m3-max-76834: VOID, its base arm spreads above 10% (41.4% on wait_p50,
41.8% on wait_a_gap_p50); its runs fall in two groups (8.3 to 9.1 us and 10.2 to 12.0 us on
wait_p50) in both arms.
run       wait_p50 wait_p90 a_gap_p50 a_gap_p90  a_per_cb b_done_p50
before 1    12.032   12.768    23.872    26.016 20877.065    160.800
after  1    10.176   12.448    22.576    25.984 21461.131    163.600
after  2    11.264   12.768    22.719    26.464 21465.165    163.700
before 2     8.960   12.512    18.272    25.984 21513.619    163.900
before 3     8.672   12.352    17.984    25.952 21537.336    163.900
after  3    11.232   12.416    22.130    25.184 21585.253    164.100
after  4     8.320   12.256    16.544    24.736 21603.339    164.000
before 4     8.512   12.480    16.832    24.736 21658.572    165.000
before 5     8.672   12.448    17.568    26.016 21687.321    165.000
after  5     9.088   12.640    19.136    26.272 21728.232    164.900
before p50   8.672   12.480    17.984    25.984 21537.336    163.900
before spr   41.4%     3.4%     41.8%      5.2%      3.9%       2.6%
after p50   10.176   12.448    22.130    25.984 21585.253    164.000
after spr    35.4%     4.2%     37.3%      7.0%      1.2%       0.8%
after/before 1.173    0.997     1.231     1.000     1.002      1.001

Columns: wait_p50 and wait_p90 are B's GPU start after the signaller's GPU end; a_gap_p50 and
a_gap_p90 are the harness's wait_a_gap keys (A's GPU idle before each of its command buffers);
a_per_cb is wait_a_per_cb.

At 4ab995b621: lint job m3-max-76840 green (fmt, signatures, api_surface, clippy in all three
configurations, Rustdoc -D warnings); the runtime suite on lavapipe under the validation layer,
jobs m3-max-76841 (394 passed) and m3-max-76842 (444 passed), none failed. This commit
changes the README alone; its check is fmt and Rustdoc -D warnings, run on it once made.
2026-11-27 04:57:51 -08:00
2026-07-22 13:15:24 +03:00

metal2vulkan

License: GPL-2.0-or-later OR LGPL-3.0-or-later

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.x series. Version your cached outputs.

The crates

Crate Directory What it is
metal2vulkan crates/metal2vulkan The translator. A Metal-shaped API (device, library, pipeline descriptors) 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 the interface a consumer binds each draw and dispatch by. 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 from ash::vk, and DeviceDescription::query, which reads a physical device.
  • cli: the metal2vulkan command (enables serde).

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
  • --profile is 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 under the runtime's policy (DevicePolicy::default(), the identity pointer and handle domains), so a profile without bufferDeviceAddress and shaderInt64 is refused. --device FILE takes 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, under that policy.
  • Without --function it compiles the library's only kernel or vertex function. A kernel with --color-format compiles as a tile pipeline. A post-tessellation vertex function adds .tesc.spv and .tese.spv modules; on a device without tessellationShader it answers FALLBACK, 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:VALUE for a function constant, --stage-input FILE or --vertex-descriptor FILE for a stage-input or vertex descriptor (as JSON).
  • A .ll input is assembled with llvm-as (LLVM 21 or newer). Each module written is checked with spirv-val when it is found, under the environments the library states for the device; --no-spirv-val skips it. Both tools come from PATH, or from METAL2VULKAN_LLVM_AS and METAL2VULKAN_SPIRV_VAL.
  • Success prints a line with PASS and exits 0. Failure prints metal2vulkan: FALLBACK (<why>), writes nothing, and exits 2; a failure after the inputs are read also writes a repro bundle under $TMPDIR/metal2vulkan-repros (or METAL2VULKAN_REPRO_DIR), whose repro.sh replays it.
  • metal2vulkan --help lists 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,
// and bind each dispatch by the interface, as metal2vulkan-runtime does.

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):

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.

S
Description
No description provided
Readme
1.7 GiB
0 Stars 1 Watchers 0 Forks
Languages
Rust 61.3%
LLVM 31.7%
Metal 3%
Objective-C 2.2%
Python 1.2%
Other 0.5%