Anees Iqbal 3501e41448 Expect the served blit out of a plane whose GPU rows share bytes
One work packet, landed as 8 commits (8f359821ba..742b94ac06 on archive/development-linear-2026-10-28), in order:

* Expect the served blit out of a plane whose GPU rows share bytes

b31e26710b serves copyFromTexture:toBuffer: out of an IOSurface plane whose
GPU rows share bytes (a read settles no row order; Metal's own copy reads each
row at its GPU pitch, probes/overlapping_plane_row_reads.m), and keeps the
copy into such a plane refused. Its commit and docs/REFUSALS.md dropped the
read's OverlappingSurfaceRows site, but the announcement lane
an_iosurface_plane_whose_gpu_rows_share_bytes_is_announced still expected
the read to be refused, so it failed on every device since.

The lane now holds the served read (each buffer row at its own GPU row, the
bytes a_blit_out_of_a_plane_whose_gpu_rows_share_bytes_reads_each_row_at_its_own_pitch
holds over more shapes), that it announces nothing of its own, and that the
copy into the plane stays refused OverlappingSurfaceRows.

Verified: the test passes on MoltenVK 1.4.2 (Apple M3 Max, --cfg m2v_gpu,
under maclock and memcap); clippy -D warnings clean, plain and --cfg m2v_gpu.

* Count the packed 10-bit pair among the heap footprints answered with no image

