diff --git a/CHANGELOG.md b/CHANGELOG.md index c01cde828..017f4cb58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,17 +14,12 @@ A full rewrite: nothing of 0.1.0's API or command line remains. buffers run on a Vulkan device through `ash`. - **AIR front end** (`metal2vulkan-air`): the metallib container, the bitcode reader, a typed IR, AIR's metadata ABI and canonicalization, as a crate of its own. -- **Fast by default**: off Apple's GPUs, choices that trade exactness for speed take the device's - native form, and each has an opt-in exact switch ([docs/FAST-PATHS.md](docs/FAST-PATHS.md)). -- **Typed refusals and announced degradations**: input a device cannot run fails with an error that - names what is missing; a recorded near-equivalent or an extra cost is announced once per device - with a stable code. +- **Typed refusals and static precision notes**: input a device cannot run fails with an error that + names what is missing; where a device's answer can differ from Metal's, the operation carries a + static precision note. - **Validation tooling** (unpublished): authored cases run on Metal and on Vulkan and compared, plus bounded audits over a private corpus. - **License**: dual-licensed `GPL-2.0-or-later OR LGPL-3.0-or-later`; 0.1.0 was `LGPL-3.0-or-later`. -- **Known failing**: a latency test fails on some GPUs: a device's teardown can wait past 16 ms for - its queue-switch check (an RTX 2080), an open gap in - [docs/FAST-PATHS.md](docs/FAST-PATHS.md#known-gaps). ## 0.1.0 diff --git a/README.md b/README.md index aa0aa0873..28b54bc2d 100644 --- a/README.md +++ b/README.md @@ -136,7 +136,6 @@ For the runtime, start at [its README](crates/metal2vulkan-runtime/README.md). | [docs/API.md](docs/API.md) | You use the translator's API: devices, libraries, pipelines, binding, caching, errors; and the runtime's precision notes | | [Runtime README](crates/metal2vulkan-runtime/README.md) | You use the Metal API on Vulkan | | [docs/HOWTO.md](docs/HOWTO.md) | You integrate: tools, caching, failures, isolation, the runtime's shader cache | -| [docs/RUNTIME-PORTING.md](docs/RUNTIME-PORTING.md) | You port Metal calls (Objective-C or metal-rs) to the runtime | | [docs/RESOURCE-ID.md](docs/RESOURCE-ID.md) | You compute a texture's or sampler's `gpuResourceID` on the guest's side | | [docs/METAL-COVERAGE.md](docs/METAL-COVERAGE.md) | You ask whether a Metal API item is covered | | [docs/REFUSALS.md](docs/REFUSALS.md) | You ask what Metal accepts that the code refuses | diff --git a/crates/metal2vulkan-validation/fixtures/public/examples/texel_rows.metal b/crates/metal2vulkan-validation/fixtures/public/examples/texel_rows.metal index 04e2a3aa4..ecaa13b91 100644 --- a/crates/metal2vulkan-validation/fixtures/public/examples/texel_rows.metal +++ b/crates/metal2vulkan-validation/fixtures/public/examples/texel_rows.metal @@ -1,5 +1,6 @@ -// Owned fixture: the kernels the metal2vulkan-runtime crate's texel rows device tests run -// (src/tests/texel_rows_device.rs). Written from scratch for them; `scripts/regen-air-fixtures/ +// Owned fixture: kernels that move texels between a texture and a buffer. The runtime's +// aliased-encoder device tests (crates/metal2vulkan-runtime/src/tests/aliased_encoders.rs) run +// `rows_write` and `rows_read`. Written from scratch; `scripts/regen-air-fixtures/ // regen-air-fixtures.sh --dir examples texel_rows` compiles it. No translator sweep reads this // directory. #include diff --git a/crates/metal2vulkan/src/device/derive.rs b/crates/metal2vulkan/src/device/derive.rs index 57fe5fe97..221f0c4c2 100644 --- a/crates/metal2vulkan/src/device/derive.rs +++ b/crates/metal2vulkan/src/device/derive.rs @@ -48,8 +48,8 @@ struct DeviceInner { /// The description's `generated_commands`, which only the device replay reads; not a profile /// field, as above. generated_commands: Option, - /// The description's allocation sizes, which the Metal-facing `maxBufferLength` and the - /// runtime's heap sizes read; not a profile field, as above. + /// The description's allocation sizes, which the Metal-facing `maxBufferLength` reads; not a + /// profile field, as above. allocation: AllocationLimits, } diff --git a/crates/metal2vulkan/src/device/profile.rs b/crates/metal2vulkan/src/device/profile.rs index 4fbff786a..902c028f1 100644 --- a/crates/metal2vulkan/src/device/profile.rs +++ b/crates/metal2vulkan/src/device/profile.rs @@ -216,19 +216,18 @@ impl DeviceProfile { } /// Whether this profile runs object and mesh functions as compute work: it does not enable - /// `VK_EXT_mesh_shader` and `meshShader`. Then a mesh function writes its primitives as - /// records that a synthesized vertex stage draws (`GraphicsState::mesh_records`), each stage's - /// threadgroups are held to the compute stage's limits, and the runtime announces each draw - /// (`emulated-mesh-draws`). Elsewhere they are `TaskEXT` and `MeshEXT` entries, held to the - /// task and mesh stages' limits, and an object function needs `taskShader` too. + /// `VK_EXT_mesh_shader` and `meshShader`. Then a mesh function writes its primitives as records + /// that a synthesized vertex stage draws (`GraphicsState::mesh_records`), each stage's + /// threadgroups are held to the compute stage's limits. Elsewhere they are `TaskEXT` and + /// `MeshEXT` entries, held to the task and mesh stages' limits, and an object function needs + /// `taskShader` too. pub fn emulates_mesh_shading(&self) -> bool { crate::lower::mesh::emulates(self) } /// Whether a function reads a two-plane YCbCr texture's planes in place where its slot reads /// the texture only so (`bind::YCbCrInPlace`): on every device. The planes read in place are - /// sampled by Vulkan's Y′CbCr model where the sample allows it. The runtime reads it - /// to state a texture's planes (`TextureFacts::ycbcr_in_place`). + /// sampled by Vulkan's Y′CbCr model where the sample allows it. pub fn reads_ycbcr_planes_in_place(&self) -> bool { self.fields.ycbcr_in_place } @@ -1572,13 +1571,10 @@ pub enum DriverWorkaround { /// constant. Keyed on the driver and that GPU alone. There a storage view's slot declares /// `SpecKey::RangeAtBindOffset` as a uniform view's does (`lower::access`), which the binder /// sets where the slot is bound at offset 0, a storage view's range then starting at its bind - /// offset (`bind::plan::slots::range_at_bind_offset`), and the runtime keeps that key. A + /// offset (`bind::plan::slots::range_at_bind_offset`). A /// storage view's slot bound to nothing takes what a bind at offset 0 gives it, the commonest /// bind, so a plan made before any bind names the key of a command that binds the slot there. - /// The runtime's creation of a state makes that key and, beside it and at the same time, its - /// general form, every view read at its residual, which a command binding a storage view - /// elsewhere takes at once while its own key is made: otherwise one of the two would be a - /// second pipeline made at the state's first command. A uniform view read at its bind offset + /// A uniform view read at its bind offset /// alone is no faster there: a kernel of three storage views at offset 0 and inline bytes ran /// in 161.8 us a dispatch with the bytes' uniform view read so and in 142.8 us with it read at /// its residual, and in 102.1 us with the bytes read through a storage view at their bind @@ -1599,9 +1595,7 @@ pub enum DriverWorkaround { /// many times as long as the same read of a storage buffer, while one address for every lane /// is read faster through the uniform buffer: a measured cost fact that chooses between two /// exact encodings of a `constant` slot. Never keyed on an identity: the profile takes it where - /// the description's `measured` set holds it, - /// which the runtime's view check decides on each driver (its storage view's time over its - /// uniform buffer's for per-lane reads below 0.3). Measured with a bare Vulkan program (256 + /// the description's `measured` set holds it. Measured with a bare Vulkan program (256 /// workgroups of 64 invocations, each adding 64 or 1024 `uvec4` reads of a window of 1 to /// 32 KiB of device-local memory; median of 15 dispatches): with each invocation reading its /// own word, or walking the window per invocation, the storage buffer took 0.011 to 0.16 of the @@ -1619,25 +1613,22 @@ pub enum DriverWorkaround { /// Uniform-buffer reads of external memory skip a cache that the same reads through a uniform /// texel buffer keep: a measured cost fact that chooses between two exact encodings of a /// uniform view. Never keyed on an identity: the profile takes it where the description's - /// `measured` set holds it, which the runtime's - /// view check decides on each driver (a uniform texel buffer's time over a uniform buffer's - /// for the reads it moves, over imported host memory: below 1 in every one, below 0.7 in at - /// least one). ANV, Mesa 26.2.6, on the Iris Xe of RPL-P gives imported and exported memory - /// the memory object control state of a displayable surface, which leaves out the data port's - /// L1 cache a uniform buffer of the - /// device's own memory is given (Mesa's `isl_mocs`, Linux i915's Gen12 MOCS table; read, not - /// measured). Measured there (jobs m3-max-37703, m3-max-37729 and m3-max-37780): a uniform - /// buffer over a host allocation or a udmabuf took 2.0 to 2.5 times as long as over the - /// device's own memory with every invocation reading one word of a 1 KiB window, and 5.2 to - /// 5.5 times with each reading its own; a uniform texel buffer 0.98 to 1.04 times, and for - /// windows of up to 4 KiB no longer than the uniform buffer there. Where the profile takes it, - /// the uniform view of a slot with an indexed read (`memory::plan`'s indexed reads) whose - /// window is at most `memory::views::TEXEL_WINDOW_BYTES` is a uniform texel buffer of - /// `R32G32B32A32_UINT` texels read with `OpImageFetch` (`DescriptorView::UniformTexel`, - /// `lower::access::view_kind`); a slot read at constant offsets alone, whose words a driver may - /// load ahead into registers as no texel fetch can be, and a longer window keep the uniform - /// buffer. With [`UniformBufferPerLaneReadsSerialize`](Self::UniformBufferPerLaneReadsSerialize) - /// too, a slot with a per-lane read keeps its storage view first. It changes no answer. + /// `measured` set holds it. ANV, Mesa 26.2.6, on the Iris Xe of RPL-P gives imported and + /// exported memory the memory object control state of a displayable surface, which leaves out + /// the data port's L1 cache a uniform buffer of the device's own memory is given (Mesa's + /// `isl_mocs`, Linux i915's Gen12 MOCS table; read, not measured). Measured there (jobs + /// m3-max-37703, m3-max-37729 and m3-max-37780): a uniform buffer over a host allocation or a + /// udmabuf took 2.0 to 2.5 times as long as over the device's own memory with every invocation + /// reading one word of a 1 KiB window, and 5.2 to 5.5 times with each reading its own; a + /// uniform texel buffer 0.98 to 1.04 times, and for windows of up to 4 KiB no longer than the + /// uniform buffer there. Where the profile takes it, the uniform view of a slot with an indexed + /// read (`memory::plan`'s indexed reads) whose window is at most + /// `memory::views::TEXEL_WINDOW_BYTES` is a uniform texel buffer of `R32G32B32A32_UINT` texels + /// read with `OpImageFetch` (`DescriptorView::UniformTexel`, `lower::access::view_kind`); a + /// slot read at constant offsets alone, whose words a driver may load ahead into registers as + /// no texel fetch can be, and a longer window keep the uniform buffer. With + /// [`UniformBufferPerLaneReadsSerialize`](Self::UniformBufferPerLaneReadsSerialize) too, a slot + /// with a per-lane read keeps its storage view first. It changes no answer. ExternalUniformReadsSkipACache, } diff --git a/crates/metal2vulkan/src/error/mod.rs b/crates/metal2vulkan/src/error/mod.rs index 9eadf8aec..235a998a3 100644 --- a/crates/metal2vulkan/src/error/mod.rs +++ b/crates/metal2vulkan/src/error/mod.rs @@ -1142,10 +1142,7 @@ pub enum RuntimeDriverDefect { /// one memory ("Memory Aliasing": memory bound through external memory import mechanisms): /// in one blit encoder, a copy through a buffer bound in one import of the pages read their /// bytes from before a fill, recorded before the barrier, through a buffer bound in another - /// import of them. Nothing is refused: where the runtime would bind a no-copy object over a - /// guest RAM's chunk not yet imported in an import of the object's own pages - /// (`metal2vulkan_runtime::Device::use_host_ram`), it binds it in the chunk's import, which - /// the object then waits for, so that every object over a chunk's pages lies in one import. + /// import of them. AliasedImportBlitsUnordered, /// A render pass's color resolve into a 2D view of a 3D image (made /// `VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT`, the view's layers depth planes of it) is diff --git a/crates/metal2vulkan/src/lower/fragment/logic.rs b/crates/metal2vulkan/src/lower/fragment/logic.rs index ede92889c..55f9e9a6f 100644 --- a/crates/metal2vulkan/src/lower/fragment/logic.rs +++ b/crates/metal2vulkan/src/lower/fragment/logic.rs @@ -27,8 +27,8 @@ //! operation (probe `logic_operation`, an Apple M3 Max under macOS 27.0.1). Vulkan's `logicOp` //! takes and stores the lowest code itself ([`vulkan_differs`]). A channel the write does not //! store (outside the write mask, and every channel under no-op, which draws unwritten) keeps -//! its lowest code over an input attachment, where Metal's pass stores the code above: the -//! runtime's `snorm-minimum-kept`, as for any draw into such an attachment. +//! its lowest code over an input attachment, where Metal's pass stores the code above: +//! `PrecisionNote::SnormMinimumKept`, as for any draw into such an attachment. //! //! A 10-bit unorm format (`RGB10A2Unorm`, `BGR10A2Unorm`) operates on 16-bit codes: Metal widens //! each stored code to 16 bits (`round(d * 65535 / max)`), operates on it and the output's 16-bit diff --git a/crates/metal2vulkan/src/pipeline/artifact.rs b/crates/metal2vulkan/src/pipeline/artifact.rs index f4ddd7801..1e96b57d0 100644 --- a/crates/metal2vulkan/src/pipeline/artifact.rs +++ b/crates/metal2vulkan/src/pipeline/artifact.rs @@ -436,7 +436,7 @@ pub struct ModuleStats { /// writes memory other than an invocation's own and its workgroup's (`Function`, `Private` /// and `Workgroup` storage), writes an image, or emits or drops an output of its stage. So /// every invocation ends, and a dispatch of a kernel of it leaves nothing behind but the time - /// it took: `metal2vulkan-runtime` records none. An instruction the classification does not + /// it took. An instruction the classification does not /// name as reading or computing alone (an interlock, a ray query) makes it not inert. #[cfg_attr(feature = "serde", serde(default))] pub inert: bool, @@ -2423,9 +2423,7 @@ pub enum PrecisionNote { /// 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, as the stage's - /// `reconvergence` is, on a device `Device::from_queries` made. A device `Device::new` made - /// records the field alone (`metal2vulkan-runtime` announces it as - /// `ImplementationDefinedReconvergence`). + /// `reconvergence` is. /// /// Validation derives no tolerance from it: a difference stays a mismatch, which the note /// explains. @@ -2438,10 +2436,8 @@ pub enum PrecisionNote { /// writes too (measured on an Apple M3 Max under macOS 27.0.1: every such code of each tile a /// draw reaches, none in other tiles, none in a pass that draws nothing). The device's pass /// keeps the bytes its draws do not write. Static per pipeline: recorded on the fragment stage - /// (the vertex stage where the pipeline has none) of every such pipeline on a device - /// `Device::from_queries` made, whatever its passes load. A device `Device::new` made records - /// none: `metal2vulkan-runtime` announces `snorm-minimum-kept` at each draw in a pass that loads - /// such an attachment, which only its encoder knows. + /// (the vertex stage where the pipeline has none) of every such pipeline, whatever its passes + /// load. /// /// Validation derives no tolerance from it: a difference stays a mismatch, which the note /// explains. @@ -2466,24 +2462,21 @@ pub enum PrecisionNote { /// negative one not below it; and RADV and ANV store a denormal a GPU write gives a depth image /// as a zero, where Metal keeps it. Static per operation: no pipeline stage records it; /// `metal2vulkan-runtime`'s depth-stencil state carries it - /// (`DepthStencilState::precision_note`). `metal2vulkan-runtime` announces the same - /// difference as its `depth-denormals` kind, which this note announces too. + /// (`DepthStencilState::precision_note`). /// /// Validation derives no tolerance from it: a difference stays a mismatch, which the note /// explains. DepthDenormals, /// `generateMipmapsForTexture:` of a filterable colour format: each level below the first is /// the device's linear filter of the one above, its blit (`vkCmdBlitImage` with - /// `VK_FILTER_LINEAR`, the level above sampled at each texel's centre scaled into it). - /// Apple's documentation states no filter. Metal filters bilinearly at the same scaled - /// centres, measured on an M3 Max and an M4, but by Apple's datapath, whose answers differ - /// between those GPUs by up to a unit in the last place (`metal2vulkan-runtime`'s - /// `device-filtered-mipmaps`). Where a level halves an even size, each sample falls between - /// two texels on the axis, so the filter is a box of them at the device's filter precision; an - /// sRGB format is filtered in linear space. Static per operation: no - /// pipeline stage records it; `metal2vulkan-runtime`'s blit encoder carries it - /// (`BlitCommandEncoder::GENERATE_MIPMAPS_NOTE`). `metal2vulkan-runtime` announces the same - /// difference as its `device-filtered-mipmaps` kind, which this note announces too. + /// `VK_FILTER_LINEAR`, the level above sampled at each texel's centre scaled into it). Apple's + /// documentation states no filter. Metal filters bilinearly at the same scaled centres, + /// measured on an M3 Max and an M4, but by Apple's datapath, whose answers differ between those + /// GPUs by up to a unit in the last place. Where a level halves an even size, each sample falls + /// between two texels on the axis, so the filter is a box of them at the device's filter + /// precision; an sRGB format is filtered in linear space. Static per operation: no pipeline + /// stage records it; `metal2vulkan-runtime`'s blit encoder carries it + /// (`BlitCommandEncoder::GENERATE_MIPMAPS_NOTE`). /// /// Validation derives no tolerance from it: a difference stays a mismatch, which the note /// explains. @@ -2494,7 +2487,7 @@ pub enum PrecisionNote { /// tables, where a device may round a tie down and Vulkan only recommends the linear average /// for an sRGB format; a float channel's average may differ in its last bits, and a NaN or /// infinite sample's average is the device's. Measured against Metal's rules at 2 and 4 - /// samples (`metal2vulkan-runtime`'s `device-rounded-resolve`, which this note announces too): + /// samples: /// on RADV, ANV, NVIDIA and lavapipe every unorm, snorm and packed 16-bit unorm channel within /// one code of Metal's, an sRGB channel within two. Static per operation: no pipeline stage /// records it; `metal2vulkan-runtime`'s render pass carries it for every color attachment it @@ -2509,9 +2502,7 @@ pub enum PrecisionNote { /// decode), where Metal interpolates a block's endpoints with 6-bit weights. Its blocks' /// bytes, copies and sizes are Metal's. Static per texture, decided by its pixel format alone /// on every device: no pipeline stage records it; `metal2vulkan-runtime`'s texture carries it - /// (`Texture::precision_note`). `metal2vulkan-runtime` announces the same difference as its - /// `compressed-texel-decode` kind, for a BC texture on a driver not measured to decode its - /// format as Metal does, which this note announces too. + /// (`Texture::precision_note`). /// /// Validation derives no tolerance from it: a difference stays a mismatch, which the note /// explains. @@ -2523,9 +2514,7 @@ pub enum PrecisionNote { /// (measured on an Apple M3 Max under macOS 27.0.1). The device's pass keeps the words its /// draws do not write. Static per pipeline, as [`PrecisionNote::SnormMinimumKept`] is: /// recorded on the fragment stage (the vertex stage where the pipeline has none) of every such - /// pipeline on a device `Device::from_queries` made, whatever its passes load. A device - /// `Device::new` made records none: `metal2vulkan-runtime` announces `shared-exponent-kept` - /// at each draw in a pass that loads such an attachment, which only its encoder knows. + /// pipeline, whatever its passes load. /// /// Validation derives no tolerance from it: a difference stays a mismatch, which the note /// explains. diff --git a/docs/API.md b/docs/API.md index c3fe91102..e838af1e3 100644 --- a/docs/API.md +++ b/docs/API.md @@ -945,11 +945,7 @@ where its axes are among the masks of `relief`, the kernel's unit-axes variant 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. `metal2vulkan-runtime` begins the variant on -its pipeline pool at the first dispatch it is offered to, and runs that dispatch and the next ones -on the plain variant until the variant's translation and its regions' `VkPipeline`s are made, so -no dispatch waits for it (`WorkCounts::unit_axes_variants_begun`, `unit_axes_meanwhile`, -`unit_axes_dispatches`). On the Iris Xe, an authored kernel of four shuffles each way and a +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 @@ -1002,10 +998,8 @@ assert!(stats.reachable_blocks <= stats.blocks); - `inert` says the module holds no loop and that no instruction of it writes memory other than an invocation's own and its workgroup's (`Function`, `Private` and `Workgroup` storage), 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: - `metal2vulkan-runtime` records no Vulkan dispatch of it. The command buffer still uses what the - dispatch binds, as Metal's does: a `Managed` buffer's ranges named by `did_modify_range` are - copied in by that command buffer, not by the next one that reads them. An instruction the + 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. @@ -2049,15 +2043,11 @@ a `device` pointer (`constant` loads and texture writes allowed), which a runtim 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. `metal2vulkan-runtime` runs a kernel's whole grids there where -its module holds 65,536 SPIR-V words or more and its ragged grids run there too: it observes its -threadgroup partition (`CompiledFunction::observes_threadgroup_partition`), and for a one-row grid -in threadgroups of one row otherwise than through its simdgroups alone -(`observes_partition_through_simdgroups_alone`, whose such grids run flat). That is one driver -compile of the module instead of two: on a guest's run on an RX 7900 XTX, the plain pipeline's -compile of a kernel of 2,415,531 words was 26.9 s of a 39.8 s warm pass. Measured once on that GPU -(RADV) over four straight-line kernels, the variant ran their whole grids at 0.997 to 1.020 times -the plain pipeline's GPU time. Smaller kernels keep the plain pipeline for whole grids. A kernel +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: diff --git a/docs/RUNTIME-PORTING.md b/docs/RUNTIME-PORTING.md deleted file mode 100644 index ddbb96716..000000000 --- a/docs/RUNTIME-PORTING.md +++ /dev/null @@ -1,623 +0,0 @@ -# Porting Metal code to the runtime - -This page maps Metal's calls, as Objective-C or `metal-rs` makes them, onto -`metal2vulkan-runtime`, the Metal API on Vulkan -([its README](../crates/metal2vulkan-runtime/README.md)). The tables follow the seam of one -consumer, a paravirtualized GPU that wraps Metal behind its own traits; the **Item** column names -that seam's item, and the section headings name the Metal class. A port from plain Metal code reads -the tables by the **Metal** column. - -Each runtime item's rustdoc names its Metal selector and says what differs or is refused; read it -for the details a row leaves out. A row marked *(partial)* covers the item with a difference or a -narrow refusal that the call's rustdoc describes. - -## Conventions - -| Metal (objc or metal-rs) | Runtime | -|---|---| -| `MTLDevice`, `MTLBuffer`, ... | the same names without the prefix: `Device`, `Buffer`, ... | -| a selector, `newBufferWithLength:options:` | a snake_case method on the receiver: `Device::new_buffer(length, options)` | -| `retain` / `release` | `Clone` / `Drop`; object handles are `Send + Sync` | -| object identity (`==` on `id`) | `PartialEq`, `Eq` and `Hash` by identity | -| `nil` arguments and results | `Option` | -| an `NSError **` out-argument, or a nil result on failure | `Result<_, Error>`; `Error` is typed (the runtime's README, "Errors") | -| descriptor objects (`MTLTextureDescriptor`, `MTLRenderPassDescriptor`, ...) | plain values with public fields; a setter is a field write | -| pipeline descriptors | `metal2vulkan::pipeline` values, from the translator crate | -| encoders, closed by `endEncoding` | owned values; `end_encoding(self)` consumes them | -| completion and scheduled blocks | `Handler`, a boxed `FnOnce(&CommandBuffer) + Send` | -| `MTLSize`, `MTLOrigin`, `MTLRegion` | `Size`, `Origin`, `Region` | -| `MTLResourceOptions`, `MTLTextureUsage`, ... | typed values (`ResourceOptions`; `metal2vulkan::metal::TextureUsage`, ...) | -| Apple-private selectors (SPI) | where the runtime has the call, a method of the same name; `Error::AppleOnly` where Vulkan has no exact form | - - -## By object - -### `Handle`: every object - -| Item | Metal | Runtime | -|---|---|---| -| `clone_ref` | | `Clone` (a retain); `Drop` releases | -| `id` | | `PartialEq`, `Eq` and `Hash` by identity | - -### `Platform`: the object types and their constructors - -| Item | Metal | Runtime | -|---|---|---| -| `type Device` | `id` | `Device` | -| `type CommandQueue` | `id` | `CommandQueue` | -| `type CommandBuffer` | `id` | `CommandBuffer` | -| `type BlitEncoder` | `id` | `BlitCommandEncoder` | -| `type ComputeEncoder` | `id` | `ComputeCommandEncoder` | -| `type RenderEncoder` | `id` | `RenderCommandEncoder` | -| `type Buffer` | `id` | `Buffer` | -| `type Texture` | `id` | `Texture` | -| `type Heap` | `id` | `Heap` | -| `type SamplerState` | `id` | `SamplerState` | -| `type DepthStencilState` | `id` | `DepthStencilState` | -| `type Fence` | `id` | `Fence` | -| `type Event` | `id` | `Event` | -| `type SharedEvent` | `id` | `SharedEvent` | -| `type SharedEventHandle` | `MTLSharedEventHandle *` | `SharedEventHandle`: in one process only *(partial)* | -| `type SharedEventListener` | `MTLSharedEventListener *` | `SharedEventListener` | -| `type SharedTextureHandle` | `MTLSharedTextureHandle *` | `SharedTextureHandle`: in one process only *(partial)* | -| `type Library` | `id` | `Library` | -| `type Function` | `id` | `Function` | -| `type ComputePipeline` | `id` | `ComputePipelineState` | -| `type RenderPipeline` | `id` | `RenderPipelineState` | -| `type RateMap` | `id` | `RasterizationRateMap` | -| `type Icb` | `id` | `IndirectCommandBuffer` | -| `type IndirectRenderCommand` | `id` | `IndirectRenderCommand` | -| `type IndirectComputeCommand` | `id` | `IndirectComputeCommand` | -| `type TextureDescriptor` | `MTLTextureDescriptor *` | `TextureDescriptor`, a plain value | -| `type RenderPassDescriptor` | `MTLRenderPassDescriptor *` | `RenderPassDescriptor`, a plain value | -| `type RenderPipelineDescriptor` | `MTLRenderPipelineDescriptor *` | `metal2vulkan::pipeline::RenderPipelineDescriptor` | -| `type ComputePipelineDescriptor` | `MTLComputePipelineDescriptor *` | `metal2vulkan::pipeline::ComputePipelineDescriptor` | -| `type TileRenderPipelineDescriptor` | `MTLTileRenderPipelineDescriptor *` | `metal2vulkan::pipeline::TileRenderPipelineDescriptor` | -| `type RateMapDescriptor` | `MTLRasterizationRateMapDescriptor *` | `metal2vulkan::bind::RateMapDescriptor` | -| `type RateMapLayerDescriptor` | `MTLRasterizationRateLayerDescriptor *` | `metal2vulkan::bind::RateMapLayerDescriptor` | -| `new_render_pass_descriptor` | `new` | `RenderPassDescriptor::new` | -| `new_shared_event_listener` | `new` | `SharedEventListener::new` | -| `render_pass_descriptor` | `renderPassDescriptor` | `RenderPassDescriptor::new` | -| `texture_2d_descriptor` | `texture2DDescriptorWithPixelFormat:width:height:mipmapped:` | `TextureDescriptor::texture_2d` | -| `new_rate_map_layer` | `initWithSampleCount:` | `metal2vulkan::bind::RateMapLayerDescriptor::new`; a refused sample count is a typed error | -| `texture_descriptor` | | `TextureDescriptor`'s fields | -| `rate_map_descriptor` | | `metal2vulkan::bind::RateMapDescriptor` | -| `open_device` | | `Device::all`, matched by `Device::registry_id` | - -### `BlitCmd`: `MTLBlitCommandEncoder` commands - -| Item | Metal | Runtime | -|---|---|---| -| `CopyBufferToTexture` | `copyFromBuffer:sourceOffset:sourceBytesPerRow:sourceBytesPerImage:…` | `BlitCommandEncoder::copy_from_buffer_to_texture` *(partial)* | -| `CopyBufferToTextureOptions` | `copyFromBuffer:sourceOffset:sourceBytesPerRow:sourceBytesPerImage:…` | `BlitCommandEncoder::copy_from_buffer_to_texture` with `BlitOption` *(partial)* | -| `CopyBufferToBuffer` | `copyFromBuffer:sourceOffset:toBuffer:destinationOffset:size:` | `BlitCommandEncoder::copy_from_buffer_to_buffer` | -| `CopyTextureToBuffer` | `copyFromTexture:sourceSlice:sourceLevel:sourceOrigin:sourceSize:…` | `BlitCommandEncoder::copy_from_texture_to_buffer` *(partial)* | -| `CopyTextureToBufferOptions` | `copyFromTexture:sourceSlice:sourceLevel:sourceOrigin:sourceSize:…` | `BlitCommandEncoder::copy_from_texture_to_buffer` with `BlitOption` *(partial)* | -| `CopyTextureRegion` | `copyFromTexture:sourceSlice:sourceLevel:sourceOrigin:sourceSize:…` | `BlitCommandEncoder::copy_from_texture_to_texture` *(partial)* | -| `CopyTextureSlices` | `copyFromTexture:sourceSlice:sourceLevel:toTexture:destinationSlice:…` | `BlitCommandEncoder::copy_texture_slices`; `BlitCommandEncoder::copy_texture` is `copyFromTexture:toTexture:` *(partial)* | -| `CopyIndirectCommandBuffer` | `copyIndirectCommandBuffer:sourceRange:destination:destinationIndex:` | `BlitCommandEncoder::copy_indirect_command_buffer` | -| `EndEncoding` | `endEncoding` | `BlitCommandEncoder::end_encoding` | -| `FillBuffer` | `fillBuffer:range:value:` | `BlitCommandEncoder::fill_buffer` | -| `FillBufferPattern4` | `fillBuffer:range:pattern4:` (SPI) | `BlitCommandEncoder::fill_buffer_pattern4` | -| `FillTexture` | `fillTexture:level:slice:region:bytes:length:` (SPI) | `BlitCommandEncoder::fill_texture`: every texture type, placed as Metal places it, every format; a multisample texture's samples each take their own bytes of the pattern, as Metal's do; a texture buffer's fill writes its buffer's bytes, the pattern across them, as Metal's does (zeros where Metal's are its stack's, announced, `texture-buffer-fill-leftover`) *(partial)* | -| `FillTextureColor` | `fillTexture:level:slice:region:color:pixelFormat:` (SPI), and `...color:` | `BlitCommandEncoder::fill_texture_color`, packed as Metal's fills pack; a plain fill of a texture of a normalized, sRGB, half, float or small-float format the device renders is the device's clear of the color (announced where it may stand a code from Metal's, `device-color-conversion`); a color packed in a format Metal packs none in fills the command buffer's last packed texel (announced, `unpacked-fill-color`) *(partial)* | -| `GenerateMipmaps` | `generateMipmapsForTexture:` | `BlitCommandEncoder::generate_mipmaps` *(partial)* | -| `InvalidateCompressedTexture` | `invalidateCompressedTexture:` (SPI) | `BlitCommandEncoder::invalidate_compressed_texture`: a no-op (Vulkan shows no compression) | -| `InvalidateCompressedTextureSlice` | `invalidateCompressedTexture:slice:level:` (SPI) | `BlitCommandEncoder::invalidate_compressed_texture_slice`: a no-op | -| `OptimizeForCpu` | `optimizeContentsForCPUAccess:` | `BlitCommandEncoder::optimize_contents_for_cpu_access` (a hint; no-op) | -| `OptimizeForCpuSlice` | `optimizeContentsForCPUAccess:slice:level:` | `BlitCommandEncoder::optimize_contents_for_cpu_access_slice_level` (a no-op) | -| `OptimizeForGpu` | `optimizeContentsForGPUAccess:` | `BlitCommandEncoder::optimize_contents_for_gpu_access` (no-op) | -| `OptimizeForGpuSlice` | `optimizeContentsForGPUAccess:slice:level:` | `BlitCommandEncoder::optimize_contents_for_gpu_access_slice_level` (a no-op) | -| `OptimizeIndirectCommandBuffer` | `optimizeIndirectCommandBuffer:withRange:` | `BlitCommandEncoder::optimize_indirect_command_buffer` | -| `ResetCommandsInBuffer` | `resetCommandsInBuffer:withRange:` | `BlitCommandEncoder::reset_commands_in_buffer` | -| `SynchronizeResource` | `synchronizeResource:` | `BlitCommandEncoder::synchronize_resource` (managed storage) | -| `SynchronizeTexture` | `synchronizeTexture:slice:level:` | `BlitCommandEncoder::synchronize_texture` | -| `UpdateFence` | `updateFence:` | `BlitCommandEncoder::update_fence` | -| `WaitForFence` | `waitForFence:` | `BlitCommandEncoder::wait_for_fence` | - -### `BlitEncoder`: `MTLBlitCommandEncoder` - -| Item | Metal | Runtime | -|---|---|---| -| `encode` | | one `BlitCommandEncoder` method per `BlitCmd` (above) | - -### `CommandQueue`: `MTLCommandQueue` - -| Item | Metal | Runtime | -|---|---|---| -| `command_buffer` | `commandBuffer` | `CommandQueue::command_buffer` | -| `set_label` | `setLabel:` | `CommandQueue::set_label` | - -### `CommandBuffer`: `MTLCommandBuffer` - -| Item | Metal | Runtime | -|---|---|---| -| `add_completed_handler` | `addCompletedHandler:` | `CommandBuffer::add_completed_handler` | -| `blit_encoder` | `blitCommandEncoder` | `CommandBuffer::blit_command_encoder` | -| `commit` | `commit` | `CommandBuffer::commit` | -| `compute_encoder` | `computeCommandEncoder` | `CommandBuffer::compute_command_encoder` | -| `device` | `device` | `CommandBuffer::device` | -| `encode_signal` | `encodeSignalEvent:value:` | `CommandBuffer::encode_signal_event` | -| `encode_signal_when_scheduled` | `encodeSignalEventScheduled:value:` (SPI) | `CommandBuffer::encode_signal_event_scheduled` | -| `encode_wait` | `encodeWaitForEvent:value:` | `CommandBuffer::encode_wait_for_event` | -| `error` | `error` | `CommandBuffer::error` | -| `render_encoder` | `renderCommandEncoderWithDescriptor:` | `CommandBuffer::render_command_encoder` *(partial)* | -| `set_protection_options` | `setProtectionOptions:` (SPI) | `CommandBuffer::set_protection_options`: an encoder made under options other than 0 fails the command buffer from there (`CommandBufferError::ProtectedEncoder`), as Metal's GPU does; 1, 3 and 7 refused where they end Metal's process; changes Metal was not measured at refused `AppleOnly::ProtectedContent` *(partial)* | -| `status` | `status` | `CommandBuffer::status` | -| `wait_until_completed` | `waitUntilCompleted` | `CommandBuffer::wait_until_completed`, or `wait_until_completed_for` with a timeout | -| `wait_until_scheduled` | `waitUntilScheduled` | `CommandBuffer::wait_until_scheduled` | -| `compute_encoder_for_pass` | `computeCommandEncoderWithDescriptor:` | `CommandBuffer::compute_command_encoder_with_dispatch_type`; `compute_command_encoder_with_raw_dispatch_type` for a raw `MTLDispatchType` (every value but 1 serial, as Metal's) | -| `used_resources` | (none: a runtime extension) | `CommandBuffer::used_resources`: the buffers, textures and heaps its ended encoders' commands use, each as what owns its memory, until it completes; what `detach_backing` waits on | -| `ended_encoders` | (none: a runtime extension) | `CommandBuffer::ended_encoders`: each ended encoder's kind, the event waits and signals before it, and what its own commands use; with `commit_failed`'s `FailedEncoders::Set`, what fails the one submission that uses a detached resource | -| `add_submission_handler` | (none: a runtime extension) | `CommandBuffer::add_submission_handler`: a handler run once the command buffer's last batch reached its `VkQueue`: where its own `commit_and_submit` call (or the thread making the pass of one left for a render encoder's end) submitted it, on that thread, inside the call; otherwise on the device's handler threads, those that run its scheduled and completed handlers, which the scheduler's thread hands it to (on that thread itself where its pass settled a switch of storage forms); in submission order, before it is `Scheduled`; never for one that fails before | -| `commit_and_submit` | (none: a runtime extension) | `CommandBuffer::commit_and_submit`: `commit`, then the calling thread submits the ready command buffers in commit order, this one among them (one held back holding back only the later commits that wait behind it, as on the scheduler's thread), where no other pass is under way and each needs no host step or storage-form switch and its `VkQueue`'s batch calls are not slow (each of its last 15 100 us or more, as timed: those the scheduler's thread submits), running their submission checks just before each submission (one that waits for a shared event's GPU signal to land is left to the scheduler's thread; a plain event's wait goes to the `VkQueue`) and its own submission handlers inside the call (other command buffers' go to the device's handler threads as its pass goes on; where it has submission handlers, its pass ends right after its own last batch); the rest goes to the scheduler's thread. One left for a render encoder's end (`RenderLoweringPolicy::Worker`) returns as `commit` does, and the thread that runs its commit once the end is lowered makes the pass | -| `add_completion_seen_handler` | (none: a runtime extension) | `CommandBuffer::add_completion_seen_handler`: a handler run once the command buffer completed, its status and GPU times final, on the runtime's thread that saw it complete where its transition to `Completed` runs there, or runs to its completion-seen handlers there (one with completed handlers, the rest on its queue's handler thread), else on its queue's handler thread, before its completed handlers; short, and never blocking | -| `set_submission_check` | (none: a runtime extension) | `CommandBuffer::set_submission_check`: a check of each of Metal's submissions of the command buffer, run once its event waits are met (an `Event` wait for a submitted signal at once, its wait on the `VkQueue`; a `SharedEvent` wait only a GPU signal still running reaches once that signal lands, as Metal schedules each), just before it is submitted, on the thread that submits it (the device's scheduler thread, or one in `commit_and_submit` or making the pass of one left for a render encoder's end); a code it answers fails that submission alone, as Metal fails one that uses a resource detached by then | -| `object_id` | (none: Metal names an object by pointer) | `Buffer::object_id`, `Texture::object_id`, `Heap::object_id`, `CommandBuffer::object_id`: an `ObjectId` unique for the object's life, never reused (a sparse heap's `gpu_address` is 0); a degrade notice announced for a command buffer's work names its command buffer's (`DegradeNotice::command_buffer`) | - -### `ComputeCmd`: `MTLComputeCommandEncoder` commands - -| Item | Metal | Runtime | -|---|---|---| -| `DispatchThreadgroups` | `dispatchThreadgroups:threadsPerThreadgroup:` | `ComputeCommandEncoder::dispatch_threadgroups` | -| `DispatchThreadgroupsIndirect` | `dispatchThreadgroupsWithIndirectBuffer:indirectBufferOffset:…` | `ComputeCommandEncoder::dispatch_threadgroups_indirect` | -| `DispatchThreads` | `dispatchThreads:threadsPerThreadgroup:` | `ComputeCommandEncoder::dispatch_threads` | -| `DispatchThreadsIndirect` | `dispatchThreadsWithIndirectBuffer:indirectBufferOffset:` (SPI) | `ComputeCommandEncoder::dispatch_threads_indirect` (a host step reads the arguments) | -| `EncodeStartDoWhile` | `encodeStartDoWhile` (SPI) | `ComputeCommandEncoder::encode_start_do_while`, as Metal runs it, its body in its unit's later encoders included, nested to any depth, laid down as 64 copies of the loop's commands (16 inside another loop, fewer past 16384 steps and gated dispatches or 16 pieces of work a host step records after the GPU's work before it, at least one), submitted again from where the loop stopped until it ends; a loop without bound runs until the process ends, as Metal's does | -| `EncodeStartElse` | `encodeStartElse` (SPI) | `ComputeCommandEncoder::encode_start_else`, as Metal runs it; with no block open an unbalanced record, dropping its range of the unit's work as Metal's does, the unit's dispatches before its first record included | -| `EncodeStartIf` | `encodeStartIf:offset:comparison:referenceValue:` (SPI) | `ComputeCommandEncoder::encode_start_if`, as Metal runs it, on a counter the runtime's step kernel moves; a live block open where its unit ends fails the command buffer where its commands skip there, as Metal's GPU recovery does (`PredicationOpenAtUnitEnd`); a word past its buffer reads as Metal reads it (the heap's bytes, or zero; zero announced where Metal reads unrelated memory) *(partial)* | -| `EncodeStartWhile` | `encodeStartWhile:offset:comparison:referenceValue:` (SPI) | `ComputeCommandEncoder::encode_start_while`, as Metal runs it, laid down as `encode_start_do_while`'s loops are; its word read as `encode_start_if` reads it *(partial)* | -| `EndEncoding` | `endEncoding` | `ComputeCommandEncoder::end_encoding` | -| `ExecuteCommandsIndirect` | `executeCommandsInBuffer:indirectBuffer:indirectBufferOffset:` | `ComputeCommandEncoder::execute_commands_in_buffer_indirect`; `_checked` adds an `IndirectCommandCheck` its host step calls on each command first, and the `IndirectCommandCheckNeeds` it looks for | -| `ExecuteCommandsInBuffer` | `executeCommandsInBuffer:withRange:` | `ComputeCommandEncoder::execute_commands_in_buffer`; `_checked` adds an `IndirectCommandCheck` that `commit` (for the CPU's records) or a host step calls on each command first, and the `IndirectCommandCheckNeeds` it looks for, which may rule it out (then it runs on the GPU alone where it can) | -| `CompressedTextureReinterpretationFlush` | `insertCompressedTextureReinterpretationFlush` (SPI) | `ComputeCommandEncoder::insert_compressed_texture_reinterpretation_flush`: a no-op | -| `MemoryBarrierWithResources` | `memoryBarrierWithResources:count:` | `ComputeCommandEncoder::memory_barrier_with_resources` | -| `MemoryBarrierWithScope` | `memoryBarrierWithScope:` | `ComputeCommandEncoder::memory_barrier_with_scope` | -| `SetBufferOffset` | `setBufferOffset:atIndex:` | `ComputeCommandEncoder::set_buffer_offset` | -| `SetBufferOffsetAttributeStride` | `setBufferOffset:attributeStride:atIndex:` | `ComputeCommandEncoder::set_buffer_offset_with_stride` | -| `SetBuffersAttributeStrides` | `setBuffers:offsets:attributeStrides:withRange:` | `ComputeCommandEncoder::set_buffers_with_strides` | -| `SetBuffers` | `setBuffers:offsets:withRange:` | `ComputeCommandEncoder::set_buffers` | -| `SetComputePipelineState` | `setComputePipelineState:` | `ComputeCommandEncoder::set_compute_pipeline_state` | -| `SetImageblockWidth` | `setImageblockWidth:height:` | `ComputeCommandEncoder::set_imageblock_size` | -| `SetSamplerStatesLodClamps` | `setSamplerStates:lodMinClamps:lodMaxClamps:withRange:` | `ComputeCommandEncoder::set_sampler_states_with_lod_clamps` | -| `SetSamplerStates` | `setSamplerStates:withRange:` | `ComputeCommandEncoder::set_sampler_states` | -| `SetStageInRegion` | `setStageInRegion:` | `ComputeCommandEncoder::set_stage_in_region` | -| `SetStageInRegionIndirect` | `setStageInRegionWithIndirectBuffer:indirectBufferOffset:` | `ComputeCommandEncoder::set_stage_in_region_indirect` (the region read by a host step, as `dispatch_threads_indirect` reads its arguments) | -| `SetTexture` | `setTexture:atIndex:` | `ComputeCommandEncoder::set_texture` | -| `SetTextures` | `setTextures:withRange:` | `ComputeCommandEncoder::set_textures` | -| `SetThreadgroupMemoryLength` | `setThreadgroupMemoryLength:atIndex:` | `ComputeCommandEncoder::set_threadgroup_memory_length` | -| `UpdateFence` | `updateFence:` | `ComputeCommandEncoder::update_fence` | -| `UseHeaps` | `useHeaps:count:` | `ComputeCommandEncoder::use_heaps` | -| `UseResources` | `useResources:count:usage:` | `ComputeCommandEncoder::use_resources` | -| `WaitForFence` | `waitForFence:` | `ComputeCommandEncoder::wait_for_fence` | - -### `ComputeEncoder`: `MTLComputeCommandEncoder` - -| Item | Metal | Runtime | -|---|---|---| -| `encode` | | one `ComputeCommandEncoder` method per `ComputeCmd` (above) | -| `encode_end_do_while` | `encodeEndDoWhile:offset:comparison:referenceValue:` (SPI) | `ComputeCommandEncoder::encode_end_do_while`, answering Metal's `BOOL`; with no block open answering `NO` and dropping its range as Metal's does; its word read as `encode_start_if` reads it *(partial)* | -| `encode_end_if` | `encodeEndIf` (SPI) | `ComputeCommandEncoder::encode_end_if`, answering Metal's `BOOL`; with no block open answering `NO` and dropping its range as Metal's does | -| `encode_end_while` | `encodeEndWhile` (SPI) | `ComputeCommandEncoder::encode_end_while`, answering Metal's `BOOL`; with no block open answering `NO` and dropping its range as Metal's does | - -### `TextureDescriptor`: `MTLTextureDescriptor` - -| Item | Metal | Runtime | -|---|---|---| -| `set_resource_options` | `setResourceOptions:` | field `TextureDescriptor::resource_options` | -| `set_rotation` | `setRotation:` (SPI) | field `TextureDescriptor::rotation`: 0 to 4, with field `framebuffer_only`, for a texture over an IOSurface plane; past 4 or without `framebuffer_only` refused `Invalid` (`TextureProblem::Rotation`, `RotationWithoutFramebufferOnly`), as Metal asserts | -| `set_usage` | `setUsage:` | field `TextureDescriptor::usage` | -| `set_width` | `setWidth:` | field `TextureDescriptor::width` | -| `set_height` | `setHeight:` | field `TextureDescriptor::height` | -| `set_depth` | `setDepth:` | field `TextureDescriptor::depth` | -| `set_texture_type` | `setTextureType:` | field `TextureDescriptor::texture_type` | -| `set_pixel_format` | `setPixelFormat:` | field `TextureDescriptor::pixel_format` (a format the device lacks is refused, typed, at creation) | -| `rotation` | `rotation` (SPI) | field `TextureDescriptor::rotation`; `Texture::rotation` | -| `storage_mode` | `storageMode` | `ResourceOptions::storage_mode` of field `TextureDescriptor::resource_options` | -| `pixel_format` | `pixelFormat` | field `TextureDescriptor::pixel_format` | -| `texture_type` | `textureType` | field `TextureDescriptor::texture_type` | - -### `RenderPassDescriptor`: `MTLRenderPassDescriptor` - -| Item | Metal | Runtime | -|---|---|---| -| `set_sample_positions` | `setSamplePositions:count:` | field `RenderPassDescriptor::sample_positions` (`VK_EXT_sample_locations`; each coordinate rounded as Metal rounds it) *(partial)* | -| `set_pass` | | `RenderPassDescriptor`'s fields | -| `set_color_attachment` | | field `RenderPassDescriptor::color_attachments` | -| `set_depth_attachment` | | field `RenderPassDescriptor::depth_attachment` | -| `set_stencil_attachment` | | field `RenderPassDescriptor::stencil_attachment` | -| `color_attachment_state` | | the fields of `RenderPassDescriptor::color_attachments[i]` | -| `depth_attachment_state` | | the fields of `RenderPassDescriptor::depth_attachment` | -| `stencil_attachment_state` | | the fields of `RenderPassDescriptor::stencil_attachment` | - -### `RenderPipelineDescriptor`: `MTLRenderPipelineDescriptor` - -| Item | Metal | Runtime | -|---|---|---| -| `set_resource_index` | `setResourceIndex:` (SPI) | `PipelineOptions::placement`: the low 32 bits of the index, below 16384 | - -### `ComputePipelineDescriptor`: `MTLComputePipelineDescriptor` - -| Item | Metal | Runtime | -|---|---|---| -| `set_resource_index` | `setResourceIndex:` (SPI) | `PipelineOptions::placement`: the low 32 bits of the index, below 16384 | - -### `GpuDevice`: `MTLDevice` - -| Item | Metal | Runtime | -|---|---|---| -| `heap_texture_size_and_align` | `heapTextureSizeAndAlignWithDescriptor:` | `Device::heap_texture_size_and_align`: Metal's answer wherever the runtime models it, the device's images' own footprint where it does not | -| `new_buffer_over_host_memory` | `newBufferWithBytesNoCopy:length:options:deallocator:` | `unsafe Device::new_buffer_with_bytes_no_copy` over a `HostMemory` (`VK_EXT_external_memory_host`; where the device refuses the pointer or imports none, the dma-bufs of `HostMemory::with_dma_buf`'s source, `VK_EXT_external_memory_dma_buf`) *(partial)* | -| `new_buffer_of_length` | `newBufferWithLength:options:` | `Device::new_buffer` | -| `new_command_queue` | `newCommandQueue` | `Device::new_command_queue` | -| `new_compute_pipeline_state` | `newComputePipelineStateWithDescriptor:options:reflection:error:` | `Device::new_compute_pipeline_state` | -| `new_compute_pipeline_state_for_function` | `newComputePipelineStateWithFunction:error:` | `Device::new_compute_pipeline_state_with_function` | -| `new_shader_library` | `newLibraryWithSource:options:error:` | `Device::new_library_with_data` over the consumer's prebuilt metallib | -| `new_event` | `newEvent` | `Device::new_event` | -| `new_fence` | `newFence` | `Device::new_fence` | -| `new_library` | `newLibraryWithData:error:` | `Device::new_library_with_data` | -| `new_rate_map` | `newRasterizationRateMapWithDescriptor:` | `Device::new_rasterization_rate_map` | -| `new_render_pipeline_state_from_descriptor` | `newRenderPipelineStateWithDescriptor:options:reflection:error:` | `Device::new_render_pipeline_state` | -| `new_tile_render_pipeline_state` | `newRenderPipelineStateWithTileDescriptor:options:reflection:error:` | `Device::new_tile_render_pipeline_state` | -| `new_shared_event` | `newSharedEvent` | `Device::new_shared_event` | -| `open_shared_event` | `newSharedEventWithHandle:` | `Device::new_shared_event_with_handle`: in one process only *(partial)* | -| `new_shared_texture` | `newSharedTextureWithDescriptor:` | `Device::new_shared_texture`: in one process only *(partial)* | -| `open_shared_texture` | `newSharedTextureWithHandle:withResourceIndex:` (SPI) | `Device::new_shared_texture_with_handle`, the index as an `IdPlacement` | -| `new_texture` | `newTextureWithDescriptor:` | `Device::new_texture` | -| `reserve_resource_indices` | `reserveResourceIndicesForResourceType:indices:indexCount:` (SPI) | `Device::reserve_resource_ids` | -| `caps` | | `Device::properties()`: Metal's public properties (see `DeviceCaps` below) | -| `new_buffer` | `newBufferWithDescriptor:` (SPI) | `Device::new_buffer_with_descriptor` (`BufferDescriptor` by value, with host contents and an `AddressPlacement`; contents to copy from memory that may change while it is read as `BufferContents::CopyHost` over a `HostBytes`) | -| `new_heap` | `newHeapWithDescriptor:` | `Device::new_heap` (`HeapDescriptor::placement` pins its address range) | -| `reserve_address_pool` | (none: a runtime extension; Metal's own pools of buffers shorter than a page) | `Device::reserve_address_pool` -> `AddressPool`, holding a pin's span; `BufferDescriptor::with_pool_slot(&pool, offset)` places a buffer at the pool's address plus a 256-byte-aligned offset, holding its length rounded up to 256 bytes | -| `new_heap_over_host_memory` | (none: a runtime extension) | `unsafe Device::new_heap_with_bytes_no_copy`: a heap over the caller's page-aligned memory, a `HostMemory` (`VK_EXT_external_memory_host`, or dma-bufs as for a buffer), the heap twin of `new_buffer_with_bytes_no_copy` | -| `rebind_host_memory` | (none: a runtime extension) | `unsafe Buffer::rebind_bytes_no_copy`, `unsafe Heap::rebind_bytes_no_copy`: another range of the same length, a `HostMemory`, under the same objects and GPU addresses, in commit order (`RebindProblem::EncodedUses` while uncommitted work or an open encoder used them; a render encoder uses its attachments' bytes from its open) | -| `new_sampler_state` | `newSamplerStateWithDescriptor:` | `Device::new_sampler_state`, or `Device::new_sampler_state_with_options` (argument-buffer support, placement) | -| `new_depth_stencil_state` | `newDepthStencilStateWithDescriptor:` | `Device::new_depth_stencil_state` | -| `new_indirect_command_buffer` | `newIndirectCommandBufferWithDescriptor:maxCommandCount:options:` | `Device::new_indirect_command_buffer` (placement as an option) | -| `new_render_pipeline_state` | `newRenderPipelineStateWithDescriptor:error:` | `Device::new_render_pipeline_state` | - -### `SharedEvent`: `MTLSharedEvent` - -| Item | Metal | Runtime | -|---|---|---| -| `new_shared_event_handle` | `newSharedEventHandle` | `SharedEvent::new_shared_event_handle` | -| `set_signaled_value` | `setSignaledValue:` | `SharedEvent::set_signaled_value` | -| `wait_until_signaled_value` | `waitUntilSignaledValue:timeoutMS:` | `SharedEvent::wait_until_signaled_value` (timeout) | - -### `IndirectCommandBuffer`: `MTLIndirectCommandBuffer` - -| Item | Metal | Runtime | -|---|---|---| -| `gpu_resource_id` | `gpuResourceID` | `IndirectCommandBuffer::gpu_resource_id` | -| `compute_command` | `indirectComputeCommandAtIndex:` | `IndirectCommandBuffer::indirect_compute_command_at` | -| `render_command` | `indirectRenderCommandAtIndex:` | `IndirectCommandBuffer::indirect_render_command_at` | -| `size` | `size` | `IndirectCommandBuffer::size` | - -### `IcbRenderCmd`: `MTLIndirectRenderCommand` commands - -| Item | Metal | Runtime | -|---|---|---| -| `ClearBarrier` | `clearBarrier` | `IndirectRenderCommand::clear_barrier`: refused `Invalid`, as `set_barrier` is | -| `DrawIndexedPatches` | `drawIndexedPatches:patchStart:patchCount:patchIndexBuffer:…` | `IndirectRenderCommand::draw_indexed_patches` (the control-point index buffer an `Option`) *(partial)* | -| `DrawIndexedPrimitives` | `drawIndexedPrimitives:indexCount:indexType:indexBuffer:…` | `IndirectRenderCommand::draw_indexed_primitives` | -| `DrawPatches` | `drawPatches:patchStart:patchCount:patchIndexBuffer:…` | `IndirectRenderCommand::draw_patches` | -| `DrawPrimitives` | `drawPrimitives:vertexStart:vertexCount:instanceCount:baseInstance:` | `IndirectRenderCommand::draw_primitives` | -| `Reset` | `reset` | `IndirectRenderCommand::reset` | -| `SetBarrier` | `setBarrier` | `IndirectRenderCommand::set_barrier`: refused `Invalid`, as Metal's validation refuses it on a buffer without mesh draws | -| `SetFragmentBuffer` | `setFragmentBuffer:offset:atIndex:` | `IndirectRenderCommand::set_fragment_buffer` | -| `SetRenderPipelineState` | `setRenderPipelineState:` | `IndirectRenderCommand::set_render_pipeline_state` | -| `SetVertexBuffer` | `setVertexBuffer:offset:atIndex:` | `IndirectRenderCommand::set_vertex_buffer` | -| `SetVertexBufferAttributeStride` | `setVertexBuffer:offset:attributeStride:atIndex:` | `IndirectRenderCommand::set_vertex_buffer_with_stride` | - -### `IndirectRenderCommand`: `MTLIndirectRenderCommand` - -| Item | Metal | Runtime | -|---|---|---| -| `encode` | | one `IndirectRenderCommand` method per `IcbRenderCmd` (above) | -| `command_type`, `fragment_buffer_address`, `vertex_attribute_stride`, `vertex_buffer_address`, `has_barrier`, `draw_args`, `draw_indexed_args`, `draw_patches_args`, `draw_indexed_patches_args`, `tessellation_factor_args` | the getters (SPI) | `IndirectRenderCommand::command_type`, `vertex_buffer`, `fragment_buffer`, `has_barrier`, `draw`: each reads its field of the record alone; or `IndirectCommandBuffer::commands`, each render command decoded as an `EncodedRenderCommand`; a patch draw's buffer addresses as Metal answers them, `NIL_PATCH_BUFFER_ADDRESS` for nil, from `IndirectDraw::patch_index_buffer_address` and `control_point_index_buffer_address` | -| `pipeline_state_unique_identifier` | `getPipelineStateUniqueIdentifier` (SPI) | `IndirectRenderCommand::pipeline_unique_identifier` (with `pipeline_state` and `pipeline_id`), or that of the command read back (`IndirectCommandBuffer::commands`) *(partial)* | - -### `IcbComputeCmd`: `MTLIndirectComputeCommand` commands - -| Item | Metal | Runtime | -|---|---|---| -| `ClearBarrier` | `clearBarrier` | `IndirectComputeCommand::clear_barrier` | -| `ConcurrentDispatchThreadgroups` | `concurrentDispatchThreadgroups:threadsPerThreadgroup:` | `IndirectComputeCommand::concurrent_dispatch_threadgroups` | -| `ConcurrentDispatchThreads` | `concurrentDispatchThreads:threadsPerThreadgroup:` | `IndirectComputeCommand::concurrent_dispatch_threads` | -| `Reset` | `reset` | `IndirectComputeCommand::reset` | -| `SetBarrier` | `setBarrier` | `IndirectComputeCommand::set_barrier` | -| `SetComputePipelineState` | `setComputePipelineState:` | `IndirectComputeCommand::set_compute_pipeline_state` | -| `SetImageblockWidth` | `setImageblockWidth:height:` | `IndirectComputeCommand::set_imageblock_size` | -| `SetKernelBuffer` | `setKernelBuffer:offset:atIndex:` | `IndirectComputeCommand::set_kernel_buffer` | -| `SetKernelBufferAttributeStride` | `setKernelBuffer:offset:attributeStride:atIndex:` | `IndirectComputeCommand::set_kernel_buffer_with_stride` | -| `SetStageInRegion` | `setStageInRegion:` | `IndirectComputeCommand::set_stage_in_region` | -| `SetThreadgroupMemoryLength` | `setThreadgroupMemoryLength:atIndex:` | `IndirectComputeCommand::set_threadgroup_memory_length` | - -### `IndirectComputeCommand`: `MTLIndirectComputeCommand` - -| Item | Metal | Runtime | -|---|---|---| -| `encode` | | one `IndirectComputeCommand` method per `IcbComputeCmd` (above) | -| `command_type`, `kernel_attribute_stride`, `kernel_buffer_address`, `stage_in_region`, `threadgroup_memory_length`, `has_barrier`, `dispatch_threadgroups_args`, `dispatch_threads_args`, `image_block_args` | the getters (SPI) | `IndirectComputeCommand::command_type`, `kernel_buffer`, `stage_in_region`, `threadgroup_memory_length`, `has_barrier`, `dispatch`, `imageblock_size`: each reads its field of the record alone; or `IndirectCommandBuffer::commands`, each compute command decoded as an `EncodedComputeCommand` | -| `pipeline_state_unique_identifier` | `getPipelineStateUniqueIdentifier` (SPI) | `IndirectComputeCommand::pipeline_unique_identifier` (with `pipeline_state` and `pipeline_id`), or that of the command read back (`IndirectCommandBuffer::commands`) *(partial)* | - -### `RateMap`: `MTLRasterizationRateMap` - -| Item | Metal | Runtime | -|---|---|---| -| `copy_parameter_data` | `copyParameterDataToBuffer:offset:` | `RasterizationRateMap::copy_parameter_data_to_buffer` | -| `layer_count` | `layerCount` | `RasterizationRateMap::layer_count` | -| `mutability` | `mutability` (SPI) | `RasterizationRateMap::mutability` | -| `physical_to_screen` | `mapPhysicalToScreenCoordinates:forLayer:` | `RasterizationRateMap::map_physical_to_screen_coordinates`; a map of no layers, and a mutable map not yet reset, are refused (Metal's process ends) | -| `reset` | `resetUsingDescriptor:` (SPI) | `RasterizationRateMap::reset_using_descriptor`; a pass not yet submitted draws by the map as reset | -| `screen_to_physical` | `mapScreenToPhysicalCoordinates:forLayer:` | `RasterizationRateMap::map_screen_to_physical_coordinates`; a map of no layers is refused (Metal's process ends) | -| `parameter_buffer_size_and_align` | `parameterBufferSizeAndAlign` | `RasterizationRateMap::parameter_buffer_size_and_align` | -| `physical_granularity` | `physicalGranularity` | `RasterizationRateMap::physical_granularity` | -| `physical_size` | `physicalSizeForLayer:` | `RasterizationRateMap::physical_size_for_layer` | - -### `RateMapDescriptor`: `MTLRasterizationRateMapDescriptor` - -| Item | Metal | Runtime | -|---|---|---| -| `set_layer` | `setLayer:atIndex:` | field `metal2vulkan::bind::RateMapDescriptor::layers` | -| `set_mutability` | `setMutability:` (SPI) | field `metal2vulkan::bind::RateMapDescriptor::mutability` | -| `layer_count` | `layerCount` | `layers.len()` | -| `layer` | | `layers[i]` | - -### `RateMapLayerDescriptor`: `MTLRasterizationRateLayerDescriptor` - -| Item | Metal | Runtime | -|---|---|---| -| `horizontal_sample_storage` | `horizontalSampleStorage` | field `metal2vulkan::bind::RateMapLayerDescriptor::horizontal` | -| `sample_count` | `sampleCount` | `horizontal.len()` and `vertical.len()` | -| `vertical_sample_storage` | `verticalSampleStorage` | field `metal2vulkan::bind::RateMapLayerDescriptor::vertical` | - -### `RenderCmd`: `MTLRenderCommandEncoder` commands - -| Item | Metal | Runtime | -|---|---|---| -| `DispatchThreadsPerTile` | `dispatchThreadsPerTile:` | `RenderCommandEncoder::dispatch_threads_per_tile` | -| `DispatchThreadsPerTileInRegion` | `dispatchThreadsPerTile:inRegion:` (SPI) | `RenderCommandEncoder::dispatch_threads_per_tile_in_region` with no index: the tiles the region touches | -| `DispatchThreadsPerTileInRegionIndex` | `dispatchThreadsPerTile:inRegion:withRenderTargetArrayIndex:` (SPI) | `RenderCommandEncoder::dispatch_threads_per_tile_in_region` with `Some(index)` | -| `DrawIndexedPatchesIndirect` | `drawIndexedPatches:patchIndexBuffer:patchIndexBufferOffset:…` | `RenderCommandEncoder::draw_indexed_patches_indirect` | -| `DrawIndexedPatches` | `drawIndexedPatches:patchStart:patchCount:patchIndexBuffer:…` | `RenderCommandEncoder::draw_indexed_patches` | -| `DrawIndexedPrimitives` | `drawIndexedPrimitives:indexCount:indexType:indexBuffer:…` | `RenderCommandEncoder::draw_indexed_primitives` (Metal's defaults for the rest) *(partial)* | -| `DrawIndexedPrimitivesInstances` | `drawIndexedPrimitives:indexCount:indexType:indexBuffer:…` | `RenderCommandEncoder::draw_indexed_primitives` *(partial)* | -| `DrawIndexedPrimitivesBase` | `drawIndexedPrimitives:indexCount:indexType:indexBuffer:…` | `RenderCommandEncoder::draw_indexed_primitives` *(partial)* | -| `DrawIndexedPrimitivesIndirect` | `drawIndexedPrimitives:indexType:indexBuffer:indexBufferOffset:…` | `RenderCommandEncoder::draw_indexed_primitives_indirect` *(partial)* | -| `DrawPatchesIndirect` | `drawPatches:patchIndexBuffer:patchIndexBufferOffset:indirectBuffer:…` | `RenderCommandEncoder::draw_patches_indirect`, a patch index buffer included | -| `DrawPatches` | `drawPatches:patchStart:patchCount:patchIndexBuffer:…` | `RenderCommandEncoder::draw_patches`, a patch index buffer included | -| `DrawPrimitivesIndirect` | `drawPrimitives:indirectBuffer:indirectBufferOffset:` | `RenderCommandEncoder::draw_primitives_indirect` *(partial)* | -| `DrawPrimitives` | `drawPrimitives:vertexStart:vertexCount:` | `RenderCommandEncoder::draw_primitives` (Metal's defaults for the rest) *(partial)* | -| `DrawPrimitivesInstances` | `drawPrimitives:vertexStart:vertexCount:instanceCount:` | `RenderCommandEncoder::draw_primitives` *(partial)* | -| `DrawPrimitivesBase` | `drawPrimitives:vertexStart:vertexCount:instanceCount:baseInstance:` | `RenderCommandEncoder::draw_primitives` *(partial)* | -| `EndEncoding` | `endEncoding` | `RenderCommandEncoder::end_encoding` | -| `ExecuteCommandsIndirect` | `executeCommandsInBuffer:indirectBuffer:indirectBufferOffset:` | `RenderCommandEncoder::execute_commands_in_buffer_indirect`: the pass is recorded at a host step (announced once); `_checked` adds an `IndirectCommandCheck` the step calls on each command first, and the `IndirectCommandCheckNeeds` it looks for *(partial)* | -| `ExecuteCommandsInBuffer` | `executeCommandsInBuffer:withRange:` | `RenderCommandEncoder::execute_commands_in_buffer`: the records as they stand at commit, on the GPU alone where the commit can tell every command draws one primitive type under the inherited state (one merged draw for points, lines or triangles), or at a host step where the GPU writes them otherwise; `_checked` adds an `IndirectCommandCheck` that `commit` (for the CPU's records) or that step calls on each command first, and the `IndirectCommandCheckNeeds` it looks for, which may rule it out *(partial)* | -| `MemoryBarrierWithScope` | `memoryBarrierWithScope:afterStages:beforeStages:` | `RenderCommandEncoder::memory_barrier_with_scope` | -| `SetAlphaTestReferenceValue` | `setAlphaTestReferenceValue:` (SPI) | `RenderCommandEncoder::set_alpha_test_reference_value`: the reference a pipeline with the private alpha test compares against | -| `SetBlendColorRed` | `setBlendColorRed:green:blue:alpha:` | `RenderCommandEncoder::set_blend_color` | -| `SetColorResolveTexture` | `setColorResolveTexture:slice:depthPlane:level:yInvert:atIndex:` (SPI) | `RenderCommandEncoder::set_color_resolve_target`: the last target set holds for every draw of the pass *(partial)* | -| `SetColorStoreAction` | `setColorStoreAction:atIndex:` | `RenderCommandEncoder::set_color_store_action` | -| `SetColorStoreActionOptions` | `setColorStoreActionOptions:atIndex:` | `RenderCommandEncoder::set_color_store_action_options`: custom sample positions refused where Metal refuses them | -| `SetCullMode` | `setCullMode:` | `RenderCommandEncoder::set_cull_mode` | -| `SetDepthBias` | `setDepthBias:slopeScale:clamp:` | `RenderCommandEncoder::set_depth_bias` *(partial)* | -| `SetDepthCleared` | `setDepthCleared` (SPI) | `RenderCommandEncoder::set_depth_cleared`: changes nothing, as on Metal | -| `SetDepthResolveTexture` | `setDepthResolveTexture:slice:depthPlane:level:yInvert:` (SPI) | `RenderCommandEncoder::set_depth_resolve_target`, as the color one *(partial)* | -| `SetDepthStencilState` | `setDepthStencilState:` | `RenderCommandEncoder::set_depth_stencil_state` (`None` for nil, Metal's default state) | -| `SetDepthStoreAction` | `setDepthStoreAction:` | `RenderCommandEncoder::set_depth_store_action` | -| `SetFragmentBuffer` | `setFragmentBuffer:offset:atIndex:` | `RenderCommandEncoder::set_fragment_buffer` | -| `SetFragmentBufferOffset` | `setFragmentBufferOffset:atIndex:` | `RenderCommandEncoder::set_fragment_buffer_offset` | -| `SetFragmentBuffers` | `setFragmentBuffers:offsets:withRange:` | `RenderCommandEncoder::set_fragment_buffers` | -| `SetFragmentSamplerStatesLodClamps` | `setFragmentSamplerStates:lodMinClamps:lodMaxClamps:withRange:` | `RenderCommandEncoder::set_fragment_sampler_states` with clamps | -| `SetFragmentSamplerStates` | `setFragmentSamplerStates:withRange:` | `RenderCommandEncoder::set_fragment_sampler_states` | -| `SetFragmentTexture` | `setFragmentTexture:atIndex:` | `RenderCommandEncoder::set_fragment_texture` | -| `SetFragmentTextures` | `setFragmentTextures:withRange:` | `RenderCommandEncoder::set_fragment_textures` | -| `SetFrontFacingWinding` | `setFrontFacingWinding:` | `RenderCommandEncoder::set_front_facing_winding` | -| `SetLineWidth` | `setLineWidth:` (SPI) | `RenderCommandEncoder::set_line_width`: every width accepted, quantized as Metal does; drawn by the device's lines where they draw it (announced `device-wide-lines`, no device's taken as Metal's parallelogram) or as the band variant; what neither draws (a triangle's edges, a line without `tessellationShader`, a rate-mapped pass's or an execution's lines) by the device's lines at the nearest width they draw, announced `lines-at-nearest-width` (the runtime's README, line widths) *(partial)* | -| `SetPointSize` | `setPointSize:` (SPI) | `RenderCommandEncoder::set_point_size`: a no-op, as on Metal | -| `SetProvokingVertexMode` | `setProvokingVertexMode:` (SPI) | `RenderCommandEncoder::set_provoking_vertex_mode`: modes 0 and 1 drawn as Metal draws them; every other mode, which Metal draws a third way, drawn as 1 (patches as 0), each draw Metal's third way draws otherwise announced (`provoking-vertex-unmatched`) *(partial)* | -| `SetRenderPipelineState` | `setRenderPipelineState:` | `RenderCommandEncoder::set_render_pipeline_state` | -| `SetScissorRect` | `setScissorRect:` | `RenderCommandEncoder::set_scissor_rect` | -| `SetScissorRects` | `setScissorRects:count:` | `RenderCommandEncoder::set_scissor_rects` | -| `SetStencilCleared` | `setStencilCleared` (SPI) | `RenderCommandEncoder::set_stencil_cleared`: changes nothing, as on Metal | -| `SetStencilFrontReferenceValue` | `setStencilFrontReferenceValue:backReferenceValue:` | `RenderCommandEncoder::set_stencil_reference_values` | -| `SetStencilResolveTexture` | `setStencilResolveTexture:slice:depthPlane:level:yInvert:` (SPI) | `RenderCommandEncoder::set_stencil_resolve_target`, as the color one *(partial)* | -| `SetStencilStoreAction` | `setStencilStoreAction:` | `RenderCommandEncoder::set_stencil_store_action` | -| `SetStencilStoreActionOptions` | `setStencilStoreActionOptions:` | `RenderCommandEncoder::set_stencil_store_action_options`, as the color one | -| `SetTessellationFactorBuffer` | `setTessellationFactorBuffer:offset:instanceStride:` | `RenderCommandEncoder::set_tessellation_factor_buffer` | -| `SetTessellationFactorScale` | `setTessellationFactorScale:` | `RenderCommandEncoder::set_tessellation_factor_scale` | -| `SetThreadgroupMemoryLength` | `setThreadgroupMemoryLength:offset:atIndex:` | `RenderCommandEncoder::set_threadgroup_memory_length` (a tile function's memory, kept across the pass's tile dispatches) | -| `SetTileBufferOffset` | `setTileBufferOffset:atIndex:` | `RenderCommandEncoder::set_tile_buffer_offset` | -| `SetTileBuffers` | `setTileBuffers:offsets:withRange:` | `RenderCommandEncoder::set_tile_buffers` | -| `SetTileSamplerStatesLodClamps` | `setTileSamplerStates:lodMinClamps:lodMaxClamps:withRange:` | `RenderCommandEncoder::set_tile_sampler_states` with clamps | -| `SetTileSamplerStates` | `setTileSamplerStates:withRange:` | `RenderCommandEncoder::set_tile_sampler_states` | -| `SetTileTextures` | `setTileTextures:withRange:` | `RenderCommandEncoder::set_tile_textures` | -| `SetTriangleFillMode` | `setTriangleFillMode:` | `RenderCommandEncoder::set_triangle_fill_mode` | -| `SetVertexAmplificationCount` | `setVertexAmplificationCount:viewMappings:` | `RenderCommandEncoder::set_vertex_amplification_count`: fewer view mappings than the count refused `Invalid` | -| `SetVertexAmplificationMode` | `setVertexAmplificationMode:value:` (SPI) | `RenderCommandEncoder::set_vertex_amplification_mode`: sets the amplification count, the view mappings kept; a count of 0, past 8 or past the mappings refused `AppleOnly::VertexAmplificationMode` *(partial)* | -| `SetVertexBuffer` | `setVertexBuffer:offset:atIndex:` | `RenderCommandEncoder::set_vertex_buffer` | -| `SetVertexBufferOffset` | `setVertexBufferOffset:atIndex:` | `RenderCommandEncoder::set_vertex_buffer_offset` | -| `SetVertexBufferOffsetAttributeStride` | `setVertexBufferOffset:attributeStride:atIndex:` | `RenderCommandEncoder::set_vertex_buffer_offset_with_stride` | -| `SetVertexBuffersAttributeStrides` | `setVertexBuffers:offsets:attributeStrides:withRange:` | `RenderCommandEncoder::set_vertex_buffers_with_strides` | -| `SetVertexBuffers` | `setVertexBuffers:offsets:withRange:` | `RenderCommandEncoder::set_vertex_buffers` | -| `SetVertexSamplerStatesLodClamps` | `setVertexSamplerStates:lodMinClamps:lodMaxClamps:withRange:` | `RenderCommandEncoder::set_vertex_sampler_states` with clamps | -| `SetVertexSamplerStates` | `setVertexSamplerStates:withRange:` | `RenderCommandEncoder::set_vertex_sampler_states` | -| `SetVertexTextures` | `setVertexTextures:withRange:` | `RenderCommandEncoder::set_vertex_textures` | -| `SetViewport` | `setViewport:` | `RenderCommandEncoder::set_viewport` *(partial)* | -| `SetViewportTransformEnabled` | `setViewportTransformEnabled:` (SPI) | `RenderCommandEncoder::set_viewport_transform_enabled`: on accepted; off refused `AppleOnly::ViewportTransformDisabled` *(partial)* | -| `SetViewports` | `setViewports:count:` | `RenderCommandEncoder::set_viewports` *(partial)* | -| `SetVisibilityResultMode` | `setVisibilityResultMode:offset:` | `RenderCommandEncoder::set_visibility_result_mode` (occlusion queries) | -| `UpdateFence` | `updateFence:afterStages:` | `RenderCommandEncoder::update_fence` | -| `UseHeaps` | `useHeaps:count:` | `RenderCommandEncoder::use_heaps`, which always names the stages | -| `UseHeapsStages` | `useHeaps:count:stages:` | `RenderCommandEncoder::use_heaps` | -| `UseResources` | `useResources:count:usage:` | `RenderCommandEncoder::use_resources`, which always names the stages | -| `UseResourcesStages` | `useResources:count:usage:stages:` | `RenderCommandEncoder::use_resources` | -| `WaitForFence` | `waitForFence:beforeStages:` | `RenderCommandEncoder::wait_for_fence` | - -### `RenderEncoder`: `MTLRenderCommandEncoder` - -| Item | Metal | Runtime | -|---|---|---| -| `encode` | | one `RenderCommandEncoder` method per `RenderCmd` (above) | -| `tile_height` | `tileHeight` | `RenderCommandEncoder::tile_height` | -| `tile_width` | `tileWidth` | `RenderCommandEncoder::tile_width` | - -### `GpuResource`: `MTLResource` - -| Item | Metal | Runtime | -|---|---|---| -| `device` | `device` | `Buffer::device`, `Texture::device` | -| `resource_options` | `resourceOptions` | `Buffer::resource_options`, `Texture::resource_options` | -| `set_label` | `setLabel:` | `Buffer::set_label`, `Texture::set_label` | -| `set_purgeable_state` | `setPurgeableState:` | `Buffer::set_purgeable_state`, `Texture::set_purgeable_state`: Metal's answers, the state kept from 16 KiB or for a shareable texture; refused for a heap's resource | -| `storage_mode` | `storageMode` | `Buffer::storage_mode`, `Texture::storage_mode` | - -### `Buffer`: `MTLBuffer` - -| Item | Metal | Runtime | -|---|---|---| -| `contents` | `contents` | `Buffer::contents` | -| `did_modify_range` | `didModifyRange:` | `Buffer::did_modify_range` | -| `gpu_address` | `gpuAddress` (SPI) | `Buffer::gpu_address`, in the runtime's Metal address space | -| `length` | `length` | `Buffer::length` | -| `new_linear_texture` | `newLinearTextureWithDescriptor:offset:bytesPerRow:bytesPerImage:` (SPI) | `Buffer::new_linear_texture` (an aliasing image, or a shadow image where Vulkan cannot alias) *(partial)* | -| `new_texture` | `newTextureWithDescriptor:offset:bytesPerRow:` | `Buffer::new_texture`, as `new_linear_texture` *(partial)* | -| `new_tiled_texture` | `newTiledTextureWithDescriptor:offset:bytesPerRow:` (SPI) | `Buffer::new_tiled_texture`: one level as `new_texture`; more, one image of every level, a copy of the bytes taken at the first use and after each `Texture::did_modify_data`, its later levels made as `generate_mipmaps` makes them; the CPU's first level is the bytes (`shadowed-texture`) *(partial)* | - -### `Texture`: `MTLTexture` - -| Item | Metal | Runtime | -|---|---|---| -| `array_length` | `arrayLength` | `Texture::array_length` | -| `depth` | `depth` | `Texture::depth` | -| `did_modify_data` | `didModifyData` (SPI) | `Texture::did_modify_data`: a tiled texture of more than one level takes its copy of the bytes again at its next use; nothing on another texture | -| `gpu_resource_id` | `gpuResourceID` | `Texture::gpu_resource_id` | -| `height` | `height` | `Texture::height` | -| `is_shareable` | `isShareable` | `Texture::is_shareable` | -| `mipmap_level_count` | `mipmapLevelCount` | `Texture::mipmap_level_count` | -| `new_shared_texture_handle` | `newSharedTextureHandle` | `Texture::new_shared_texture_handle` | -| `new_texture_view` | `newTextureViewWithPixelFormat:` | `Texture::new_texture_view` | -| `new_texture_view_at_index` | `newTextureViewWithPixelFormat:resourceIndex:` (SPI) | `Texture::new_texture_view_with_placement` | -| `new_texture_subview` | `newTextureViewWithPixelFormat:textureType:levels:slices:` | `Texture::new_texture_view_with_levels_slices` | -| `new_swizzled_texture_subview` | `newTextureViewWithPixelFormat:textureType:levels:slices:swizzle:` | `Texture::new_texture_view_with_swizzle` | -| `new_swizzled_texture_subview_at_index` | `newTextureViewWithPixelFormat:textureType:levels:slices:swizzle:…` | `Texture::new_texture_subview_with_placement` (a swizzle) | -| `new_texture_subview_at_index` | `newTextureViewWithPixelFormat:textureType:levels:slices:…` | `Texture::new_texture_subview_with_placement` (no swizzle) | -| `pixel_format` | `pixelFormat` | `Texture::pixel_format` | -| `protection_options` | `protectionOptions` (SPI) | `Texture::protection_options`: always 0 | -| `replace_region` | `replaceRegion:mipmapLevel:slice:withBytes:bytesPerRow:bytesPerImage:` | `Texture::replace_region`; from memory that may change while it is read (a guest's), `Texture::replace_region_with_host_bytes` over a `HostBytes`, which the call copies once through the pointer, with no copy of the caller's first | -| `sample_count` | `sampleCount` | `Texture::sample_count` | -| `texture_type` | `textureType` | `Texture::texture_type` | -| `usage` | `usage` | `Texture::usage` | -| `width` | `width` | `Texture::width` | - -### `Heap`: `MTLHeap` - -| Item | Metal | Runtime | -|---|---|---| -| `gpu_address` | `gpuAddress` (SPI) | `Heap::gpu_address`: the heap's Metal address range | -| `new_buffer_of_length` | `newBufferWithLength:options:offset:` | `Heap::new_buffer`, or `Heap::new_buffer_at_offset` in a placement heap | -| `new_texture` | `newTextureWithDescriptor:offset:` | `Heap::new_texture_at_offset` | -| `resource_options` | `resourceOptions` | `Heap::resource_options` | -| `set_purgeable_state` | `setPurgeableState:` | `Heap::set_purgeable_state` | -| `storage_mode` | `storageMode` | `Heap::storage_mode` | - -### `SamplerState`: `MTLSamplerState` - -| Item | Metal | Runtime | -|---|---|---| -| `gpu_resource_id` | `gpuResourceID` | `SamplerState::gpu_resource_id` | - -### `DepthStencilState`: `MTLDepthStencilState` - -| Item | Metal | Runtime | -|---|---|---| -| `gpu_resource_id` | `gpuResourceID` | `DepthStencilState::gpu_resource_id`: 0 below Apple10, plain Metal's answer; `NotImplemented(IndirectRenderCommands)` on a device that claims Apple10 | - -### `ComputePipeline`: `MTLComputePipelineState` - -| Item | Metal | Runtime | -|---|---|---| -| `gpu_resource_id` | `gpuResourceID` | `ComputePipelineState::gpu_resource_id` | -| `imageblock_memory_length` | `imageblockMemoryLengthForDimensions:` | `ComputePipelineState::imageblock_memory_length_for_dimensions` | -| `max_total_threads_per_threadgroup` | `maxTotalThreadsPerThreadgroup` | `ComputePipelineState::max_total_threads_per_threadgroup` | -| `static_threadgroup_memory_length` | `staticThreadgroupMemoryLength` | `ComputePipelineState::static_threadgroup_memory_length` | -| `support_indirect_command_buffers` | `supportIndirectCommandBuffers` | `ComputePipelineState::support_indirect_command_buffers` | -| `thread_execution_width` | `threadExecutionWidth` | `ComputePipelineState::thread_execution_width` (32) | - -### `RenderPipeline`: `MTLRenderPipelineState` - -| Item | Metal | Runtime | -|---|---|---| -| `gpu_resource_id` | `gpuResourceID` | `RenderPipelineState::gpu_resource_id` | -| `imageblock_memory_length` | `imageblockMemoryLengthForDimensions:` | `RenderPipelineState::imageblock_memory_length_for_dimensions` | -| `imageblock_sample_length` | `imageblockSampleLength` | `RenderPipelineState::imageblock_sample_length` | -| `max_total_threads_per_threadgroup` | `maxTotalThreadsPerThreadgroup` | `RenderPipelineState::max_total_threads_per_threadgroup` | -| `support_indirect_command_buffers` | `supportIndirectCommandBuffers` | `RenderPipelineState::support_indirect_command_buffers` | -| `threadgroup_size_matches_tile_size` | `threadgroupSizeMatchesTileSize` | `RenderPipelineState::threadgroup_size_matches_tile_size` | - -### `Library`: `MTLLibrary` - -| Item | Metal | Runtime | -|---|---|---| -| `function_names` | `functionNames` | `Library::function_names` | -| `new_function` | `newFunctionWithName:` | `Library::new_function_with_name` | - -### `DeviceCaps`: `MTLDevice` queries - -| Item | Metal | Runtime | -|---|---|---| -| `name` | `name` | `DeviceProperties::name` | -| `registry_id` | `registryID` | `Device::registry_id`, folded from `deviceUUID` | -| `max_threads_per_threadgroup` | `maxThreadsPerThreadgroup` | `DeviceProperties::max_threads_per_threadgroup` | -| `limits.max_threadgroup_memory_length` | `maxThreadgroupMemoryLength` | `DeviceProperties::max_threadgroup_memory_length` | -| `flags.are_raster_order_groups_supported` | `areRasterOrderGroupsSupported` | `DeviceProperties::are_raster_order_groups_supported`: yes where the device enables `fragmentShaderPixelInterlock` *(partial)* | -| `flags.is_depth24_stencil8_pixel_format_supported` | `isDepth24Stencil8PixelFormatSupported` | `DeviceProperties::is_depth24_stencil8_pixel_format_supported`; where no, making the format is refused | -| `sample_counts` | `supportsTextureSampleCount:` | `DeviceProperties::supports_texture_sample_count` | -| `families` | `supportsFamily:` | `Device::supports_family`; `Device::family_blockers` names what blocks a family | -| `heap_buffer_page_private` | `heapBufferSizeAndAlignWithLength:options:` | `Device::heap_buffer_size_and_align` | -| `min_linear_alignment_bgra8` | `minimumLinearTextureAlignmentForPixelFormat:` | `Device::minimum_linear_texture_alignment_for_pixel_format` | - -### `IdentityCaps`: `MTLDevice` identity and size answers - -| Item | Metal | Runtime | -|---|---|---| -| `sizes.max_argument_buffer_sampler_count` | `maxArgumentBufferSamplerCount` | `DeviceProperties::max_argument_buffer_sampler_count`: one fewer than the smaller of a set-1 sampler array's elements (`metal2vulkan::pipeline::heap_sampler_capacity`) and `maxSamplerAllocationCount`; 65535 on MoltenVK on an M3 Max, where Metal answers 500000 *(partial)* | - -## Composed from runtime calls - -These items have no single runtime call. The consumer builds them from the calls named. - -| Item | How | -|---|---| -| `BlitCmd::CopyTextureRegionOptions` | options 0 is `BlitCommandEncoder::copy_from_texture_to_texture`; a public `BlitOption` goes through a buffer (`copy_from_texture_to_buffer`, then `copy_from_buffer_to_texture`) | -| `RenderCmd::SetDepthClipModeSpi` | the public `RenderCommandEncoder::set_depth_clip_mode` | -| `RenderCmd::SetPrimitiveRestartEnabled` | `RenderCommandEncoder::set_primitive_restart_enabled`: indexed strips restart at the index as Metal takes it for their index type, and only there | -| `GpuDevice::allow_foreign_libraries` | nothing to call: `Device::new_library_with_data` reads a metallib of any Apple platform | -| `GpuDevice::new_buffer_on_surface`, `GpuDevice::new_texture_on_surface` | `Device::new_buffer_with_bytes_no_copy` over the surface's memory, then, for a texture, `Buffer::new_texture_with_iosurface_plane` with the plane's offset, `bytesPerRow` and whether the surface has planes (`Buffer::new_texture` applies the buffer rules, which refuse a surface plane's pitches off 16 that Metal takes) | -| `DeviceCaps::max_vertex_amplification_count` | the largest count `DeviceProperties::supports_vertex_amplification_count` accepts | -| `DeviceCaps::limits.max_rasterization_rate_layer_count` | the largest count `DeviceProperties::supports_rasterization_rate_map_with_layer_count` accepts | -| `DeviceCaps::flags.supports_programmable_sample_positions` | `DeviceProperties::are_programmable_sample_positions_supported` | -| `DeviceCaps::limits.max_viewport_count` | `DeviceProperties::max_viewports` | -| `DeviceCaps::flags.supports_shared_texture_handles` | the runtime's `SharedTextureHandle`, in one process | - -## Not the runtime's - -These stay with the consumer. The rule: what a plain Metal program needs belongs to the runtime; -what only a paravirtualized device needs belongs to its consumer. - -- **IOSurface:** the `Surface` and `IoSurfaces` traits, `Buffer::iosurface`, `Texture::iosurface`, - `GpuDevice::texture_level_info`, and the `supports_buffer_with_iosurface` flag. -- **Operating-system services:** the `Clock`, `TimerClock`, `Threads`, `Preferences` and `HostVm` - traits, and `Platform`'s `clock`, `threads`, `vm`, `globals` and `launcher`. -- **Scattered backing**: `Platform::type AddressRangeArray`, - `new_address_range_array`, and `detach_backing` and `replace_backing` on buffers and heaps. -- **The guest's own numbering:** the runtime answers `resource_index` and `unique_identifier` on - pipeline states and indirect command buffers by Metal's rules where they were measured, and - places an object's resource ID where the consumer asks (`IdPlacement`, - `Device::reserve_resource_ids`); a guest's own numbering of other objects stays the consumer's. -- **Apple's serialized pipeline descriptors:** the three `deserialize_*_pipeline_descriptor` - items. -- **Apple's descriptions of formats and devices:** `GpuDevice::pixel_format_info` (Apple's flag - words; `metal2vulkan::metal::format` holds the block facts), `DeviceCaps::gpu_core_count`, and - the private limits and flags no measurement covers.