API.md still listed "an array of samplers" among the forms the identity domains refuse, which the previous commit made a switch over the candidates. The refusal list drops it, and the sampler array paragraph says the identity domains always take the switch, each candidate sampled through the constexpr sampler the consumer pushes (their stages bind no set-0 sampler). Docs only.
235 KiB
The API
metal2vulkan compiles Metal AIR into Vulkan pipelines through an API shaped like Metal's object
lifecycle. You hand it Metal-shaped inputs (a device description, a library, pipeline
descriptors, what a draw or dispatch binds) and get back plain data to create and record Vulkan
objects with: SPIR-V per stage, one pipeline layout, fixed-function state, and per-draw descriptor
writes and push-constant bytes. You never parse AIR, never patch SPIR-V, never derive binding
numbers from Metal indices, and never classify errors by message text.
This guide walks the flow on the repository's own fixtures. Every rust block is quoted from
examples/api_preview.rs, which the test suite
runs (tests/api_preview_example.rs fails when a block here stops matching it). Sections 9 and 10
also cover the runtime crate (metal2vulkan-runtime): the precision notes it carries and its deliberate
differences from Metal. The runtime's own guide is its README.
Stability
- No feature needed. Feature
ashadds conversions toash::vkandDeviceDescription::query;serdeserializes the plain-data values;clibuilds the command. - Frozen names, additive changes. The surface is the items at the roots of
error,device,library,reflection,pipeline,bind,cache,metal(withmetal::{format, sampler, state, vertex}),vkandash_interop, plusBudgetandCancelTokenat the crate root.tests/api_surface.rspins every name. Structs and enums are#[non_exhaustive]or opaque, so build values withnew,Defaultor constants, assign fields, and match with a wildcard arm. The exceptions are exhaustive on purpose: keys and Vulkan structs (SlotRef,ResourceSlot,ApiVersion, ...), and the enums a consumer must interpret completely to bind and draw correctly (StageSource,PushHole,HeapSource,ImageSource,SamplerSource,UseTarget,SlotClass,StorageAttachmentView,VertexStride,TileMapping,CopySource,DrawCommand,PrecisionNote, and Metal'sPrimitiveType,IndexType,CullMode,WindingandTextureType), where a new variant breaks your build on purpose. - Semver covers this surface from 0.2.0 (still
0.x: a breaking change bumps the minor version). - Not API: anything the reference does not show. Hidden items, every submodule of
library,pipeline,bindanddevice(writepipeline::SlotRef, neverpipeline::sym::SlotRef), and the translator core are private. - The AIR front end (container, bitcode reader, typed IR, metadata ABI, intrinsics,
canonicalization) is the
metal2vulkan-aircrate, pinned exactly. The input and budget errors this crate re-exports are that crate's types.
scripts/api-docs renders the reference of exactly this surface (add --open to open it); it
fails when a page links to a hidden or internal item.
Run the tour
PATH=/opt/homebrew/opt/llvm/bin:$PATH cargo run -p metal2vulkan --example api_preview
No GPU is involved. The fixtures are committed as LLVM text, so the example assembles them with
llvm-as first; the API itself reads bitcode only.
1. A device
A DeviceDescription states the Vulkan physical device as you create it: API version, enabled
features and extensions, limits, subgroup and float-controls properties, format support and the
driver's identity. Three ways to get one:
DeviceDescription::from_khronos_json(json, profile_name)reads a Khronos profiles JSON. The tour uses the committed profiles undercrates/metal2vulkan-validation/profiles/, from a bare Vulkan 1.2 device to desktop GPUs and MoltenVK.unsafe DeviceDescription::query(&instance, physical_device, instance_api_version)(featureash) reads a physical device. That is what it supports: enable at leastdescription.recommended_enables()atvkCreateDevice, then passwith_enabled(&enabled)so the description states what is enabled.with_enabledrefuses a set that breaks one of Vulkan's co-enable rules, naming its VUID.VkFeature::exposure()andVkExtension::requires(version)say where each feature lives at the device's version, to chain the create info.- Build one field by field.
let description = DeviceDescription::from_khronos_json(&json, None)?;
let device = Device::from_queries(description, DevicePolicy::default())?;
Device::from_queries needs no Vulkan device: it derives the profile from the description's
queries alone, reading no vendor, device or driver identity. It refuses a device below Vulkan 1.2,
one whose maxPushConstantsSize is below the 256-byte push window every stage is lowered for
(Unsupported{PushWindow}, a Limit of MaxPushConstantsSize), and an inconsistent description
or policy. A
Device is cheap to clone; every compile and plan takes it.
The policy
DevicePolicy holds your product choices; together with the description they decide everything a
compile does. DevicePolicy::default() is DevicePolicy::UNTRUSTED:
- Bounds on a buffer-slot access at a run-time offset. Such an access stays inside the range
the binder supplied: where the device enables
robustBufferAccess, buffer accesses and vertex input are left to it, and elsewhere the shader checks them. (MoltenVK advertises the feature without implementing it; there such accesses are not bounded, as on native Metal.) - The device's arithmetic. The device's own maths library, divisions, fused multiply-adds,
floatdenormals, rounding order ofdot/mix/fast::sqrt, the grouping and fusion of fast-math sums and products (each operation in the AIR's order, its own fast-math flags its decoration), NaN bits, and the operand offmin,fmax,min3,max3,clampandsaturate, on every device and with no exact form. Each records a precision note with its bound, on every device. - The device's native forms. The device's own sampler (its filter, footprint, level,
anisotropy, texel conversion and comparison, a two-plane YCbCr texture's filter among them),
with no switch: the device's answer is the contract, recorded as
PrecisionNote::DeviceSamplingwith its measured bound. The device's ownhalfrounding and its blend of ahalfcolor have no switch either: each records its note. - The resident-table and handle-table domains (
PointerDomain::ResidentTable,HandleDomain::Table, the default). The identity domains (PointerDomain::IdentitywithHandleDomain::Identity, taken together) are the runtime's form: pointers are device addresses used directly and a texture's or sampler's handle is itsgpuResourceID(RESOURCE-ID.md). They needbufferDeviceAddressandshaderInt64. Under them a buffer slot is reached at its own device address (gpuAddressplus the bind offset), pushed less 2^31 asPushField::SlotGuestBase(section 5), with no root table and no descriptor. The constant blob (the program-scope constants whose address merges, escapes or is compared, or that are read through another type than their own) is the module's own there: aPrivatearray of its words, zero-padded to 16 bytes, which every load is checked against, and no stage carries aconstant_blob. A blob past 64 KiB is refused (Unsupported{IdentityDomains}, naming the constant data's size). An access of the slot whose byte offset is not a translation-time constant is checked against the slot's buffer (PushField::SlotBounds), from the buffer's start to its end, as Metal's domain is the buffer: an offset before the bind offset reads and writes the buffer's bytes there. Outside the buffer, a load reads zero and a store or atomic does nothing (section 5). An access at a constant offset is not checked. A pointer loaded from memory or made from an integer, null included, is used as given: no binding bounds its accesses, so the bounds the default domains place on an access do not hold for it. A slot whose argument states an alignment of at least 4 (air.arg_type_align_size) is reached from that address as it is: each access is at the pushed word plus its 32-bit byte offset plus 2^31, modulo 2^32, zero-extended, which is the address plus the offset read as signed, exact as the runtime makes no buffer longer than 2 GiB (MAX_BUFFER_LENGTH); a constant part of the offset joins the 2^31 in one constant. An access of 8 or 16 bytes at an offset proven a multiple of its size is oneuvec2oruvec4. The function statesRuntimeFact::AddressAlignmentwith that alignment (at most 16), and the runtime refuses a dispatch whose bound address is not a multiple of it, as Metal's API validation refuses the bind offset (an accepted difference, section 10). A slot whose argument states an alignment below 4, or none, is reached the same way where each of its accesses is one 1- or 2-byte unit no wider than that alignment (ani8access of aucharbuffer, ani16one of aushortbuffer) on a device with that width's storage access. Any other slot is reached from the word below each access, its offset sign-extended, so an access before the bind offset reaches below the bind address as Metal's does. Fields past a function's push window go to a parameter block in memory, read at the device addressPushField::ArgumentTableAddress, which the window always holds. The function reads the block 16 bytes at a time at multiples of 16 (its size,argument_table_size, is a multiple of 16) and never writes it, so the consumer places it at a multiple of 16 and leaves it unchanged while the command reads it. A kernel's window is 256 bytes, as the runtime's floor requires that muchmaxPushConstantsSize: a dispatch region and 24 buffer addresses below its tail. A render pipeline's two functions share one 256-byte range: the vertex function's window is[0, 248), and the fragment function's runs from the vertex function's end to 256. A post-tessellation vertex function's window is[24, 248), and its fragment function's starts at 24 or past: the pipeline's control stage pushes its fields (8 to 24 bytes) at 0, so the pair's fields, which spill where they pass their windows, never take its bytes. A vertex function is lowered without knowing its fragment function, so it leaves the last 8 bytes, where a fragment function whose fields spill always pushes its block's address; that costs only a vertex function whose own fields pass 248 bytes, which spills where it would have filled them. The fields only a checked access reads (PushField::ZeroAddressand eachPushField::SlotBounds) come last in the order, so they are the first to move to the block. Each function's push ends with its tail, 24 bytes or more above its other pushed fields: its highestPushField::SlotBoundsorPushField::ZeroAddress, moved there, or where it pushes neither, the zero wordPushField::TailWordatPushPlacement::tail_word, with which itspush_rangeends; a function that pushes one field of 8 bytes or fewer has none. A driver that uploads a stage's push bytes up to the highest one the stage reads then holds every load it widens from the other fields. The function returns at its start where its tail holds what the consumer never pushes there (a tail word other than zero, bounds whose two words are both all ones, a zero-range address of all ones), so the consumer pushes the tail word zero with the other fields; the bytes of the hole are not read. A kernel that reads a grid builtin readsPushField::DispatchRegionon every dispatch: a dispatch the host knows states Metal's grid and its piece's first threadgroup there, and an indirect dispatch a zero grid, whose kernel takesNumWorkgroupstimes its workgroup size. It reads its first threadgroup from every region (0 where the dispatch is not split, and for an indirect one) and declaresMultiRegion, default 0: at 0 Metal's threadgroup size is the pipeline's workgroup size; at 1 it is the region's, for a region whose workgroup size is not Metal's (an edge region). A kernel whose workgroup is its threadgroup (one outside the flattened SIMD-group tiers, without compute derivatives) also declaresSpecKey::DeepThreadgroup, default false: at true its workgroup is one row of the threadgroup's threads,(sx·sy·sz, 1, 1), each thread's position itsLocalInvocationIndexunflattened in Metal's order, so a threadgroup deeper than a device'smaxComputeWorkGroupSize[2]runs; the binder sets it for a region deeper thanpipeline::DEEP_THREADGROUP(64) alone, and so does a runtime, so every other pipeline specializes it away.MetalDeviceProperties::max_threads_per_threadgroupis the cappedmaxComputeWorkGroupInvocationson every axis. A texture slot'sgpuResourceIDis pushed as itsPushField::SlotGuestBase, and its texture is the element at the ID's index of set 1's two fixed arrays, the same layout for every pipeline (RESOURCE-ID.md); it binds no descriptor of its own and declares no specialization constant. An argument buffer's texture is the element at the index of thegpuResourceIDits member holds, with no handle table, so a slot and a member of one class index one array. No binder chooses a variant there: a texture reads through the plain form whatever texture its ID names, itsfloatorhalfreads take the device's sRGB decode withPrecisionNote::SrgbTexelDecode, and no texture is sparse (the consumer refuses a sparse texture). A texture slot sampled through a runtime sampler slot samples set 1's element of the sampler arrays at the index of the sampler's pushedgpuResourceID, joined to the texture's element byOpSampledImage, and reads the sampler's word from that ID. One sampled through a constexpr sampler samples the element at the index the consumer pushes for it (PushField::ConstexprSampler), where the consumer places the device samplerCombinedSampler::constexpr_samplerdescribes, normalized: the shader scales a pixel sampler's coordinate. An integer write to a storage slot without a format saturates to the channel widths the consumer pushes (PushField::TextureIntegerChannels). A sample of a 2D texture slot through a bicubic constexpr sampler at normalized coordinates reads how Metal's bicubic filter treats the bound texture's texels (its inner taps, its clamp and its border texels) from the word the consumer pushes for that slot (PushField::BicubicTexels:metal::format::bicubic_texels_wordof the bound texture's format and swizzle,metal::format::BICUBIC_TEXELS_UNBOUNDfor a slot bound to nothing), the bits the default domains specializeSpecKey::BicubicTexelsto.bicubic_texels_wordhas no word for a compressed, YUV, stencil, integer, extended-range or 8-bit sRGB format, so such a texture has no bicubic sample there (the runtime refuses the dispatch,Gap::BicubicTexels). Its arithmetic is notedPrecisionNote::BicubicFilterArithmetic, as on the default domains. A fragment function under the pipeline's private alpha test (PrivateRenderState::alpha_test_enabled, a compare function other thanNeverorAlways) compares its color 0's alpha with the code the consumer pushes (PushField::AlphaTestReference):bind::alpha_test_codeof the encoder'ssetAlphaTestReferenceValue:, 1 until the encoder sets it. It is Metal's 8-bit unorm code of the reference (a NaN taken as 0, clamped to[0, 1], the exact product with 255 rounded to nearest), the form the function converts its alpha to, so a consumer that pushes it compares as Metal does. A fragment function's read of a color attachment (framebuffer fetch, section 4) on a device with neither ordered form takes no input attachment: it reads, at the integer part of its position (its own sample where the pass is multisampled), level 0, the sampled-texture array's element at the index the consumer pushes for that attachment (PushField::FetchedColor { color, texels },texelsthe read's numeric class), and a read-only signed-integer attachment joinssigned_color_attachments. A vertex function that writes[[render_target_array_index]]compiles in the variant that writesLayer, which stores 0 for an index at or past the render pass's length the consumer pushes (PushField::RenderTargetArrayLength,renderTargetArrayLengthat least 1). Every precision note is static there: no constant or binder decides one. So far they lower a kernel that reaches memory through its buffer slots and the device addresses it loads (an argument buffer's pointer member, a storedgpuAddress) or makes from integers, and reads, writes, sizes or tests for nil its texture slots and its argument buffers' textures, those of an argument buffer a pointer member reaches included, updates its texture slots atomically (a slot declaredR32uiorR32i, the storage-image array's element at its ID's index), and samples its texture slots through its runtime sampler slots and its constexpr samplers and reads them through those (MSL 4.1'sread(sampler, coord), its border texel from bits 0-11 of the ID's word). Any other function is refused asUnsupported{IdentityDomains}, whose symbol names the first such form the function holds: one that samples through an argument buffer's sampler or samples an argument buffer's texture, emulates a sampler's anisotropy, samples a 1D texture or at pixel coordinates through a bicubic filter, uses a texture buffer, a slot's levels or swizzle, a two-plane, extended-range or sRGB-twin form, reads an argument buffer's texture through another numeric type or as raw texels, or uses any other state of a texture or sampler beyond its ID. An argument buffer's texture reads the element at its ID's index masked to its low 16 bits, so a bad ID reads an element of the arrays (RESOURCE-ID.md); the change that first lowers an argument buffer's sampler masks its index the same way.
Loops run as written: no execution bound is translated in.
What the device answers
let device = committed_device("moltenvk-m3")?;
let enables = device.required_enables();
// ...
hex(&device.profile().fingerprint()),
// ...
println!(" Metal properties: {:?}", device.metal_properties());
required_enables(): everything an artifact compiled for this device can need enabled.metal_properties(): the answers to the guest's device queries (thread execution width, threadgroup limits, argument-buffer and read-write texture tiers, ...).profile().fingerprint(): a hash of every profile field, the policy included. Every cache key includes it, so an artifact never serves another device. Facts that follow the machine's memory (DeviceDescription::allocation:maxMemoryAllocationSize,maxBufferSize) are not profile fields, so two machines that differ only there share artifacts.profile().spirv_validation(): thespirv-valenvironments and relaxations every module for the device is valid under. The command line runs exactly these.- The profile's facts:
enabled(),limits(),images(),fragment(),descriptors(), the measured deviations it takes (driver_deviations()), itssubgroups()model andsimd_tier(...), the buffer robustness that bounds a buffer-slot access (robustness(),checks_buffers_in_shader()), and the Function storage a thread holds (function_storage():FunctionStorage::Measuredbytes for a measured device, orFunctionStorage::Assumedwith the 16 KiB floor, past which a vertex or fragment function runs withFunctionStorageAssumedup to 192 KiB and any other stage is refused).
Driver behavior
Where Vulkan leaves an answer to the driver, the profile takes the device's own answer, recorded
as a precision note, or, where the answer decides a capability, its emulation or a refusal.
Device::from_queries reads no driver identity, so no answer is taken as Metal's because a driver
was measured to give it.
Metal semantics the translation keeps on every device, beyond Vulkan's: Metal's 32-lane
simdgroups (and, under the resident-table domains alone, the order Apple's lockstep gives a
simdgroup's threadgroup and device accesses within a barrier interval). fneg and
fabs are the device's OpFNegate and FAbs, so a NaN's payload and a denormal are the
device's (native-nan-encoding, device-denormals). A NaN's bits, the
operand fmin, fmax, min3, max3, clamp and saturate pick beside a NaN or between two
zeros, a half read from its bits, which is the device's widening on every device (a NaN's
bits, and a denormal on a device that may flush 16-bit ones), and a half rounded from a value
below the smallest normal half on a device without shaderFloat16 (its OpQuantizeToF16's
zero) are the device's, each recorded as a precision note.
2. A library
Library::parse takes a metallib, a bitcode wrapper or a raw AIR module; Library::from_air
takes the last two. LLVM text is not an input: assemble .ll with llvm-as first. Listing
functions decodes nothing.
let sampling = Library::from_air(&fixture_bitcode("sampling")?)?;
for info in sampling.functions() {
println!("library: {} ({:?})", info.name, info.stage);
}
-
library.function(name)finds a function likenewFunctionWithName:; a missing name isError::InvalidDescriptor(EntryNotFound). -
A metallib function's
info.air_hashis the SHA-256 of its bitcode, its content key. In every library but a Core Image kernel library it is the function'sHASHtag, checked against the bitcode: a mismatch isInvalidInput(Container(HashMismatch)), though Metal checks noHASHand loads such a library. A Core Image kernel library (file type 1,metallib -cikernel) lists its kernels as extern functions (FunctionStage::Extern, no stage) over one module, and Apple's toolchain writes them aHASHthat, for some modules, is not that module's SHA-256 (what it digests is not known); Core Image's own libraries are such. ItsHASHis read as 32 bytes and kept as read, andair_hashis the module's SHA-256, computed. The conformance crate'sprobes/metallib_function_hashes.mmeasures what Metal answers for both kinds of library. -
function.reflection(&budget)answers asreflectionForFunctionWithName:does: the function's arguments in declaration order with their types, access, indices and use, in Metal's shape (modulereflection). It isNonefor a metallib function whose library carries no reflection, where Metal answers nil. An argument whose Metal answer was not measured isUnsupported(Feature::Reflection). -
A pipeline descriptor's
reflection(&budget)answers what thereflection:out-parameter of Metal's creation call does. -
A pipeline descriptor's
slot_writes(&budget)answers, per stage, what the function may store through the object bound at each slot its arguments bind (SlotWrites, oneSlotWriteper binding).SlotWrite::may_write(slots, binding_type, index)answers for one slot:SlotWritability::Neverwhere the declaration is read-only (aconstantorconst devicebuffer, a texture declaredaccess::readoraccess::sample, a sampler, a function table, an acceleration structure, an imageblock, a mesh function's payload) and for a slot no argument binds,Maybewhere it is write-only or read-write, andUnknown(SlotWriteGap)for a slot that one argument alone leaves undetermined.The values are the ones
reflectiongives asBinding::access, worked out without the type description a reflection must also give. That is why a state that compiles always answers here, while itsreflectionis refused where Metal's answer for one argument's type was not measured, and why uncertainty stays on the slot it belongs to instead of refusing the state: a caller asking whether a read-only buffer may sit at a slot gets an answer per slot, and an undetermined slot reads as neither writable nor read-only. -
function.argument_buffer_layout(index, &constants, &budget)gives the layout of the argument buffer the function takes at a buffer index, asnewArgumentEncoderWithBufferIndex:encodes it: its length, alignment, and each argument's offset and type by[[id(n)]].ArgumentBufferLayout::from_descriptorsgives the layoutnewArgumentEncoderWithArguments:makes of a list ofArgumentDescriptors. Each argument is 8 bytes: a buffer's address plus offset, or a resource ID. -
function.properties(&budget)answers whatMTLFunctionstates about the function.
One entry of a bare module
A tool that holds bitcode and an entry name, not a library, compiles through the profile:
let bitcode = fixture_bitcode("sampling")?;
let entry = EntryDescriptor::new(&bitcode, EntryRef::Name("sample_level"));
let profile = device.profile();
let (compiled, report) = profile.compile_entry(&entry, &LoweringInputs::new(), &budget);
let alone = profile.link_standalone(&compiled?)?;
link_standalone links the function with no partner stage. The report says what the compile cost
against its budget, whether it succeeded or not.
3. A compute pipeline
Descriptors mirror Metal's. Each stage is a StageSource: a FunctionDescriptor to compile (a
function, its constant values, the functions it links) or a CompiledFunction to link as it is.
Every compile takes a Budget:
let cancel = CancelToken::new();
let mut budget = Budget::standard();
budget.cancel = Some(cancel.clone());
let kernel = FunctionDescriptor::new(sampling.function("sample_level")?);
let descriptor = ComputePipelineDescriptor::new(StageSource::Function(kernel));
let pipeline = device.compile_compute_pipeline(&descriptor, &budget)?;
Budget::standard() is a 20-second deadline. cancel.cancel() from any thread ends the attempt
at its next poll point with Error::Cancelled; a passed deadline is Error::Budget. Both are
transient. Deterministic caps (work units, a memory ledger, structural limits) apply whatever the
budget, and exceeding one is Error::LimitExceeded, permanent for that input.
A ComputePipeline is immutable plain data:
stage: aStageModule(SPIR-V 1.5 words valid for the device, the entry point, specialization constants, a required subgroup size and stage flags, precision notes,private_bytes, the private memory a thread keeps, asStageInterface::private_bytesstates it too, andstats, what the module contains);layout: the pipeline layout, dense and complete; create it as it is;interface,dependencies: what it binds and what bind-time state it depends on (section 5);metal_info: answers to Metal's per-pipeline queries (maxTotalThreadsPerThreadgroup, ...);requirements: what the device must have enabled.
Do not create the compute VkPipeline from stage alone: its specialization defaults are
placeholders (a kernel's local size is 1). Create each pipeline from a planned dispatch's
DispatchRegion (section 6), with the region's specialization, stage_flags and
required_subgroup_size. A required subgroup size needs subgroupSizeControl and the stage in
requiredSubgroupSizeStages; full subgroups need computeFullSubgroups. A pipeline compiled for
one device pins only what that device can take; DeviceProfile::check tells whether another
device can.
A kernel whose simdgroups run on 32-lane subgroups pins a required size of 32 with full
subgroups. On a device whose compiler chooses a kernel's SIMD width between a minSubgroupSize
below 32 and a maxSubgroupSize of 32 (ANV), that pin compiles the kernel in the device's widest
mode, where each lane's value takes four times the registers of the narrowest one. A kernel whose
entry, inlined, holds more than 256 AIR instructions and whose values are estimated to hold more
than 36 32-bit words at once (live intervals over the body in layout order, a value read in a loop
held to the loop's end) takes the emulated simdgroup tier there instead: each simdgroup is 32
consecutive threads, its operations and lockstep barriers go through workgroup memory and
workgroup barriers, and its module pins no subgroup size, so the driver chooses the width. Both
forms are exact. The runtime counts such kernels (WorkCounts::widest_pin_kernels_emulated). A
kernel the emulated tier refuses (a 64-bit exchange, or a scratch that does not fit beside its
threadgroup memory) keeps the pin.
The bounds come from an authored kernel measured on an Iris Xe (RPL-P, ANV): S steps, each a
branch on one of K live float accumulators whose arm stores a device word and loads the next
(a lockstep pair in divergent flow, so a subgroup barrier there), with P 1 the arm's accesses
going through a pointer it loads from memory (a resident-set search a step), then every
accumulator updated. Pressure, not size, separates the cases. The driver's compile time
(vkCreateComputePipelines) and the GPU time of a dispatch of 12,288 threads, pinned and
emulated, one run each (compile times varied up to twice between runs):
P K S |
AIR instructions | estimated words | compile ms, pinned | emulated | GPU ms, pinned | emulated |
|---|---|---|---|---|---|---|
0 16 128 |
7,850 | 24 | 589 | 559 | 0.129 | 0.159 |
1 4 32 |
874 | 34 | 783 | 766 | 0.010 | 0.018 |
0 32 64 |
7,050 | 40 | 6,652 | 282 | 1.061 | 0.107 |
1 16 16 |
1,042 | 46 | 971 | 300 | 0.070 | 0.015 |
1 16 64 |
4,066 | 46 | 11,987 | 2,585 | 0.319 | 0.074 |
0 48 8 |
1,362 | 56 | 458 | 38 | 0.168 | 0.021 |
1 48 32 |
5,186 | 78 | 25,799 | 1,277 | 1.985 | 0.081 |
At 34 estimated words or fewer the two compile alike and the pinned kernel runs as fast or faster; from 40 the pinned compile took 1.6 to 24 times the emulated one and its GPU time 1.5 to 25 times. At or below 256 instructions every pinned compile measured took at most 102 ms. Answers were the same bits on both tiers. The estimate costs time linear in the body: 5 ms of a 3.4 s release translation of a 162,914-instruction kernel.
On the emulated tier, a simdgroup operation or barrier in a block whose control flow differs
between threads is walked predicated: each thread carries a live flag, the threads that do not run
the block take part in its exchanges as inactive lanes, and a loop that holds one votes on its
exit. A kernel whose threads' positions alone make such a block differ, along some axes
(thread_position_in_threadgroup or thread_position_in_grid, read by lane), states
RuntimeFact::UnitAxes { axes: 0, relief }: relief holds, at bit m - 1, each mask m of axes
(bit 0 x, bit 1 y, bit 2 z) under which fewer of those blocks differ once the positions along
them are taken as uniform. In a threadgroup of one thread along an axis, Metal's
threads_per_threadgroup is 1 there, so every thread's thread_position_in_threadgroup on that
axis is 0 and its thread_position_in_grid is its threadgroup's position, partial threadgroups
included. BindingPlan::unit_axes_variant(&dispatch) offers a dispatch of such threadgroups,
where its axes are among the masks of relief, the kernel's unit-axes variant
(VariantKey::unit_axes, which LoweringInputs::unit_axes compiles): the same kernel with those
positions uniform, walked without the predication they caused, giving the same answers. Its plan
states UnitAxes { axes, relief: 0 } and sends a dispatch with more than one thread along one of
its axes back to the variant without them (BindError::NeedsVariant). A kernel has at most seven
such variants per variant it runs on, one per mask. On the Iris Xe, an authored kernel of four shuffles each way and a
simdgroup sum in a loop of 8 to 11 trips, in threadgroups of 8 x 1 x 16, ran 1.14 to 2.16 times
the GPU time predicated (its trip count read from thread_position_in_grid.y) as with the same
trip counts read from threadgroup_position_in_grid.y, over four sizes from 46 to 126 estimated
words (one run each), with the same bits.
What the module contains
Every stage states the size and shape of its module, counted by the verifier that runs on every
translation, in every build: stage.stats, a ModuleStats. A function compiled on its own states
the same counts as module_stats(), before it is linked. Reading them is how a caller watches the
size of what it hands a driver, and what in it grew.
let stats = pipeline.stage.stats;
println!(
"{} blocks, {} instructions",
stats.blocks, stats.instructions
);
assert!(stats.reachable_blocks <= stats.blocks);
blocksandinstructionsare the module's size: a larger module costs more to compile on the drivers measured. Canonicalization inlines every direct call before the module is emitted, so they count the whole program, not one function.functions-- the entry point and the functions left beside it -- says how farblocksstands for that program. A driver inlines before it charges, so a module of few functions is one whose blocks are the program's, while a module that calls a many-block function from many sites holds a program far larger than its own blocks; the two read alike inblocksalone. Lowering emits such functions itself: the handle-table search (unrolled branch-free steps) and the root-table search (a loop), each emitted once and called at every access.- Compare one module against the next of the same shader, not one shader against another. Measured
cost per block differed several-fold between a synthetic module and a real workload, so a
per-block figure taken from one shader predicts nothing for the next;
instructionsis the second number for that reason. constructs(selection, switch and loop headers) andloopssay whose blocks those are. Translation adds blocks of its own -- inlining, and the structurizer's layout of control flow as SPIR-V requires -- and the input has blocks of its own. The structurizer makes no loop the input does not have, so ablocksthat has risen whileloopsholds still is translation's work or a changed shape of the same control flow, not new control flow in the shader.reachable_blocksis a bound, not a lever. It is never aboveblocks, and below it by the merge blocks SPIR-V requires a construct to declare that no path reaches -- both arms of a conditional inside a loop leaving the construct, say -- which the module terminates withOpUnreachable. The difference is blocks the driver still reads and no invocation runs.- The AIR side of the comparison is yours, through
metal2vulkan-air. For the counts the input itself holds, before inlining, decode it and count the blocks of each function's body (metal2vulkan_air::decode, then eachir::Function'sbody); for the ones canonicalization produced, walk the entryDeviceProfile::specialized_entrygives, which is that AIR specialized and canonicalized. A decoded function'sir::InstKind::Callsites give each callee's call count, which is what turns its own blocks into the program inlining will make of it. inertsays the module holds no loop and that no instruction of it writes memory other than an invocation's own and its workgroup's (Function,PrivateandWorkgroupstorage), writes an image, or emits or drops an output of its stage. Every invocation of such a module ends and leaves nothing behind, so a dispatch of an inert kernel computes nothing anyone can read. An instruction the check does not classify as reading or computing alone (an interlock, a ray query) makes a module not inert.
The counts are of the module spirv holds: the verifier counts the module it checked, and
serialization and relocation assign link numbers without adding or removing an instruction. They
are part of the encoded artifact, so a cache hit states them too, and they are left out of
content_digest, which already covers the words they describe.
A kernel with [[stage_in]]
A kernel's [[stage_in]] attributes are fetched in the shader, as Metal does. The compile asks for
the stage-input descriptor it needs, and you supply it:
match device.compile_compute_pipeline(&descriptor, budget) {
Err(Error::NeedsInput(RuntimeInput::StageInputDescriptor { attribute })) => {
let mut stage_input = StageInputDescriptor::new();
let fetch = StageInputAttributeDescriptor::new(AttributeFormat::Float, 0, 1);
stage_input.attributes.insert(attribute, fetch);
let mut layout = StageInputLayoutDescriptor::new(Some(4));
layout.step_function = StepFunction::ThreadPositionInGridX;
stage_input.layouts.insert(1, layout);
descriptor.stage_input = Some(stage_input);
}
// ...
let mut inputs = LoweringInputs::new();
inputs.stage_input = descriptor.stage_input.clone();
let compiled = device.compile_function(&kernel, &inputs, budget)?;
A fresh StageInputLayoutDescriptor steps per vertex at rate 1, as a fresh Metal layout does. A
layout stride of None is MTLBufferLayoutStrideDynamic: the stride comes from the encoder.
A kernel that takes a patch control-point input (air.patch_control_point_input, the input of a
post-tessellation vertex function) is refused, InvalidInput(Abi(UnknownKey)) at that argument and
key. Metal's compiler writes that input for no kernel, and Metal makes no compute pipeline of a
kernel that takes one: on an M3 Max under macOS 27.0.1 it makes the library and the function, then
fails the pipeline with "Internal compiler error." under every compute step function. A kernel reads
vertices by index through [[stage_in]] under a stage-input descriptor (one element per thread), or
through buffer arguments it reads at any index.
Other compute features
- Visible functions and recursion. Linked visible functions, function tables and
intersection function tables compile; recursion through visible functions runs on a stack of
frames sized by
max_call_stack_depth. A call that finds the stack full returns zero. - Linked functions: names and constants. A visible-function reference resolves to the linked
function whose
LinkedFunction::nameit names: its specialized name where it was made with one (with_specialized_name, Metal'sMTLFunctionDescriptor.specializedName), else its library function's own; its body is still that library function's. A linked function whose module declares function constants is specialized with its own values before it is linked, its module's static initializer run over them. A function made specialized (LinkedFunction::specialized: with constant values, or bynewFunctionWithDescriptor:with or without them) reads a constant it was given no value for as an entry's undefined constants read (section 10, "Function constants"). One made unspecialized (newFunctionWithName:) that reaches one of its module's constants refuses the pipeline at a call that survives specialization,DescriptorError::LinkedFunctionwithLinkProblem::UnresolvedConstant { index }, guarded byis_function_constant_definedor not, as Metal fails the creation ("cannot lower module with unresolved function constants"); one that reaches none links. The specialized name and the specialization are part of the compile key. A reference resolves againstfunctionsandprivate_functions(LinkedList::resolves_references), never againstbinary_functions, whose functions only a visible-function table calls: a reference only a binary function names isNeedsInput(LinkedFunction), as Metal fails the creation ("unresolved visible function reference"). Two different functions of one name, one infunctionsand one inbinary_functions, are two functions a table holds, each with its handle, and the reference calls the one offunctions, as Metal links them. - Linked functions: types. A reference resolves to the linked function of its name whatever
the definition's type is, and Metal makes every such pipeline (the probe
linked_function_signatures.m, an M3 Max under macOS 27.0.1). The call passes its arguments by position: one past the definition's last parameter is dropped, and a parameter past the reference's last argument reads zero. An argument of another plain-value type (an integer or floating-point scalar or vector, aboolas one bit) passes its bits: all of them at the same width, its low bits to a narrower parameter, its bits with zeros above to a wider one. The result passes back the same way; a definition returning nothing returns zero, and a reference returning nothing drops the result. A struct a[[visible]]function takes by value reaches it as its fields, so a reference passing the fields one by one is passing it. A pointer for a value or a value for a pointer, a pointer of another address space, and an aggregate of another type refuse the pipeline at a call that survives specialization,UnsupportedwithFeature::Linking(section 10, "Linked functions"). - Stitched functions. A function Metal's stitcher made (
newLibraryWithStitchedDescriptor:) links like any other visible function, infunctionsor inprivateFunctions: hand the stitched library's bytes toLibrary::from_metallib, and link its function. Each stitched function is a module of its own whose!air.signaturedescribes the graph it was made from; the module's own code, the graph's nodes inlined, is what is linked. The translator makes no stitched library itself. A module whose linkage signature has no reading (a linked-constants signature on a module that still declares function constants) refuses the pipeline at a call that survives specialization,UnsupportedwithFeature::Linking. - Threadgroup memory. No threadgroup memory access is
bounded: a load or store, atomic, memory intrinsic, pointer cell or imageblock access of a
threadgroup arena, and a typed threadgroup object's index, run as the program states them, and
one past the memory is undefined, as in Metal. A kernel whose every threadgroup access is a
whole, aligned
float(a scalar or a vector of two to four), with no atomic, memory intrinsic, imageblock or pointer kept in it, and whose SIMD groups are not emulated, holds its threadgroup memory as aWorkgrouparray offloat: each access is one typed load or store a lane, with no branch and no bitcast, at the wordoffset / 4and the words after it. The array is the memory's own words (the static part and the specialized[[threadgroup(n)]]lengths), at least four: the memory Metal allocates, so its threadgroup memory is Metal's static length and lengths, and a length filling the limit runs. The strategy census names its accessesaccess.threadgroup.load.floatsandaccess.threadgroup.store.floats. Every other kernel holdsu32words. - Threadgroup memory before the program writes it. A function's threadgroup memory reads zero until the program writes it: the
Workgroupvariables that hold it, its threadgroup arena (declared threadgroup variables,[[threadgroup(n)]]arguments and an explicit imageblock) and its typed threadgroup objects, have a null initializer, in every threadgroup of every dispatch. That needsshaderZeroInitializeWorkgroupMemory, which Vulkan 1.3 requires; a function that uses threadgroup memory on a profile without it isUnsupportedwithFeature::ZeroedThreadgroupMemory. The translator's ownWorkgroupwords have none: an emulated SIMD group's exchange scratch and vote word, an object function's mesh grid, a mesh function's primitive count and staged indices, and those of the binder's own shadow-merge and index-rewrite kernels. Each is written before any read of it, and an object function's payload "is assumed uninitialized at the entry of the object function" (the Metal Shading Language Specification, thepayloadattribute). Metal's documents give threadgroup memory no first contents:MTLComputeCommandEncoder.h'ssetThreadgroupMemoryLength:atIndex:reads "Set the threadgroup memory byte length at the binding point specified by the index. This applies to all compute kernels.", Apple's page for it "Configures the size of a block of threadgroup memory." and points to the specification's section 4.4, which says "Threadgroup variables in a kernel, mesh, or object function only exist for the lifetime of the threadgroup that executes the kernel." and nothing of what they hold first. An Apple M3 Max under macOS 27.0.1 reads zero there, a declared array and a[[threadgroup(n)]]argument alike, in the later threadgroups of a dispatch of 2048 threadgroups of 16 KiB each, many more than its cores hold at once, and in a second dispatch (the conformance casecompute-threadgroup-memory-reads-zero); recorded programs read entries of it they have not written. - Binary functions, required threadgroup sizes, buffer mutability. Whether a binary function
was compiled to a binary (
LinkedFunction::precompiled), required threadgroup sizes and buffer mutability change no translation and are in no compile key; the runtime checks them as Metal does. - Dynamic libraries.
DynamicLibrary::new(library, &budget)checks a dynamic metallib as Metal'snewDynamicLibrary:does; pipelines link its exported functions. - OpenCL C kernels. Metal compiles OpenCL C (
newLibraryWithSourcewith the compile options'sourceLanguage1, which the GL renderer's compute path uses), naming each kernel__entry_<name>, and its AIR has shapes MSL's does not:- A helper left out of line that passes its parameter on as an intrinsic's immediate operand:
OpenCL C's
barrier(flags)passes its flags toair.wg.barrier, andmem_fence(flags)computesair.atomic.fence's flags from them withllvm.bitreverse.i2. Each inlined copy reads its own call site's constants, folded through the integer arithmetic between them. An immediate that is still not a constant after that isInvalidInput(Intrinsic(ImmediateNotConstant))at the call.llvm.ctpop,llvm.bitreverse,llvm.bswapand the scalarllvm.umin,llvm.umax,llvm.sminandllvm.smaxare folded over constants, on a width no SPIR-V type has (i2) too; an integerllvm.*operation on such a width that is not folded is refused (Lowering(Arith)). - An argument passed by value (a kernel's scalar, vector or struct parameter,
air.constant): the entry reads it from a constant-space pointer at its location, so it is a read-only constant buffer holding its own bytes, bound withset_bytesor a buffer at an offset. The reflection lists it as such a buffer of its own data type, size and alignment, a struct asStructwith its members, as the M3 Max answers:float kisFloat, 4 bytes aligned to 4, andstruct { float a; int b; }isStruct, 8 bytes aligned to 4. - A required work-group size (
reqd_work_group_size(x, y, z),air.work_group_size) caps the pipeline'smax_total_threads_per_threadgroupatx * y * zthreads, as the M3 Max answers (64 for(64, 1, 1)). A dispatch in smaller threadgroups runs, as it does there. - OpenCL mode. Metal makes a pipeline of such a kernel only with
ComputePipelineDescriptor::open_cl_mode_enabled(openCLModeEnabled, Apple SPI), and the crate compiles the kernel as Metal links it then (LoweringInputs::open_cl_mode, part of the key). Three hidden buffers come before the kernel's own:__global_offset_and_num_dimsat index 0, fouruints the dispatcher fills with the dispatch's global offset in each of its dimensions and its dimension count,__printf_bufferat 1 and__image_order_data_type_tableat 2. Each argument the kernel binds at a buffer index sits 3 past its own; threadgroup memory (__local), textures and samplers keep theirs. The reflection lists the kernel's arguments at those indices, then the three buffers (read-onlyuint4 bytes, read-writechar1 byte, read-onlyuint4 bytes), each used, as the M3 Max answers. OpenCL C's work-item functions read the dispatch:get_global_id(d)is the thread's position in the grid plus the offset ind,get_global_offset(d)andget_work_dim()read buffer 0,get_local_id,get_group_id,get_local_size,get_global_sizeandget_num_groupsare the built-ins of those names, and a dimension the kernel reads from its data selects among the three. A dimension past 2 answers OpenCL's 0 for an id or an offset and 1 for a size or a count. A compiled kernel serves only a pipeline of the mode it was compiled in (RuntimeFact::OpenClMode,InvalidDescriptor(OpenClMode)otherwise). Without the mode Metal refuses the pipeline ("Internal compiler error"); the crate compiles the AIR as Metal AIR, its buffers at their own indices, and refuses a read ofget_global_offsetorget_work_dim(UnsupportedwithLowering(Dispatch)). - Images in OpenCL mode.
get_image_channel_order(image)andget_image_channel_data_type(image)(air.get_channel_order_texture_<kind>andair.get_channel_data_type_texture_<kind>,Query::ChannelOrderandQuery::ChannelDataType) read the third hidden buffer as it holds them: word2t + 1for the order and word2tfor the data type of the image at texture indext, as an M3 Max (macOS 27.0.1) and a Radeon Pro 5300M (macOS 26.7.1) answer. Metal refuses the queries of a buffer or a depth image, and the crate decodes none (UnknownIntrinsic); without the mode it refuses each query (UnsupportedwithLowering(Texture)). Apple's OpenCL binds a 2D texture of height 1 for animage1d_t, which the AIR declarestexture1d, and a 2D array texture of height 1 for animage1d_array_t(texture1d_array). In the mode the kernel's slot is that texture's type (TextureType::Type2D,Type2DArray), and each read, sample and write of the image,get_image_widthandget_image_array_sizeis the 2D texture's at row 0 (a sampled coordinate at the row's centre), as both Macs answer. A real 1D texture bound for animage1d_t, or a 1D array texture for animage1d_array_t, which Apple's OpenCL never binds, takes the kernel's variant that declares that slot as the 1D texture (RuntimeFact::OpenClLineTexture,VariantKey::open_cl_lines): each read, sample and size query answers the 1D texture's values, of the layer an array access names, as a Radeon Pro 5300M (macOS 26.7.1) answers (an Intel UHD Graphics 630 reads layer 0 of the array, an M3 Max texel 0 at every coordinate). Apple's OpenCL binds an image of most channel orders as a swizzled view (on an M3 Max, macOS 27.0.1, withCL_UNORM_INT8:CL_R,CL_RG,CL_A,CL_RAandCL_INTENSITYasR8UnormorRG8Unormviews,CL_BGRA,CL_ARGBandCL_RGBasRGBA8Unormviews). A read (with a sampler or without) answers the swizzled texel, a write stores it with the swizzle undone (each channel from the first lane whose source it is), and a query answers the view's size and the hidden buffer's words, which no swizzle reaches, as plain Metal answers for the same view; the order is never applied twice. A storage slot the kernel only queries binds the texture's view with no swizzle. The reflection states each image argument as the texture bound for it, animage1d_tTextureType::Type2Dand animage1d_array_tType2DArray, of data typeDataType::None(the AIR names its componentunknown) whatever the kernel reads it as, as an M3 Max (macOS 27.0.1) answers for 1D, 1D array, 2D and 3D images read as float, int, uint and half, written, only queried and unused. - OpenCL C's
native_<function>andhalf_<function>offloattypes (air.native_<stem>.<type>andair.half_<stem>.<type>, forcos,exp,exp10,exp2,log,log10,log2,powr,rsqrt,sin,sqrtandtan, scalar and of every vector width) are the function's fast form, asfast::<function>is (Precision::Fast). OpenCL C leaves their precision to the implementation, and Metal's devices differ:native_powr(100, 0.5)is0x1.400002p+3on the M3 Max and0x1.4p+3on the Radeon Pro 5300M. - OpenCL C's vector data functions (
vload<n>,vstore<n>,vload_half[<n>],vloada_half<n>,vstore_half[<n>][_<rounding>]andvstorea_half<n>[_<rounding>], which the compiler spellsair.vload[a][_half].<space>.<type>andair.vstore[a][_half].<space>[.<rounding>].<type>,VectorData) read and writenelements atp + offset * n(offset * 4forvloada_half3andvstorea_half3), each at its own element's alignment, in every address space and of every element type the compiler spells.vload3of auintpointer one element past a buffer's start reads the three words that follow, as the M3 Max, a Radeon Pro 5300M and a UHD Graphics 630 (macOS 26.7.1) do.vstorea_half3writes three halves of each four, as the M3 Max and the UHD Graphics 630 do (the Radeon Pro 5300M's writes the fourth too). Thehalfforms widen eachhalfread tofloatand narrow each lane stored tohalf; a store's rounding is an accepted difference (section 10, Conversions).
- A helper left out of line that passes its parameter on as an intrinsic's immediate operand:
OpenCL C's
4. A render pipeline
let mut vertex_descriptor = VertexDescriptor::new();
let layout = VertexBufferLayoutDescriptor::new(Some(24));
vertex_descriptor.layouts.insert(0, layout);
// ...
let mut descriptor = RenderPipelineDescriptor::new(StageSource::Function(vertex));
descriptor.fragment = Some(StageSource::Function(fragment));
descriptor.vertex_descriptor = Some(vertex_descriptor);
let color = ColorAttachmentDescriptor::new(PixelFormat::RGBA8Unorm);
descriptor.color_attachments[0] = Some(color);
// ...
let pipeline = device.compile_render_pipeline(&descriptor, &Budget::standard())?;
A RenderPipeline holds:
stages: vertex, then fragment when rasterization is enabled, with three geometry stages before the fragment stage when the fragment function reads[[barycentric_coord]]on a device withoutfragmentShaderBarycentric, or the vertex function selects its slice or viewport on a device without the output (below). AVkPipelinetakes the stagesRenderPipeline::runs_stage(at, topology)says its topology runs;layout: one pipeline layout for every stage;vertex_input: Vulkan bindings and attributes. An attribute Vulkan cannot fetch as described is pulled in the shader instead, and so is every attribute on a device withoutrobustBufferAccess. AFloatRGB9E5attribute is pulled on every device: no device must fetch the shared-exponent format as vertex input, and its decode is exact, so the shader's is the answer a conformant fetch gives. Under the identity domains nothing is pulled, as the pulled fetch reads through a descriptor: every attribute is fetched in fixed function, with or without buffer robustness (a fetch outside its buffer reads what the device gives), an unnormalized signed-integer format into a variable declaredint, the constant step at vertex rate on a binding of stride 0 (no divisor); an attribute fixed-function input cannot take is refused,Unsupported{VertexStepRate}(a per-instance rate above 1, naming the missingvertexAttributeInstanceRateDivisoror themaxVertexAttribDivisorit passes; a device that lacks onlysupportsNonZeroFirstInstancetakes the divisor, and the consumer refuses each draw through it at a base instance other than 0),Unsupported{Format}(a format the device cannot fetch asVERTEX_BUFFER, andFloatRGB9E5) orUnsupported{VertexInputLayout}(an offset or stride off the format's alignment or past the device's limits, more attributes or layouts than its limits, or the constant step's stride of 0 under the portability subset);graphics: the fixed-function state (topology, attachment formats and blend states, sample count, dynamic states, input attachments, ...). BuildVkPipelineColorBlendStateCreateInfo::pAttachmentsfromgraphics.color_blend_attachments().
Where Metal's rules differ from Vulkan's, the pipeline gives Metal's answer:
- A color attachment no fragment output names keeps its texels (an empty write mask).
- What Metal refuses, the link refuses as
InvalidDescriptor(ColorAttachment): an output with fewer components than its attachment's channels, a blend that reads the second output without the first, alpha to coverage over an integer attachment 0. Function-constant values that put two outputs at one attachment areInvalidDescriptor(DuplicateColorOutput), and values that put two arguments of one argument table (buffer, threadgroup memory, texture or sampler) on overlapping slots areInvalidDescriptor(OverlappingArgument), naming the later argument, of any stage: Metal refuses both when it makes the function. ColorAttachment'smetalis how plain Metal answers the pipeline (measured on an Apple M3 Max under macOS 27.0.1):MetalAnswer::NilWithError, nil and anNSError(code 3), for an output or color input of another numeric class than its attachment, an output with fewer components, a blend of the second source without both outputs, and a color input or tile imageblock member of an attachment without a format;MetalAnswer::EndsProcess, Metal's descriptor validation asserting, for a blend into a bfloat attachment and for alpha to coverage over an integer attachment 0. A layer that answers as Metal does ends the process only for the second.- On a device without
independentBlend, attachments the function does not write copy the blend state of those it does; where those differ the pipeline is refused, naming the feature. - A packed 16-bit attachment (
A1BGR5Unorm,ABGR4Unorm,BGRA4Unorm) of a format the device samples but does not render (the RTX 5080) renders through anR16_UINTview of its texture (metal::format::WordAttachment,LoweringInputs::word_colors): the fragment function writes the word Metal stores andgraphicsgives the attachment that format; a pass clears it to the word of Metal's clear. Exact, for a write unblended (or blended one and zero); under a mask of some of its channels the function merges the word into the texel in the interlocked storage form (aGraphicsState::storage_attachmentsentry ofR16_UINT) where the device orders fetch through the pixel interlock. Blended otherwise, there too the function computes Metal's blend of ahalf4orfloat4output over the word it reads, within one code of Metal's (PrecisionNote::DeviceColorConversion: the attachment holds codes where Metal's tile holds a clear's or an earlier blend's result in the pass as ahalf, and under fast math Metal sums a few states otherwise). A blend of the second source, and a blend or partial mask on a device without the interlock, is refused as the device lacking the format; a blend of an output of fewer lanes isNotImplemented; a color input of one is read in the interlocked storage form, the word decoded to each channel's code over its maximum code rounded tohalf, nearest even, which is Metal's value (measured on an Apple M3 Max under macOS 27.0.1 for afloat4and ahalf4input, every code of each 4-bit channel). - An 8-bit sRGB attachment of one or two channels (
R8Unorm_sRGB,RG8Unorm_sRGB) the device does not render (the RTX 5080: it renders neitherR8_SRGBnorR8G8_SRGB, and holds the latter in its UNORM twin) renders through anR8_UINTorR16_UINTview of its texture the same way: the fragment function writes the bytes of the device's sRGB encode (DevicePackConversion), a pass clears it to the bytes of Metal's clear, and a partial mask merges the word in the interlock, or over the attachment's input attachment on a device that orders fetch through rasterization-order input attachments (lavapipe;RuntimeFact::WordInputMerge). A blend of one other than one and zero is refused as the device lacking the format; a color input of one isNotImplemented(Format). - An
RGB9E5Floatattachment the device does not render (the RTX 5080) renders through anR32_UINTview of its texture: the fragment function writes Metal's word of afloatoutput (each channel clamped to[0, 65408], a NaN 0, the exponent of the largest, every mantissa truncated), and a pass clears it to the word of Metal's clear. Exact. Ahalfoutput to one isNotImplemented(Format)(Metal rounds thefloatthehalfwas converted from, half up); a blend, or a mask of some of its channels, is refused as the device lacking the format; a color input of one isNotImplemented(Format). - A multisampled texture of one of these formats, on a device that samples the format but
renders it at no count (the RTX 5080), is held in its word's format (
R8_UINT,R16_UINTorR32_UINT) wherever the device renders that format at the texture's count: its samples are the words Metal stores, read through the format's own view as Metal reads them, and copied bitwise. Its resolve is the crate-owned one, a pass after the pass that reads the stored words: Metal's forRGB9E5Float(each channel's mean of the samples' values, rounded to the nearesthalf, then encoded with its mantissas rounded half up) and an 8-bit sRGB format, every pixel; for a packed 16-bit format each field's mean of the samples' codes, a tie rounded down (a one-bit field's up), within one code of Metal's, which averages its tile's finer values. A device whose word's format renders one sample at that count refuses the texture (TextureSampleCount). - A fragment function that reads a color attachment (framebuffer fetch) reads it in an ordered
form wherever the device has one. On a device with neither ordered form it reads the attachment
as an input attachment without rasterization-order access
(
GraphicsState::rasterization_order_attachment_accessfalse), and the consumer records a barrier of the subpass's dependency on itself, by region, before each draw that reads input attachments after an earlier draw of the subpass, or its load operations, wrote a color, and before each draw that writes a color after an earlier one read them: a fetch reads what every earlier draw stored, Metal's answer, but the overlapping fragments of one draw are not ordered, which the fragment stage records (PrecisionNote::UnorderedFetchWithinDraw; the runtime does all of this itself). Under the identity domains the read is the pushed texture of section 1 instead, at the fragment's own pixel, with the same note: the consumer reads the attachment's texture there and orders each fetching draw after the earlier draws of its pass. Linking refuses an attachment the read cannot take: none attached, or one of another numeric class than the read's (InvalidDescriptorat the color attachment), or one of a rotated, Y'CbCr or extended-range format (Unsupported{Format}). A read of one of Apple's extended-range formats (BGR10_XR,BGRA10_XR,RGB10A8_2P_XR10and their_sRGBtwins), and a blend into one, are refused on every device in either form (Unsupported{Format}at the color attachment): Metal's tile holds such an attachment ashalfthrough the render pass and rounds it to the codes only at the store, so a read or a blend after an earlier draw's write sees that draw'shalf, which the stored codes do not keep. An unblended write, under any write mask, is built. A raster order group on such a color input, or on a color output of an attachment the function reads, orders that read alone there and takes no interlock; a group on anything else still needs the pixel interlock (Unsupported{RasterOrderGroups}). The ordered forms are rasterization-order attachment access, or the interlocked storage form, which binds the attachment as a storage image viewed inStorageAttachmentUse::view_format(): its own format, an 8-bit sRGB format's unsigned-integer view, or, where the device declares a BGRA-order format neither typed nor without a format, its RGBA-order twin (the shader exchanges red and blue). A[[stencil]]output usesVK_EXT_shader_stencil_export. [[barycentric_coord]]readsBaryCoordKHRorBaryCoordNoPerspKHR, whose vertex order is Vulkan's first-vertex order and Metal's for every primitive type. Afloat3read takes the first two weights and computes the third as1 - (x + y)infloat, as Metal does, not the device's own third lane. On a device withoutfragmentShaderBarycentricthe weights are a varying instead: the pipeline carries a generated geometry stage for each topology class (points, lines, triangles, in that order), which writes(1, 0),(0, 1)and(0, 0)at the primitive's vertices in their order and passes the vertex function's outputs, clip distances, point size and the primitive ID through, and a draw runs its class's. Acentroidorsamplequalifier reads the pixel center's weights, as Metal does. That needsgeometryShader; without it, or for what a geometry stage cannot carry (tessellation, mesh pipelines, a vertex function's own layer or viewport index, amplification withoutmultiviewGeometryShader, a written point size in a point draw withoutshaderTessellationAndGeometryPointSize, more varyings than the geometry limits), the pipeline is refused, naming what it needs. Measured on the Iris Xe (ANV), such a pipeline takes about 2.6 ms longer to create, and a geometry stage's presence costs about 15% of fill rate.- A primitive renders into the slice and through the viewport its first vertex selects, the range
check applying to that vertex's index, and its fragments read the first vertex's indices as
written, where Vulkan asks every vertex of a primitive to write the same
LayerandViewportIndex. A vertex function stores an index to its builtin only where it writes the same at every vertex of a primitive, decided from its structure (computed from constants,constantmemory, the instance, the amplification and per-instance attributes, asStageIo::uniform_outputslists), or on MoltenVK, which hands the builtins to Metal (DriverDeviation::MetalFirstVertexIndices). Otherwise, and on a device withoutshaderOutputLayerorshaderOutputViewportIndex, the vertex function stores the index it selects to a flat varying and the same generated geometry stages (one set serving the weights, the primitive ID and the indices) storeLayerorViewportIndexfrom the primitive's first vertex at every vertex they emit; where it stores one index so, it stores the other so too. The variant for a pass of one layer selects no slice and carries no stage. A device withoutmultiViewportdraws through one viewport, so there the vertex function stores no viewport index at all; a draw that selects among more than one viewport there is refused at the draw,Unsupported(LayeredRendering)needingmultiViewport. WithoutgeometryShadereither, a vertex function that selects its slice is refused needing either feature (its pass of one layer still runs), and so is one that selects its viewport on a device withmultiViewport; one whose index differs among a primitive's vertices is refused needinggeometryShader. The stages cannot serve a post-tessellation vertex function, nor sit beside a vertex function that writes the builtins itself (a device with the outputs but withoutfragmentShaderBarycentric): those are refused as not implemented. A fragment function that reads an index no stage writes, on a device that can declare neither builtin, reads 0, Metal's value with no vertex write. [[primitive_id]]counts the draw's primitives in each instance from 0; vertex start, base vertex and base instance do not move it. A fragment stage declaresPrimitiveIdthroughgeometryShaderortessellationShader. Without both it reads a flat varying the vertex function writes (IoRole::PrimitiveId,PushField::VerticesPerPrimitive); an indirect draw's arguments are then read on the CPU only withoutshaderDrawParameters. An indexed draw runs de-indexed (VariantKey::primitive_id_indices: needs device addresses, shades every index).NotImplemented(PrimitiveId): an indexed strip, an indirect indexed draw, indices past their buffer, a vertex function that writes memory in that form, and a mesh pipeline. A draw of Metal's private quads or quad strip, which the consumer lists as two triangles a quad (BindState::quad_primitive_ids), runs the fragment variant that readsPrimitiveIdshifted right by one (VariantKey::quad_primitive_ids), as Metal counts one primitive a quad. A private type's draw whose vertex function writes the varying, or writes memory (Metal runs it once for each vertex of its list, where an indexed draw may run a shared vertex once), runs the private list form (VariantKey::private_list,BindShape::private_list; needs device addresses): the consumer draws its list without indices from its first index as first vertex, and the vertex function reads each position's index, and Metal's base vertex in the word before the list, at the list's address (PushHole::CaptureIndexAddress), adding them as Metal's vertex ID wraps, so each position runs once and the positions count Metal's primitives.- A device draws to at most the lesser of its
maxColorAttachmentsandmaxFragmentOutputAttachmentscolor attachments at once (eight at the runtime's floor), where Metal takes eight. A pipeline with an attachment at an index at or past the first is refusedInterfaceComponentsatMaxColorAttachments, and a fragment function with a color output at a location at or past the second atMaxFragmentOutputAttachments. - A pipeline's band variant (
VariantKey::line_band, of aBandPrimitive) draws each line, or each edge of a triangle in fill modeLines, as the parallelogram Metal draws for a line under Apple'ssetLineWidth:at a width the device's own lines do not draw (the runtime chooses where: its README's line widths). Link adds two stages after the vertex stage (pipeline::link::band): a tessellation control stage that passes the primitive's vertices through, and an evaluation stage that places each vertex of a quad patch at an endpoint, moved across the segment along its minor axis by half the width in framebuffer pixels. A line's patch is two triangles over its parallelogram, front-facing underLineBandState::FRONT_FACE; a triangle's is the fans of the quad domain's degenerate inner ring over its three edges' parallelograms, which face as the triangle does under the draw's front face (a zero-area triangle faces back).graphics.line_band(LineBandState) states the draw's contract: each primitive one patch of its vertices (PATCH_LIST,BandPrimitive::patch_control_points), a line's without culling under front faceLineBandState::FRONT_FACEand without depth bias, a triangle's under the draw's cull mode, front face and depth bias, and the band's[sx, sy, h, f]pushed to the evaluation stage atpush_offset(BindState::line_band: Vulkan viewport 0's half extent, the half width, and for triangles 1 under a clockwise front face, -1 under a counter-clockwise one). A smooth varying and the clip distances are each endpoint's, a flat or integer varying the first vertex's. It needstessellationShader(Unsupported{WideLines}needing it); a post-tessellation vertex function, a vertex function that writes a layer or viewport index, synthesized geometry stages, a fragment function that reads barycentric weights and multiview are not implemented. graphicsalso states what the runtime needs to record draws correctly: whether the fragment function reads flat inputs, barycentrics or its position's depth, whether the vertex function writes memory or a layer or viewport index, and which colors the function may write.- On a device with
VK_KHR_portability_subset(MoltenVK), each of the subset's missing features is checked against what the pipeline uses.
metal::state maps the encoder-side Metal state a pipeline does not own (cull mode, winding,
depth/stencil state, ...) to Vulkan values.
Tessellation
A post-tessellation vertex function makes a tessellation pipeline:
let vertex = FunctionDescriptor::new(library.function("tess_quad_buffer")?);
let mut descriptor = RenderPipelineDescriptor::new(StageSource::Function(vertex));
descriptor.tessellation = Some(TessellationDescriptor::default());
let pipeline = device.compile_render_pipeline(&descriptor, &Budget::standard())?;
Its stages are a synthesized vertex and tessellation control stage, the function as the
evaluation stage, and the fragment stage. It draws patches only (DrawCall::Patches or
PatchesIndirect), with the factors from a tessellation factor buffer. The device's tessellator
orders the triangles (PrecisionNote::TessellationTriangleOrder where it is not Apple's).
A device without tessellationShader refuses the function (Unsupported{Tessellation}, naming
the feature), and a fragment [[primitive_id]] behind it is NotImplemented(Tessellation).
Mesh pipelines
Device::compile_mesh_pipeline compiles a MeshPipelineDescriptor (an optional object function,
a mesh function and a fragment function), and compile_mesh_variant its variants. Its plan draws
mesh draws only (DrawCall::MeshThreadgroups, MeshThreads and their indirect forms). The
stages are task and mesh shaders, which need VK_EXT_mesh_shader with meshShader (and
taskShader for an object function). A device without them (MoltenVK, older ANV) refuses the
pipeline and each of its object and mesh functions (Unsupported{MeshShading}, naming what it
lacks).
A grid Metal draws nothing for (an axis past bind::METAL_MESH_GRID_AXIS, or more than
bind::METAL_MESH_GRID_TOTAL threadgroups, measured on the M3 Max) draws nothing in every form:
a direct draw's command is zeroed, an object function's wrapper launches nothing for such a grid,
and an indirect draw reads its counts on the GPU. An indirect draw's
DrawCommands::mesh_arguments is a pass to record before the render pass
(bind::mesh_arguments_module, one invocation): it writes the draw's counts into the consumer's
scratch (MeshArguments::scratch_bytes), which the draw reads in place of Metal's arguments.
An object grid runs at any count Metal runs, past the task stage's limits too, on a device with
device addresses, shaderInt64, multiDrawIndirect and drawIndirectCount (every committed
profile with the extension): the object function is compiled folded, and each draw runs its grid
in pieces within the task limits (bind::fold_object_grid), its object stage reading the
threadgroups Metal runs and its grid from a 32-byte region record at its
PushHole::ReplayRegionAddress. A direct draw's fold is DrawCommands::object_fold, whose bytes
the consumer uploads (the record, and its pieces' commands where draw is indirect); an indirect
draw's arguments pass (MeshArgumentsForm::FoldedObject) writes the record, the pieces and their
commands, which draw (DrawMeshTasksIndirectCount) reads. Metal's threads per grid wrap to 32
bits along each axis, as its builtins report them; a direct draw runs only the threadgroups those
threads fill, rounded up, an indirect one every threadgroup (bind::metal_object_grid). Every
device runs a grid of up to bind::METAL_OBJECT_GRID_TOTAL (2^29) threadgroups, the most Metal's GPU
ran within its watchdog's 5 seconds. A larger one, which Metal's GPU discards, draws nothing and
fails its command buffer with Metal's error (the runtime's CommandBufferError::GpuRecoveryVictim):
a direct draw says so in DrawCommands::discards_command_buffer, and the consumer fails the command
buffer from the draw's encoder on, as Metal does; an indirect draw's arguments pass sets
StatusBits::MESH_GRID_DISCARDED in the command buffer's ExecutionStatus. Where the device cannot
launch a grid Metal draws, the draw draws nothing and the command buffer fails with the runtime's
own error (CommandBufferError::MeshGridPastLimits, not Metal's): an indirect draw's object grid past
the task limits of a device that does not fold object grids, or a mesh grid past the mesh limits,
through StatusBits::MESH_GRID_PAST_LIMITS, or a fold of more pieces than
MeshArguments::OBJECT_PIECES (only under task limits below Vulkan's required least), its past.
A direct object grid past the task limits of a device that does not fold is refused naming the
limit.
Tile pipelines
Device::compile_tile_pipeline compiles a TileRenderPipelineDescriptor (the tile function and the
render pass's color attachment formats) into a ComputePipeline that stands in for
dispatchThreadsPerTile:. Dispatch it as Dispatch::Threadgroups over the render area, one
threadgroup per tile, with BindState::imageblock_size and BindState::render_area set, and bind
each attachment it reaches as a storage image where the plan writes WriteSource::TileAttachment.
Its threads are numbered as Metal's tile dispatch numbers them, for every threadgroup of even sides
up to 32x32 and the single thread; a threadgroup with an odd side, whose quads Metal leaves partly
empty, is refused. A tile function runs on a single-sample pass: a multisample
imageblock's operations (its sample count, the colors a pixel holds and their coverage masks, a
store to the samples a coverage mask selects) are refused as not implemented
(Feature::Imageblocks, naming the intrinsic).
5. The interface and the plan
The pipeline states what it binds and how:
for (slot, interface) in &pipeline.interface.slots {
println!(" slot {slot:?}: {interface:?}");
}
for set in &pipeline.layout.sets {
for binding in &set.bindings {
// ...
for dependency in &pipeline.dependencies {
let (fact, mechanism) = (dependency.fact, dependency.mechanism);
println!(" depends on {fact:?} via {mechanism:?}");
}
interface.slotsholds every statically used Metal slot (SlotRef: stage, table, index): how the shader accesses it, and for a buffer the byte window it can touch. A buffer slot'skindsays whether Metal binds a buffer, a visible-function table or an intersection function table there.- Under the identity domains (section 1) a buffer slot's
PushField::SlotGuestBaseis its address, the bound buffer'sgpuAddressplus the bind offset (or the address of itssetBytescopy, or of the consumer's nil buffer where nothing is bound), less 2^31, modulo 2^64. An access through the slot adds its 32-bit byte offset plus 2^31, modulo 2^32, zero-extended, to that word; a pointer compare, a pulled vertex fetch and an access from the word below it add the 2^31 back to read the address itself, and so does a slot pointer converted to an integer or stored, which is the slot's address plus its offset. The binder (BindingPlan::instantiate_*) of a device that compiles under the identity domains writes the word so. A pointer loaded from memory (an argument buffer's pointer member, agpuAddressthe program stored) and a pointer made from an integer are the device address the word holds, unbiased and used directly, unchecked: there is no root table, noPushField::RootTableAddressand no search. A texture's or sampler'sSlotGuestBaseis itsgpuResourceID, unbiased. - Under the identity domains, a buffer slot that an access may reach at a
byte offset that is not a translation-time constant (an index the memory plan does not prove
one value, a looping
memcpyormemset, a pulled fetch) also readsPushField::SlotBounds: auvec2, the bound buffer's bytes before the bind offset (the bind offset), then the buffer's length; 0 and the length of itssetBytescopy; 0 and 0 where nothing is bound. Each such access whose offset the module does not hold as a constant is checked against the buffer: for ann-byte access at its 32-bit byte offsetmfrom the bind offset, read as signed, the normative check(len >= n) && (m + before <= len - n)inu32. The domain is the bound buffer, as Metal's is and as a storage view of a whole window's is (from the buffer's start): an offset before the bind offset is inside where the buffer holds it, and one before the buffer's start wraps to at least 2^31, outside. The module computes it asm + before < limit, the slot's limit forn-byte accesseslen - min(len, n - 1)(0 for a slot shorter than one access), made once per slot and size in the function's first block: one add and one compare per access. A load outside reads each of its units atPushField::ZeroAddress, au64the consumer pushes: the address of 16 bytes of zeros, a multiple of 16, that nothing writes. That is one select of each unit's address, with no select of the value and no branch, and the load touches nothing of the slot. A store or an atomic outside sits in the check's selection and runs nothing; an atomic's answer there is 0. Nil and a slot shorter than one access push a length that every such access past it fails. An access at a constant offset, and an access through a pointer loaded from memory or made from an integer, is not checked. The binder writesSlotBoundsfrom the bound buffer and refusesZeroAddress(Unsupported{IdentityDomains}): the zero range is the runtime's own memory. What the check costs, measured on the runtime against the same build with the check removed (release, no validation layer): in the compute harness's GPU time,wide_bindings34.7% slower on a Radeon 780M (job m3-max-56485), 38.5% on an RTX 3090 (m3-max-56486) and 68% on an Iris Xe (m3-max-56546);bind_200017.9%, 32.1% and 11.3%;constant_managedandconstant_private8.0% and 8.3% on the 780M, 22.2% and 25.8% on the 3090, level on the Iris Xe;row_cellslevel on the 780M and the 3090, 9.5% on the Iris Xe. A recorded replay stream's GPU time a frame, its players built from653014c278(the same jobs): 3.3% more on the 780M over 438 frames (one round), level on the 3090 over 464 frames, and 5.5% more on the Iris Xe over 200 frames (m3-max-56641). Making two recorded sessions' render pipelines cold takes 3.5% and 3.8% more driver time on two RTX 3090s with the check than without it (players built from84b4f52e4b, jobs m3-max-58076 and m3-max-58098). - The layout numbers set 0 densely, in
ResourceSlotorder. Set 1 holds the heap arrays (the resources reached through argument buffers and resource IDs);pipeline::heap_sampler_capacityis the most elements a set-1 sampler array has on a profile. A texture buffer reached so is an element of a texel-buffer class: a uniform texel buffer array where the function only reads it, a storage texel buffer array declared without a format where it writes it, each needing the texel buffer kind's non-uniform indexing and update-after-bind features (a storage one alsoshaderStorageImageWriteWithoutFormat, and where it is readshaderStorageImageReadWithoutFormator, without it, the formats' own read bits, section 10).bind::heap_elementanswersHeapElement::TexelBufferfor a texture buffer such a class holds, the format of its texel buffer view; a planned heap's members are textures with images, so only a heap set the consumer keeps for every command (each live texture at its resource ID) holds texture buffers. Push constants carry the values the binder writes per command. A stage that writes the command buffer'sExecutionStatus(aseq_cstfence, an argument buffer's cubic sampler) reaches it by device address, a push hole, where the device addresses buffers (bufferDeviceAddressandshaderInt64), and through a set-0 storage buffer of its own (SyntheticBinding::ExecutionStatus) where it does not. That binding counts against the stage's storage-buffer limits: past one, an absent read or a fence is refused (DescriptorCount), and a stage that would bind it only to test its argument samplers for a cubic filter binds nothing, so the plan refuses a cubic sampler listed beside it (SamplerBicubicFilter). - A heap texture sampled through one of several constexpr samplers, the one a sampler handle names
at run time (a table of constexpr samplers read at a computed index), samples once through a
set-0 array of those samplers (
ResourceKind::SamplerArray,BindingSource::SamplerArray), at the element the handle names. The binding'simmutable_samplersholds each element's sampler,countof them, each made as a heap texture sampled through that sampler alone bakes it; it takes no descriptor write, and a pushed set 0 pushes them.StageInterface::sampler_arrayslists each array's constexpr samplers by its slot. The module takes this form where the candidates' handles are consecutive, each candidate's sampling is the same but for its sampler, and the device indexes a sampler array by a value that may differ between invocations (shaderSampledImageArrayNonUniformIndexing, which heap textures already need); otherwise, and always under the identity domains (whose stages bind no set-0 sampler), it switches over the candidates, one sampling per candidate, each through the constexpr sampler the consumer pushes. - Each binding's
variablesis the most variables one stage's entry point uses at it (those itsOpEntryPointlists): a function that reaches a buffer through several types uses a variable of each type at the buffer's binding. A set-0 uniform or storage buffer binding may be created as its dynamic type (VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC,..._STORAGE_BUFFER_DYNAMIC), its descriptor written at offset 0 and its range's offset bound as the dynamic offset: the module reads the same bytes, and commands that differ only in offsets can bind one set. The runtime does so for each such binding of one descriptor and one variable that no stage the pipeline adds reads, in binding order withinmaxDescriptorSetUniformBuffersDynamicandmaxDescriptorSetStorageBuffersDynamic, where it does not push set 0; the rest stay of their own types. Keep a binding of several variables static on MoltenVK 1.4.1: its SPIRV-Cross writes Metal that does not compile for a dynamic buffer an entry point uses through more than one variable. - A buffer slot's uniform view is a
Uniformblock (DescriptorView::UniformWords, orUniformVec4withoutuniformBufferStandardLayout). - On MoltenVK, push set 0 (a push descriptor set layout) for a pipeline whose fragment stage writes
a storage buffer of set 0 inside its interlock (an interlock execution mode, and a
StorageBuffervariable of set 0 not decoratedNonWritable): binding through Metal argument buffers, MoltenVK packs a bound set 0 into one argument buffer, and Metal leaves such a buffer out of its raster order group where the function also reads another buffer of that argument buffer, so overlapping fragments of a draw read it unordered (measured on an M3 Max with 1.4.2). A pushed set's buffers are discrete arguments, which Metal orders. MoltenVK's pushed sets do not hold their buffers' sizes, so bind set 0 there for a pipeline a stage of which reads a buffer's length (OpArrayLength). dependencieslists the bind-time state the pipeline depends on (RuntimeFact: threadgroup sizes, sampler coordinate modes, buffer ranges, ...) and how this profile honors each (Mechanism: a specialization constant, a push field, a plan-time check, a variant). The plan acts on them; you do not have to.- The format class of a bound texture is read by the shader as push data, not specialized, so binds
that differ only in their textures' formats share one
VkPipeline. On MoltenVK a slot read with ahalfresult also specializes one bit of it: whether the class converts its texels tohalfby rounding to nearest even alone (every class but those with 32-bit float channels, 16-bit normalized ones and YCbCr fields on the grid8192), so a slot bound to both kinds of format takes two pipelines. Other bound values (a slot's presence, a sampler's word, whether a uniform buffer's descriptor range starts at its bind offset) are specialization constants. The last lets a driver load the constants ahead of the shader: inline bytes take that form, and so does a buffer bound at a multiple ofmax(minUniformBufferOffsetAlignment, 16)at a slot whose table tells that alignment apart (state.view_base_alignment, and the slot's bit in its table'sat_bind_views). A buffer bound at any other offset, or at a slot left out, takes the other form, a pipeline of its own: leave out a slot bound at offsets that move, so that its draws keep one shape and one pipeline (the runtime leaves out each slot of a state once it finds one bound at an offset the alignment does not divide). A consumer that draws and dispatches every key with its uniform views at their residuals (each uniform view'sRangeAtBindOffsetat 0, as the runtime does on every device whose driver is not measured to load such reads ahead of the shader) says so withstate.uniform_views_at_residual = true: its uniform views then bind ranges their bind offsets share (below), as a bounded storage view's do. No storage view declares the key: it reads at its residual, its range from the buffer's start, so the bytes before a bind offset stay reachable. - A bound buffer's length enters its shape only as a length class (
bind::length_class), which a plan compares with the device'smaxUniformBufferRangeandmaxStorageBufferRangealone (whether every range of the buffer fits each). Set each table'sbuffer_ranges = BufferRanges::of(limits)and its shape tells apart only the classes those limits tell apart (BufferRanges::length_class: a class rounded up to the greatest one that fits the same limits), so commands over buffers of many sizes keep one shape and one plan: on a device whose two limits are both 4 GiB, every buffer below 4 GiB. The default tells every class apart. The runtime sets them on every table it reads. - A two-plane YCbCr texture whose planes a function may read in place states them in its facts
(
TextureFacts::ycbcr_in_place, aYCbCrInPlaceof its planes). A slot whose function only samples it (nearest or linear, no comparison, anisotropy ormin_lod_clamp), gathers it or reads its size (RuntimeFact::YCbCrInPlace) takes the pipeline's in-place variant (VariantKey::ycbcr_in_place): the slot binds a uniform texel buffer over the planes' bytes (WriteSource::YCbCrInPlace, inYCbCrInPlace::format), its push field (PushField::YCbCrInPlace) holdsYCbCrInPlace::words, and the function converts and filters the codes as Metal does, exactly (a gather Metal's taps of them). Any other slot, and any texture without the fact, binds the texture's image of converted texels. Where the consumer also holds the planes as a linear image of their multi-planar 4:2:0 format over their bytes, which the device's sampler Y′CbCr conversion reads with Metal's reconstruction, it states so (YCbCrInPlace::with_planes_image, its conversionYCbCrInPlace::sampler, aYCbCrPlanesSampler). A slot whose every sample the device's sampler takes (the fact'sdevice: no border address mode, no texel offset placed by a parent's size, no gather; a runtime sampler's word without a border mode) then takes the planes variant (VariantKey::ycbcr_planes_sampled): the slot is a combined image sampler of the image (ResourceKind::YCbCrPlanes,BindingSource::YCbCrPlanes, written fromWriteSource::YCbCrPlanesImage) whose immutable sampler isSamplerDesc::ycbcrof the conversion. The consumer chains itsVkSamplerYcbcrConversionInfointo that sampler and makes the image's view with an identically defined conversion, and sizes a pool for the format'scombinedImageSamplerDescriptorCountdescriptors at the binding. Each sample is the device's, at level 0, its conversion and filter of the codes rather than Metal's. - A 2D texture whose image is a shadow but whose bytes the consumer reads and writes in place
states its rows in its facts (
TextureFacts::texel_rows, aTexelRows: its width, height, the texels from one row's first to the next's, and its first texel in a texel buffer view of its bytes; the runtime states one for a shadow over host pages whose image the device refused, not one its policy asks for). A slot whose function only reads, writes or asks the size of it (no sample, gather, atomic, read through a sampler, level views, switch at use or residency;RuntimeFact::TexelRows) takes the pipeline's rows variant (VariantKey::texel_rows) where the device views the texture's format as a texel buffer of the slot's kind (uniform where the slot's declaration only reads, storage otherwise, read and written without a declared format): the slot binds a texel buffer of the format over the rows' bytes (WriteSource::TexelRows, from the view's first texel through the last row's last; a use of classAccessClass::TexelRowsof those bytes), its push field (PushField::TexelRows) holdsTexelRows::words, and the function addresses texel(x, y)atfirst + y · row + x, testing every read and write against the texture's size itself (a coordinate past the width names the next row's texel in the view): a read outside is Metal's out-of-bounds texel and a write there is dropped, and a size query answers the field's size and one level. A texel buffer's texels go through the device's format conversion as an image's do, so the reads and writes are the image route's, bit for bit (the runtime'stexel_rows_devicetests compare everyRGBA8UnormandRGBA16Floatcode), and no precision note is recorded. Any other slot, and any texture without the fact, binds the image. - A texture buffer of more texels than the device's
maxTexelBufferElements(Metal makes them up to 2^28 texels on every Mac; one texel buffer view holds 2^27 on ANV and lavapipe and 2^26 on MoltenVK) is bound through views of its parts. State with its binding the views its texels take (BoundTexture::Buffer::parts,bind::texel_buffer_parts(limits, texels): 1 within the limit, which binds one view as before and keeps the pipeline and its key). Each part but the last holdsbind::part_texels(limits)texels, the limit rounded down to a multiple ofminTexelBufferOffsetAlignment, so every part starts on that alignment where the texture buffer does; the last holds the rest. A slot whose function only reads (not through a sampler), writes, updates by an atomic or asks the width of the texture buffer, on a device that indexes an array of the slot's kind of texel buffer by aNonUniformvalue (RuntimeFact::TexelBufferParts), takes the pipeline's parts variant (VariantKey::texel_buffer_parts) where the shape binds more than one part there: the slot is an array of the parts' texel buffers, oneWriteSource::TexelBufferper array element, each element's view the bytes of the instance'sDescriptorRangeat thatelement. The function reads texelias texeli - k · Pof partk = min(⌊i / P⌋, parts - 1); a texel past the last lies past the last part's end, so its read is Metal's out-of-bounds texel and its write is dropped, as through one view, and the width is(parts - 1) · Pplus the last part's. Each part is the device's own view in the format one view takes, so a read converts its texel as that view does, and no precision note is recorded. Still refused withBindError::TexelBufferTooLarge: a slot that reads the texture buffer through a sampler, a device withoutshaderUniformTexelBufferArrayNonUniformIndexing(orshaderStorageTexelBufferArrayNonUniformIndexingfor a slot that writes), and a format whose block holds several texels; parts past a stage's sampled or storage image descriptors are the link's descriptor-count refusal. A texture buffer past the limit in an argument buffer is the heap class's neutral. interface.reaches_command_buffersandinterface.texture_writing_stagessay, provably, which pipelines may touch an indirect command buffer and which stages may write a texture.interface.command_writes(CommandWrites) says what its functions may write into the records they reach: the indirect-command operations they may call, and the primitive types their draws may pass (a draw's constant type, or all five where it is not a constant). A clear bit is proven.interface.writes_memorysays, provably, whether a pipeline's functions write memory another invocation or a later command can read: a store to a buffer or through a device address, a texture write, or an atomic update. A compute pipeline without it has no effect a program can observe, so a runtime may run nothing for its dispatches.interface.reads_unbound_resourcesandinterface.writes_unbound_resourcessay, provably, whether a pipeline's functions may read or write a resource through anything but their bound slots: through a pointer or texture they load from memory or make from an integer (an argument buffer's resources, an address stored in a buffer, a resource ID), an indirect command buffer, ray tracing, or a call the function cannot see into. Metal requires such resources to be declared withuseResourceoruseHeap. With each slot'saccess, they are what a compute encoder needs to place a barrier only on a hazard.interface.unbound_storage_texturessays, provably, whether a pipeline's functions may reach a texture through its storage image through anything but their bound slots: a texture write or atomic, or a read the operation does not declareaccess::sampleoraccess::read, through a texture they load from memory or make from an integer (an argument buffer's texture, a resource ID), or an intersection or a call the function cannot see into. A runtime that gives some textures no storage image needs it to find such an access to one.
Plans
Per draw or dispatch, describe what is bound, keyed by Metal slot, as a BindState. The binder
never sees your resources, only facts about them:
let mut table = StageTable::default();
table.buffers.insert(0, buffer(4096, 0));
let facts = TextureFacts::new(TextureType::Type2D, PixelFormat::RGBA8Unorm);
let texture = BoundTexture::Texture {
facts,
resource_id: None,
};
table.textures.insert(0, texture);
let sampler = BoundSampler::new(SamplerDescriptor::new());
table.samplers.insert(0, sampler);
let mut state = BindState::default();
state.stages.insert(Stage::Kernel, table);
let plan = pipeline.plan(&device, &state.shape())?;
assert!(plan.variant.is_empty(), "this shape needs no other variant");
state.shape() keeps only what can change a plan (which slots are bound with what kind of
resource, formats, level counts, sampler modes, alignment classes). A plan is a pure function of the
pipeline, the device and the shape: memoize it on (PipelineKey, BindShape). A consumer that keeps
the shapes it planned can find a state's among them without making it: state.has_shape(&shape)
answers state.shape() == shape, compared in place.
The plan holds one DescriptorWrite per layout binding element (the resource at a slot, a buffer
the binder synthesizes, or a neutral resource where nothing compatible is bound), the vertex
buffers, and the ResourceUses that drive staging, writeback and barriers. List in the state
every live sampler state and visible-function table the command can reach through argument buffers
(argument_samplers, function tables), and the resources it uses (used_resources). A consumer
that lists those in token order says so (used_in_token_order), and one that points every root
table at a resident set it uploads apart, holding them and the ranges it lists
(resident_ranges), says that (resident_apart, with ResidentSet): a command's
instantiation then costs its own bindings and heap members, not every resource the state lists.
A plan whose variant is not empty asks for another variant of the pipeline (a storage texture's
format, a buffer range past the descriptor limit, a vertex buffer that fixed-function input cannot
fetch, ...). Compile it and plan it for the same shape: device.compile_render_variant(&descriptor, &plan.variant, &budget) for a render pipeline, or compile the kernel with
plan.variant.lowering_inputs(Stage::Kernel) and link it as StageSource::Compiled. A dispatch can
ask too (plan.dispatch_variant(&dispatch), or BindError::NeedsVariant from instantiation).
Textures follow Metal's texel rules: sparse textures report residency where the device can,
Depth32Float texels are the device's depth image's (a value it clamps or a denormal it flushes is
the device's, PrecisionNote::DepthDenormals), ulong textures and their atomics use
64-bit images where the device has them, and half and sRGB reads give Metal's values or record
their bound (an sRGB texel is the device's own decode wherever the device samples its format,
srgb-texel-decode). The
rustdoc of BindState, TextureFacts and BindingPlan states each rule. A read's, sample's or
gather's {T, i8} result (the texel and its residency word) may pass through phis, selects,
freezes and member insertions and extractions, Apple's GL code generator's swizzled read among
them. A function whose effects depend on a bit of the word other than bit 0 (resident()'s), or
that stores, passes or returns a value holding the word, is refused (Lowering(Texture)): Metal
establishes no other bit.
6. At bind time
Instantiate the plan per dispatch or draw:
let dispatch = Dispatch::Threads {
threads: [100, 1, 1],
threads_per_group: [32, 1, 1],
};
let commands = plan.instantiate_dispatch(&state, &dispatch)?;
for region in &commands.regions {
// ...
println!(" descriptor ranges: {:?}", commands.descriptor_ranges);
println!(" push holes: {:?}", commands.push_holes);
let plan = pipeline.plan(device, &state.shape())?;
let draw = DrawCall::Primitives {
vertex_start: 0,
vertex_count: 6,
instance_count: 1,
base_instance: 0,
};
let commands = plan.instantiate_draw(&state, &draw)?;
A buffer slot read through a storage view of its whole window (a device pointer the function
indexes) takes the descriptor range from the start of the bound buffer's space to its end padded
to 16 bytes, whatever its bind offset, which its SlotBindOffset push field holds: draws and
dispatches that bind one buffer at other offsets write the same descriptors, and only push data
differs. Where that range would pass the view's maxStorageBufferRange or 4 GiB, or the offset
lies at or past the padded end, the range starts at the bind offset aligned down to the
descriptor base alignment. An access that reaches back before the bind offset, inside the buffer,
reads the buffer's bytes there, as Metal's does.
A slot of a bounded window read at its residual -- a storage view's always, a uniform view's
where the state says uniform_views_at_residual -- takes a range its bind offsets share in the
same way: the buffer from 0 to its padded end where that fits the view's maximum range (a uniform
view's is maxUniformBufferRange capped at 64 KiB, its texel form's maxTexelBufferElements
texels) and 4 GiB, else the block of half that
maximum (rounded down to a power of two) its window starts in, to the maximum past the block's
start. A window of at most half the maximum starting in a block ends inside its block's range; a
longer one, or one at or past the padded end, takes the range from its bind offset, as every
other descriptor-form slot does. So draws that move such a slot's offset along one buffer (a
consumer's staged setVertexBytes, a constant reference bound at the next offset of an upload
chunk) write the same descriptor, keep set 0 and push only the slot's SlotBindOffset. Each read
inside the window reads the bytes it read before; one outside it, which Metal leaves undefined,
reads the buffer's bytes inside the range.
instantiate_draw_into writes the same commands over a DrawCommands you keep, in the storage
its vectors already hold: keep one from draw to draw (DrawCommands::default() to start) and the
draws allocate none of it again once it holds as much. instantiate_dispatch_into does the same
for a compute dispatch over a DispatchCommands you keep (one instantiate_dispatch made, to
start): each region's specialization and push bytes, and the argument table's, are written in the
storage the commands before held.
A plan that reads handles (a texture's or sampler state's resource ID, a visible function table's)
writes heap tables among its descriptor bytes, after the stage tables: its handle tables, sampler
tables and function-table directories. Their bytes grow with the resources the state lists as
used and the textures its slots bind that a handle names, and they depend on nothing else of the
state but its argument samplers, function tables and heap placement. heap_elements is a
function of the same inputs and the heap's capacity.
A dispatch is one or more regions (a grid that is not whole threadgroups adds edge regions), each
with its group count, specialization and push constants: create one VkPipeline per distinct
specialization. The plan of a kernel's partial-threadgroups variant (VariantKey::partial_threadgroups,
which LoweringInputs::partial_threadgroups compiles) runs such a grid as the threadgroups its
threads fill at the dispatch's threadgroup size instead, the last along an axis Metal's partial
threadgroup, so every remainder takes the same VkPipeline; a kernel the variant cannot run
exactly (a tile function, a stage-input region, compute derivatives, emulated simdgroups) is
refused it, Unsupported{GpuEncodedIndirectCommands, NotImplemented}, and keeps the edges. On
the identity domains the variant of a kernel that does not
observe its threadgroup partition (KernelFacts::partition_oblivious) runs its grid in tiles
instead (RuntimeFact::GridTiles): its plans run a direct dispatch's threads in
pipeline::grid_tile's tiles, one workgroup of pipeline::GRID_TILE_THREADS each with the tile
as the region's nominal size (MultiRegion 1), the region flagged NONUNIFORM where the tile
does not divide the grid, and a range of threadgroups at its own size (MultiRegion 0); the
kernel runs the same positions with the same answers: where the region is flagged NONUNIFORM,
every invocation compares its position with the region's grid and one past it returns before the
body, a test inside one branch on the flag; an unflagged region runs no such test, so a runtime
flags every region of a grid its workgroups do not divide. At MultiRegion 0 a runtime may run a
direct dispatch of the variant in workgroups of a size it picks, flagged where they do not divide
the grid, whose invocations past it return before the body as a tile's do; an indirect dispatch's
region states no grid and is unflagged, and all of its invocations run.
Device::kernel_observes_partition(&kernel, &inputs, &budget, &entries) answers, before any
lowering, what CompiledFunction::observes_threadgroup_partition answers for the compile under the
same inputs (from the specialized entry entries holds, ordered for the device where its
profile takes the lockstep order), so a runtime lowers only the variant a creation needs.
CompiledFunction::is_image_only (KernelFacts::image_only) states, from the AIR alone, a kernel
that samples, gathers or reads a texture and loads, stores and updates atomically nothing through
a device pointer (constant loads and texture writes allowed), which a runtime may run in
square workgroups. On
that plan a grid of whole threadgroups, of Threads or Threadgroups, takes the same regions
unflagged (each MultiRegion 1, every thread live), so one VkPipeline of a threadgroup size runs
all of a kernel's direct dispatches. The runtime lowers a kernel that does not observe its
partition once, as that variant, and runs every direct dispatch of it in its tiles; a kernel that
observes its partition runs its whole grids, threadgroup dispatches and indirect dispatches on its
plain module at their own threadgroup size, and a dispatchThreads grid that is not a whole
number of threadgroups on its partial-threadgroups variant. A kernel
that steps a stage-in attribute by thread position, or reads [[grid_origin]] or [[grid_size]],
needs the encoder's stage-in region:
match plan.instantiate_dispatch(&state, &dispatch) {
Err(BindError::MissingStageInRegion) => {}
// ...
state.stage_in_region = Some(StageInRegion::new([0, 0, 0], [64, 1, 1]));
let commands = plan.instantiate_dispatch(&state, &dispatch)?;
A tessellation pipeline draws patches, with the factors' buffer in the state:
let factors = TessellationFactorBuffer::new(4096, 0, 0);
state.tessellation_factors = TessellationFactors::new(Some(factors), 1.0);
let plan = pipeline.plan(device, &state.shape())?;
let draw = DrawCall::Patches {
control_points: 4,
patch_start: 0,
patch_count: 16,
patch_index: None,
instance_count: 1,
base_instance: 0,
control_point_index: None,
};
let commands = plan.instantiate_draw(&state, &draw)?;
What you record from DispatchCommands or DrawCommands:
- Descriptors. Write each of the plan's
descriptors, binding each buffer descriptor over exactly itsdescriptor_rangesentry. Uploaddescriptor_bytes(argument and handle tables) and the resident root tables where present. A handle table maps each resident resource'sgpuResourceIDto its heap element; a consumer that keeps one heap for every command buffer can bind one table of every texture ID instead (bind::handle_entry,bind::heap_element,bind::handle_entry_flags), as the runtime does. - Push constants. Write
push_constants, and fill each of thepush_holeswith the device address it names: the uploaded root table, the command buffer'sExecutionStatusbuffer, an indirect command buffer's records. A snapshot variant'sPushHole::SnapshotPhaseis a word, not an address (below). - The dispatch or draw. Record
regionsordrawas given: the binder has already applied Metal's offsets, bases and clamps. - Status. Per command buffer, keep one
ExecutionStatusbuffer for what translated shaders report (a resident-set miss, for one), and read it when the command buffer completes. A plan binds it asWriteSource::ExecutionStatuson a device that does not address buffers: bind the same buffer there, itsExecutionStatus::BYTESbytes.
Snapshot reads
A draw that reads, at its fragments' own pixels, a texture its own subpass renders can read it
through a snapshot instead of a copy taken before the render pass instance. The interface lists
the fragment slots that allow it (StageInterface::snapshot_textures, StageModule:: snapshot_textures): own-pixel slots whose texels reach no derivative, sample, quad or subgroup
operation, branch, integer divisor, dynamic vector index or store outside the invocation, directly
or through a call, in a function that writes no memory. A selection on a texel is allowed where
its arms leave through its merge alone and hold no derivative, implicit-level sample or
level-of-detail query, quad or subgroup operation, loop or undefined operand, nor call a function
that does; what its arms leave behind (its merge's phis, the variables they store to) is judged
as the texel is. It says why it leaves out each other
own-pixel slot (snapshot_refusals: each slot with every SnapshotRefusal that holds for it).
Name the slots in BindState::snapshot_textures; the plan keeps those its pipeline can read so
and states them in variant.snapshot_textures, each with the form its snapshot holds texels in
(SnapshotForm::of the slot's bound view and declared type: the texel's codes for an 8- or 16-bit
normalized, half-float or integer format of the slot's class, which a read decodes as Metal reads
the format, and the fetched lanes' bits for any other), compiled like any other variant. It keeps
none on a
device without fragmentShaderPixelInterlock, fragmentStoresAndAtomics,
attachmentFeedbackLoopLayout or extendedDynamicState3ColorWriteMask, for a pipeline of more
than one sample, a depth or stencil attachment, attachments in the storage form, input
attachments, an imageblock, tile memory, a shader-side stencil or tests, tessellation or mesh
stages, or a function that writes memory, and for an amplified or layered draw. Serve every other
read as before.
A pipeline of that variant states GraphicsState::snapshot_reads: create it with
VK_PIPELINE_CREATE_COLOR_ATTACHMENT_FEEDBACK_LOOP_BIT_EXT; its dynamic_states hold
VK_DYNAMIC_STATE_COLOR_WRITE_MASK_EXT, and its requirements attachmentFeedbackLoopLayout and
extendedDynamicState3ColorWriteMask. Bind the slot's own texture in the attachment's feedback-loop
layout, and at WriteSource::SnapshotTexels a storage image of the slot's form's
SnapshotForm::format (R8G8B8A8_UINT, R16G16B16A16_UINT or R32G32B32A32_UINT) covering the
render area, in GENERAL layout. Record each draw twice in its subpass: first with every color
write mask 0 and PushHole::SnapshotPhase set to 1, each fragment copying its texel into the
snapshot and running nothing else; then with the pipeline's own masks and the phase 0 (the plan's
bytes), each fragment reading the snapshot. A by-region pipeline barrier before the first draw
makes the attachment's earlier writes visible to the copy, and one between the two makes the copy
visible to the reads and orders it before the second draw's color writes. Each step rests on a
sentence of the Vulkan specification: the feedback loop's per-pixel barrier, the color write mask
leaving memory unmodified, the invariance of fragment generation under write masks (Rule 2,
Corollary 1), and the ordered pixel interlock. One draw alone cannot be exact: nothing orders a
fragment shader's read of a texel before the same draw's color write of it.
Where the attachment's image lacks feedback-loop usage (NVIDIA's drivers make no linear image with
it), the two draws can run in two render pass instances instead, after the instance before them
ends. Record the first in a render pass instance of its own over the framebuffer of the instance
that follows, of a render pass compatible with that instance's that loads every attachment and
stores none (VK_ATTACHMENT_STORE_OP_NONE, core in Vulkan 1.3 and brought below it by
VK_KHR_load_store_op_none or VK_EXT_load_store_op_none), every color in GENERAL and the
slot's texture bound in GENERAL, between pipeline barriers from everything before and to
everything after; then begin the next instance and record the second draw first in it, with no
barrier between the draws. Neither instance enables a feedback loop, and neither needs one: the
first writes no color, by its masks or by its load and store operations
(VUID-vkCmdDraw-None-10795, VUID-vkCmdDraw-None-12338), and the second's fetch of the texture
never runs. The same pipeline serves both, as render pass compatibility ignores load and store
operations and layouts. The runtime takes this form for such a read after a memory barrier inside
the instance (WorkCounts::reading_draws_snapshotted_leading), where it would otherwise split the
instance and copy the texture, and where it weighs cheaper than the split by the scissors' area or,
on a device with precise occlusion queries, by the pixels the draw covered in its last measured
pass, even over a buffer's bytes: its first draw reads the texture at every pixel the draw covers.
A draw whose pipeline writes no channel of the color it reads so needs no snapshot: the runtime creates its pipeline (the variant without snapshots) with the feedback-loop flag, binds the slot's own texture in the attachment's feedback-loop layout, and records a by-region barrier before the draw, from the color writes to the fragment shader's reads, and one after it, from those reads to the color output (section 10 says what it then reads).
Levels a slot reads
Each texture slot of a stage states the levels of its bound view its reads reach, counted from the
view's first level (StageModule::level_reads, one LevelReads a slot): whether some read may
reach any level (any: a level the function computes, a level-count query used beyond the
containment of a constant level, a level-of-detail query, a sample through no sampler or with a
minimum level of detail, a storage access, or a use the analysis does not follow), the highest
constant level a fetch, size query or gather names (named) and the lowest whose texels a fetch
or gather reads (lowest_read), and its samples by the sampler each reads through (sampled, with the highest
and the lowest constant level of detail). A sample's level is its sampler's to bound.
Indirect command buffers
An indirect command buffer's commands are records in ordinary buffer storage
(bind::indirect_commands): one format whatever the descriptor, written by the CPU or by a kernel.
The binder replays records into dispatches and draws: on the host, or on the device through a
preprocessing kernel (replay_preprocess), and through VK_EXT_device_generated_commands where
the device has it (replay_preprocess_generated). Draws of primitives under the encoder's
pipeline replay on the device through draw_replay_preprocess: one indirect draw per command
and primitive type the execution names, the pipeline compiled as its replay variant
(VariantKey::replay_bindings), whose vertex and fragment functions read each command's buffers
from the slot tables the preprocess writes. The variant pulls every layout fixed-function vertex
input would fetch (draw_replay_vertex_layouts, named in the shape's far_vertex_buffers: the
pulled-vertex-buffer variant, no buffer bound there), so each attribute reads its command's buffer
at the command's own vertex and instance; a layout whose stride is set per bind keeps an
execution off the device (DrawReplayRule::VertexAttributes), since each command binds its own
stride. Draws of one list type or points whose fragment function
reads no buffer and no [[primitive_id]] may instead merge into one draw (DrawReplay::merged):
two merge passes (draw_merge_module) write each command's first vertex in the merged draw, and
the vertex function, compiled as its merged variant (VariantKey::merged_draws), finds its
command by that prefix and runs the command's vertex, instance and buffers, in the commands'
order. A kernel that encodes commands writes the records that start at
bind::indirect_commands::records_address of the buffer's ID, outside every Metal address, and
finds them only at their start: records may run past later IDs' starts, and a resident set
(bind::ResidentSet) keeps each records range whole. Each of the kernel's writes of a command's
record also stores 1 at the command's written flag, a u32 a command past the records
(bind::indirect_commands::written_flag_offset), where the storage holds them; storage that ends
at its records takes none. A consumer whose own writes of the records set the flags too may reset
only the flagged records of a run of commands, clearing each flag with its record.
7. Caching
The crate keeps no cache; keys and encodings let you keep one across processes. Keys are SHA-256
hashes of the inputs, cache::SEMANTICS_VERSION and the profile fingerprint, known before
compiling (device.compute_pipeline_key(&descriptor), render_pipeline_key(&descriptor, &budget), function_compile_key):
let bytes = pipeline.to_bytes();
let cached = ComputePipeline::from_bytes_for_key(&bytes, &pipeline.key, &device)?;
assert_eq!(cached, pipeline);
A decode checks the format and semantics versions, the key, the profile fingerprint and a
checksum. Every ArtifactError is a cache miss: compile again and replace the entry.
Functions cache on their own, so pipelines that share a function share its compile, and a pipeline links a cached function without decoding it again:
let kernel = FunctionDescriptor::new(sampling.function("sample_level")?);
let inputs = LoweringInputs::new();
let key = device.function_compile_key(&kernel, &inputs);
let compiled = device.compile_function(&kernel, &inputs, &budget)?;
let bytes = compiled.to_bytes();
let function = CompiledFunction::from_bytes_for_key(&bytes, &key, &device)?;
let descriptor = ComputePipelineDescriptor::new(StageSource::Compiled(function));
let linked = device.compile_compute_pipeline(&descriptor, &budget)?;
assert_eq!(linked, pipeline);
- A compiled function states before linking what its stage will:
stage(),requirements()(check it against another profile withDeviceProfile::check),precision_notes()(the pipeline's stage adds those of its own state: a fragment stage's attachment writes, a vertex stage's formats its fixed-function vertex input converts),reconvergence(),required_subgroup_size(),requires_full_subgroups(),module_stats()(section 3) andwrites_memory()(stores or atomics, which a render pipeline drawn in more than one color group refuses).compile_function_with_reportalso returns aCompileReportof what the compile cost. - A render pipeline's stages compile under inputs that a decode of its functions learns.
render_pipeline_keyreturnsRenderPipelineKeys: each stage's function key, and the inputs to compile a missing stage under. So does a compute pipeline's kernel:kernel_inputs_read(&kernel, &inputs, &budget, &entries)narrows the stage-input descriptor to the attributes its entry reads, and the kernel keys and compiles under those, so states that differ only in an attribute it never reads share one compiled function. Those are the plain module's inputs;inputs.kernel_variant(variant)gives eachKernelVariant's (Plain,PartialThreadgroups,EmulatedSimdgroups), so consumers that lower a kernel's variants on one device lower one module per variant. What a creation reads of the descriptor past the fetch -- its layout agreement, its reflection, andcompute_pipeline_key-- reads it whole. - A key names an artifact by its inputs and versions; a content digest names it by what it says.
pipeline.content_digest()hashes everything but the key and profile, andplan.content_digest()(withserde) everything a plan states. A cache of driver objects keyed on the digest survives a release that bumpedSEMANTICS_VERSIONwithout changing the output. A digest identifies content; it authenticates nothing. - A compiled function keeps its last relocation beside it, so a sweep of pipeline states over
one function pair takes the same
Arc<[u32]>on every creation. - A memo that holds pipelines in memory and bounds itself by bytes can weigh one it never encoded.
pipeline.footprint()is the bytes aRenderPipelineor aComputePipelinekeeps live -- every word of every stage, each stage's constant blob and notes, and its own storage -- so a pipeline kept withoutto_bytes()is weighed by what it costs rather than by the zero length of an encoding that was not made. - Versions move independently: the crate's (the API),
SEMANTICS_VERSION(the output),ARTIFACT_FORMAT_VERSION(the encoding) andRUNTIME_VERSION(what the runtime does with an unchanged artifact).
8. Refusals, requested inputs, and precision
Every failure is typed; match variants, never messages. A refusal says what would change the answer:
let floor = committed_device("runtime-floor")?;
let min_lod = FunctionDescriptor::new(sampling.function("sample_min_lod")?);
match floor.compile_function(&min_lod, &LoweringInputs::new(), &Budget::standard()) {
Err(Error::Unsupported(refusal)) => match (&refusal.feature, &refusal.needs) {
(feature, Needs::AnyOf(alternatives)) => {
println!("refused {feature:?}: needs any of {alternatives:?}");
}
(feature, needs) => println!("refused {feature:?}: {needs:?}"),
},
Error has these variants:
| Variant | Means | Retry |
|---|---|---|
Unsupported |
The device cannot run this exactly. feature names the Metal feature, needs what would change it |
No |
NeedsInput |
The compile needs a pipeline input you did not supply | After supplying it |
InvalidInput |
The AIR or container is malformed | No |
InvalidDescriptor |
The descriptor is invalid as Metal would refuse it, or names a missing entry | No |
LimitExceeded |
A deterministic cap (work units, ledger bytes, output size, structural limits) | No |
Budget |
The deadline passed | Later |
Cancelled |
The CancelToken was triggered |
Later |
Internal |
A translator bug (a panic, a verifier failure) | No; report it |
Needs says what a refusal needs:
AnyOf: alternative sets of device capabilities; a device that enables every capability of one set compiles it.NotImplemented: a gap of this version.NotRepresentable: no Vulkan mechanism exists.StageBound: a stage that the device's plan writes heavier than the translator hands any driver (the heaviest measured to compile within host-sized memory);symbolnames its entry weight and the bound. A device whose plan writes it lighter compiles it.MetalGpuFamily: a Metal GPU family the device does not claim, where Metal itself refuses the input without it.
location and symbol are diagnostics only. A render pipeline's refusal of one attachment's
state names it (location.attachment()). REFUSALS.md lists every refusal in the
code, with its device condition.
A compile that needs an input asks for it (Error::NeedsInput) instead of guessing: a storage
texture's format, a linked function, a kernel's stage-input descriptor. Supply it and compile
again. A function-constant value is no such input: a constant the request leaves undefined
compiles, as plain Metal's does (section 10, "Function constants").
A storage texture's format (RuntimeInput::StorageTextureFormat { slot }) comes from what is
bound: metal::format::storage_image_choice(pixel_format, device.profile()), placed in a
VariantKey's storage_images and compiled as a variant. The plan asks for it itself where the
bound format needs a declared format.
What to cache. error.retry() says whether the same request can succeed later. A
BindError from plan depends only on the pipeline, the device and the shape, so it
memoizes beside the plan; one from instantiation does not.
Precision. Where an output gives a near-equivalent of Metal's answer, its stage lists it in
precision_notes (a PrecisionNote, each documenting its bound), and reconvergence says
whether subgroup reconvergence after divergence matches Metal's
(Reconvergence::ImplementationDefined where the profile lacks maximal reconvergence). A note
that holds only under some bound values is in specialized_notes;
stage.precision_notes_bound(&plan.specialization, &|key| plan.specialized_value(key)) gives the
notes a plan reaches. Section 9 lists every note.
The runtime's errors are its own type, metal2vulkan_runtime::Error;
REFUSALS.md lists its refusals with their basis, and its README states each known gap.
9. Degrade notices
Where an answer may differ from Metal's, the operation carries a precision note
(metal2vulkan::pipeline::PrecisionNote), fixed per operation and never decided at run time: by
the translated module, the pixel format, the descriptor or the state, on every device.
metal2vulkan-runtime gives them through these items:
ComputePipelineState::precision_notesandRenderPipelineState::precision_notes: the translator's notes of the state's modules, withSwizzledOpaqueBlackBorderwhere a function samples through a constexpr sampler whose address mode reads an opaque-black border, andDeviceLineRasterizationwhere a render pipeline's descriptor enables alpha to coverage or alpha to one;Texture::precision_note:CompressedTexelDecodewhere the texture's own pixel format is block-compressed;SamplerState::precision_note:SwizzledOpaqueBlackBorderwhere an address mode reads an opaque-black border;DepthStencilState::precision_note:DepthDenormalswhere the state tests or writes depth;RenderPassDescriptor::precision_note:DeviceRoundedResolvewhere a color attachment resolves;BlitCommandEncoder::GENERATE_MIPMAPS_NOTE(DeviceFilteredMipmaps, ofgenerate_mipmaps) andRenderCommandEncoder::DEPTH_BIAS_NOTE(DeviceDepthBias, of a draw of triangles under a depth bias).
A note is never fatal: the work runs on every device. The runtime prints and sends no note; a consumer reads them through these items. The translator's own API gives a stage's notes (section 8).
Each entry below is named by a code, metal2vulkan-degrade- and the note's name in kebab case
(PrecisionNote::NativeFma is metal2vulkan-degrade-native-fma), with its category, and says what
makes an operation carry the note and what may differ. Each PrecisionNote's rustdoc states its
bound.
metal2vulkan-degrade-device-rounded-resolve(precision).DeviceRoundedResolve: A multisample color resolve averages through Vulkan'sAVERAGEmode, which leaves the rounding of the average (and the sRGB encoding) to the device: any color attachment but an extended-range one and one resolving into its format's sRGB twin (each resolved after the pass), one a fetching pass's sample planes hold as it ends included (the planes merged back first). Also, on every device, a resolve into an 8-bit UNORM attachment's sRGB twin where the device has the sRGB format: the crate-owned resolve decodes the samples and encodes their average by the device's own sRGB conversions, where Metal's resolve takes its own 12-bit tables (with correctly rounded conversions, 1,758 of the 65,536 pairs of codes at 2 samples land one code from Metal's; MoltenVK 1.4.2 on the M3 Max: 696 of 262,144 channels at 2 samples, one code below; lavapipe, Mesa 26.0.8: 57,865 of 524,288 at 4, within one code). Measured against Metal's rules at 2 and 4 samples on RADV (Mesa 26.0.8, the Radeon 780M and the RX 7900 XTX), ANV (Mesa 26.2.4, the Iris Xe), NVIDIA (615.71, the RTX 5080 Laptop GPU) and lavapipe (Mesa 26.2.4, at 4 samples): every unorm, snorm and packed 16-bit unorm channel within one code of Metal's, an sRGB channel within two (NVIDIA's at 4 samples; one elsewhere). Each rounds an 8-bit unorm tie down (RADV and ANV: 32512 ofR8Unorm's 65536 pairs of samples one code below at 2 samples); an sRGB or packed channel lands above Metal's code in some texels and below in others. A float channel's average differs in its last bits, counted and not bounded (RADV: 8565 ofR32Float's 65536 channels at 2 samples). Cost: a resolved channel can differ from Metal's by one code (an sRGB channel by two) where the average lies near a rounding boundary, a float channel in its last bits, and wholly where a sample is a NaN or an infinity: Metal's resolve counts a half or small-float NaN as 0 and a half infinity as 65536 of its sign, and makes any 32-bit float NaN 0x7fc00000, where the device's average may keep them. Onmetal2vulkan-runtimeit is the static notePrecisionNote::DeviceRoundedResolveof a render pass that resolves a color attachment (RenderPassDescriptor::precision_note), by Vulkan'sAVERAGEin the pass's own rendering, on every device: an extended-range, bfloat or YCbCr attachment's resolve isGap::RenderPassofRenderPassKind::Resolve, and an integer one isRefusal::ResolveFormat.metal2vulkan-degrade-device-filtered-mipmaps(precision).DeviceFilteredMipmaps:generate_mipmapsof a filtered format (an integer format's texels are picked as plain Metal picks them), the static noteBlitCommandEncoder::GENERATE_MIPMAPS_NOTEon every device: each level is the device's linear filter of the one above at the scaled texel centres, its blit chain (vkCmdBlitImagewithVK_FILTER_LINEAR); a format the device's blits cannot filter isGap::MipmapFilter. The device's filter is not Apple's datapath, whose answers also differ between Apple's GPUs (an M3 Max's and an M4's by up to a unit in the last place). No bound against Metal's answer is measured. Cost: a channel can differ from Metal's where the filtered value lies near a rounding boundary, and wholly where a box averages infinities, NaNs or a float format's extremes.metal2vulkan-degrade-capped-lod-bias(precision).CappedLodBias: A sampler state whoselodBiasthe consumer has the device add to every sample's level (SamplerUse::lod_bias, for a GPU that adds it, as a Mac with an Intel or AMD GPU does; the runtime sets it nowhere and samples as an Apple GPU does, with no bias), where the device's samplers cannot add it as it is (metal::sampler::DeviceLodBias): past the device'smaxSamplerLodBias(an infinity included), a NaN, or a bias other than 0 where the device's portability subset withholdssamplerMipLodBias(MoltenVK). Cost: its samples add the device's limit of the bias's sign where the bias is past it, and no bias where the device withholds it or the bias is NaN: a sample whose level with what the device adds has not reached the last level the sampler reads (a positive bias) or level 0 (a negative one) reads another level than Metal's, which adds the whole bias and then clamps the level into the texture's levels; what Metal samples for a NaN bias is not measured. The translator states the same difference as the sampler state's static note,PrecisionNote::CappedLodBias(DeviceLodBias::note), which no pipeline stage records.metal2vulkan-degrade-device-reconvergence(precision).DeviceReconvergence: A stage holds a tangled instruction (a simdgroup or quad operation, or a barrier whose lanes depend on reconvergence) on a device without maximal reconvergence (shaderMaximalReconvergence): after divergent control flow the device decides which lanes run it together, where Metal's lanes reconverge maximally, so such an operation may see other lanes active than Metal's. Under subgroup-uniform control flow (shaderSubgroupUniformControlFlow) the lanes reconverge where control flow is uniform. Static per stage: recorded for any tangled instruction in the entry.metal2vulkan-degrade-simdgroup-access-order(precision).SimdgroupAccessOrder: A kernel holds two accesses of threadgroup or device memory, at least one a write, that different threads of one SIMD-group may make to the same bytes between two barriers, and no barrier or atomic orders them (a lane reads the slot another lane of its SIMD-group wrote one instruction earlier). An Apple GPU runs a SIMD-group's 32 threads in lockstep, so such a pair runs in program order there; the module keeps the pair as the AIR states it, and the device runs the threads in its own order between barriers, so the values the pair reads and leaves may be other than Metal's. The Metal Shading Language calls such a pair a data race, and the difference is an accepted one (section 10, "The threads of a SIMD-group run in no order between barriers"). It is the static notePrecisionNote::SimdgroupAccessOrderof every kernel in which the translator finds such a pair, from the AIR's structure alone, on every device under the identity domains (metal2vulkan-runtime). The resident-table domains order each pair with barriers of their own and record none.metal2vulkan-degrade-snorm-minimum-kept(precision).SnormMinimumKept: A draw in a render pass that loads a single-sampled color attachment of a signed normalized format (R8Snorm,RG8Snorm,RGBA8Snorm,R16Snorm,RG16Snorm,RGBA16Snorm) and does not discard it at the store. Cost: the texels the pass's draws do not write keep their bytes; Metal's pass rewrites a channel's minimum code (-128, or -32768 for 16 bits) as the code above it (-127, -32767) in each tile a draw reaches: a texel whose bytes no Metal write left (uploaded or copied bytes) keeps a code Metal's pass would change. It is the static notePrecisionNote::SnormMinimumKeptof every single-sampled render pipeline that draws into such an attachment, whatever its passes load, on its fragment stage (its vertex stage where it has none), on every device.metal2vulkan-degrade-shared-exponent-kept(precision).SharedExponentKept: A draw in a render pass that loads a single-sampledRGB9E5Floatcolor attachment and does not discard it at the store. Cost: the texels the pass's draws do not write keep their words; Metal's pass normalizes a word whose largest mantissa is below 256 (its exponent above 0) in each tile a draw reaches: a texel whose bytes no Metal write left (uploaded or copied words) keeps a word Metal would change, of the same value. It is the static notePrecisionNote::SharedExponentKeptof every single-sampled render pipeline that draws into such an attachment, whatever its passes load, on its fragment stage (its vertex stage where it has none), on every device.metal2vulkan-degrade-compressed-texel-decode(precision).CompressedTexelDecode: The static note of every texture or view whose own pixel format is block-compressed (BC1 to BC7, and the ASTC, ETC2 and EAC formats where the device makes them;Texture::precision_note), on every device. The texture's image is its own image of that format, which the device samples through its own decode: no BC texture keeps a decoded twin. The bounds are the largest differences from Metal's texels measured on random blocks of every format; a driver not named is unmeasured. Validation derives no tolerance from them; the conformance suite's BC1 to BC5 decode cases hold each texel to its family's largest bound on any driver (an sRGB form's to the sRGB decode's largest step over 4/255), and its ASTC cases each linear (_LDR) texel to 1/2048, plus both values' rounding tofloat, justified by the note alone. Cost: a read, sample or gather of its texels answers the device's decode of its blocks (an sRGB form's code through the device's sRGB decode), where Metal interpolates with 6-bit weights: a BC1 to BC3 channel up to 4/255 off Metal's on NVIDIA (615.71.09, the RTX 3090 and RTX 5080 Laptop GPU; BC3's alpha 6/255), 3/255 on lavapipe, 1/255 on ANV; a BC4 or BC5 channel up to 7.4/255 (signed 0.065) on NVIDIA, 1.3/255 (signed 0.013) on ANV, 2.4/255 (signed 0.022) on lavapipe, and on RADV (Mesa 26.2.4, the Radeon 780M) a signed texel with an endpoint of -128 up to 1.7/255; a BC7 channel afloatulp on lavapipe; its blocks' bytes, copies and sizes are Metal's. An ASTC LDR channel is up to 1/2048 off Metal's on ANV (Mesa 26.2.6, the Iris Xe of Raptor Lake-P), over the fourteen footprints. Measured on more drivers: NVIDIA's 620.70.06 (the RTX 2080) a BC1 to BC3 channel 3/255 (BC3's alpha 6/255) and a BC4 or BC5 channel 7.33/255 (signed 0.064); ANV (the Iris Xe of Raptor Lake-P) and Intel's Windows driver (the UHD 630) BC3's alpha 2/255 and a BC4 or BC5 channel 1.4/255 (signed 0.0134), a BC4 or BC5 texel within 0.0001 of the specification's exact decode there, so what moves is Metal's 6-bit weights.metal2vulkan-degrade-depth-denormals(precision).DepthDenormals: A write that may store a denormal in the 32-bit float depth of a depth image (a pass's clear to one, a blit's copy into aDepth32FloatorDepth32Float_Stencil8texture's depth, areplace_regionwhose bytes hold one): a driver may store one a write on the GPU gives it as a zero (RADV and ANV do; a host copy keeps it), and a depth test may compare one otherwise than Metal's (every driver measured but MoltenVK on an Apple M4). Cost: a denormal depth may read, sample and copy out as a zero, or the depth test may compare it as zero (a positive one) or below zero (a negative one), where Metal keeps it and compares a positive one above zero and a negative one not below it. Onmetal2vulkan-runtimeit is the static notePrecisionNote::DepthDenormalsof every depth-stencil state that tests or writes depth (DepthStencilState::precision_note), on every device.metal2vulkan-degrade-f16-fma-double-rounding(precision).PrecisionNote::F16FmaDoubleRounding: Widened half fma rounds twice.metal2vulkan-degrade-f16-int-conv-double-rounding(precision).PrecisionNote::F16IntConvDoubleRounding: Widened half-integer conversions round twice.metal2vulkan-degrade-grad-from-bias(precision).PrecisionNote::GradFromBias: Bias sampling emulated with gradients may pick another level and another anisotropic footprint than Metal's: derivatives hoisted out of a per-fragment texture choice, which scale by2^Bthrough every sampler, and, on every device, a bias whose sum with the sampler's own may lie beyond the device'smaxSamplerLodBias, which Vulkan clamps, or that an anisotropic sampler applies to its footprint's minor axis alone. On a device withoutmaintenance8, a fragment's implicit-level sample with a dynamic texel offset samples with its derivatives too, taken before the switch over the offset's values.metal2vulkan-degrade-device-transcendentals(precision).PrecisionNote::DeviceTranscendentals: Transcendentals answer within Apple's stated bound, not Metal's bits: the device's precision for a call no other note bounds. Apple states no answer at a NaN operand under fast math, and where the device's compiler takes one math mode for the whole entry (MoltenVK) a precise function of a fast-math entry answers by its fast form, so a NaN operand may answer a number (precise::sinandprecise::cosof a NaN answer0on the Apple M3 Max through MoltenVK 1.4.2, where Metal answers the NaN).metal2vulkan-degrade-reduction-order(precision).PrecisionNote::ReductionOrder: Float reductions use the device's association order.metal2vulkan-degrade-device-denormals(precision).PrecisionNote::DeviceDenormals:floatdenormals follow the device: Metal reads anf32denormal operand of its float arithmetic, comparisons, and functions as the zero of its sign and flushes a denormal result to one, where a Vulkan device keeps or flushes them by its own float controls (this translation declares noDenormFlushToZero). Recorded where the module leaves an operation's denormals to the device, on every device:+ - *, the comparisons,fma,dot,sqrt,rsqrt,trunc,rintandldexponfloat(by the device's products);fneg,fabs,floorandceilonfloat; the divisions and the remainder, the device's maths functions (fast::fmod's fused multiply-add,signandfractamong them),mixbyFMix,fast::sqrtbySqrt,dotof vectors of other than two to four lanes, whose chunks' products the device sums where Metal flushes each one below2^-126, and a conversion to or fromdouble, where Metal's reading is not measured. The operations that read a denormal on its bits answer Metal on every device:copysignandatan2. Where the minimum and maximum functions andsaturateare the device'sNMin,NMaxandNClamp, their pick of a denormal isNativeMinMax's. Off MoltenVK the device's multiply and fused multiply-add, andldexponfloatby that multiply, round a result whose exact value is below2^-126up to2^-126, which Metal flushes. A nearest pixel-coordinate sample at its texel's centrefloor(x) + 0.5, and a pixel fetch atfloor(x) + kunder an offset, records it for thatfloor: Metal's sampler reads a negative subnormalxas texel -1, where MoltenVK'sfloorreads it as the zero of its sign, texel 0 (an Apple M3 Max). An address mode that reads texel -1 as texel 0 (clamp to edge, mirror clamp to edge, mirrored repeat) answers alike, so the sample records it only where itssortmode is repeat, clamp to zero or clamp to the border: through a constexpr sampler of such a mode; through a runtime sampler slot only under a pipeline made for a nearest pixel state (SpecKey::NearestPixelSampler), never under a normalized one, and there where the bound state is of such a mode (SpecKey::BoundSamplerWord); through an argument buffer's samplerargument-pixel-sampler-scalingrecords it instead. A pixel fetch under an offset records it outright.metal2vulkan-degrade-pixel-sampler-scaling(precision).PrecisionNote::PixelSamplerScaling: A pixel-coordinate sampler's coordinate reaches the device's normalized sampler divided by the texture's level-0 size in the shader, and the device reads its texels and weights from that coordinate in its own arithmetic: within a few units in the last place of the edge of a linear filter's pair of texels, a gather's block or one of the filter's sub-texel steps it may read the neighbouring pair, block or step, where Metal's sampler reads the coordinate as given. Recorded for a linear sample, a gather and a level query through a constexpr pixel sampler of an array, a 3D texture or a texture whose residency the function observes, and through a runtime sampler slot (where the bound state reads pixel coordinates, and for a sample or comparison where it is not a nearest one of one isotropic level). Measured: the device's normalized sampler's answer within onef32ulp of the quotient on MoltenVK and at the quotient on lavapipe; a linear downscale by 8 within 1/255 of Metal's on MoltenVK and 2/255 on lavapipe. Under the identity domains it is also recorded for a linear sample and a gather through any constexpr pixel sampler, whose device sampler the consumer makes normalized. Nothing is recorded where Metal's texel or footprint follows from the coordinate itself: elsewhere a constexpr pixel sampler's sample or gather of a 1D or 2D texture that is no array hands the coordinate, moved by its offset, to the device's unnormalized sampler; a nearest sample elsewhere hands the device its texel's centre, where the device reads exactly Metal's texel; and a nearest constexpr sampler clamped to the edge fetches its texel.metal2vulkan-degrade-device-arithmetic(precision).PrecisionNote::DeviceArithmetic: Float division, remainder, square root, fused multiply-add, and dot products use Vulkan's precision bounds (e.g. 2.5 ULP division, a possibly unfusedFma) rather than correct rounding.metal2vulkan-degrade-device-signed-zero-inf-nan(precision).PrecisionNote::DeviceSignedZeroInfNan: Float operations LLVM requires to keep signed zeros, infinities, and NaNs run withoutSignedZeroInfNanPreserve, which the device does not support at their width. Without the mode the device may answer such a zero with either sign.metal2vulkan-degrade-device-ray-intersection(precision).PrecisionNote::DeviceRayIntersection: A ray intersection traversed by the device's ray query.metal2vulkan-degrade-fast-math-rewrites(precision).PrecisionNote::FastMathRewrites: Float arithmetic whose AIR lets a compiler rewrite it with a neighbouring operation: an addition or subtraction and the multiply feeding it both carry LLVM'scontract, two chained additions, subtractions, or multiplies both carryreassoc, or anllvm.fmuladd(fused or not, as the implementation chooses). The module states each operation in the AIR's order with its own flags: one carrying bothcontractandreassocis the device's compiler's to group and fuse, any other is kept apart (NoContraction); Metal's compiler groups and fuses by its own choice. On a device withoutshaderFloat16, a chain of suchhalfadditions, subtractions and products is held atfloatprecision between the roundings where its values leave it. On MoltenVK ahalfaddition, subtraction or product carrying both flags is the 16-bit instruction left undecorated, whose conversions Metal's fast compile folds away: thefloatresult, unrounded. Cost: a sum of mixed signs grouped otherwise, or a multiply-add fused on one side alone, differs from Metal's by any amount relative to the result; a heldhalfchain, or a MoltenVKhalfoperation left to the compiler, by the roundings it skips, a value inside it pasthalf's range staying finite.metal2vulkan-degrade-tessellation-winding(precision).PrecisionNote::TessellationWinding: A tessellation pipeline's vertex order: Metal's clockwise output winding is declaredVertexOrderCcwand its counter-clockwise oneVertexOrderCw, as MoltenVK maps them under Vulkan's default upper-left domain origin. Measured for both windings against Metal's bytes (recorded on an Apple M3 Max) by a consumer's device test,tessellation_states_tessellate_as_metals, on RADV (Radeon 780M, RX 7900 XTX), NVIDIA Turing and MoltenVK; other drivers are not measured.metal2vulkan-degrade-tessellation-factor-edge-cases(precision).PrecisionNote::TessellationFactorEdgeCases: A tessellation pipeline's factors at the edges of Metal's stated rules: a subnormal edge factor is positive and does not cull (its level is the range's lower end), where a flush to zero would cull the patch; and a NaN inside factor's level is the range's lower end.metal2vulkan-degrade-tessellation-factor-scale(precision).PrecisionNote::TessellationFactorScale: A tessellation pipeline withtessellationFactorScaleEnabledmultiplies each factor by the encoder's scale rounded tohalf, exactly infloat, after the cull.metal2vulkan-degrade-tessellation-factor-instance(precision).PrecisionNote::TessellationFactorInstance: A tessellation pipeline whose factor step function is per instance reads instancei's factors ati · instanceStride,icounting the draw's base instance as[[instance_id]]does.metal2vulkan-degrade-tessellation-fractional-spacing(precision).PrecisionNote::TessellationFractionalSpacing: A tessellation pipeline of a fractional partition (fractionalOdd,fractionalEven) drawn through the device's tessellation stages: Vulkan leaves where a fractional spacing places its vertices to the implementation (its two shorter segments' length need only fall monotonically with the rounded level less the level, and their place on the edge is the implementation's), where Metal's tessellator places them by its own rule. Measured equal to Metal's, at factors within the device's range, by a consumer's device tests on RADV (Radeon 780M, RX 7900 XTX), NVIDIA Turing, ANV (Intel Iris Xe) and MoltenVK; other drivers, lavapipe among them, and factors past the range are not measured. A device withouttessellationShaderdraws Metal's tessellator through the emulation and records none.metal2vulkan-degrade-tessellation-triangle-order(precision).PrecisionNote::TessellationTriangleOrder: A tessellation pipeline drawn through the device's tessellation stages (a device withtessellationShader), on every device (no query tells Apple's tessellator apart): the device's tessellator orders each patch's triangles, picks each one's first corner, and joins the patch's rings where Vulkan leaves that to the implementation. The domain points are Metal's; a flat varying, a value interpolated across another triangulation, and the order a patch's triangles blend in may differ.metal2vulkan-degrade-unmeasured-group-speculation(precision).PrecisionNote::UnmeasuredGroupSpeculation: A function holds a branch whose arms hold a quad or simdgroup operation that answers over every lane of the branch's block when Metal's backend speculates the arms (a quad shuffle, broadcast or vote, a simdgroup shuffle,simd_is_first), where no measurement says whether Metal speculates them: an arm of an instruction, size or shape no probe covers. The branch keeps the AIR's lanes, so that operation may answer over the lanes that take the arm where Metal's answers over the block's. A branch Metal was measured to speculate is speculated, and one it was measured to keep is kept, with no note.metal2vulkan-degrade-device-sample-level(precision).PrecisionNote::DeviceSampleLevel: An extended-range texture's (BGR10_XR,BGRA10_XRand their sRGB twins) fragment sample at an implicit level, or with explicit gradients, on every device: its texels are read in the shader, at Vulkan's level of detail computed there and Metal's level rule, where a constexpr sampler states a mip filter or a runtime sampler's word does. The device takes the level of detail by Vulkan's rules, whose scale factor may be approximated; Metal's level of detail from derivatives is not measured. The sample may read another level or filter than Metal's near a boundary.metal2vulkan-degrade-unmeasured-fetch-blend(precision).PrecisionNote::UnmeasuredFetchBlend: A fragment function reads a color attachment the pipeline blends, on a device that orders framebuffer fetch only through the pixel interlock (MoltenVK, RADV, ANV), of a format whose Metal blend arithmetic is not built: a format whose channels read as floats but a 16-bit float, a 32-bit float, an sRGB and an extended-range one (a 16-bit normalized, 8-bit signed normalized, 10-bit, packed float orA8Unormformat, among others), an 8-bit unorm one written by an output of fewer than four lanes, a 32-bit float one (R32Float,RG32Float,RGBA32Float) written by an output of fewer than four lanes, by a module without fast math, or under a blend state the one sweep that measured that family does not fit: a color or alpha arithmetic of more than a lone term, a lone fused multiply-add, or a minimum or maximum, outside the states measured word for word. A one-channel attachment'sSourceColoroverDestinationColoris such a state, and so is a blend color's difference, which a 16-bit float attachment's blend fits and a 32-bit float one's does not; a lone term that reads the blend color,OneMinusBlendColoroverZeroamong them, is fitted and takes the exact form. Also a 16-bit float or 8-bit unorm one under a blend of the second source or beside a second (index 1) output. No Vulkan blend applies to the storage write, so the shader computes the pipeline's blend infloat: each factor, product and sum rounded to nearest even, the source and the blend color clamped first to a normalized format's range (a NaN to its low end), an output's missing lane zero, and the result stored through the device's conversion. Metal's blend arithmetic for these formats is not measured, so the bound is not known. A factor of the second source reads the function's second output, clamped as the source. An 8-bit sRGB attachment (R8Unorm_sRGB,RG8Unorm_sRGB,RGBA8Unorm_sRGB,BGRA8Unorm_sRGB) under a blend of the second source, a one- or two-channel one under a lerp, each in a module compiled with fast math, and one written by an output of fewer than four lanes, record it too: the shader computes Metal's 8-bit unorm blend's rounded forms over the decoded texel, in the output's type (a missing lane zero), and stores the result by the device's sRGB encode (DevicePackConversion), Metal's blend without fast math at four lanes; under fast math Metal regroups the blend, unmeasured.metal2vulkan-degrade-unordered-fetch-within-draw(precision).PrecisionNote::UnorderedFetchWithinDraw: A fragment function reads a color attachment (framebuffer fetch) on a device with neither rasterization-order color attachment access norfragmentShaderPixelInterlock(Honeykrisp on Apple's M2 Pro; RADV on the RX 550), or under the identity domains on any device without rasterization-order access, the pixel interlock's included: there the interlock chooses no fetch form, as its storage form is a descriptor the identity domains do not hold. It reads the attachment as an input attachment, and the runtime records a barrier of the draws' subpass's dependency on itself, by region, before each draw that reads input attachments after an earlier draw of its render pass instance, or its load operations, wrote a color, and before each draw that writes a color after an earlier one read them: a fetch reads what every earlier draw stored at its pixel, Metal's answer. Under the identity domains it reads the attachment's texture at its own pixel instead (PushField::FetchedColor), and the consumer orders each fetching draw after the earlier draws of its pass by a barrier between them (the runtime'sMetrics::attachment_loop_reads, or its copies into the attachment's shadow on a device without the attachment feedback loop). Vulkan orders nothing between the overlapping fragments of one draw there, where Metal orders them in primitive order: a fragment that covers a pixel an earlier fragment of its own draw covered may read the texel from before that fragment's write. Exact for a draw whose primitives do not overlap at a pixel; otherwise each such pixel holds the result of some order of the draw's fragments there. A raster order group on the color input, or on a color output of an attachment the function reads, takes the same form.metal2vulkan-degrade-fp8-value(precision).PrecisionNote::Fp8Value: An 8-bit float converts to an integer from the format's documented value with Metal's saturating float-to-integer rule, where Metal's device here answers otherwise: Metal on Apple M3 compiles these reads but extends the carrier byte as an integer, the same for every format, so the result is unverified on Metal.metal2vulkan-degrade-multisample-position(precision).PrecisionNote::MultisamplePosition: A fragment function of a render pipeline that rasterizes more than one sample reads a value Metal reads at the pixel center in every invocation and Vulkan evaluates at an implementation-defined position within the fragment:[[position]]'s z or w (the interpolated depth and1/w, whose position Vulkan does not state), a center-sampled varying on a device without its pixel form (interpolation functions whoseInterpolateAtOffsetreads from the pixel center: "an implementation-defined position within the fragment area being shaded"), a centroid varying or aninterpolantread throughinterpolate_at_centroid(anywhere in the fragment's covered area, where Metal, measured on Apple M3 Max, moves it to the lowest covered sample's location only under partial coverage), aninterpolantread throughinterpolate_at_centeras a center varying,[[point_coord]]("the fragment center, or the location of a sample"), or[[barycentric_coord]](its builtin). A function that runs per sample under sample shading reads all but the center varying where Vulkan evaluates them for its sample, where Metal reads every one as the pixel's in each sample's run (Apple M3 Max at 4x, measured). Each is evaluated at a point of the pixel, so it differs from Metal's by at most its change over half the pixel's diagonal, and a centroid varying by at most its change across the pixel's covered area; exact where the device evaluates a read where Metal does.metal2vulkan-degrade-rasterization-rate-map(precision).PrecisionNote::RasterizationRateMap: A render pass drawn by regions over a rasterization-rate map that is not the identity: its regions' lines are this crate's tiles' exact lines, where Apple's are its fixed-point ones, so a fragment's evaluated point lies within a bounded distance of Metal's.metal2vulkan-degrade-bicubic-filter-arithmetic(precision).PrecisionNote::BicubicFilterArithmetic: a filter emulated by fetches (Metal's bicubic filter on every format, and an extended-range texture's linear, 3D and linear-mip-filter samples) sums its taps in the device's arithmetic: the Catmull-Rom weights computed inf32from the fraction, the taps summed by the device's multiply and add, a bilinear, trilinear or level blend by itsFMixat thef32fractions, and ahalfresult the device's narrowing. The footprint, addressing, filter choice, level and clamps are Metal's. Metal's fixed-point weights, exact grid sums, float accumulators and sixty-fourth level fractions are not reproduced: a lane may differ by a few grid steps (1/4080at 8 bits), by up to2.1e-3on an extended-range sRGB texture's bicubic sample, and by up to1/64of the two levels' difference under a linear mip filter. Measured for the bicubic filter by the conformance casebicubic-texel-classes(Metal on an Apple M3 Max, macOS 27.0.1): Metal's results lie on the format's grid, a sixteenth of a code forRGBA8Unorm,R8UnormandRGBA8Snorm, a whole code forRGBA16Unormand an exacthalfforRGBA16Float, and at the sixRGBA16Floatsamples whose sum lies exactly halfway between two halves Metal rounds away from zero. Ours is the unroundedf32sum;R32Float's samples compare exactly. The largest difference per format,floatandhalfresults together, over lavapipe, the M3 on KosmicKrisp and on MoltenVK, a Radeon 780M, an RTX 3090 and an Iris Xe:RGBA8Unorm2.44e-4,R8Unorm1.53e-4,RGBA8Snorm4.88e-4,RGBA16Float3.74e-4,RGBA16Unorm2.16e-4on lavapipe, KosmicKrisp and the 3090 and7.8e-6elsewhere (lavapipe'shalfresults keep theirf32values). Through a runtime sampler slot it holds only where the bound sampler filters (a linear minification or magnification filter, anisotropy, a cubic filter or a linear mip filter): a nearest sampler's sample is the decoded texel at Metal's position. Through an argument buffer it holds only where the command can name a texture held by its raw texels in a form the function filters (BGR10_XR,BGRA10_XR, the padded forms; not a bfloat one).metal2vulkan-degrade-sparse-residency(precision).PrecisionNote::SparseResidency: A stage samples or gathers a texture whose residency it observes (sparse_color::resident) through the slot's sparse form, which the module has where the profile enablesshaderResourceResidency: the word is the device'sOpImageSparse*residency, whose footprint may count a texel of zero weight Metal does not or call a footprint of the border alone not resident where Metal answers resident, and an unmapped texel's lanes the device's non-resident value. Where the device has no residency of its own, the slot's tile map answers Metal's footprint rule exactly, unrecorded.metal2vulkan-degrade-device-nan-encoding(precision).PrecisionNote::DeviceNanEncoding: AfloatNaN result's bit pattern follows the device: Metal answers the canonical0x7fc00000for the NaN results of its float arithmetic and functions, and Vulkan states no encoding, so a device may answer another sign or payload (llvmpipe:0xffc00000). Also a blend a fragment function computes into a 16-bit float attachment through the pixel interlock: a NaN of the blend is the device's arithmetic's, which the storage image's store converts, where Metal stores every NaN of the blend as0x7e00. A texture write records it where the stored NaN is the device's: a constant texel none of whose lanes is a NaN records nothing, and ahalforfloatwrite through an argument buffer holds only where the command can name a texture of a format family whose stored NaN is the device's (for ahalfwrite, a texture of any format that holds a NaN; for afloatwrite, a 16-bit float orRG11B10Floatone). So does a fragment function's color output where the device's conversion stores its NaN, but one every return of which holds such a constant records nothing.metal2vulkan-degrade-restricted-depth-range(precision).PrecisionNote::RestrictedDepthRange: The device compares a depth texture's texels on a device withoutVK_EXT_depth_range_unrestrictedenabled (MoltenVK on the M3 Max, ANV on the Iris Xe, RADV), where Vulkan gives a depth image no value outside[0, 1], whatever its driver is measured to keep: an upload into a 32-bit float depth is refused (Gap::FloatDepthUpload), and a render write is clamped to the viewport's depth range. A comparison of a texel Metal holds outside[0, 1]can differ; one within it is exact.metal2vulkan-degrade-cube-gradient-footprint(precision).PrecisionNote::CubeGradientFootprint: An explicit-gradient sample of a cube texture takes Metal's footprint in the form Vulkan's rule reads, in every stage on every device. Cost: the sample takes the device's logarithm of Metal's footprint and, if anisotropic, the device's taps, so a level or blend near a boundary can differ from Metal's. Where the shader takes Metal's level and taps itself (PrecisionNote::AnisotropicFilter) this note is not recorded.metal2vulkan-degrade-half-texel-conversion(precision).PrecisionNote::HalfTexelConversion: The module reads, gathers, or samples a texture with ahalfresult, the device'sfloattexel rounded to nearest even on every device: within onehalfulp of Metal's, but a 32-bit float texel's sample past±65504, the infinity where Metal saturates. Recorded outright for every such access, a heap element's and a depth texture's included: the device'sfloattexel is its own.metal2vulkan-degrade-half-sample-filter(precision).PrecisionNote::HalfSampleFilter: The module samples a texture with ahalfresult through a filter (linear minification or magnification, a linear mip filter, anisotropy, or a runtime sampler slot whose bound sampler filters so) by Vulkan's Y′CbCr model of a 4:2:0 two-plane YCbCr texture's planes read in place, which blends the codes, not Metal's exact filter of the format, on every device.metal2vulkan-degrade-srgb-texel-decode(precision).PrecisionNote::SrgbTexelDecode: The module reads, samples, or gathers a texture with ahalforfloatresult through the device's sRGB decode, or decodes the device's filter of its codes, where the texture may be bound in an 8-bit sRGB format. The device's decode is the only form wherever it samples the format (an 8-bit sRGB format, or the sRGB form of a BC, PVRTC, ETC2, EAC or ASTC format, through the texture's or its decoded twin's sRGB view), so it holds where a command binds such a texture, at an argument buffer's texture access, and for a render pipeline that reads an sRGB color attachment as an input attachment, on every device. Where the device holds the format as its UNORM twin, or a storage texture holds it through its UNORM alias (at a slot, or held by an argument buffer), the module decodes the codes (or the device's filter of them) by the MSL transfer through the device'sPow, at every such access on every device.metal2vulkan-degrade-float-sample-filter(precision).PrecisionNote::FloatSampleFilter: The module samples a texture with afloatresult through a filter by Vulkan's Y′CbCr model of a 4:2:0 two-plane YCbCr texture's planes read in place, which blends the codes, not Metal's exact filter of the format, on every device.metal2vulkan-degrade-function-storage-assumed(precision).PrecisionNote::FunctionStorageAssumed: A vertex or fragment function keeps more private memory (itsallocas, a call stack among them, or constants held asPrivatevariables) than the floor, 16 KiB a thread, on a device whose Function storage was not measured, up to the 192 KiB a thread Metal was measured to hold (device::function_storage). The risk is the driver's: past what it holds it can answer wrongly or hang the GPU with no error.metal2vulkan-degrade-quads-counted-before-discard(precision).PrecisionNote::QuadsCountedBeforeDiscard: A fragment function runs a non-quad simdgroup operation (a reduction, scan, ballot, broadcast, shuffle, vote, or simdgroup matrix) before a discard on a path to it, in a shape where Metal's placement of it is not known.metal2vulkan-degrade-view-base-texel-offset(precision).PrecisionNote::ViewBaseTexelOffset: The module places a texel offset on an axis that may repeat or mirror as Metal does in an access of an argument buffer's texture: in an emulated raw sample (heap_raw) or a bicubic filter's footprint.metal2vulkan-degrade-device-color-conversion(precision).PrecisionNote::DeviceColorConversion: A fragment function writes a float to a color channel whose conversion the device makes, on every device: a normalized, sRGB or small float channel, an attachment that blends with factors other than one and zero (ChannelWrite::Device), the alpha of attachment 0 under alpha-to-coverage, a format whose conversion Metal was not measured with (the packed 16-bit unorm formats,A8Unorm, the packed floats). Near a tie between two codes the device may store the other one: the RTX 5080 Laptop GPU (NVIDIA 615.71.09) stores 0.5 in an 8-bit unorm channel as0x7f, and the lower code of every input up to twof32steps above a tie, where Metal stores0x80and rounds the exact product to nearest, a tie up; ANV, RADV and lavapipe round thef32product with ties to even. Also afloattexel a function writes to a storage texture that may hold a normalized or half-float format, orARGB8Unorm; an integer texel written into a storage texture of the float class that may hold a half-float or small-float format, which Metal rounds to nearest even and the device's store as it rounds afloat(toward zero on every measured driver, one unit in the last place, a finite value past 65504 stored as 65504); and a fragment function'sfloatblend into a 16-bit float attachment through the pixel interlock, and a blend into an 8-bit unorm attachment through the pixel interlock, whose result the storage image's store converts to its code, or into anARGB8Unormattachment over its input attachment where no Vulkan blend state on its rotated image gives Metal's (a destination alpha in a color factor, say), whose result the attachment's write converts; and a render pipeline's private logic operation that the fragment function computes on a device withoutlogicOpinto an 8- or 16-bit unorm or snorm attachment, which converts the output to the codes it operates on by the device'sfloatproduct rounded to nearest even where Metal rounds the exact product (the two differ only near a half-code tie). The recorded bound past one code, measured on lavapipe against plain Metal on an Apple M3 Max: a blend into an 8-bit unorm attachment (RGBA8Unorm,ARGB8Unorm) within 2 codes of Metal's; a fragment function that fetches an 8-bit sRGB attachment and writes it again, within 2 codes once a later draw reads an earlier one's code (withsrgb-texel-decode); a blend into an 8-bit sRGB attachment, within 4 codes; a blend into a 4-sampleA1BGR5Unormattachment the device renders itself (Mesa 26.2.4), within 2 codes, over a sample whose fill it stored a code from Metal's. RADV (Mesa 26.2.6 on the Radeon 780M) blends into anRGB9E5Floatattachment it renders itself a source whose channels and alpha are halves rounded toward zero, a value past 65504 as 65504, where Metal blends thefloats (Vulkan asks a blend for no more precision and range than the attachment's): at 2 and 4 samples, 30 of 96 blended samples are not Metal's, up to 33 units of the larger value's last mantissa bit apart where the source passes 65504, and 7 where the half's alpha weighs a destination far larger than the source. Another device is not bounded past one code (an NVIDIA RTX 5080 Laptop GPU's blend into an 8-bit sRGB attachment stored up to 11 codes from Metal's).metal2vulkan-degrade-device-interpolation(precision).PrecisionNote::DeviceInterpolation: A fragment function reads a varying the device interpolates (center_perspective,centroid,sampleorno_perspective, notflat), on every device. Vulkan states no precision for interpolation, and RADV, ANV, lavapipe and NVIDIA's driver each round most interpolated lanes otherwise than Metal, up to about1.5e-4apart (3e-4on lavapipe) on the probes. RADV's read of a perspective input at a sample or an offset is further off, and recordsextrapolated-interpolation.metal2vulkan-degrade-device-interpolation-offset(precision).PrecisionNote::DeviceInterpolationOffset: A fragment function reads aninterpolantthroughinterpolate_at_offset, which Metal evaluates at the offset as given from the pixel's upper-left corner, at any distance and on no grid (an Apple M3 Max, macOS 27.0.1: 0.999 read at 0.999,1e9extrapolated, a NaN or infinite offset NaN). The device reads at the offset moved to its origin (the pixel center; 7/16 on MoltenVK) and clamped to its[minInterpolationOffset, maxInterpolationOffset], which Vulkan requires, a NaN to the minimum, and rounds it to itssubPixelInterpolationOffsetBits(at least sixteenths): within the range the read lies within half a step of Metal's, past it at the range's nearer end. On MoltenVK Metal reads the offset itself, so within the range ([-1/16, 15/16]from the corner on the M3 Max) the read is Metal's.metal2vulkan-degrade-extrapolated-interpolation(precision).PrecisionNote::ExtrapolatedInterpolation: A fragment function reads a perspective input at a sample or an offset (interpolate_at_sample,interpolate_at_offset, or a sample-qualified varying a function looping over its covered samples reads at each pass's sample), recorded on every device: a device may answer such a read with the value at the pixel center extrapolated along the quad's coarse derivatives, as RADV does, where Metal interpolates in perspective at the location itself. The answer is first-order, off by the value's curvature across the distance, which grows with the triangle's spread of clipw: on a triangle ofw1, 2 and 4 over a 6x6 target, up to about 1.0 in a lane whose vertices hand 3, -2 and 0.5 (the Radeon 780M, Mesa 26.2.6). A no-perspective input is exact there and records nothing. It is the device's own interpolation, which Vulkan states no precision for.metal2vulkan-degrade-quads-split-by-clipping(precision).PrecisionNote::QuadsSplitByClipping: A fragment function runs a quad or simdgroup operation, recorded on every device: a device may shade a triangle it clips as several triangles, and then a quad a seam between the pieces crosses runs once per piece, each run with the other piece's pixels as helper invocations, so the operation counts or combines fewer active lanes than Metal's, whose quad holds all four.metal2vulkan-degrade-fragment-simdgroup-grouping(precision).PrecisionNote::FragmentSimdgroupGrouping: A fragment function runs a simdgroup operation (a reduction, scan, vote, ballot, shuffle, broadcast or AGX multiply-add) or reads its[[thread_index_in_simdgroup]], or discards, asksquad_is_helper_threadorsimd_is_helper_threadand runs a quad operation, on every device. A simdgroup operation runs over the pixels the device's rasterizer packs into a subgroup, so a sum, a ballot or a shuffle combines other pixels than on an Apple GPU, whose packing is measured, and the lane is the pixel's place in the device's subgroup, or in its aligned 32 lanes where the subgroup holds 64 or 128 (each such run of 32 lanes is one simdgroup, as[[threads_per_simdgroup]]'s 32 says). An Apple GPU also shades some quads of a function that discards as several partial quads from the function's start, each run holding the quad's other covered pixels as helpers, where the device shades them as one quad: a ballot of the helper query names covered pixels as helpers on the M3 Max (3 of the 16 quads of an 8x8 target, 2 to 4 of the 12 of a 7x5 one, under the full-screen triangle with every third pixel discarded) and none on the device. A device whose fragment subgroup holds fewer than two quads combines the one quad's pixels alone, so a reduction ahead of adiscard_fragmentcounts no quad the discard drops, where an Apple GPU's simdgroup counts the dropped quads of its 8x4 pixel block; the device states one fragment subgroup size, so no required size widens it, and no exact form exists there.metal2vulkan-degrade-blended-write-rounding(precision).PrecisionNote::BlendedWriteRounding: A fragment function writes a float to a half-float color channel of a render pipeline underTextureWriteRoundingMode::NearestEventhat blends with factors other than one and zero (ChannelWrite::BlendedNearestEven): Metal rounds the blend's result to nearest even, and the device's blend converts it by its own rounding (MoltenVK's toward zero), so a blended value off the half grid may store the neighbouring half; under a constant factor Metal's result is neither rule's on 2,376 of 580,508RGBA16Floatchannels near the half denormals.metal2vulkan-degrade-coverage-reads-rounded-alpha(precision).PrecisionNote::CoverageReadsRoundedAlpha: A render pipeline covers by alpha (alphaToCoverageEnabled) underTextureWriteRoundingMode::NearestEven, and its fragment function writes afloatalpha to a half-float attachment 0 that stores it as written: Metal stores the alpha rounded to the nearest-even half and reads the coverage from the alpha before rounding, which no device separates, so the function rounds the alpha and the coverage reads the rounded one. The stored alpha is Metal's; a fragment whose alpha lies within half ahalfstep of a coverage threshold may cover one sample more or fewer (2 of 16,384 alphas on an Apple M3 Max). Which samples an alpha covers is the device's own (device-alpha-coverage).metal2vulkan-degrade-device-alpha-coverage(precision).PrecisionNote::DeviceAlphaCoverage: A render pipeline covers by alpha (alphaToCoverageEnabled, over a four-component float first output at attachment 0), on every device. The device converts the alpha to its coverage mask by its own algorithm, which Vulkan does not specify ("It is intended that the number of 1's in this value be proportional to the alpha value", and "The algorithm may be different at different framebuffer coordinates"). Metal, measured over 639 alphas a sample count on an Apple M3 Max under macOS 27.0.1, covers a pixel at one sample above an alpha of 1/2, and at two and four samplesceil(alpha * n - t)samples,ta 2x2 ordered dither of the pixel's window coordinates (1/8, 5/8; 7/8, 3/8), either count within anf32ulp of a threshold. Recorded bound, pixel by pixel against Metal's reading: on lavapipe (Mesa 26.0.8, arm64) every pixel coversfloor(alpha * n)orceil(alpha * n)samples, so within one sample of Metal's and Metal's wherealpha * nis an integer; at one sample, where lavapipe dithers too, a whole fragment is stored or dropped where its alpha lies between its own threshold and 1/2 (2,560 of the sweep's 10,224 pixels); at four samples a pixel is one sample apart only within anf32ulp of a threshold (96 of 10,224). An NVIDIA RTX 5080 Laptop GPU stores a fragment of alpha 1/2 at one sample, where Metal drops it; every other device and count is unmeasured.metal2vulkan-degrade-rotated-blend-rounding(precision).PrecisionNote::RotatedBlendRounding: A fragment function writes an attachment held with its channels rotated (ARGB8Unorm) whose blend is not exact by construction (LoweringInputs::rotated_blends): every blend but a minimum, a maximum, and one whose Vulkan factors are allZEROorONE. A blend may compute a factor pair apart in its color and alpha arithmetic, as Apple's does, and the rotation moves Metal's blue into the image's alpha and Metal's alpha into its red, so a channel may store one code apart from Metal's.metal2vulkan-degrade-linked-sampler-numbering(precision).PrecisionNote::LinkedSamplerNumbering: The sampler resource IDs a pipeline state takes for the constexpr samplers of the visible functions its stage links may be other than Metal's: two or more linked functions bring constexpr samplers, which Metal numbers in an order the pipeline's inputs do not decide; or a function a table can hold that linking did not import could not be planned, so its samplers are not known; or a dynamic library's symbol, a binary function or a function-pointer group's function brings them, whose numbering is not measured.metal2vulkan-degrade-argument-pixel-sampler-scaling(precision).PrecisionNote::ArgumentPixelSamplerScaling: A sample, gather or comparison through an argument buffer's sampler whose word the specialized module cannot read may hand the device a pixel coordinate scaled by the texture's size, where the sampler states pixel coordinates, withpixel-sampler-scaling's bound. A sample through a state of nearest filters, one level and no anisotropy hands the device its texel's centre instead, where the device reads exactly Metal's texel but at a negative subnormal coordinate, whoseflooris the device's (device-denormals' reading, which this note records for such a sampler).metal2vulkan-degrade-half-output-precision(precision).PrecisionNote::HalfOutputPrecision: A fragment function returns ahalfcolor output (a scalar or vector of AIR'shalf) to an attachment the pipeline has, and either its module is compiled without fast math (air.compile.fast_math_disable) and that attachment blends, factors one and zero included, with some channel written (StageIo::half_blend_colors, which the pipeline's stage reads), or its module names no math mode (under fast math the pipeline's stage recordsPrecisionNote::HalfOutputFastMathBlendinstead).metal2vulkan-degrade-extended-range-blend-source(precision).PrecisionNote::ExtendedRangeBlendSource: A fragment function'shalfcolor output (a scalar or vector of AIR'shalf) is blended into a padded 10-bit attachment (R10Unorm_X6,RG10Unorm_X12, their_sRGBtwins,RGB10A2Unorm_sRGB), whose raw codes no device's blend unit reads, so the function blends in the shader in the device's arithmetic:S·Fs op D·Fdinfloat, in the blend equation's order, the source, second source and blend color unclamped, as Metal takes them there (a blend into one of Apple's extended-range formats is refused, section 4). The device's compiler may contract a product into its sum and may regroup the blend: MoltenVK on the M3 Max and NVIDIA's driver on an RTX 5080 compute a second source's blendS·F + D·(1 - F)asD + F·(S - D). Metal's compiler rounds each step tohalf, so a blended channel may store another code than Metal's: within two codes on a linear format and within six on an sRGB twin near zero, where its transfer is steepest, in the conformance suite's extended-range and padded blend cases; and where the device's compiler regroups a padded format's blend, an infinite second source stores the end code its sign picks where Metal's sum is NaN, stored as code 0.metal2vulkan-degrade-extended-range-float-blend-source(precision).PrecisionNote::ExtendedRangeFloatBlendSource:PrecisionNote::ExtendedRangeBlendSourcefor afloatcolor output (a scalar or vector of AIR'sfloat): blended into a padded 10-bit attachment in the shader in the device's arithmetic, which the device's compiler may contract and regroup, where Metal's compiler rounds the output and each step of the blend tohalf; a blended channel withinExtendedRangeBlendSource's bound of Metal's.metal2vulkan-degrade-anisotropic-filter(precision).PrecisionNote::AnisotropicFilter: The module samples a texture through an anisotropic sampler with Metal's anisotropic filter emulated by the device's samples at explicit levels (lower::sampler::anisotropic), on a device withoutsamplerAnisotropy, every Vulkan sampler being isotropic there, each tap the device's isotropic filter: a sample without comparison of a 2D texture or 2D array at the fragment's implicit level or with explicit gradients, or of a cube or cube array with explicit gradients, through a constexpr sampler ofmaxAnisotropyabove 1, or through a runtime sampler slot whose word states anisotropy (under that word alone). A device with the feature samples with its own anisotropic filter. The footprint's logarithms and powers are the device'sLog2andExp2, its level and spacing unrounded, and a linear mip filter's two levels the device's own blend at the fractional level, where Metal takes a piecewise-linearlog2, 256ths and 4096ths. Cost: a cube's taps step across its face by Metal's face gradients, and a tap past the face's edge reads the next face as the device projects it, which Metal's own is not measured against.metal2vulkan-degrade-device-anisotropic-filter(precision).PrecisionNote::DeviceAnisotropicFilter: The module samples a texture through a sampler whose anisotropy is known where Metal's anisotropic filter is not emulated (PrecisionNote::AnisotropicFilter's reach), on a device withoutsamplerAnisotropy, which filters it isotropically: a cube, a 3D texture, a comparison, a sample whose residency the function observes, or a texture of another class than its declared one, at an implicit level or with explicit gradients, through a constexpr sampler ofmaxAnisotropyabove 1 or a runtime sampler slot whose word states anisotropy (under that word alone). An argument buffer's anisotropic sampler, which the function cannot record, is refused there (SamplerAnisotropy).metal2vulkan-degrade-device-point-size(precision).PrecisionNote::DevicePointSize: A vertex function writes[[point_size]], or a mesh function that outputs pointsset_point_size, on a device whosepointSizeRangeends below Metal's largest point, 511 pixels (Limits::max_point_size: 255 on ANV, 256 on lavapipe). A line or triangle mesh's size draws nothing, and its function records no note. The render pipeline state carries the note whatever primitive a draw of it takes; a draw of lines or triangles of it is Metal's exactly.metal2vulkan-degrade-clipped-coverage-split(precision).PrecisionNote::ClippedCoverageSplit: A fragment function compiled for a multisampled pipeline reads[[sample_mask]], or reads a centroid varying and runs once per pixel, on every device (no query tells Apple's rasterizer apart): Apple's GPU draws a triangle that extends past the viewport as pieces whose shared edges cross pixels, and such a pixel's fragments can run once per piece, each reading that piece's coverage, where the device hands the pixel's fragment its coverage by the whole primitive (lavapipe by its own pieces). A centroid varying is read at the centroid of the whole coverage there.metal2vulkan-degrade-looped-sample-outputs(precision).PrecisionNote::LoopedSampleOutputs: A fragment function that reads[[sample_mask]], runs once per covered sample on Metal and writes an output runs once per pixel in a multisampled pipeline, its body once per covered sample, on every device. The samples Metal writes are written, but each with the last pass's outputs, where Metal writes each sample's from that sample's run: equal where every pass computes the same outputs. Vulkan hands an invocation under sample shading only its own sample's bit of the coverage.metal2vulkan-degrade-half-output-fast-math-blend(precision).PrecisionNote::HalfOutputFastMathBlend: A fragment function of a module compiled with fast math (air.compile.fast_math_enable) returns ahalfcolor output to an attachment the pipeline has that stores some channel (its write mask names one of its format's channels;StageIo::half_fast_colors, which the pipeline's stage reads, or the interlocked storage form's write), wherePrecisionNote::HalfOutputPrecision's conditions hold; or computes the blend of a 16-bit float attachment it fetches in the interlocked storage form (no Vulkan blend applies to a storage write) where Metal's compiler may fold the output's own arithmetic into that blend or regroup a sum of it: within 2halfunits in the last place of Metal's at the operands' magnitude, 16 at the stored value's under cancellation. Where the output is opaque to the blend and its form fits every measured state, the function's blend is Metal's and records nothing; so does the blend of a fetched 8-bit unorm attachment it computes there (every factor, operation, write mask and blend color it builds), which Metal reads the output into clamped, folding none of it (the storage image's store of its result is the device's conversion,DeviceColorConversion). Every device receives the output widened tofloat.metal2vulkan-degrade-device-sampling(precision).PrecisionNote::DeviceSampling: Native device sampler, on every device (the module requiresVkProperty::DeviceSampling), its level clamp the descriptor's as given (alodMinClamppast level 15, past every texture's last level, handed as 15, which reads the same level; Metal holds it on a1/64grid, and its nearest mip filter reads the lower level at a clamp halfway between two, where the device may read the upper) and a subnormal coordinate the device's to read (Metal reads a normalized one as a zero before addressing, and a negative pixel one as texel -1). That includes a linear sample of a two-plane YCbCr texture, whose texels hold Metal's reads exactly: the device's filter of them lands within 1.183 codes (1/255) of Metal's sum on the format's grid, so a draw binding such a texture makes no pipeline of its own.metal2vulkan-degrade-native-transcendentals(precision).PrecisionNote::NativeTranscendentals: Native device maths: the module computes afloatorhalfmath-library function by the device's ownGLSL.std.450instruction (exp,log,pow,sinh,coshandtanhamong them; a composition of the device'sExp2andLog2only forexp10andlog10, which no instruction is);fast::sqrtthe device'sSqrt, and ahalfsqrtits 16-bitSqrtwhere the module computeshalfin 16 bits under the 16-bit float controls; the fastsin,cos,tan,sinh,cosh,tanhandatanhthe device's instructions, not MSL's fast-math formulas (fast::sinof1e7is the device's sine, where Metal answers+0;fast::tanh(45)is1, where Metal answers NaN);fabs,signandfractthe device'sFAbs,FSignandFract, their special operands the instruction's (Metal'ssignof a NaN, a zero and anf32denormal is+0, itsfractof an infinity+0); ahalffunction's signed zeros and NaN signs itsfloatinstruction's (halfsin(-0)is-0, where Metal answers+0), and on every device ahalffmod's zero remainder itsfloatremainder's (halffmod(-2, 0.5)is-0, where Metal answers+0);pow,powrandatan2C99's special values by the device's comparisons around its instruction (pow(x, 1)the device'sPow, where Metal answersx; anf32denormal operand as the device reads it); androundC99's from the device'sTruncon every device (round(-0.3)is-0, where Metal answers+0).metal2vulkan-degrade-native-division(precision).PrecisionNote::NativeDivision: Native device maths: a precisefloatorhalfdivision, or Metal's fast division or reciprocal, is the device'sOpFDiv, on every device: within Vulkan's 2.5 ulp, where Metal's precise division is correctly rounded. Ahalfone is thefloatquotient rounded tohalf, or, where the module computeshalfin 16 bits under the 16-bit float controls, the device's 16-bitOpFDiv: within 2.5halfulp, its divisor scaled by a power of two into[2^-14, 2^14].metal2vulkan-degrade-native-fma(precision).PrecisionNote::NativeFma: Native device maths: afloatfused multiply-add on a device withoutOpFmaKHR, or ahalfone where the device has no 16-bitOpFmaKHRunder the 16-bit float controls, is the device'sGLSL.std.450 Fma(on thehalfoperands held infloat, its result rounded tohalf), where Metal's rounds once. On a device that computeshalfin 16 bits under the 16-bit float controls, ahalfone is the device's 16-bitFmaon thehalfoperands. Recorded bound: ahalfresult held infloatwithin onehalfulp of Metal's; afloatone, and a 16-bit one, within half an ulp of the product plus half an ulp of the result, in its own format.metal2vulkan-degrade-device-texel-conversion(precision).PrecisionNote::DeviceTexelConversion: Native device sampling (a texel conversion): the module hands a read, sample or gather with afloatresult the device's own conversion of the texel's codes, on every device. Recorded bound, of a texel read from one texel of one level: an 8-, 10- or 16-bit normalized code within onef32ulp of Metal'sc / (2^b - 1)where measured (lavapipe multiplies by the reciprocal: some 8-bit codes one ulp high; some 10-bitBGR10A2Unorm, a 16-bit and 512Depth16Unormcodes one ulp low), and a 10-bit code within 0.015 of a code where the device widens it by replicating its bits to 16,(c << 6 | c >> 4) / 65535(NVIDIA's RTX 5080 Laptop GPU); a 4-, 5- or 6-bit channel of a packed format within onef32ulp where the device converts it by the reciprocal (lavapipe: someABGR4Unormcodes one ulp high), and within 0.18 of a code where it widens a 5- or 6-bit channel by replicating its bits (ANV, NVIDIA; a 4-bit channel's replication is exact); a half-float or small-float texel's NaN in the device's encoding, where Metal answers0x7fc00000; a 32-bit float texel's NaN in a gather in the device's encoding, and its denormal in a gather a zero of its sign, where Metal hands back the texel's bits (NVIDIA's 615.71.09 on the RTX 5080 Laptop GPU gathers every NaN as0x7fffffffand every denormal as a zero); a 32-bit float texel's NaN in a nearest sample in the device's encoding, and its denormal there a zero of its sign on a device that flushes it there (ANV's Mesa 26.2.6 on the Iris Xe samples every NaN as0xffc00000and every denormal as a zero of its sign, and reads and gathers both as stored; RADV's Mesa 26.2.6 on the RX 7900 XTX and the Radeon 780M samples a denormal as a zero and gathers it as stored); every other class Metal's value.metal2vulkan-degrade-device-vertex-conversion(precision).PrecisionNote::DeviceVertexConversion: Native vertex input (a conversion): a render pipeline's vertex descriptor gives a normalized format (UCharNormalizedthroughShort4Normalizedof either sign,UChar4Normalized_BGRA,Int1010102Normalized,UInt1010102Normalized) to an attribute that fixed-function vertex input fetches, so the attribute is the device'sUNORMorSNORMconversion of its codes, where Metal's fetch answers the code over its maximum correctly rounded (anInt1010102Normalized10-bit field timesfloat(1/511)): within onef32ulp where measured (lavapipe reads some 8-bit unsigned codes one ulp high), but lavapipe's per-instance fetch, which reads the most negative code of an 8- or 16-bit signed format unclamped (-128/127, -32768/32767) where Metal reads -1. Recorded on the pipeline's vertex stage on every device; one module serves every format the device fetches. A normalized attribute the shader pulls from its buffer instead (an offset, stride or step fixed-function input cannot fetch, a kernel's[[stage_in]]attribute) is the module's product of the code and its maximum's reciprocal, rounded once, the signed one clamped to -1: within onef32ulp of Metal's quotient (some 8-bit unsigned codes one ulp high, some signed, 10-bit and 16-bit codes one ulp toward zero; 0, the maximum and -1 exact). The function records it on every device, read asfloatfor every normalized format butInt1010102Normalized(Metal's own product), and read ashalffor a 16-bit format (onehalfulp at four codes).metal2vulkan-degrade-native-half-conversion(precision).PrecisionNote::NativeHalfConversion: Native half rounding (a conversion): the module rounds ahalfresult it computes infloat(ahalfoperation's, a function's, a conversion fromfloat's, a texel's) by the device's conversion of thefloatto 16 bits and its widening, on every device withshaderFloat16. Without the float controls that make that conversion Metal'shalf(float)(RoundingModeRTE,DenormPreserveandSignedZeroInfNanPreservefor 16 bits) the conversion is the device's own. Under them it is Metal's by the Vulkan spec, but a driver's compiler may fold the conversion's round trip into the value it started from (NVIDIA's does) or fuse thefloataddition, subtraction, multiply or fused multiply-add computing the value into the narrowing and round its exact result once (RADV's does, onehalfulp from Metal's where thefloatresult lies on ahalfmidpoint), so a pipeline that rounds through the pair records the note there too, a static note of the rounding. Under those controls ahalf+,-,*,/andsqrtare the device's 16-bit instructions, whose results take no such rounding. Also recorded where ahalfread from its bits is the device's widening, or ahalfencoded to its bits (where they are not the bits it was read from) is the device's narrowing, and that conversion is not under those controls: the device's conversion without them, andGLSL.std.450 UnpackHalf2x16andPackHalf2x16on every device withoutshaderFloat16. A half denormal may read or encode as the zero of its sign.metal2vulkan-degrade-native-half-quantize(precision).PrecisionNote::NativeHalfQuantize: Native half rounding (a quantize): the module rounds ahalfresult it computes infloat(ahalfoperation's, a function's, a conversion fromfloat's, a texel's) by the device'sOpQuantizeToF16alone, on every device withoutshaderFloat16, its quantize measured or not: a value below the smallest normalhalfmay round to a zero where Metal answers the half denormal (or2^-14, from just below it). An integer'shalfrounds exactly instead.metal2vulkan-degrade-native-nan-encoding(precision).PrecisionNote::NativeNanEncoding: Native device maths: afloatorhalfoperation's NaN result is the device's, its sign and payload unselected, where Metal answers a NaN, on every device: afloatfnegandfabs, which keep a NaN operand's payload on Metal, ahalffract, which returns it, and a precisefloatpowof a NaN base to the exponent one, which returns the base, among them. Afloatldexp, which the module computes on the bits, returns a NaN operand itself as Metal does, on every device, and records nothing. Also recorded wherever ahalfis read from its bits, on every device, since the read is the device's widening (its conversion withshaderFloat16,UnpackHalf2x16without): a NaN's bits the device's, where Metal widens everyhalfNaN to0x7fc00000and moves one it does not widen with its bits. And wherever ahalfis encoded to its bits (a store, a reinterpretation, a texel's bits) where they are not the bits it was read from (ahalfmoved unchanged from its read keeps them, through a struct's member too), on every device, since the encode is the device's narrowing (its conversion withshaderFloat16,PackHalf2x16without): a NaN's bits the device's, where Metal keeps ahalfNaN's sign and payload.metal2vulkan-degrade-native-min-max(precision).PrecisionNote::NativeMinMax: Native device maths: Metal'sfmin,fmax,min3,max3,clamporsaturate(itsclamp(x, +0, 1)) onfloatorhalfis the device'sGLSL.std.450NMin,NMaxorNClamp, andmedian3min(max(c, min(a, b)), max(a, b))of the device'sNMinandNMax, on every device, whose pick of two NaNs and of anf32denormal is the device's. The result is one of the operands, Metal's but at three ties (of two NaNs a NaN of the device's bits, where Metal answers the second operand's; of+0and-0either zero; anf32denormal beside a zero or a denormal compared by its value, where Metal compares it as a zero and answers the second) and one undefined answer:fast::median3of two NaN first operands and a number answers the number, as precisemedian3does on Metal, where Metal's fast form answers the second NaN. MSL leaves a NaN operand under fast math undefined (section 8.1).metal2vulkan-degrade-native-dot(precision).PrecisionNote::NativeDot: Native device maths: Metal'sdotonfloatandhalfis the device'sOpDot(ahalfone summed infloatand rounded once tohalf, or the device's 16-bitOpDotwhere the module computeshalfin 16 bits under the 16-bit float controls), not Metal's fused chain of its products, on every device.metal2vulkan-degrade-native-mix(precision).PrecisionNote::NativeMix: Native device maths: Metal'smix(x, y, t)onfloatandhalfis the device'sFMix(ahalfone computed infloatand rounded once tohalf, or the device's 16-bitFMixwhere the module computeshalfin 16 bits under the 16-bit float controls), not Metal'sfma(t, y, fma(-t, x, x)), on every device.metal2vulkan-degrade-native-logic-operation(precision).PrecisionNote::NativeLogicOperation: A render pipeline's private logic operation (other than copy and no-op) is drawn by the device'slogicOpinto anRGB10A2Unorm,BGR10A2Unormor signed normalized attachment the fragment function writes, with a channel its write mask keeps. Vulkan's operation takes the fragment's value converted to the channel's own code and the stored code as it is, and stores its result as it is; Metal widens a 10-bit (or 2-bit) code and the fragment's to 16-bit codes, operates, and narrows the result to the channel's code, rounded to nearest, and reads a signed channel's lowest code (0x80, or0x8000) as the code above it and stores a result of the lowest code as the code above (probelogic_operationon an Apple M3 Max, macOS 27.0.1). So a channel may store another code than Metal's (lavapipe's xor intoRGB10A2Unormstored green 938 where Metal's rule gives 937, and its xor of0xe0over anRGBA8Snormchannel's0x80stored0x60where Metal's gives0x61), by a distance the note does not bound: the result follows the codes' bits. The device'slogicOpis its native form there, and no other form is built for it; a device withoutlogicOpcomputes Metal's rule in the fragment function and records none. A signed channel the draw does not write (outside the write mask, or every channel under no-op) keeps its lowest code where any draw's unwritten texel does (snorm-minimum-kept).metal2vulkan-degrade-native-float8(precision).PrecisionNote::NativeFloat8: A tensor's 8-bit float element (MTLTensorDataTypeFloat8E4M3orFloat8E5M2, which amatmul2dproduct reads) widens through the device's own 8-bit float on a device withshaderFloat8(SPV_EXT_float8'sFloat8E4M3EXTorFloat8E5M2EXT, OCP's encodings), the only form there: an e4m3 code0x7For0xFFreads as a NaN, where Metal reads 480 and -480 (measured on the M3 Max), and an e5m2 NaN's bits are the device's, where Metal reads0x7FC00000. Every other code reads Metal's value. A device withoutshaderFloat8decodes the fields with integers, as Metal reads them, and records none. Anair.convertfromf8e4m3fnorf8e5m2and a simdgroup-matrix cell of those formats widen through the same type there and record none: their formats are OCP's own, and Metal on Apple M3 does not compile them.metal2vulkan-degrade-device-depth-bias(precision).PrecisionNote::DeviceDepthBias: A draw of triangles under a depth bias (setDepthBias:slopeScale:clamp:with a bias or a slope scale other than 0) onmetal2vulkan-runtime, whose render encoder carries it as a static note (RenderCommandEncoder::DEPTH_BIAS_NOTE): the biased depth is the device's. Vulkan biases bym × slopeScale + r × depthBias, where the maximum depth slopemis the device's (exact, or the larger of the two derivatives' magnitudes) and the unitris2^(e - n)of the primitive's largest depth exponent for a float depth attachment and the device's for a fixed-point one (at most2 × 2^-n). Apple's documentation states neither the slope measure nor the unit. A draw of lines is not biased, as Metal biases triangles alone.metal2vulkan-degrade-swizzled-opaque-black-border(precision).PrecisionNote::SwizzledOpaqueBlackBorder: A sampler that reads its border (ClampToZeroorClampToBorderColoron an axis, both of which read the sampler's colour) with an opaque-black border colour. A sampler state carries it as a static note (SamplerState::precision_note), decided by its descriptor alone on every device; a compute or render pipeline whose function samples through such a constexpr sampler carries it among its notes (precision_notes), decided by the sampler's own constants. Sampled through a view whose Vulkan component mapping is not the identity (the texture's swizzle, or the mapping its pixel format takes), its border texel is the device's answer on a device withoutborderColorSwizzleFromImage(VK_EXT_border_color_swizzle): Vulkan leaves it undefined unless the sampler names the view's mapping, which a sampler that meets every view cannot, and the NVIDIA driver reads(0, 0, 0, 1), where Metal reads the border colour in the format's channels through the swizzle. A device with the feature reads Metal's texel.metal2vulkan-degrade-device-line-rasterization(precision).PrecisionNote::DeviceLineRasterization: A render pipeline state that enables alpha to coverage or alpha to one, which carries it among its notes (precision_notes), decided by its descriptor alone. Its lines are drawn by the device's default rule, not Bresenham's, which Vulkan takes with neither (VUID-VkGraphicsPipelineCreateInfo-lineRasterizationMode-02766). Metal covers the pixels whose diamond a line exits; a device whosestrictLinesis set (lavapipe, NVIDIA's driver) covers the rectangle of the line's width instead, so the pixels at a line's two ends, and on either side of a pixel boundary the line runs along, may differ from Metal's. Every other state draws its lines by Bresenham's rule (bresenhamLines, the runtime's floor).metal2vulkan-degrade-device-pack-conversion(precision).PrecisionNote::DevicePackConversion: Native device maths (a conversion):air.packorair.unpackof a normalized format is the device's:GLSL.std.450'sPack/UnpackUnorm4x8,Snorm4x8,Unorm2x16andSnorm2x16, their definition by the device'sNClamp, multiply,RoundEvenand reciprocal forrgb10a2andrgb565, and the MSL transfer functions by the device'sPowforunorm4x8_srgb's colour. Metal rounds the exact product and divides correctly rounded (unorm565infloat: the product rounded tofloatfirst, and the code times thefloatnearest the reciprocal, as the definition does), answers code 0 for a NaN channel, and takes an sRGB colour through its twelve-bit table; a packed code is within one of Metal's, an unpacked value within 2.5 ulp, a decoded sRGB colour within half a twelve-bit step (1 / 8190) of Metal's step beyond itsPow's bound. Also a write of an 8-bit sRGB storage texture held through its UNORM alias (at a slot, or held by an argument buffer), which encodes byunorm4x8_srgb's pack. Recorded on every device. The same conversions serve an implicit imageblock access of a normalized attachment (ahalfload rounding the unpackedfloatonce more), a fragment function's read and write of an 8-bit sRGB attachment in the interlocked storage form or through its word view, and a snapshot read's decode of a normalized code (ctimes thef32nearest1 / D), noted alike. So does every conversion of an extended-range, padded 10-bit or bfloat texel (BGR10_XR,BGRA10_XR,RGB10A8_2P_XR10,R10Unorm_X6,RG10Unorm_X12, their sRGB twins,RGB10A2Unorm_sRGB,R16Bfloat,RG16Bfloat,RGBA16Bfloat), which no Vulkan format holds: a read isfloat(c - 384)(a padded codec) times thef32nearest1 / 510(1 / 1023), a writeRoundEvenof the clamped value'sf32product plus 384, an sRGB twin's colour the MSL transfer by the device'sPowon the magnitude, ahalfresult the device's narrowing, a bfloat code's NaN as it is (a write's kept a NaN by its quiet bit). Metal divides correctly rounded, rounds the exact product, rounds ahalfwith ties away from zero, converts the sRGB twins through its own tables, makes a bfloat NaN0x7fc00000or0x7fc0, and rounds a bfloat sample'shalftoward zero: a linear value within onef32ulp, a code within one (R10Unorm_X6_sRGB's andRGB10A2Unorm_sRGB's colour within two below0.0031308, where Metal rounds the value to2^-13before its table, a step there spanning 1.6 codes), an sRGB twin's decoded value within half a2^-13step of Metal's table (R10Unorm_X6_sRGB's andRGB10A2Unorm_sRGB's colour 1.64 steps) beyond thePow's bound, ahalfresult within onehalfulp. A texture a heap holds by its raw texels alone (BGR10_XR,BGRA10_XR,R10Unorm_X6,RG10Unorm_X12and the bfloat formats:bind::heap_raw_form), whosefloatread, sample or gather through an argument buffer the function decodes the same way: such a stage records the note as a specialized note, holding where a texture its handles can name is one (SpecKey::HeapRawTextures, which the binding plan gives from the textures the command makes resident or binds), so a reading of the module alone holds it, and so does a command that can name one.metal2vulkan-degrade-device-fragment-runs(precision).PrecisionNote::DeviceFragmentRuns: A fragment function that writes memory (StageInterface::writes_memory) in a render pipeline of more than one sample, which the pipeline's compile records on its fragment stage, decided by the sample count and the function's writes alone. It runs as many times per pixel as the device runs it, each run reading the pixel's whole coverage as[[sample_mask]], so its writes repeat as often as the device's runs, and whatever it derives from its own writes across runs follows the device's count too, its stored colours and[[sample_mask]]output included, not only memory. Apple's GPUs were measured to run it once per covered sample; documented Metal names no count (MSL section 5.5 makes a function run per sample only for a sample-qualified input,[[sample_id]]or[[color(m)]]). Vulkan runs a fragment shader without sample shading at least once per pixel and more where the device chooses (vkspec 35.5).
10. Accepted differences
Where the runtime answers otherwise than Metal on purpose, the difference is listed here. Most carry no degrade notice, since nothing is slower or approximate for them; an entry whose answer is the device's own names the static note its stage records. Most are answers Metal leaves undefined or ends the process for, and answers the runtime adds beyond Metal's API. The rustdoc of each item named states the rule in full.
Draws
- A point near the viewport's edge or the clip volume is clipped or culled by the device's own
rule: its
pointClippingBehaviorand the driver's handling of the viewport. Metal states no clipping rule for a point (MTLPrimitiveType.point; the MSL specification's[[point_size]]). Measured, Metal on an Apple M3 Max keeps a point whose centre lies within 1.5 w of the viewport's centre and covers its square whole, past the viewport's edge, where lavapipe covers no pixel whose centre lies on or past that edge and culls no point at the clip volume (the conformance casepoint-viewport-coverage). - A line's tie-break is the device's own. Lines draw by Bresenham's rule, which is Metal's
(
bresenhamLines, the runtime's floor): the pixels whose diamond the line exits. Vulkan's diamond is open (|p - x| + |q - y| < 0.5), so a line that only touches a diamond's vertex exits neither diamond the vertex joins, and no Vulkan control decides which pixel a conforming driver covers there. Measured, where a line of the conformance caseprimitive-type-restart-indicesruns through the boundary point (3.5, 1.0), Metal on an Apple M3 Max covers the lower pixel and NVIDIA's driver on an RTX 5080 the upper. - A memory-writing fragment function runs as many times as the device runs it. Metal's GPUs
were measured to run a memory-writing fragment once per covered sample; documented Metal names
no count; here the count is the device's, for its memory writes and for anything it derives from
them across runs, stored colours and sample mask included. The pipeline's fragment stage records
PrecisionNote::DeviceFragmentRuns(section 9). The conformance casea2c-off-4-alpha-50records four runs of a fully covered pixel at four samples on an Apple M3 Max, and compares the runs word as nonzero alone.
Resource IDs and identifiers
- A nil, stale or forged texture or sampler ID reads a defined element. A texture ID no live texture holds reads a null descriptor: zeros, 0 to its size and level queries, and its writes dropped. A sampler ID no live sampler state holds samples through its array's default sampler, nearest and clamped to the edge, and a comparison through it answers 0. The Metal Shading Language leaves every member function of a null texture undefined (section 6.13.18), and Metal's read through a stale or forged ID is undefined.
- Two live textures with one ID: a function reads the holder, the texture placed there last.
Render passes
-
The runtime's
DontCarestore writes what the pass rendered (metal2vulkan-runtime's render encoder stores aDontCareattachment as it stores aStoreone, its README's render passes). Apple's page forMTLStoreAction.dontCare: "The GPU has permission to discard the rendered contents of the attachment at the end of the render pass, replacing them with arbitrary data." and "Some GPUs may still store the contents back to the texture, but you can't rely on that behavior. You need to assume that GPU discarded the texture's contents."MTLRenderPass.hstates only that it is the default store action. An Apple M3 Max on macOS 27.0.1 leaves the texels of a texture over a buffer as they were before a clearing pass; the runtime stores the clear there. The bytes of the buffer outside the texels keep what they held on both. -
A barrier over the render targets orders what it names, as a Mac2 GPU's does. The Metal Feature Set Tables give
MTLBarrierScopeRenderTargetsto Mac2 GPUs, not to Apple GPUs, and an M3 Max (macOS 27.0.1) orders nothing with it: a draw after one that samples its own pass's color attachment's texture reads the texels from before the pass, whatever the pass's load action or draws wrote before the barrier. The runtime orders the draws before such a barrier ahead of the next draw that reads an attachment of the pass, which reads what they rendered (the runtime's README, Render encoders). The conformance casespass-start-barrier-*keep the M3 Max's texels and take the Mac2 answer as the one other. -
A draw that reads its own pass's color attachment with no barrier reads, at the pass's first such draw, what the load and the draws before it rendered: the runtime orders them ahead of that draw (the runtime's README, Render encoders). Metal defines no answer here, and the Macs disagree: an M3 Max (macOS 27.0.1) read the texels from before the pass at every pixel, in a pass that clears too; an AMD Radeon Pro 5300M and an Intel UHD Graphics 630 (macOS 26.7.1) read the earlier draw's texels at 98.6% and 99.99% of the pixels, and at all of them after a barrier over the render targets; the rest read the load's or the clear's texels.
Heaps and memory
- The runtime answers as a Mac that keeps no texture compressed, as a Mac with an Intel or
AMD GPU keeps none, where an Apple silicon Mac's GPU keeps textures losslessly compressed: a new
texture reads zero until written (the runtime's README, Textures), where an Apple silicon Mac's
new
Privatetexture reads zero or the compressed texture's fixed pattern, and a GPU blit through any texture keeps its bytes, where Apple's blit through a compressed texture writes some formats' canonical encoding. Metal leaves a new texture's contents undefined. The conformance suite's venue on the runtime presents no compression, so the answers such a Mac gives hold there. - The runtime's heap texture size and alignment are the device's own (
metal2vulkan-runtime'sDevice::heap_texture_size_and_align, its README's textures): the device's own image requirements, not Metal's, the size rounded up to and the alignment raised to the device'sbufferImageGranularity, so a buffer placed by the same answers never shares a granularity page with the texture. The answers differ by device, so the consumer places by this device's. The conformance suite does not compare the two numbers with Metal's; it holds each answer to three steps: (1) the alignment is a power of two; (2) a Private descriptor's texture is made at offsetalignin a heap ofalign + sizebytes; (3) there, level 0's first slice written from a buffer reads back unchanged. A Shared, Managed or Memoryless descriptor is held to step 1 alone, as the runtime places heap textures in Private blocks only. A descriptor whose bytes the runtime does not move (depth and stencil both, multisample,Depth32Float) is held to steps 1 and 2. - Apple's private texture usage bits are kept in
TextureUsage(NO_CONCURRENT_ACCESS,VIDEO,BLOCK_WRITES_ONLY). - A heap's buffer and texture over the same bytes alias them, in the device's layout, not Apple's tiled or compressed one.
- The runtime's Managed copies read the consumer's bytes when the GPU reaches them
(
metal2vulkan-runtime'sBuffer::did_modify_rangeandTexture::upload_region). A Managed buffer with a device copy (on a device that is neither integrated nor a CPU) takes its named ranges into that copy at the next commit of a command buffer with commands, on any queue, by device copies ahead of that command buffer's commands; a Managed texture's uploaded region is one device copy from its named bytes into its image, ahead of every command buffer committed after the call on every queue. The copy reads the bytes as they are when the GPU runs it, so a write the consumer makes after the commit and before then may be seen. Metal leaves it undefined: an Apple M3 and an Intel UHD 630 take the bytes when the GPU reads them, an AMD Radeon Pro 5300M at the commit.
Function constants
- A function constant the request leaves undefined reads as zero. A value computed from it
alone is its type's zero (an
and,orormulwith a constant that decides it is that constant), and a branch orselecton one takes its false way; a value it meets with one the run computes is computed with that zero. As Metal's,is_function_constant_definedis false for it and an argument gated on it, negated or not, is absent. Metal makes the same pipeline of a specialized function (made with constant values, none among them too, or bynewFunctionWithDescriptor:), and its reads of the constant vary from read to read: on an M3 Max under macOS 27.0.1 it readu + 3as 0,u * 7 + 1as 1,u == 0 ? 111 : 222as 222 andb ? 5 : 6as 5. The compile is the same for a function made bynewFunctionWithName:, which Metal makes no pipeline state of where its function declares a constant: its creation ends the process at every stage ("function ko cannot be used to build a pipeline state. Use newFunctionWithName:constantValues:... to get the specialized function"), whether the constant is required, read only whereis_function_constant_definedsays, or only gates an argument.FunctionDescriptor::needs_specializationanswers it (FunctionDescriptor::specializedand the function'sfunction_constants_dictionary); the runtime does not ask it and makes the state, each constant without a value reading as above. A linked function keeps its own rule (section 3, "Linked functions: names and constants"). - A fast-math float operation of a NaN function constant and a value the run computes stores
that NaN. An
fadd,fsub,fmulorfdivthat carriesnnan(Metal's default fast math) and whose operand is a function constant bound to a NaN ispoisonin the AIR once the constants are bound, so any value is a correct answer for it. The translation answers the NaN operand, its bits unchanged, as it does for the same operation without fast math, where that NaN is Metal's answer. Metal answers a NaN for a fragment function's output of it on an Apple M3 Max, an AMD Radeon Pro 5300M and an Intel UHD Graphics 630 under macOS 27.0.1. On the M3 Max a kernel's store of it writes nothing,floatandhalfalike, and the memory keeps what it held, while the same kernel's store of the run value is written (the fixturesfold_fast_poison, case2d9a7e3091e1f9d9, job m3-max-12877; the case stays out of the corpus, whose comparisons are exact). - A linked function's constant without a value reads as zero too, where the function was made
specialized (section 3, "Linked functions: names and constants"). Metal makes that pipeline,
and its read is undefined: a kernel storing
x * scale + 1of such a function stored nothing on an M3 Max under macOS 27.0.1. - A program-scope constant that the function constants make a division by zero reads as an
undefined constant reads. A static initializer's scalar integer division or remainder by
zero (
udiv,sdiv,urem,srem) has a result the AIR leaves undefined, and so does everything computed from it: the translation reads it as zero, and a branch orselecton it takes its false way, as for a constant the request leaves undefined. Metal makes that pipeline on an M3 Max under macOS 27.0.1 and stores nothing of the quotient, nor of a value chosen by it; where a loop's trip count is computed from it, the kernel stores nothing at all (the probestatic_init_division.m). A vector division with a zero lane is stillUnsupported{StaticInitializer}.
Linked functions
- A reference of another type reads zero or its arguments' bits where Metal's read is
undefined (section 3, "Linked functions: types"). A parameter the reference passes nothing
for reads zero, as Metal's read zero on an M3 Max under macOS 27.0.1 and on a Radeon Pro 5300M
and a UHD Graphics 630 under macOS 26.7.1. An argument of another width passes its low bits to a
narrower parameter, as the 5300M did for a
floatpassed to ahalf, where the M3 Max and the UHD 630 left the parameter undefined (a kernel storing a value computed from it stored nothing); it passes its bits with zeros above to a wider parameter, and a result of another width or one a definition returning nothing gives passes the same way or reads zero, where the M3 Max stored nothing. - A reference passing a pointer for a value or a value for a pointer, a pointer of another
address space, or an aggregate of another type is refused (
Unsupported,Feature::Linking), where Metal makes the pipeline: on the M3 Max each such read was undefined (the kernel stored nothing); on the 5300M a value for a pointer read the pointer's low 32 bits and aconstantpointer for adeviceone read through it.
Conversions
-
air.convertwith a rounding (.rte,.rtz,.rtp,.rtn) and.satafter its types is honored in a compute pipeline of OpenCL mode and is the conversion its types name elsewhere. Apple's OpenCL compiler spells these on everyconvert_<type>[_sat][_<mode>].In OpenCL mode (
ComputePipelineDescriptor::open_cl_mode_enabled) Metal honors them. Measured over OpenCL C of our own, one work-item per operand (probe jobs m3-max-15651 on a Radeon Pro 5300M and m3-max-15652 on a UHD Graphics 630, both macOS 26.7.1):Form, OpenCL mode Radeon Pro 5300M UHD Graphics 630 Runtime integer of 8 to 64 bits to float,.rtz,.rtp,.rtnrounded as named rounded as named rounded as named floatto an integer of 8 to 64 bits,.rte,.rtp,.rtnrounded as named, then clamped where .satas the 5300M, but a uintof 2^31 or more is0x7fffffffand aucharwith.satabove 127 is 127rounded as named, then saturated (the 5300M's answer) integer to integer, .satclamped to the destination's range clamped to the destination's range clamped to the destination's range a halfside, any suffixno pipeline no pipeline the conversion its types name An integer to
floatby.rte, afloatto an integer by.rtz, and an integer to an integer with a rounding and no.satare the conversion their types name on both, as on the runtime. Neither creates a pipeline of OpenCL mode for a conversion with ahalfside (its library compiles), so no Metal answer exists for one, and the runtime makes the pipeline. The device has no directed conversion (Vulkan's integer-to-float conversion rounds in a direction of its own, its float-to-integer one truncates), so the runtime builds each exactly: afloatis rounded to an integral value (RoundEven,Ceil,Floor) before the conversion, and the device's conversion of an integer tofloatmoves one unit in the last place where it lies on the wrong side of the integer.Outside OpenCL mode Metal's compilers do not answer them alike. Measured over the owned fixture
kernel_convert_rounding_modes's edge values, one kernel per form (probe jobs m3-max-14380 on a Radeon Pro 5300M and m3-max-14381 on a UHD Graphics 630, both macOS 26.7.1; m3-max-14382 on the M3 Max, macOS 27.0.1), the runtime differs from a Mac in three places:Form M3 Max Radeon Pro 5300M UHD Graphics 630 Runtime float to integer, .rterounds to nearest even truncates no pipeline truncates float to half,.rtz,.rtp,.rtn.rtzas named; no pipeline for the othersnearest even as named nearest even float to integer, .satan unsigned destination keeps a negative's wrapped bits; a longof an infinity is 0, past its range wrapsan 8-bit destination is not clamped; a longis clamped toint's rangeno pipeline clamps, as its conversion without the suffix Everywhere else every Mac that creates the pipeline answers the conversion without the suffix, which is no difference: an integer to
floatorhalfby any rounding is rounded to nearest even (the M3 Max creates no pipeline for a directed one), an integer to an integer with.satwraps (the M3 Max creates none), and a float to an integer by.rtpor.rtntruncates on the 5300M (the others create none). The M3 Max's compiler service exits on the forms it does not compile, where the runtime compiles them all. -
vstore_halfandvstorea_halfwith a rounding (_rtz,_rtp,_rtn) store each lane as the device converts afloattohalf, to nearest even. Measured over 32 values among them ties, overflows past the largesthalf, subnormals and zeros, with thevstore_half4forms alike (probe jobs m3-max-15563 on the M3 Max, macOS 27.0.1; m3-max-15564 on a Radeon Pro 5300M and m3-max-15584 on a UHD Graphics 630, macOS 26.7.1):Form M3 Max Radeon Pro 5300M UHD Graphics 630 Runtime vstore_half_rtz,_rtp,_rtn(70000.0by_rtz)as named ( 0x7bff)nearest even ( 0x7c00)nearest even ( 0x7c00)nearest even ( 0x7c00) -
A float past an integer's range converts to the integer's nearest bound, a
longof an infinity too, where Metal's is 0. MSL states two answers of a conversion from a floating-point type to an integer (MSL 8.6): it rounds toward zero, and a NaN converts to 0. Metal's compiler spells every such conversion of MSL as anair.convertcall (measured overint,uint,static_castand two-lane vector forms offloatandhalf, in a kernel and in fragment functions, with fast math on and off: probe job m3-max-55309, Metal compiler 32023.922), which the runtime converts so, and which takes a value past the destination's range to its nearest bound. Metal on the M3 Max (macOS 27.0.1) answers the same at every width fromchartoulong, fromfloatand fromhalf, but converts either infinity to alongas 0, whereulongof +inf is its maximum (conformance casenan-to-integer-conversions). A plain LLVMfptosiorfptoui, which Metal's compiler does not emit, is Vulkan'sOpConvertFToSorOpConvertFToU, whose result for a NaN or a value its integer cannot hold SPIR-V leaves undefined: the device's own.
Inline assembly
- An empty
asm volatile("")is no compiler barrier. It is the one inline assembly MSL accepts (a template, an operand or a clobber is an "illegal asm statement"), and it assembles to no instruction: the translator drops its call,asm sideeffect "", ""of typevoid (), with no notice. In Metal it acts on the compiler alone: no memory access moves across it, and a loop that holds it is kept. Only a racy spin loop over plain (non-atomic) memory can tell the difference, and MSL's memory model leaves that loop undefined; a loop with a visible effect runs every iteration either way. Any other inline assembly, which only hand-written AIR can hold, is refused where an entry reaches it (Feature::InlineAsm).
Kernels
- A buffer argument a kernel only reads is read-only memory to the device where the AIR
declares the argument unaliased (the
air-buffer-no-aliasattribute, which the AIR of Metal's current compiler carries on every buffer argument) and no store, atomic, volatile or coherent access of the kernel reaches it, through the argument or through a pointer its address may come back as: its views are decoratedNonWritable, and under the identity domains (the runtime) its device-address loads go throughNonWritableplaces. Under the identity domains aconstantbuffer argument is read-only memory too, whether or not the AIR declares it unaliased: Metal'sconstantaddress space is read-only. A dispatch that binds memory to such an argument and to an argument the kernel writes may read those bytes as they were before its own writes, where the device reads read-only memory through another path (RADV reads a uniform address of it with a scalar load). The attribute states that no other argument reaches that memory. - A dispatch that reaches a buffer bound off its argument's alignment is refused (the
alignment the kernel's AIR states for the argument,
air.arg_type_align_size, at most 16;RuntimeFact::AddressAlignment): the runtime refuses the dispatch (Refusal::BufferOffsetAlignment) where the bound address, the buffer'sgpuAddressplus the offset, is not a multiple of it, before anything is recorded, as Metal's API validation refuses such a bind offset ("must be a multiple of 4 but was set to 2" for auint *argument). Without validation an Apple M3 Max (macOS 27.0.1) runs it, reaching each element at its address rounded down to the smaller of the element's alignment and 4, for loads, stores and pointers stored in a buffer alike (crates/metal2vulkan-conformance/probes/misaligned_buffer_binds.m). - A recursive call past the call stack yields zero: the stack holds what Metal's byte model
holds for the pipeline's
max_call_stack_depth; a call that finds it full returns zero, where Metal's answer is corrupt. - The threads of a SIMD-group run in no order between barriers under the identity domains (the
runtime), where an Apple GPU runs them in lockstep: the Metal Shading Language orders their
memory accesses only through barriers and atomics, and calls two of them that conflict between
barriers a data race. A kernel holding such a pair carries the static note
PrecisionNote::SimdgroupAccessOrder(metal2vulkan-degrade-simdgroup-access-order). - A simdgroup barrier in divergent code waits for its tangle, as SPIR-V defines it. The Metal
Shading Language requires every thread of the SIMD-group to execute a
simdgroup_barrierthat any of them executes in a conditional or a loop iteration, so Metal defines no answer there. - A state whose descriptor requires a threadgroup size answers that size's threads as its
maxTotalThreadsPerThreadgroup, lowered only to the device's own limit (ComputePipelineState::max_total_threads_per_threadgroup). A compute state compiled by Metal for the first time answers the same (M3 Max, macOS 27.0.1, each state of a source compiled once: 1 for 1x1x1, 21 for 7x3x1, 128 for 8x8x2, 1024 for 32x32x1). The runtime differs in that each state answers its own size: Metal hands a state of a function it has already compiled under another size the earlier state's limit, in the same process or a later one. A compute state of the sameMTLFunctionanswered 16 after a 4x4x1 state, with an 8x8x1 size and with none, where the runtime's answers 64 and the compiled limit (compute_pipeline_limits.m). - A reset compute pipeline descriptor is a fresh one, every field at its default:
ComputePipelineDescriptor::newstands forreset, asMTLComputePipeline.hdocuments it ("Restore all compute pipeline descriptor properties to their default values", and ofmaxTotalThreadsPerThreadgroup, "If it is not set, returns zero"). Metal'sreseton the M3 Max (macOS 27.0.1) restores every other field and keeps three as the program set them:threadGroupSizeIsMultipleOfThreadExecutionWidth,maxTotalThreadsPerThreadgroupandrequiredThreadsPerThreadgroup(true, 96 and 8 by 6 by 2 incompute-descriptor-reset, where the runtime answers false, 0 and 0 by 0 by 0). The tile and mesh render pipeline descriptors' resets restore every field on the same machine. - An OpenCL work-item read of a dimension past 2 answers OpenCL's value in a pipeline of
OpenCL mode: 0 for
get_global_id,get_local_id,get_group_idandget_global_offset, 1 forget_local_size,get_global_sizeandget_num_groups, as OpenCL C defines them. The M3 Max (macOS 27.0.1) leaves unwritten the store ofget_global_id(3) + get_local_size(4) + get_global_size(5), where the runtime stores 2.
Queues and command buffers
- The runtime schedules a command buffer once its submit thread is free
(
metal2vulkan-runtime'sCommandBuffer::status,add_scheduled_handlerandwait_until_scheduled). Apple definesMTLCommandBufferStatusScheduledas "All dependencies have been resolved and the command buffer has been scheduled for execution", and promises no time between the two. Every queue's command buffers go to the device's oneVkQueue, which takes onevkQueueSubmit2call at a time, all made by the device's one submit thread, and the runtime schedules each command buffer there once that thread's earlier calls have returned, whichever queue they were for (the runtime's README, Queues, command buffers and events). So a command buffer whose wait an earlier submission's signal meets staysCommitted, its scheduled handlers not run, for as long as that submission's driver call lasts, where an Apple M3 Max had scheduled it while the signalling command buffer still ran. - A command buffer that waits for a shared event's value is
Scheduledas it is submitted (metal2vulkan-runtime'sCommandBufferStatus::Scheduled,Device::new_shared_event), its scheduled handlers run, while the GPU still waits for the value, as for anMTLEvent's value. Apple's MTLCommandBuffer.h describesMTLCommandBufferStatusScheduledas "All dependencies have been resolved and the command buffer has been scheduled for execution" (lines 47-48), andencodeWaitForEvent:value:as a command that "pauses execution of this command buffer until the specified event reaches a given value" (lines 405-406): execution pauses after scheduling. An Apple M3 Max with macOS 27.0.1 holds a command buffer that waits for anMTLSharedEvent's value not yet reached atCommitted, with no scheduled handler run, and its queue's next command buffer with it, until the value lands, and holds none for anMTLEvent(the conformance caseevent-wait-behind-a-running-signal). No documented Metal states that hold, so the runtime keeps none. The GPU's order and when each command buffer completes are the same either way; what moves is when the program's threads and handlers seeScheduled.
Command queues
- A write whose queue holds nothing back is seen by another queue's command buffer committed
after it (
metal2vulkan-runtime). A writer whose queue has fewer than three submissions in flight is submitted at once, ahead of every command buffer committed after it on any queue, so a later reader on another queue reads the write, on every device and every run: all 1024 words in the conformance casefence-none-tracked-behind-one, whose writer's queue has one busy command buffer in flight. That is the order Apple describes for a tracked resource: the framework prevents subsequent commands from running until write operations finish. Metal's 0 words there is measured, not documented: on an M3 Max with macOS 27.0.1, the copy on the other queue ran before the fill and read none of it in 5 runs of 5 (job m3-max-52432), and behind three busy command buffers likewise (job m3-max-52415); Metal's tracking ordered the copy only against work it had already submitted. The runtime's README states what was measured (crates/metal2vulkan-runtime/README.md, "Queues, command buffers and events").