8016e80f42 moved R10Unorm_PACKED and RG10Unorm_PACKED from Metal's nil to
this crate's own NotImplemented(Format) gap for a placement heap's
new_texture_at_offset (plain Metal's placement heap makes a texture of either),
and their 0 bytes at 16 joined the "no image" arm of
shared_heap_textures_are_made_or_refused_for_linear_tiling. The arm pushes
every format it takes, but the closing count still left the NoTexture shape
out, so the lane counted 128 answers against 120 on every device: a stale
count, not a product regression.

The count now takes every format whose footprint the product's table decides,
the NoTexture pair included.

Verified: the test passes on MoltenVK 1.4.2 (Apple M3 Max, --cfg m2v_gpu,
under maclock and memcap; 128 answered a footprint with no image); clippy
-D warnings clean, plain and --cfg m2v_gpu.

* Hand a refused self-check's driver errors to the sink as one informational line

The device's self-check of a set-0 buffer binding of several variables as a
dynamic descriptor (20b73503c0, takes_multi_variable_dynamic) creates one
pipeline the driver may refuse: that refusal is the answer the runtime asked
for. MoltenVK 1.4.2 refuses it and reports two errors through the debug
messenger inside the creation (the Metal SPIRV-Cross wrote that does not
compile, and the failed pipeline), and those reached the device's message
sink as errors of the program's work. Every validation lane whose kernel has
such a binding then failed its layer claim on MoltenVK:
kept_variants::the_least_recently_released_variants_go_first failed on them
after spse_write_barrier (a-thread-reads-its-own-write-after-a-texture-
barrier-without-sparseness) made the device ask.

Now the self-check holds what the driver reports inside its creation
(device::compiles::holding, nestable, and keeping what a relay thread held for
a holding asking thread). A creation that succeeds hands those messages on as
before; one that fails hands the sink one Info line,
metal2vulkan-self-check-refused, with the driver's result and each message's
id name and text, in place of them. A creation that reported nothing says
nothing. RUNTIME_VERSION 1668 (what a device's sink hears changed); the
runtime sources re-pinned. docs/API.md names the line.

The lane now also prints why it skipped each selected case (KEPT skipped):
it skipped them silently, so a run without llvm-as or with any other mapping
failure read "0 against 64" with no cause.

Verified on MoltenVK 1.4.2 (Apple M3 Max, --cfg m2v_gpu, under maclock and
memcap): before, the lane failed on the two mvk-error messages; after, it
passes, and the new runtime test
tests::dynamic_multi_variable::a_refused_self_check_reaches_the_sink_as_one_informational_line
passes with its DYNMULTI line showing the device answered no and its sink heard
one metal2vulkan-self-check-refused line carrying 2 messages and no error; the
other four dynamic_multi_variable tests pass. clippy -D warnings clean, plain
and --cfg m2v_gpu; rustdoc -D warnings clean for the runtime; the runtime pin
guard passes.

* Hold the ASTC heap lanes to the size query that answers Metal's model

f7d857ec55 made a heap texture the device holds in an ASTC carrier with a
decoded twin answer heapTextureSizeAndAlignWithDescriptor: with Metal's model
of its blocks while its making stays refused NotImplemented(DecodedHeapTexture)
(the twin would decode what the heap's bytes held). Three lanes still expected
the query refused too, and failed on every device without ASTC (lavapipe)
since:

- astc_textures_the_runtime_does_not_hold_are_refused asserted the query's
  refusal, where its own doc already said the device answers the size; it now
  holds the answer to Metal's model (metal_heap_texture_size_and_align) and the
  making's refusal;
- a_host_heap_s_block_compressed_texture_lies_as_metal_lays_it_out took the
  refusal at the query only; it now takes it from the making, the query having
  answered;
- shared_heap_textures_are_made_or_refused_for_linear_tiling panicked on a
  query that answers and a making refused; it now takes that pair for a
  format the device holds decoded (astc_textures::decodes_astc), holds the
  answer to Metal's model, and prints a HEAPTEX shared decoded line for each.

Verified on lavapipe (Mesa 26.0.8, the gate container, --cfg m2v_cpu_icd): the
three pass, the lines naming each refused ASTC texture; on MoltenVK 1.4.2
(Apple M3 Max, --cfg m2v_gpu, maclock and memcap), where the device holds ASTC,
the three pass. clippy -D warnings clean under --cfg m2v_gpu.

* Say where a directory's mode bits do not bind the cache refusal lane

an_entry_that_cannot_be_written_is_announced_and_ends_nothing makes the
shader cache's build directory unwritable with mode 0o500 and expects the
entries refused. The Linux gate's container runs as root, which the mode bits
do not bind, so every entry was written and the lane failed there on every
run (writes 2, write_failures 0).

The lane now writes a file of its own into the directory first; where that
goes through it prints CACHE-UNWRITABLE and holds nothing, instead of failing
on an environment where nothing can be refused, and elsewhere it runs as
before.

Verified: on lavapipe in the container it prints CACHE-UNWRITABLE and passes;
on MoltenVK 1.4.2 (Apple M3 Max, not root) it runs the whole check and passes.
clippy -D warnings clean under --cfg m2v_gpu.

* Expect a heap texture's tiled shadow where the device makes one

Two resource_ids lanes expected heap-texture-untiled-layout for a Private
heap's texture on any driver without ColorImagesLieAsMetalHeapTextures. On
lavapipe the runtime makes that texture a shadow of its elements in Metal's
tiles in the heap's bytes (AliasRoute::Tiled, texture/heap.rs): it lies as
Metal lays it out, announces shadowed-texture (and unnamed-shadowed-texture
where a command reaches it through its ID alone) and no untiled layout. So
a_texture_made_in_a_used_heap_after_a_dispatch_is_reached and
a_heap_s_token_drops_at_its_release_whatever_keeps_its_textures_images failed
there (not announced: HeapTextureUntiledLayout).

heap_texture_kinds now takes whether the making moved
WorkCounts::heap_textures_tiled; where it did it expects that shadow (and the
larger-than-Metal kind as before), else the route and layout kinds as before.

Verified on lavapipe (the gate container, --cfg m2v_cpu_icd) and on MoltenVK
1.4.2 (Apple M3 Max, --cfg m2v_gpu, maclock and memcap): both pass. clippy
-D warnings clean under --cfg m2v_gpu.

* Bump RUNTIME_VERSION past the mipmap change's 1668

The refused self-check's sink line (3c840cbc3a) changes the runtime, and the mipmap change took
1668 on development first; both branches set 1668, which merged silently.

* 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.
2026-10-28 17:24:21 +02: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, 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.
  • 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; the runtime's speed-for-accuracy choices default to the fast form, each with 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 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.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
  • --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.
  • 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 with tessellationShader; on one without, it is the .vert.spv module 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: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).
  • 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::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):

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%