diff --git a/crates/metal2vulkan-runtime/README.md b/crates/metal2vulkan-runtime/README.md index 80473f3dc..3bf58ff03 100644 --- a/crates/metal2vulkan-runtime/README.md +++ b/crates/metal2vulkan-runtime/README.md @@ -1525,8 +1525,9 @@ made, with no lock, and never rewritten for layouts. for a draw completes that one form and adds none. - An opaque-black border sampled through a view whose component mapping is not the identity (a swizzle, or the mapping a pixel format takes: `A8Unorm` is held in `R8_UNORM` read through - `(0, 0, 0, r)` on every device, as rt uses Vulkan 1.3 and does not enable - `VK_KHR_maintenance5`, so `A8_UNORM` is not exposed) is the device's answer on a device that + `(0, 0, 0, r)` on every device, as rt uses Vulkan 1.3 and takes no format of + `VK_KHR_maintenance5`, so `A8_UNORM` is not used; where indirect command buffers enable + `VK_KHR_maintenance5`, that changes nothing here) is the device's answer on a device that does not report `borderColorSwizzleFromImage` (`VkPhysicalDeviceBorderColorSwizzleFeaturesEXT`, `VK_EXT_border_color_swizzle`): Vulkan leaves that texel undefined, and the NVIDIA driver reads `(0, 0, 0, 1)` through such a view, where @@ -2458,7 +2459,8 @@ while the driver's exit handler waited on a lock, with every runtime thread alre the descriptor's size, `[0, 0, 0]` where it set none, as the M3 recordings `pipeline-facts-compute-plain` and `pipeline-facts-compute-described` answer, and `supportIndirectCommandBuffers` (`support_indirect_command_buffers`) is false: a descriptor that - asks for indirect command buffers is refused at the making (`Gap::IndirectCommandBuffers`). + asks for indirect command buffers is refused at the making (`Gap::IndirectCommandBuffers`, + `IndirectCommandsKind::ComputeCommands`). ### The cache directory @@ -2671,9 +2673,10 @@ or does not check is rebuilt from the generations' names, with young counted ful fetch, or a sampler or texture state the translator would take from the bound object rather than from its resource ID, is refused (`Gap::KernelInput`, whose `KernelInputKind` names what the runtime found: `Slot` for a function table, `StageIn` for a `[[stage_in]]` fetch). So is a state - for indirect command buffers (`Gap::IndirectCommandBuffers`), and a kernel that encodes commands - into one, which the translator refuses (`Unsupported{GpuEncodedIndirectCommands, - NotImplemented}`). + for indirect command buffers (`Gap::IndirectCommandBuffers`, `IndirectCommandsKind::ComputeCommands`). + A kernel that encodes indexed triangle draws into an indirect command buffer is built (Indirect + command buffers, below); one that encodes anything else the translator refuses + (`Unsupported{GpuEncodedIndirectCommands, NotImplemented}`). - A threadgroup that is not whole SIMD groups of a kernel whose SIMD groups run one per subgroup of 32 is refused (`Gap::PartialSimdgroups`) where the state has no emulated-SIMD-group module: for a kernel the consumer compiled (`StageSource::Compiled`), and where the translator refuses @@ -2782,9 +2785,10 @@ or does not check is rebuilt from the generations' names, with young counted ful with indirect-command support or without; `R8Unorm` then `RG16Float` 6 and 192 (`RG16Float` at byte 2, its component's alignment, where packing tight would answer 5 and aligning to 4 would answer 8); `RGBA8Unorm` then `RGBA16Float` with a `Depth32Float_Stencil8` depth and - stencil attachment 12 and 384, as without it. `support_indirect_command_buffers` is false, as a - compute state's is: a descriptor that asks for indirect command buffers is refused at the - making. The runtime makes no tile render state, so it has no tile getters + stencil attachment 12 and 384, as without it. `support_indirect_command_buffers` is the + descriptor's: a state made with it pulls every vertex attribute its vertex function reads, and + its commands run in an execution of an indirect command buffer (Indirect command buffers, + below). The runtime makes no tile render state, so it has no tile getters (`maxTotalThreadsPerThreadgroup`, a tile threadgroup's, `threadgroupSizeMatchesTileSize`, `requiredThreadsPerTileThreadgroup`). - A state numbers its functions' samplers as a compute state numbers its kernel's: @@ -2927,8 +2931,8 @@ or does not check is rebuilt from the generations' names, with young counted ful that reads what a draw does not supply (`DrawInput`: a function table, a table the binder builds, a parameter block past the push range, a push field or bind-time fact the encoder does not fill, an unnormalized constexpr sampler). Of the replay streams' contents that translate, every one - reads only its slots' addresses, resource IDs and constexpr sampler indices. A state for indirect - command buffers is `Gap::IndirectCommandBuffers`. The `completionHandler:` forms are not built. + reads only its slots' addresses, resource IDs and constexpr sampler indices. The + `completionHandler:` forms are not built. - On a device that does not list `VK_EXT_shader_stencil_export`, a fragment function's `[[stencil]]` output is refused at creation, an `Error::Translation` naming `StencilExport`: under the identity domains the pixel interlock chooses no other form. Metal's feature set tables give stencil @@ -3393,13 +3397,12 @@ or does not check is rebuilt from the generations' names, with young counted ful a declared write of a Shared buffer, or of a texture over one, reaches the host once the command buffer completes. A declared write of a texture with no storage element refuses the encoder's later draws that may reach one beyond their slots (the known gaps of textures). -- Not built, and so not methods: `useHeap:stages:`, the store action options setters, tile - functions, `setVertexBuffer:offset:attributeStride:atIndex:`, `setTessellationFactorScale:` (read - only by a state that enables the scale, which is refused) and `drawIndexedPatches:` (whose - control-point index buffer only a state of a control-point index type reads, which is refused). - Where a replay stream calls `useHeap:stages:` (`command-replay shapes` counts a stream's calls of - each selector), it is built in the compute encoder's form, `use_heap`: the command buffer keeps - the block and declares no access. +- Not built, and so not methods: the store action options setters, tile functions, + `setVertexBuffer:offset:attributeStride:atIndex:`, `setTessellationFactorScale:` (read only by a + state that enables the scale, which is refused) and `drawIndexedPatches:` (whose control-point + index buffer only a state of a control-point index type reads, which is refused). + `useHeap:stages:` is `use_heap`, in the compute encoder's form: the command buffer keeps the + block and declares no access. - Refused by `Gap::RenderPass`, naming its `RenderPassKind`: a depth and a stencil attachment that are not one texture's same level and slice (`DepthStencilViews`: Vulkan's rendering takes one view for both), a `Clear` load of a depth attachment whose clear depth is outside `[0, 1]` @@ -3505,6 +3508,106 @@ or does not check is rebuilt from the generations' names, with young counted ful another texture. At 3648 × 2038 a pass that reads its target after a barrier takes 4,836.4 µs, and one that loads its target and reads it at its first draw 3,849.6 µs. +## Indirect command buffers + +`Device::new_indirect_command_buffer` (`newIndirectCommandBufferWithDescriptor:maxCommandCount:options:`) +makes a buffer of indexed draw commands on a device that enables `VK_EXT_device_generated_commands` +and `VK_KHR_maintenance5` (`floor::INDIRECT_COMMANDS`, in the Floor's extensions). The runtime builds +the commands a kernel encodes: indexed triangle draws (`MTLIndirectCommandTypeDrawIndexed` alone) +that inherit the executing encoder's pipeline state (`inheritPipelineState`) and bind their own +vertex and fragment buffers (`inheritBuffers` false), at most 31 of each stage. + +- Its records are a Private block in the layout `metal2vulkan::pipeline::IndirectDrawLayout` names: + a 24-byte header (the capacity, the vertex and fragment slots a command holds, the stride, and + the index address a reset command binds), then one command a stride: an 8-byte word a slot, the + index buffer token's 16 bytes, 4 bytes for the sequence index and the indexed draw's 20 bytes + (152 bytes for 7 vertex and 7 fragment slots, 536 at most). `gpu_resource_id` is the header's + device address, which the consumer writes into an argument buffer's `command_buffer` member; a + kernel's `set_vertex_buffer`, `set_fragment_buffer`, `draw_indexed_primitives` and `reset` of a + `render_command` write the command's fields through it, under the identity domains. `size` is + the `maxCommandCount`. +- A new buffer's commands are copies of the device's template of reset commands of its layout (up + to 64 KiB of commands, each drawing nothing with every slot the nil buffer's; 16 layouts kept, the + least recently used forgotten first), in the upload of the next commit. + `BlitCommandEncoder::reset_commands_in_buffer` copies the same commands over its range, and + `optimize_indirect_command_buffer` records nothing. +- `RenderCommandEncoder::execute_commands_in_buffer` runs the range in parts of 64 commands, in + order, the last part the rest: one `vkCmdExecuteGeneratedCommandsEXT` a part, a sequence a + command, with the encoder's pipeline state and render state: a push constant token for each run + of slot words the state's functions read at consecutive push offsets, the index buffer token, a + sequence index token and the indexed draw token. Before each part the execution pushes the part's + first command, which the vertex function adds to the sequence index. The device keeps 64 command + layouts, one per shape of tokens, and 256 execution shapes of a part's 64 commands, one per + state, raster state (the depth clip and triangle fill modes, which choose the state's pipeline) + and layout. `execute_commands_in_buffer_with_range` reads the range + (`MTLIndirectCommandBufferExecutionRange`) where a buffer holds it when the command runs: the + execution runs every command of the buffer, and the vertex function returns before its body for + a command outside the range. +- A state made with `supportIndirectCommandBuffers` pulls every vertex attribute its vertex function + reads, so a command binds no vertex buffer of its own, and its vertex function tests its command + against the execution's range; a direct draw of the state tests it against a range of every + command. +- A command's buffer slots are not bounds-checked: an execution pushes their bounds as 2^31 - 1 + bytes before the address and `u32::MAX` bytes after it. An access through one past the buffer's + end reaches the memory there, as an access through a pointer loaded from memory does. An access + at a negative offset that stays inside the buffer reads the buffer's own bytes. +- After an execution the push bytes and the index buffer are undefined, as Vulkan leaves them, and + the next draw pushes and binds its own; the pipeline and the vertex buffers stay bound. +- Each execution takes a preprocess region when it is recorded, an idle one of the device's pool + or one made then, its parts' preprocess one after another, each sized by + `vkGetGeneratedCommandsMemoryRequirementsEXT` with the inherited pipeline at 64 commands, and + gives it back when its command buffer completes. The pool + keeps at most 128 MiB of idle regions, the oldest freed past that; nothing waits and no execution + is refused for the pool's sake. The gauges `indirect_command_buffers`, `preprocess_used_bytes` + and `preprocess_idle_bytes` count them, each zero once the device is dropped. +- Of `VK_KHR_maintenance5` the runtime uses one structure, `VkBufferUsageFlags2CreateInfoKHR`, for + the preprocess buffers' `VK_BUFFER_USAGE_2_PREPROCESS_BUFFER_BIT_EXT`. + +### Known gaps of indirect command buffers + +- An execution over a range a buffer holds processes the buffer's whole capacity: each command + outside the range, reset or not, costs its vertex work and draws nothing. +- A state made with `supportIndirectCommandBuffers` pays one 8-byte load a vertex on its direct + draws too: its vertex function reads the execution range. +- An execution over a range a buffer holds takes a preprocess region for the buffer's whole + capacity, whatever the range: up to 592 bytes a command on NVIDIA's driver and 360 on RADV, held + until the command buffer completes. +- Every execution runs in parts of 64 commands, on every device. One execution of more did not draw + every command in order where it was measured: on RADV (Mesa 26.2.6, a Radeon RX 7900 XTX) an + execution of N commands whose generated commands pass about 4 MiB (296 bytes a command, 14,170 + commands) drew only its first N - 14,170 commands, or none, a driver bug; on NVIDIA's driver (620.70.06, an RTX 2080) one of + more than 64 commands ended out of order, a cause not yet found. The parts cost, at 14,000 + commands against one execution: 62% more GPU time on the XTX and 61 times as much on the 2080, + and 25 to 34 times the recording time. +- On Mesa's CPU device (lavapipe, Mesa 26.2.6) an indirect command buffer of 5,792 commands or more + overruns the driver's preprocess buffer: its `vkGetGeneratedCommandsMemoryRequirementsEXT` size + for a draw layout is quadratic in the command count and wraps at 2^32, while its preprocessing + writes linearly (16 + 100 bytes a command for an index-buffer and indexed-draw layout); a driver + bug. Below that count the size covers the writes but grows quadratically (134 MB at 1,024 + commands). +- On the Iris Xe (ANV, Mesa 26.2.6), which does not list `VK_EXT_device_generated_commands`, an + indirect command buffer is refused (`Gap::IndirectCommandBuffers`, + `IndirectCommandsKind::Extension`). +- On the UHD 630 (its Windows driver), which does not list `VK_EXT_device_generated_commands`, an + indirect command buffer is refused the same way. +- On the Mac host (KosmicKrisp, Mesa 26.3.1, on an Apple M3 Max), which does not list + `VK_EXT_device_generated_commands`, an indirect command buffer is refused the same way. +- Refused by `Gap::IndirectCommandBuffers`, naming its `IndirectCommandsKind`: command types other + than indexed draws alone (`CommandTypes`), commands that set their own pipeline state + (`CommandPipelines`, on every device), commands that inherit the encoder's buffers + (`InheritedBuffers`), more than 31 buffers of a stage (`BindCount`), a count of 0 or one past + `maxIndirectSequenceCount` (`Capacity`), a compute state for indirect command buffers + (`ComputeCommands`), an execution with a state made without `supportIndirectCommandBuffers` + (`UnflaggedState`), one whose slot runs take more tokens than `maxIndirectCommandsTokenCount` + (`Tokens`: 16 on lavapipe, 32 on NVIDIA's driver, 128 on RADV), and one whose functions read what + a command cannot carry: a slot the command holds outside the push bytes, a fixed-function vertex + binding, or a vertex layout that must draw from base instance 0 (`DrawInput`). +- Commands draw with the executing encoder's render states whatever the descriptor's other + `inherit*` properties say. Not built: commands the CPU encodes (`indirectRenderCommandAtIndex:`), + `copyIndirectCommandBuffer:sourceRange:destination:destinationIndex:`, compute commands, and a + kernel's draws other than indexed triangles, which the translator refuses + (`Unsupported{GpuEncodedIndirectCommands, NotImplemented}`). + ## Presenting The consumer presents on the runtime's own device, in its process: it owns the surface, the @@ -3654,6 +3757,8 @@ Presenting runs on the runtime's own device; nothing is exported or imported. | `VK_EXT_device_fault` | device, where listed | a lost device's fault report, read once at its first loss (`DeviceLoss::fault`), through the fault-report feature below | | `VK_EXT_custom_border_color` | device, where reported from the image | Vulkan requires it of a device that enables the border swizzle below; none of its features is enabled | | `VK_EXT_border_color_swizzle` | device, where reported from the image | an opaque-black border sampled through a view whose component mapping is not the identity, defined and read through that mapping (Border swizzle, below) | +| `VK_EXT_device_generated_commands` | device, with indirect command buffers | an indirect command buffer's execution, through `deviceGeneratedCommands`, enabled where the device reports it with the limits an execution needs (Indirect command buffers, above) | +| `VK_KHR_maintenance5` | device, with indirect command buffers | the preprocess buffers' usage flag (`VkBufferUsageFlags2CreateInfoKHR`), through `maintenance5`, enabled with the extension above alone | | `VK_KHR_fragment_shader_barycentric` | device, where reported | a fragment function's `[[barycentric_coord]]`, through the barycentric feature below; `Device::extensions` names it only where that feature is enabled | ### Features diff --git a/crates/metal2vulkan-runtime/src/blit.rs b/crates/metal2vulkan-runtime/src/blit.rs index fd39107c5..a86b38982 100644 --- a/crates/metal2vulkan-runtime/src/blit.rs +++ b/crates/metal2vulkan-runtime/src/blit.rs @@ -38,6 +38,7 @@ use crate::encoder::Resource; use crate::error::{Error, Gap, Refusal}; use crate::fence::Fence; use crate::hazard::Access; +use crate::indirect::{reset_regions, IndirectCommandBuffer}; use crate::memory::Own; use crate::over::{self, Reached}; use crate::record::{memory_barrier, Reach}; @@ -645,6 +646,80 @@ impl BlitCommandEncoder { Ok(()) } + /// `resetCommandsInBuffer:withRange:`: commands `range` of `buffer` reset, each drawing nothing + /// with every slot bound to nothing, by copies from the device's template of reset commands of + /// the buffer's layout (`crate::indirect`): one `vkCmdCopyBuffer`, a region for each run of + /// as many commands as the template holds, between a fill's two barriers. An empty range + /// records nothing. The command buffer keeps the buffer's records and the template until it + /// retires. + /// + /// Err: [`Refusal::OtherDevice`] for another device's buffer; [`Refusal::CommandRange`] for a + /// range past the buffer's commands; what making the template returns + /// ([`Device::new_indirect_command_buffer`](crate::Device::new_indirect_command_buffer)'s); + /// [`Error::Vulkan`] where the command buffer cannot record. + pub fn reset_commands_in_buffer( + &mut self, + buffer: &IndirectCommandBuffer, + range: Range, + ) -> Result<(), Error> { + let (core, building) = self.parts(); + if !buffer.is_of(core) { + return Err(Error::Refused(Refusal::OtherDevice)); + } + if range.start > range.end || range.end > buffer.size() { + return Err(Error::Refused(Refusal::CommandRange)); + } + if range.is_empty() { + return Ok(()); + } + let indirect = (core.indirect.as_ref()) + .expect("a device that made an indirect command buffer enabled the extension"); + let template = indirect.template(core, buffer.layout())?; + let (source, destination, regions) = + reset_regions(&template, buffer.layout(), buffer.records(), range); + building.keep_block(buffer.records()); + building.keep_block(template.block()); + let command = building.ordered_command()?; + let earlier = [memory_barrier(Reach::Commands)]; + let written = [written()]; + let device = &core.device; + // SAFETY: the command buffer records outside any render pass and keeps both blocks until + // it retires; each region lies in the template and in the records (`reset_regions`). + unsafe { + device.cmd_pipeline_barrier2( + command, + &vk::DependencyInfo::default().memory_barriers(&earlier), + ); + device.cmd_copy_buffer(command, source, destination, ®ions); + device.cmd_pipeline_barrier2( + command, + &vk::DependencyInfo::default().memory_barriers(&written), + ); + } + building.count(Metric::Barriers); + building.count(Metric::Barriers); + Ok(()) + } + + /// `optimizeIndirectCommandBuffer:withRange:`: records nothing, the commands already in the + /// form an execution reads. + /// + /// Err: [`Refusal::OtherDevice`] for another device's buffer; [`Refusal::CommandRange`] for a + /// range past the buffer's commands. + pub fn optimize_indirect_command_buffer( + &mut self, + buffer: &IndirectCommandBuffer, + range: Range, + ) -> Result<(), Error> { + if !buffer.is_of(&self.core) { + return Err(Error::Refused(Refusal::OtherDevice)); + } + if range.start > range.end || range.end > buffer.size() { + return Err(Error::Refused(Refusal::CommandRange)); + } + Ok(()) + } + /// The static precision note of [`generate_mipmaps`](Self::generate_mipmaps): each level is /// the device's linear filter of the one above, where Apple states no filter. pub const GENERATE_MIPMAPS_NOTE: PrecisionNote = PrecisionNote::DeviceFilteredMipmaps; @@ -821,7 +896,8 @@ impl BlitCommandEncoder { /// the segment so its end barrier reaches the host, and the command buffer keeps the resource /// until it retires. A buffer with no device copy is one the host reads where shaders write /// it, and a texture without named bytes has none the host reads apart from its image: the - /// call records nothing for either. + /// call records nothing for either, nor for an indirect command buffer, whose records the host + /// never reads. /// /// Metal's validation stops the call on a resource that is not Managed (probe /// `blit_synchronize_rules.m` in the conformance crate, an Apple M3 Max, macOS 27.0.1, job @@ -836,6 +912,7 @@ impl BlitCommandEncoder { Resource::Texture(texture) if texture.is_of(&self.core) => { self.read_back_texture(texture)? } + Resource::IndirectCommandBuffer(commands) if commands.is_of(&self.core) => {} _ => return Err(Error::Refused(Refusal::OtherDevice)), } self.building().count(Metric::Synchronizations); diff --git a/crates/metal2vulkan-runtime/src/command.rs b/crates/metal2vulkan-runtime/src/command.rs index 9a0a84700..ac30b0c8b 100644 --- a/crates/metal2vulkan-runtime/src/command.rs +++ b/crates/metal2vulkan-runtime/src/command.rs @@ -276,6 +276,9 @@ pub(crate) struct Gpu { /// The fences its encoders wait on and update: the submit thread orders it after another /// queue's command buffer it holds that updates one it waits on (`crate::fence`). pub(crate) fences: Fences, + /// Its executions of indirect command buffers' layouts and preprocess regions, each region + /// given back to the device's pool as it retires (`crate::indirect`). + pub(crate) executed: Vec, } impl Gpu { @@ -385,6 +388,7 @@ impl CommandBuffer { managed: false, images: Vec::new(), fences: Fences::default(), + executed: Vec::new(), }, handlers: Handlers { scheduled: Vec::new(), @@ -1248,6 +1252,17 @@ impl Building { unsafe { self.gpu.kept.buffers.keep(buffer) } } + /// Keeps an execution's layout and preprocess region until the command buffer retires. + pub(crate) fn keep_executed(&mut self, executed: crate::indirect::Executed) { + self.gpu.executed.push(executed); + } + + /// The push bytes are undefined from now: an execution of an indirect command buffer's + /// commands left them so, and the next draw pushes its own again. + pub(crate) fn pushes_lost(&mut self) { + self.pushed = Pushed::default(); + } + /// Keeps `block` until the command buffer retires. pub(crate) fn keep_block(&mut self, block: &Arc) { let blocks = &mut self.gpu.blocks; @@ -1573,12 +1588,13 @@ pub(crate) fn retire( managed: _, images, fences, + executed, } = gpu; if let Some(recorder) = recorder { core.recorders.give_back(core, recorder); } ring.give_back(core); - drop((segments, blocks, images, fences)); + drop((segments, blocks, images, fences, executed)); kept.clear(); if let Some(pair) = stamps { times::reset(&core.device, pair.pool, pair.first, written); diff --git a/crates/metal2vulkan-runtime/src/counters.rs b/crates/metal2vulkan-runtime/src/counters.rs index d3c5da6b2..43b4cf186 100644 --- a/crates/metal2vulkan-runtime/src/counters.rs +++ b/crates/metal2vulkan-runtime/src/counters.rs @@ -439,6 +439,12 @@ pub(crate) enum Gauge { SurfaceImportBytes, /// [`Gauges::releases_waiting`]. ReleasesWaiting, + /// [`Gauges::indirect_command_buffers`]. + IndirectCommandBuffers, + /// [`Gauges::preprocess_used_bytes`]. + PreprocessUsedBytes, + /// [`Gauges::preprocess_idle_bytes`]. + PreprocessIdleBytes, } /// A site that allocates on the consumer's threads, inside its calls, counted on its own in @@ -719,6 +725,9 @@ struct Atomics { import_bytes: AtomicU64, surface_import_bytes: AtomicU64, releases_waiting: AtomicU64, + indirect_command_buffers: AtomicU64, + preprocess_used_bytes: AtomicU64, + preprocess_idle_bytes: AtomicU64, /// Segment ends whose barrier reaches the host, for the tests. #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] host_reaches: AtomicU64, @@ -1397,6 +1406,9 @@ impl Counters { Gauge::ImportBytes => &a.import_bytes, Gauge::SurfaceImportBytes => &a.surface_import_bytes, Gauge::ReleasesWaiting => &a.releases_waiting, + Gauge::IndirectCommandBuffers => &a.indirect_command_buffers, + Gauge::PreprocessUsedBytes => &a.preprocess_used_bytes, + Gauge::PreprocessIdleBytes => &a.preprocess_idle_bytes, } } @@ -1702,6 +1714,9 @@ impl Counters { import_bytes: a.import_bytes.load(Relaxed), surface_import_bytes: a.surface_import_bytes.load(Relaxed), releases_waiting: a.releases_waiting.load(Relaxed), + indirect_command_buffers: a.indirect_command_buffers.load(Relaxed), + preprocess_used_bytes: a.preprocess_used_bytes.load(Relaxed), + preprocess_idle_bytes: a.preprocess_idle_bytes.load(Relaxed), } } } @@ -2776,4 +2791,13 @@ pub struct Gauges { /// block-maker thread has taken it: an index vacated, so its grant may be returned, an object /// handed to the reaper thread, which frees it next. pub releases_waiting: u64, + /// Indirect command buffers alive, each with its records' block + /// ([`Device::new_indirect_command_buffer`](crate::Device::new_indirect_command_buffer)). + pub indirect_command_buffers: u64, + /// Bytes of the preprocess regions executions of indirect command buffers hold: each taken + /// at an execution's record and given back when its command buffer completes. + pub preprocess_used_bytes: u64, + /// Bytes of the preprocess regions no execution holds, kept for the next ones, at most 128 + /// MiB; zero once the device is dropped. + pub preprocess_idle_bytes: u64, } diff --git a/crates/metal2vulkan-runtime/src/device.rs b/crates/metal2vulkan-runtime/src/device.rs index 83a227c69..9163ce557 100644 --- a/crates/metal2vulkan-runtime/src/device.rs +++ b/crates/metal2vulkan-runtime/src/device.rs @@ -268,6 +268,10 @@ pub(crate) struct Core { /// `VK_EXT_device_fault`'s command, where device creation enabled it (where the device lists /// it): a lost device's fault report, read once, at its first loss (`crate::fault`). pub(crate) fault: Option, + /// `VK_EXT_device_generated_commands`' entry points, limits and the indirect command buffers' + /// caches, where device creation enabled it (`floor::Capabilities::indirect_commands`); an + /// indirect command buffer is refused without them. + pub(crate) indirect: Option, /// A draw may read an attachment of its own pass through a texture /// (`floor::Capabilities::attachment_reads`): through the feedback loop where `feedback` is /// set, else through a copy of the image into its shadow (`crate::shadow`). @@ -521,6 +525,8 @@ impl Device { mut linear_attachment, mut fault, mut line_rasterization, + mut generated_commands, + mut maintenance5, } = enabled_features; // `sparseBinding` for imports over several dma-bufs (`Device::import_dma_bufs`), only where // the device's queries offer that import: it changes no other path, as only that import @@ -584,6 +590,11 @@ impl Device { if enabled(ash::ext::device_fault::NAME) { features = features.push_next(&mut fault); } + if capabilities.indirect_commands.is_some() { + features = features + .push_next(&mut generated_commands) + .push_next(&mut maintenance5); + } // SAFETY: as for the floor check. let listed = unsafe { vk_instance.enumerate_device_extension_properties(raw) } .map_err(Error::vulkan("vkEnumerateDeviceExtensionProperties"))?; @@ -686,6 +697,12 @@ impl Device { .extensions .contains(&ash::ext::device_fault::NAME)) .then(|| ash::ext::device_fault::Device::new(vk_instance, &device)); + let indirect = (capabilities.indirect_commands).and_then(|limits| { + // SAFETY: the device was made from `vk_instance`, with the extension, as the limits + // are there. + let entries = unsafe { crate::dgc::Dgc::load(vk_instance, device.handle()) }?; + Some(crate::indirect::Indirect::new(entries, limits)) + }); let limits = &properties.properties.limits; // The sampler arrays' two defaults count against the device's samplers too. let sampler_cap = limits.max_sampler_allocation_count.saturating_sub(2); @@ -741,6 +758,7 @@ impl Device { calibrated, feedback, fault, + indirect, attachment_reads: capabilities.attachment_reads, linear_attachments: (capabilities.features.linear_attachment).linear_color_attachment == vk::TRUE, @@ -1596,6 +1614,10 @@ impl Drop for Shared { // The map's kernels hold the core: a kernel no state holds goes now, its modules and // pipelines freed with the core. core.kernels.clear(&core.counters); + // So do the templates of reset commands, whose blocks hold it. + if let Some(indirect) = &core.indirect { + indirect.clear(core); + } }; if matches!(role(&self.core), Role::Complete | Role::Submit) { // A handler or listener dropped the last handle: the reaper tears down, once the @@ -1632,6 +1654,10 @@ impl Drop for Core { // SAFETY: every upload that copied through it retired, and no call reads it. unsafe { region.free(self) }; } + // The idle preprocess regions of executions that retired after the teardown's. + if let Some(indirect) = &self.indirect { + indirect.clear(self); + } memory::free_all(self); #[cfg(unix)] self.imports.destroy(&self.device); diff --git a/crates/metal2vulkan-runtime/src/dgc.rs b/crates/metal2vulkan-runtime/src/dgc.rs new file mode 100644 index 000000000..81361b81f --- /dev/null +++ b/crates/metal2vulkan-runtime/src/dgc.rs @@ -0,0 +1,367 @@ +//! `VK_EXT_device_generated_commands`, which ash 0.38 does not bind: the structures, constants and +//! entry points of it the runtime's indirect command buffers use, declared from the +//! specification, and the device's entry points, loaded where device creation enabled it. Each +//! structure's size and its members' offsets are checked against the specification's layout as +//! the crate compiles. The file goes once ash binds the extension. + +use ash::vk; +use std::ffi::{c_void, CStr}; + +/// The extension's name. +pub(crate) const NAME: &CStr = c"VK_EXT_device_generated_commands"; + +const fn structure(offset: i32) -> vk::StructureType { + vk::StructureType::from_raw(1_000_572_000 + offset) +} + +/// `VK_BUFFER_USAGE_2_PREPROCESS_BUFFER_BIT_EXT`. +pub(crate) const PREPROCESS_USAGE: vk::BufferUsageFlags2KHR = + vk::BufferUsageFlags2KHR::from_raw(1 << 31); +/// `VK_INDIRECT_COMMANDS_TOKEN_TYPE_*_EXT`. +pub(crate) const TOKEN_PUSH_CONSTANT: i32 = 1; +pub(crate) const TOKEN_SEQUENCE_INDEX: i32 = 2; +pub(crate) const TOKEN_INDEX_BUFFER: i32 = 3; +pub(crate) const TOKEN_DRAW_INDEXED: i32 = 5; +/// `VK_INDIRECT_COMMANDS_INPUT_MODE_VULKAN_INDEX_BUFFER_EXT`. +pub(crate) const INPUT_MODE_VULKAN: u32 = 1; +/// The stages an execution's commands run: a render pipeline's vertex and fragment stages. +pub(crate) const STAGES: vk::ShaderStageFlags = vk::ShaderStageFlags::from_raw( + vk::ShaderStageFlags::VERTEX.as_raw() | vk::ShaderStageFlags::FRAGMENT.as_raw(), +); + +/// No Metal counterpart: `VkPhysicalDeviceDeviceGeneratedCommandsFeaturesEXT`, which ash 0.38 +/// does not declare, as the floor reads and enables it ([`Features`](crate::floor::Features)). +#[repr(C)] +#[derive(Clone, Copy)] +pub struct DgcFeatures { + s_type: vk::StructureType, + pub(crate) p_next: *mut c_void, + /// `deviceGeneratedCommands`. + pub device_generated_commands: vk::Bool32, + /// `dynamicGeneratedPipelineLayout`, never enabled. + pub dynamic_generated_pipeline_layout: vk::Bool32, +} + +/// `VkPhysicalDeviceDeviceGeneratedCommandsPropertiesEXT`. +#[repr(C)] +#[derive(Clone, Copy)] +pub(crate) struct DgcProperties { + s_type: vk::StructureType, + pub(crate) p_next: *mut c_void, + pub(crate) max_indirect_pipeline_count: u32, + pub(crate) max_indirect_shader_object_count: u32, + pub(crate) max_indirect_sequence_count: u32, + pub(crate) max_indirect_commands_token_count: u32, + pub(crate) max_indirect_commands_token_offset: u32, + pub(crate) max_indirect_commands_indirect_stride: u32, + pub(crate) supported_input_modes: u32, + pub(crate) supported_shader_stages: vk::ShaderStageFlags, + pub(crate) stages_pipeline_binding: vk::ShaderStageFlags, + pub(crate) stages_shader_binding: vk::ShaderStageFlags, + pub(crate) transform_feedback: vk::Bool32, + pub(crate) multi_draw_indirect_count: vk::Bool32, +} + +// SAFETY: plain data; the chain pointer is cleared once the structure is read, as ash's +// structures' are. +unsafe impl Send for DgcFeatures {} +// SAFETY: as above. +unsafe impl Sync for DgcFeatures {} +// SAFETY: each starts with `sType` and `pNext`, as the chain requires. +unsafe impl vk::ExtendsPhysicalDeviceFeatures2 for DgcFeatures {} +// SAFETY: as above. +unsafe impl vk::ExtendsDeviceCreateInfo for DgcFeatures {} +// SAFETY: as above. +unsafe impl vk::ExtendsPhysicalDeviceProperties2 for DgcProperties {} + +impl Default for DgcFeatures { + fn default() -> DgcFeatures { + DgcFeatures { + s_type: structure(0), + p_next: std::ptr::null_mut(), + device_generated_commands: vk::FALSE, + dynamic_generated_pipeline_layout: vk::FALSE, + } + } +} + +impl Default for DgcProperties { + fn default() -> DgcProperties { + DgcProperties { + s_type: structure(1), + p_next: std::ptr::null_mut(), + max_indirect_pipeline_count: 0, + max_indirect_shader_object_count: 0, + max_indirect_sequence_count: 0, + max_indirect_commands_token_count: 0, + max_indirect_commands_token_offset: 0, + max_indirect_commands_indirect_stride: 0, + supported_input_modes: 0, + supported_shader_stages: vk::ShaderStageFlags::empty(), + stages_pipeline_binding: vk::ShaderStageFlags::empty(), + stages_shader_binding: vk::ShaderStageFlags::empty(), + transform_feedback: vk::FALSE, + multi_draw_indirect_count: vk::FALSE, + } + } +} + +/// `VkIndirectCommandsPushConstantTokenEXT`. +#[repr(C)] +pub(crate) struct PushConstantToken { + pub(crate) update_range: vk::PushConstantRange, +} + +/// `VkIndirectCommandsIndexBufferTokenEXT`. +#[repr(C)] +pub(crate) struct IndexBufferToken { + pub(crate) mode: u32, +} + +/// `VkIndirectCommandsLayoutTokenEXT`; `data` points at the token's own structure, or is null. +#[repr(C)] +pub(crate) struct LayoutToken { + s_type: vk::StructureType, + p_next: *const c_void, + pub(crate) token_type: i32, + pub(crate) data: *const c_void, + pub(crate) offset: u32, +} + +impl LayoutToken { + pub(crate) fn new(token_type: i32, data: *const c_void, offset: u32) -> LayoutToken { + LayoutToken { + s_type: structure(7), + p_next: std::ptr::null(), + token_type, + data, + offset, + } + } +} + +/// `VkIndirectCommandsLayoutCreateInfoEXT`. +#[repr(C)] +pub(crate) struct LayoutCreateInfo { + s_type: vk::StructureType, + p_next: *const c_void, + flags: u32, + shader_stages: vk::ShaderStageFlags, + indirect_stride: u32, + pipeline_layout: vk::PipelineLayout, + token_count: u32, + p_tokens: *const LayoutToken, +} + +impl LayoutCreateInfo { + /// Ordered sequences (no flag) of `tokens` at `stride`, for vertex and fragment stages, + /// through `layout`. + pub(crate) fn new( + stride: u32, + layout: vk::PipelineLayout, + tokens: &[LayoutToken], + ) -> LayoutCreateInfo { + LayoutCreateInfo { + s_type: structure(6), + p_next: std::ptr::null(), + flags: 0, + shader_stages: STAGES, + indirect_stride: stride, + pipeline_layout: layout, + token_count: tokens.len() as u32, + p_tokens: tokens.as_ptr(), + } + } +} + +/// `VkGeneratedCommandsPipelineInfoEXT`. +#[repr(C)] +pub(crate) struct PipelineInfo { + s_type: vk::StructureType, + p_next: *mut c_void, + pipeline: vk::Pipeline, +} + +impl PipelineInfo { + pub(crate) fn new(pipeline: vk::Pipeline) -> PipelineInfo { + PipelineInfo { + s_type: structure(13), + p_next: std::ptr::null_mut(), + pipeline, + } + } +} + +/// `VkGeneratedCommandsMemoryRequirementsInfoEXT`, with no execution set. +#[repr(C)] +pub(crate) struct MemoryInfo { + s_type: vk::StructureType, + p_next: *const c_void, + execution_set: u64, + layout: u64, + max_sequence_count: u32, + max_draw_count: u32, +} + +impl MemoryInfo { + pub(crate) fn new(pipeline: &PipelineInfo, layout: u64, sequences: u32) -> MemoryInfo { + MemoryInfo { + s_type: structure(2), + p_next: <*const PipelineInfo>::cast(pipeline), + execution_set: 0, + layout, + max_sequence_count: sequences, + max_draw_count: 0, + } + } +} + +/// `VkGeneratedCommandsInfoEXT`, with no execution set and no count address. +#[repr(C)] +pub(crate) struct CommandsInfo { + s_type: vk::StructureType, + p_next: *const c_void, + shader_stages: vk::ShaderStageFlags, + execution_set: u64, + layout: u64, + indirect_address: u64, + indirect_address_size: u64, + preprocess_address: u64, + preprocess_size: u64, + max_sequence_count: u32, + sequence_count_address: u64, + max_draw_count: u32, +} + +impl CommandsInfo { + /// `sequences` sequences of `layout` at `indirect` (`size` bytes), preprocessed into + /// `preprocess` (`preprocess_size` bytes), with the inherited `pipeline`. + pub(crate) fn new( + pipeline: &PipelineInfo, + layout: u64, + (indirect, size): (u64, u64), + (preprocess, preprocess_size): (u64, u64), + sequences: u32, + ) -> CommandsInfo { + CommandsInfo { + s_type: structure(4), + p_next: <*const PipelineInfo>::cast(pipeline), + shader_stages: STAGES, + execution_set: 0, + layout, + indirect_address: indirect, + indirect_address_size: size, + preprocess_address: preprocess, + preprocess_size, + max_sequence_count: sequences, + sequence_count_address: 0, + max_draw_count: 0, + } + } +} + +pub(crate) type CreateLayout = unsafe extern "system" fn( + vk::Device, + *const LayoutCreateInfo, + *const c_void, + *mut u64, +) -> vk::Result; +pub(crate) type DestroyLayout = unsafe extern "system" fn(vk::Device, u64, *const c_void); +pub(crate) type MemoryRequirements = + unsafe extern "system" fn(vk::Device, *const MemoryInfo, *mut vk::MemoryRequirements2<'static>); +pub(crate) type Execute = + unsafe extern "system" fn(vk::CommandBuffer, vk::Bool32, *const CommandsInfo); + +/// The extension's device entry points. +pub(crate) struct Dgc { + pub(crate) create_layout: CreateLayout, + pub(crate) destroy_layout: DestroyLayout, + pub(crate) memory_requirements: MemoryRequirements, + pub(crate) execute: Execute, +} + +impl Dgc { + /// The entry points of `device`; `None` where one is missing. + /// + /// # Safety + /// + /// `device` was made from `instance` with the extension enabled. + pub(crate) unsafe fn load(instance: &ash::Instance, device: vk::Device) -> Option { + let get = |name: &CStr| { + // SAFETY: the caller's contract; the name is the extension's own entry point. + unsafe { (instance.fp_v1_0().get_device_proc_addr)(device, name.as_ptr()) } + }; + // SAFETY: each pointer is the entry point of its name, whose signature the type declares + // from the specification. + unsafe { + Some(Dgc { + create_layout: std::mem::transmute::>( + get(c"vkCreateIndirectCommandsLayoutEXT"), + )?, + destroy_layout: std::mem::transmute::>( + get(c"vkDestroyIndirectCommandsLayoutEXT"), + )?, + memory_requirements: std::mem::transmute::< + vk::PFN_vkVoidFunction, + Option, + >(get( + c"vkGetGeneratedCommandsMemoryRequirementsEXT", + ))?, + execute: std::mem::transmute::>(get( + c"vkCmdExecuteGeneratedCommandsEXT", + ))?, + }) + } + } +} + +/// Each structure's size and members' offsets, as the specification's C declarations lay them out +/// on a 64-bit target: a wrong declaration fails the build, not a driver call. +#[cfg(target_pointer_width = "64")] +const _: () = { + use std::mem::{offset_of, size_of}; + assert!(size_of::() == 24); + assert!(offset_of!(DgcFeatures, p_next) == 8); + assert!(offset_of!(DgcFeatures, device_generated_commands) == 16); + assert!(offset_of!(DgcFeatures, dynamic_generated_pipeline_layout) == 20); + assert!(size_of::() == 64); + assert!(offset_of!(DgcProperties, max_indirect_pipeline_count) == 16); + assert!(offset_of!(DgcProperties, max_indirect_sequence_count) == 24); + assert!(offset_of!(DgcProperties, max_indirect_commands_token_count) == 28); + assert!(offset_of!(DgcProperties, max_indirect_commands_token_offset) == 32); + assert!(offset_of!(DgcProperties, max_indirect_commands_indirect_stride) == 36); + assert!(offset_of!(DgcProperties, supported_input_modes) == 40); + assert!(offset_of!(DgcProperties, supported_shader_stages) == 44); + assert!(offset_of!(DgcProperties, multi_draw_indirect_count) == 60); + assert!(size_of::() == 12); + assert!(size_of::() == 4); + assert!(size_of::() == 40); + assert!(offset_of!(LayoutToken, token_type) == 16); + assert!(offset_of!(LayoutToken, data) == 24); + assert!(offset_of!(LayoutToken, offset) == 32); + assert!(size_of::() == 56); + assert!(offset_of!(LayoutCreateInfo, flags) == 16); + assert!(offset_of!(LayoutCreateInfo, shader_stages) == 20); + assert!(offset_of!(LayoutCreateInfo, indirect_stride) == 24); + assert!(offset_of!(LayoutCreateInfo, pipeline_layout) == 32); + assert!(offset_of!(LayoutCreateInfo, token_count) == 40); + assert!(offset_of!(LayoutCreateInfo, p_tokens) == 48); + assert!(size_of::() == 24); + assert!(offset_of!(PipelineInfo, pipeline) == 16); + assert!(size_of::() == 40); + assert!(offset_of!(MemoryInfo, execution_set) == 16); + assert!(offset_of!(MemoryInfo, layout) == 24); + assert!(offset_of!(MemoryInfo, max_sequence_count) == 32); + assert!(offset_of!(MemoryInfo, max_draw_count) == 36); + assert!(size_of::() == 96); + assert!(offset_of!(CommandsInfo, shader_stages) == 16); + assert!(offset_of!(CommandsInfo, execution_set) == 24); + assert!(offset_of!(CommandsInfo, layout) == 32); + assert!(offset_of!(CommandsInfo, indirect_address) == 40); + assert!(offset_of!(CommandsInfo, indirect_address_size) == 48); + assert!(offset_of!(CommandsInfo, preprocess_address) == 56); + assert!(offset_of!(CommandsInfo, preprocess_size) == 64); + assert!(offset_of!(CommandsInfo, max_sequence_count) == 72); + assert!(offset_of!(CommandsInfo, sequence_count_address) == 80); + assert!(offset_of!(CommandsInfo, max_draw_count) == 88); +}; diff --git a/crates/metal2vulkan-runtime/src/encoder.rs b/crates/metal2vulkan-runtime/src/encoder.rs index 3a8be3ee6..e8e6dc160 100644 --- a/crates/metal2vulkan-runtime/src/encoder.rs +++ b/crates/metal2vulkan-runtime/src/encoder.rs @@ -9,6 +9,7 @@ use crate::error::{Error, Gap, Limit, Refusal}; use crate::fence::Fence; use crate::floor; use crate::hazard::Access; +use crate::indirect::IndirectCommandBuffer; use crate::kept::{Handle, Lent, Uncounted}; use crate::memory::BlockId; use crate::over::{self, Reached, Span}; @@ -89,6 +90,9 @@ pub enum Resource<'a> { Buffer(&'a Buffer), /// An `MTLTexture`. Texture(&'a Texture), + /// An `MTLIndirectCommandBuffer`: its records, which a function reaches through its + /// `gpuResourceID` ([`IndirectCommandBuffer::gpu_resource_id`]). + IndirectCommandBuffer(&'a IndirectCommandBuffer), } /// What a buffer slot holds. @@ -720,6 +724,10 @@ impl ComputeCommandEncoder { /// writes such a texture there, and the runtime would drop the writes. A kernel with no such /// access dispatches. [`use_heap`](Self::use_heap) declares no write and finds nothing. /// + /// An indirect command buffer's records are kept and declare no access, as a heap's block + /// ([`use_heap`](Self::use_heap)): a kernel reaches them through an address outside its + /// slots, which orders against every write since the last barrier. + /// /// Err: [`Refusal::OtherDevice`] for another device's resource. pub fn use_resource( &mut self, @@ -758,6 +766,13 @@ impl ComputeCommandEncoder { None, ) } + Resource::IndirectCommandBuffer(commands) => { + if !commands.is_of(building.device.core()) { + return Err(Error::Refused(Refusal::OtherDevice)); + } + building.keep_block(commands.records()); + return Ok(()); + } }; let Some(access) = usage.access() else { return Ok(()); @@ -1500,7 +1515,10 @@ impl Parameters { | FieldValue::AlphaTestReference | FieldValue::FetchedColor(_) | FieldValue::RenderTargetArrayLength - | FieldValue::ViewportCount => {} + | FieldValue::ViewportCount + | FieldValue::IndirectRange + | FieldValue::IndirectSequence + | FieldValue::IndirectBase => {} } } self.block_address = (interface.block_len > 0).then_some(interface.block_address); diff --git a/crates/metal2vulkan-runtime/src/error.rs b/crates/metal2vulkan-runtime/src/error.rs index 48350e11b..a3b5da2ea 100644 --- a/crates/metal2vulkan-runtime/src/error.rs +++ b/crates/metal2vulkan-runtime/src/error.rs @@ -292,6 +292,18 @@ pub enum Refusal { /// Basis: metal-documented (a compute dispatch needs a compute pipeline state set first, and a /// draw a render pipeline state). NoPipeline, + /// A range of an indirect command buffer's commands past them, in an execution + /// ([`RenderCommandEncoder::execute_commands_in_buffer`](crate::RenderCommandEncoder::execute_commands_in_buffer)), + /// a reset or an optimization + /// ([`BlitCommandEncoder::reset_commands_in_buffer`](crate::BlitCommandEncoder::reset_commands_in_buffer), + /// [`BlitCommandEncoder::optimize_indirect_command_buffer`](crate::BlitCommandEncoder::optimize_indirect_command_buffer)), + /// or an execution range a buffer holds at an offset that is not a multiple of 4 or whose 8 + /// bytes leave the buffer + /// ([`RenderCommandEncoder::execute_commands_in_buffer_with_range`](crate::RenderCommandEncoder::execute_commands_in_buffer_with_range)). + /// + /// Basis: metal-documented (each call names commands of the buffer, and the offset of a range + /// a buffer holds must be a multiple of 4 bytes). + CommandRange, /// A draw of patches with a render pipeline state whose vertex function is not a /// post-tessellation one, or a draw of primitives with one whose vertex function is. /// @@ -945,11 +957,16 @@ pub enum Refusal { #[non_exhaustive] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum Gap { - /// A compute pipeline state for indirect command buffers - /// (`supportIndirectCommandBuffers`): the runtime has no indirect command buffers yet. + /// An indirect command buffer, its execution, or a compute pipeline state for one, of what the + /// runtime does not build, `kind` naming it. Built: GPU-encoded indexed triangle draws with + /// the executing encoder's pipeline state, on a device with `VK_EXT_device_generated_commands` + /// (`floor::INDIRECT_COMMANDS`). /// - /// Basis: ours (indirect command buffers are not built). - IndirectCommandBuffers, + /// Basis: ours (the first cut of indirect command buffers builds that alone). + IndirectCommandBuffers { + /// What is not built. + kind: IndirectCommandsKind, + }, /// A kernel that reads something the compute encoder does not supply yet, `kind` naming what: /// a function table, a `[[stage_in]]` fetch, an explicit imageblock, a parameter the runtime /// does not fill, or a specialization the runtime does not set, among others. Buffers, @@ -1343,6 +1360,45 @@ pub enum LinearPlanePassKind { Resolve, } +/// What of an indirect command buffer the runtime does not build ([`Gap::IndirectCommandBuffers`]). +#[non_exhaustive] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +pub enum IndirectCommandsKind { + /// Any indirect command buffer, on a device without `VK_EXT_device_generated_commands` and + /// `VK_KHR_maintenance5` with their features (`floor::INDIRECT_COMMANDS`): an Intel Iris Xe, + /// the UHD 630 on Windows, and Mesa's Mac Vulkan driver among the venues. + Extension, + /// Command types other than indexed draws alone (`MTLIndirectCommandTypeDrawIndexed`): plain, + /// patch or mesh draws, or dispatches, which take other command layouts. + CommandTypes, + /// Commands that set their own pipeline state (`inheritPipelineState` false), which Vulkan + /// draws through an indirect execution set: a set of graphics pipelines is offered on none of + /// the AMD cards, and its pipelines must share every state. + CommandPipelines, + /// Commands that draw with the executing encoder's buffers (`inheritBuffers` true). + InheritedBuffers, + /// More than 31 vertex or fragment buffers a command binds (`maxVertexBufferBindCount` or + /// `maxFragmentBufferBindCount`). + BindCount, + /// A command count of 0, or past the device's most commands of one execution + /// (`maxIndirectSequenceCount`). + Capacity, + /// A compute pipeline state for indirect command buffers (`supportIndirectCommandBuffers`): + /// compute commands are not built. + ComputeCommands, + /// An execution with a pipeline state made without `supportIndirectCommandBuffers`, whose + /// vertex function does not skip the commands outside the range. + UnflaggedState, + /// An execution whose pipeline state's buffer slots need more tokens than the device takes in + /// one command (`maxIndirectCommandsTokenCount`): one per run of slots its functions push + /// consecutively, the sequence index, the index buffer and the draw. + Tokens, + /// An execution whose pipeline state reads what a command cannot carry: a buffer slot the + /// command binds placed outside the push constants (in a parameter block), a fixed-function + /// vertex binding, or a draw that must be at base instance 0. + DrawInput, +} + /// What a render pipeline state asks that the runtime does not build ([`Gap::RenderPipeline`]). #[non_exhaustive] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] @@ -1401,11 +1457,6 @@ pub enum KernelInputKind { /// pushes each one's resource ID. Metal's counterpart is a texture or sampler the kernel /// reads, which Metal resolves by its `gpuResourceID`. HandleTranslation, - /// An indirect command buffer the kernel may reach - /// (`PipelineInterface::reaches_command_buffers`). Metal's counterpart is a `command_buffer` - /// the kernel takes, as an argument or a member of an argument buffer, of an - /// `MTLIndirectCommandBuffer` it can encode, reset or copy. - CommandBuffers, /// A `[[stage_in]]` argument, which fetches by the stage-in region /// (`PipelineInterface::stage_in`). Metal's counterpart is the descriptor's /// `stageInputDescriptor`. @@ -2035,6 +2086,10 @@ impl fmt::Display for Refusal { } Refusal::EncoderOpen => f.write_str("an encoder of the command buffer is open"), Refusal::NoPipeline => f.write_str("no pipeline state is set"), + Refusal::CommandRange => f.write_str( + "the range lies past the indirect command buffer's commands, or the range \ + buffer's offset is not a multiple of 4 or leaves the buffer", + ), Refusal::PatchDraw => f.write_str( "patches are drawn with a post-tessellation vertex function's pipeline state, and \ only with one", @@ -2299,8 +2354,8 @@ impl fmt::Display for Refusal { impl fmt::Display for Gap { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Gap::IndirectCommandBuffers => { - f.write_str("pipeline states for indirect command buffers are not built") + Gap::IndirectCommandBuffers { kind } => { + write!(f, "indirect command buffers of {kind:?} are not built") } Gap::KernelInput { kind } => write!( f, diff --git a/crates/metal2vulkan-runtime/src/floor.rs b/crates/metal2vulkan-runtime/src/floor.rs index ae183cab3..8e5421882 100644 --- a/crates/metal2vulkan-runtime/src/floor.rs +++ b/crates/metal2vulkan-runtime/src/floor.rs @@ -112,6 +112,36 @@ pub const BORDER_SWIZZLE_EXTENSIONS: &[&CStr] = &[ /// otherwise, so [`Device::extensions`](crate::Device::extensions) names it only with its feature. pub const BARYCENTRIC_EXTENSIONS: &[&CStr] = &[ash::khr::fragment_shader_barycentric::NAME]; +/// The device extensions of Metal's indirect command buffers of draws +/// (`VK_EXT_device_generated_commands`) and of the one structure its preprocess memory takes +/// beside it (`VkBufferUsageFlags2CreateInfoKHR`, for `VK_BUFFER_USAGE_2_PREPROCESS_BUFFER_BIT_EXT`), +/// `VK_KHR_maintenance5`. Device creation enables both, with `deviceGeneratedCommands` and +/// `maintenance5`, where the device lists both, reports both features and offers what +/// [`IndirectCommandLimits`] needs at least; and neither otherwise, where an indirect command +/// buffer is refused (`IndirectCommandsKind::Extension`). No other path reads either, so no form +/// differs. Of what `maintenance5` changes, a core entry point past the asked Vulkan 1.3 answers +/// null, and the runtime loads none. +pub const INDIRECT_COMMANDS: &[&CStr] = &[crate::dgc::NAME, ash::khr::maintenance5::NAME]; + +pub use crate::dgc::DgcFeatures; + +/// What a device with [`INDIRECT_COMMANDS`] offers an indirect command buffer's execution: the +/// most commands one execution runs, tokens a command takes, bytes into a command a token reads, +/// and bytes of a command (`VkPhysicalDeviceDeviceGeneratedCommandsPropertiesEXT`'s +/// `maxIndirectSequenceCount`, `maxIndirectCommandsTokenCount`, +/// `maxIndirectCommandsTokenOffset` and `maxIndirectCommandsIndirectStride`). +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub struct IndirectCommandLimits { + /// `maxIndirectSequenceCount`. + pub sequences: u32, + /// `maxIndirectCommandsTokenCount`. + pub tokens: u32, + /// `maxIndirectCommandsTokenOffset`. + pub token_offset: u32, + /// `maxIndirectCommandsIndirectStride`. + pub stride: u32, +} + /// The translator's name for an extension device creation enables that its shaders may use, or /// that its description of the device must enable: the portability subset, where the device lists /// it. @@ -287,6 +317,13 @@ pub struct Features { /// `VkPhysicalDeviceLineRasterizationFeaturesEXT`, of `VK_EXT_line_rasterization`: /// `bresenhamLines` is enabled, and none of the other line modes beside it. pub line_rasterization: vk::PhysicalDeviceLineRasterizationFeaturesEXT<'static>, + /// `VkPhysicalDeviceDeviceGeneratedCommandsFeaturesEXT`, of + /// `VK_EXT_device_generated_commands`: read where the device lists it, and + /// `deviceGeneratedCommands` enabled with [`INDIRECT_COMMANDS`] alone. + pub generated_commands: DgcFeatures, + /// `VkPhysicalDeviceMaintenance5FeaturesKHR`, of `VK_KHR_maintenance5`: read where the device + /// lists it, and `maintenance5` enabled with [`INDIRECT_COMMANDS`] alone. + pub maintenance5: vk::PhysicalDeviceMaintenance5FeaturesKHR<'static>, } /// One feature: the Vulkan structure that reports it, its member as ash spells it, the member, and @@ -672,6 +709,9 @@ pub(crate) struct Queried { /// The time domains the device calibrates together, read where it lists /// `VK_EXT_calibrated_timestamps`. pub(crate) time_domains: Vec, + /// The generated commands' properties, read where the device lists + /// `VK_EXT_device_generated_commands`. + pub(crate) generated_commands: crate::dgc::DgcProperties, } /// One item of the floor that a device lacks. @@ -825,6 +865,9 @@ pub struct Capabilities { pub queue_family: u32, /// The device's memory types and heaps, for device creation to choose from. pub memory: vk::PhysicalDeviceMemoryProperties, + /// What an indirect command buffer's execution may take, where device creation enables + /// [`INDIRECT_COMMANDS`]; `None` on a device without them. + pub indirect_commands: Option, } /// The memory types the runtime allocates its buffers from, each the first memory type with its @@ -888,16 +931,11 @@ unsafe fn query( families: Vec::new(), memory: vk::PhysicalDeviceMemoryProperties::default(), time_domains: Vec::new(), + generated_commands: crate::dgc::DgcProperties::default(), }; if version < VERSION { return queried; } - let mut properties = - vk::PhysicalDeviceProperties2::default().push_next(&mut queried.vulkan12); - instance.get_physical_device_properties2(physical, &mut properties); - queried.limits = properties.properties.limits; - queried.vulkan12.p_next = std::ptr::null_mut(); - // A device whose extensions cannot be listed offers none the floor can rely on. queried.extensions = instance .enumerate_device_extension_properties(physical) @@ -906,6 +944,17 @@ unsafe fn query( .filter_map(|extension| extension.extension_name_as_c_str().ok()) .map(CStr::to_owned) .collect(); + let generated_listed = + (queried.extensions.iter()).any(|name| name.as_c_str() == crate::dgc::NAME); + let mut properties = + vk::PhysicalDeviceProperties2::default().push_next(&mut queried.vulkan12); + if generated_listed { + properties = properties.push_next(&mut queried.generated_commands); + } + instance.get_physical_device_properties2(physical, &mut properties); + queried.limits = properties.properties.limits; + queried.vulkan12.p_next = std::ptr::null_mut(); + queried.generated_commands.p_next = std::ptr::null_mut(); // An extension's feature structure may be read only from a device that lists the // extension; on another, its features stay false. let listed = |extension: &CStr| { @@ -931,6 +980,7 @@ unsafe fn query( let linear_attachment_listed = listed(ash::nv::linear_color_attachment::NAME); let fault_listed = listed(ash::ext::device_fault::NAME); let line_rasterization_listed = listed(ash::ext::line_rasterization::NAME); + let maintenance5_listed = listed(ash::khr::maintenance5::NAME); let Features { core, @@ -951,6 +1001,8 @@ unsafe fn query( linear_attachment, fault, line_rasterization, + generated_commands, + maintenance5, } = &mut queried.features; let mut features = vk::PhysicalDeviceFeatures2::default() .push_next(&mut *vulkan11) @@ -998,6 +1050,12 @@ unsafe fn query( if line_rasterization_listed { features = features.push_next(&mut *line_rasterization); } + if generated_listed { + features = features.push_next(&mut *generated_commands); + } + if maintenance5_listed { + features = features.push_next(&mut *maintenance5); + } instance.get_physical_device_features2(physical, &mut features); *core = features.features; vulkan11.p_next = std::ptr::null_mut(); @@ -1017,6 +1075,8 @@ unsafe fn query( linear_attachment.p_next = std::ptr::null_mut(); fault.p_next = std::ptr::null_mut(); line_rasterization.p_next = std::ptr::null_mut(); + generated_commands.p_next = std::ptr::null_mut(); + maintenance5.p_next = std::ptr::null_mut(); queried.families = instance.get_physical_device_queue_family_properties(physical); queried.memory = instance.get_physical_device_memory_properties(physical); @@ -1144,6 +1204,7 @@ pub(crate) fn decide(device: &Queried) -> Result { *(feature.field)(&mut features) = *(feature.field)(&mut reported); } } + let indirect_commands = indirect_commands(device, &mut features); Ok(Capabilities { float16: features.vulkan12.shader_float16 == vk::TRUE, storage_read_without_format: features.core.shader_storage_image_read_without_format @@ -1170,10 +1231,47 @@ pub(crate) fn decide(device: &Queried) -> Result { .chain(ATTACHMENT_READ_EXTENSIONS.iter().filter(|_| feedback_loop)) .chain(BORDER_SWIZZLE_EXTENSIONS.iter().filter(|_| border_swizzle)) .chain(BARYCENTRIC_EXTENSIONS.iter().filter(|_| barycentric)) + .chain( + INDIRECT_COMMANDS + .iter() + .filter(|_| indirect_commands.is_some()), + ) .copied() .collect(), queue_family, memory: device.memory, + indirect_commands, + }) +} + +/// The indirect commands' limits ([`INDIRECT_COMMANDS`]), their features set in `features`, where +/// the device offers them: both extensions and their features, the Vulkan index buffer token's +/// input mode, the vertex and fragment stages, and a command of the runtime's largest layout +/// (`IndirectDrawLayout`'s stride of 536 bytes, and a token at most that far in). +fn indirect_commands(device: &Queried, features: &mut Features) -> Option { + let listed = |name: &CStr| (device.extensions.iter()).any(|listed| listed.as_c_str() == name); + let reported = &device.features; + let p = &device.generated_commands; + let most = metal2vulkan::pipeline::IndirectDrawLayout::MAX_SLOTS; + let largest = metal2vulkan::pipeline::IndirectDrawLayout::new(most, most) + .map_or(u32::MAX, |layout| layout.stride()); + let offered = INDIRECT_COMMANDS.iter().all(|&name| listed(name)) + && reported.generated_commands.device_generated_commands == vk::TRUE + && reported.maintenance5.maintenance5 == vk::TRUE + && p.supported_input_modes & crate::dgc::INPUT_MODE_VULKAN != 0 + && p.supported_shader_stages.contains(crate::dgc::STAGES) + && p.max_indirect_commands_indirect_stride >= largest + && p.max_indirect_commands_token_offset >= largest; + if !offered { + return None; + } + features.generated_commands.device_generated_commands = vk::TRUE; + features.maintenance5.maintenance5 = vk::TRUE; + Some(IndirectCommandLimits { + sequences: p.max_indirect_sequence_count, + tokens: p.max_indirect_commands_token_count, + token_offset: p.max_indirect_commands_token_offset, + stride: p.max_indirect_commands_indirect_stride, }) } diff --git a/crates/metal2vulkan-runtime/src/indirect.rs b/crates/metal2vulkan-runtime/src/indirect.rs new file mode 100644 index 000000000..aab1782b6 --- /dev/null +++ b/crates/metal2vulkan-runtime/src/indirect.rs @@ -0,0 +1,860 @@ +//! Metal's indirect command buffers of indexed draws (`MTLIndirectCommandBuffer`), on +//! `VK_EXT_device_generated_commands` ([`crate::dgc`]). +//! +//! A buffer is its records, in a Private block the runtime takes, laid out as `metal2vulkan`'s +//! [`IndirectDrawLayout`] names: a header, then one command a stride. A kernel's encoding writes +//! them through the buffer's `gpuResourceID`, the header's device address, which the consumer's +//! argument encoder writes into the `command_buffer` member; an execution +//! ([`RenderCommandEncoder::execute_commands_in_buffer`](crate::RenderCommandEncoder::execute_commands_in_buffer)) +//! reads them, one `VkIndirectCommandsLayoutEXT` sequence a command. +//! +//! A new buffer's commands, and the commands a reset names +//! ([`BlitCommandEncoder::reset_commands_in_buffer`](crate::BlitCommandEncoder::reset_commands_in_buffer)), +//! are copied from the device's template of reset commands of the buffer's layout: up to +//! [`TEMPLATE_BYTES`] of commands each drawing nothing, copied in regions over the range, Metal's +//! own write of it. The device keeps at most [`TEMPLATES`] templates, the least recently used +//! forgotten first; a command buffer or upload that copies from one keeps it until it retires. + +use std::ops::Range; +use std::sync::{Arc, Mutex}; + +use ash::vk; +use metal2vulkan::pipeline::IndirectDrawLayout; + +use crate::counters::{Gauge, Metric, Site}; +use crate::device::{lock, Core}; +use crate::dgc::{self, Dgc}; +use crate::error::{Error, Gap, IndirectCommandsKind}; +use crate::floor::IndirectCommandLimits; +use crate::kernel_map::Lru; +use crate::memory::{self, Block}; +use crate::pipeline::{address_word, FieldValue, PUSH_STAGES}; +use crate::record::{self, Reach}; +use crate::render::{DrawPlace, Draws, Raster, RenderCompiled, VERTEX}; +use crate::submit::Held; +use crate::{Device, MemoryClass}; + +/// The most templates of reset commands a device keeps, one per record layout. +pub(crate) const TEMPLATES: usize = 16; +/// The most bytes of one template: `vkCmdUpdateBuffer`'s most. +pub(crate) const TEMPLATE_BYTES: u32 = 65536; +/// The most command layouts (`VkIndirectCommandsLayoutEXT`) a device keeps, one per shape of +/// tokens ([`Tokens`]). +pub(crate) const LAYOUTS: usize = 64; +/// The most execution shapes (a content, a raster state, a record layout and a command count) +/// whose layout and preprocess requirements a device keeps ([`Shape`]). +pub(crate) const SHAPES: usize = 256; +/// The most commands one `vkCmdExecuteGeneratedCommandsEXT` runs: an execution of more is one of +/// each part of `PART` commands in order, the last the rest, each its own preprocess in the +/// execution's region, its sequences counted from the part's first command +/// (`PushField::IndirectBase`). One form on every device; its cost is a known gap (README). +pub(crate) const PART: u32 = 64; +/// The most bytes of preprocess regions no execution holds that a device keeps for the next ones: +/// three frames of Apple's published rendering sample's 45,024 commands at the most a command +/// takes (592 bytes, NVIDIA's for 17 tokens), about 81 MB, with room for the regions' rounding. +pub(crate) const IDLE_BYTES: u64 = 128 << 20; +/// The granule a preprocess region's bytes are rounded up to. +const REGION_GRANULE: u64 = 64 << 10; +/// The bounds of a buffer slot a command holds, which an execution pushes for it: its offset +/// before the address (2^31 - 1) and its length (`u32::MAX`), the widest a checked access passes, +/// and not the all-ones pair of a slot bound to nothing. An access through the slot reads and +/// writes at the address the command holds plus its offset, unchecked, as one through a pointer +/// loaded from memory does. +pub(crate) const UNCHECKED_BOUNDS: [u8; 8] = { + let (before, len) = (0x7fff_ffff_u32.to_le_bytes(), u32::MAX.to_le_bytes()); + [ + before[0], before[1], before[2], before[3], len[0], len[1], len[2], len[3], + ] +}; + +/// `MTLIndirectCommandType`: the kinds of command a buffer holds, Metal's bits. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] +pub struct IndirectCommandType(u64); + +impl IndirectCommandType { + /// `MTLIndirectCommandTypeDraw`. + pub const DRAW: IndirectCommandType = IndirectCommandType(1 << 0); + /// `MTLIndirectCommandTypeDrawIndexed`: the one kind the runtime builds. + pub const DRAW_INDEXED: IndirectCommandType = IndirectCommandType(1 << 1); + /// `MTLIndirectCommandTypeDrawPatches`. + pub const DRAW_PATCHES: IndirectCommandType = IndirectCommandType(1 << 2); + /// `MTLIndirectCommandTypeDrawIndexedPatches`. + pub const DRAW_INDEXED_PATCHES: IndirectCommandType = IndirectCommandType(1 << 3); + /// `MTLIndirectCommandTypeConcurrentDispatch`. + pub const CONCURRENT_DISPATCH: IndirectCommandType = IndirectCommandType(1 << 5); + /// `MTLIndirectCommandTypeConcurrentDispatchThreads`. + pub const CONCURRENT_DISPATCH_THREADS: IndirectCommandType = IndirectCommandType(1 << 6); + /// `MTLIndirectCommandTypeDrawMeshThreadgroups`. + pub const DRAW_MESH_THREADGROUPS: IndirectCommandType = IndirectCommandType(1 << 7); + /// `MTLIndirectCommandTypeDrawMeshThreads`. + pub const DRAW_MESH_THREADS: IndirectCommandType = IndirectCommandType(1 << 8); + + /// The type of Metal's bits `bits`. + pub const fn from_bits(bits: u64) -> IndirectCommandType { + IndirectCommandType(bits) + } + + /// Metal's bits. + pub const fn bits(self) -> u64 { + self.0 + } +} + +impl std::ops::BitOr for IndirectCommandType { + type Output = IndirectCommandType; + + fn bitor(self, other: IndirectCommandType) -> IndirectCommandType { + IndirectCommandType(self.0 | other.0) + } +} + +/// `MTLIndirectCommandBufferDescriptor`, of the properties the runtime reads. Built: commands of +/// [`IndirectCommandType::DRAW_INDEXED`] alone that inherit the executing encoder's pipeline +/// state and bind their own buffers; every other answer is [`Gap::IndirectCommandBuffers`] at +/// [`Device::new_indirect_command_buffer`]. The render states the commands draw with are the +/// executing encoder's, whatever Metal's `inherit*` properties say, as an M4's commands draw +/// with them. +#[non_exhaustive] +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +pub struct IndirectCommandBufferDescriptor { + /// `commandTypes`. + pub command_types: IndirectCommandType, + /// `inheritPipelineState`: commands draw with the executing encoder's pipeline state. Metal's + /// default is false; the runtime builds true alone. + pub inherit_pipeline_state: bool, + /// `inheritBuffers`: commands draw with the executing encoder's buffers. The runtime builds + /// false alone. + pub inherit_buffers: bool, + /// `maxVertexBufferBindCount`: the vertex buffer slots below which a command binds buffers, + /// at most 31. + pub max_vertex_buffer_bind_count: u32, + /// `maxFragmentBufferBindCount`, as `max_vertex_buffer_bind_count`. + pub max_fragment_buffer_bind_count: u32, + /// `maxKernelBufferBindCount`: read by no render command. + pub max_kernel_buffer_bind_count: u32, +} + +impl IndirectCommandBufferDescriptor { + /// A descriptor with Metal's defaults. + pub fn new() -> IndirectCommandBufferDescriptor { + IndirectCommandBufferDescriptor::default() + } +} + +/// `MTLIndirectCommandBuffer`: a buffer of indexed draw commands, the handle of its records. +/// Clones are the same buffer. Its records live while a handle, or a command buffer that uses it, +/// holds them. +#[derive(Clone)] +pub struct IndirectCommandBuffer { + inner: Arc, +} + +struct IcbInner { + core: Arc, + records: Arc, + layout: IndirectDrawLayout, + capacity: u32, +} + +impl Drop for IcbInner { + fn drop(&mut self) { + self.core.counters.fall(Gauge::IndirectCommandBuffers); + } +} + +impl IndirectCommandBuffer { + /// `size`: the commands it holds, its `maxCommandCount`. + pub fn size(&self) -> u32 { + self.inner.capacity + } + + /// `gpuResourceID`: the device address of its records' header, which a kernel's encoding + /// reaches the records through (Metal states no value). The consumer writes it into an + /// argument buffer's `command_buffer` member. + pub fn gpu_resource_id(&self) -> u64 { + self.inner.records.memory.address + } + + /// Whether `core` is the device it was made on. + pub(crate) fn is_of(&self, core: &Arc) -> bool { + Arc::ptr_eq(&self.inner.core, core) + } + + /// Its records' block. + pub(crate) fn records(&self) -> &Arc { + &self.inner.records + } + + /// Its records' layout. + pub(crate) fn layout(&self) -> IndirectDrawLayout { + self.inner.layout + } +} + +/// The device's state for indirect command buffers, where it enabled +/// `VK_EXT_device_generated_commands` (`floor::INDIRECT_COMMANDS`). +pub(crate) struct Indirect { + pub(crate) dgc: Dgc, + pub(crate) limits: IndirectCommandLimits, + templates: Mutex>>, + layouts: Mutex>>, + shapes: Mutex>, + regions: Mutex>, +} + +/// The tokens of an execution of a content's commands of one record layout: each run of slot +/// words the content pushes one after another (its offset in a command, its push offset and its +/// bytes), then the index buffer, the sequence index at its push offset, and the indexed draw at +/// the layout's offsets; and the push offset of the part's first command, which an execution +/// pushes before each part. +#[derive(Clone, Debug, PartialEq, Eq, Hash)] +pub(crate) struct Tokens { + pub(crate) layout: IndirectDrawLayout, + pub(crate) pushes: Vec<(u32, u32, u32)>, + pub(crate) sequence: u32, + pub(crate) base: u32, +} + +impl Tokens { + /// The tokens a command takes. + pub(crate) fn count(&self) -> u32 { + self.pushes.len() as u32 + 3 + } +} + +/// A `VkIndirectCommandsLayoutEXT`, destroyed once neither the device's cache nor a command +/// buffer that executed through it holds it. +pub(crate) struct CommandsLayout { + handle: u64, + device: vk::Device, + destroy: dgc::DestroyLayout, +} + +impl CommandsLayout { + /// Its `VkIndirectCommandsLayoutEXT`. + pub(crate) fn handle(&self) -> u64 { + self.handle + } +} + +impl Drop for CommandsLayout { + fn drop(&mut self) { + // SAFETY: the layout is the device's, which is live while a cache or a command buffer + // holds it, and no submitted command that executes through it is pending: every command + // buffer that did holds it until it retires. + unsafe { (self.destroy)(self.device, self.handle, std::ptr::null()) }; + } +} + +/// An execution shape's layout and preprocess requirements, with the inherited pipeline. +#[derive(Clone)] +pub(crate) struct Shape { + pub(crate) layout: Arc, + /// The push offset of the part's first command ([`Tokens::base`]). + pub(crate) base: u32, + preprocess: vk::MemoryRequirements, +} + +impl Shape { + /// The preprocess bytes an execution of the shape takes. + pub(crate) fn preprocess_size(&self) -> u64 { + self.preprocess.size + } + + /// The bytes from one part's preprocess to the next in an execution's region: its size at + /// its alignment. + pub(crate) fn part_stride(&self) -> u64 { + (self.preprocess.size).next_multiple_of(self.preprocess.alignment.max(1)) + } +} + +/// A preprocess region: a buffer of its own, with +/// `VK_BUFFER_USAGE_2_PREPROCESS_BUFFER_BIT_EXT`, on its own allocation. +pub(crate) struct Region { + buffer: vk::Buffer, + memory: vk::DeviceMemory, + memory_type: u32, + address: u64, + size: u64, +} + +impl Region { + /// Whether the region holds `need`, from its first byte at `need`'s alignment. + fn holds(&self, need: &vk::MemoryRequirements) -> bool { + let start = self.address.next_multiple_of(need.alignment.max(1)) - self.address; + need.memory_type_bits & (1 << self.memory_type) != 0 + && start.saturating_add(need.size) <= self.size + } + + /// Frees it. + /// + /// # Safety + /// + /// No pending work uses it. + unsafe fn destroy(self, core: &Core) { + // SAFETY: by the caller. + unsafe { + core.device.destroy_buffer(self.buffer, None); + memory::free(&core.device, self.memory); + } + core.counters.fall(Gauge::Blocks); + } +} + +/// What a command buffer that executed commands holds until it retires: the execution's layout +/// and its preprocess region, which goes back to the device's pool then. +pub(crate) struct Executed { + core: Arc, + _layout: Arc, + region: Option, +} + +impl Drop for Executed { + fn drop(&mut self) { + if let (Some(indirect), Some(region)) = (&self.core.indirect, self.region.take()) { + indirect.give_back(&self.core, region); + } + } +} + +/// A template of reset commands of one layout ([`Indirect::template`]): `commands` of them, from +/// the block's first byte. +pub(crate) struct Template { + block: Arc, + commands: u32, +} + +impl Indirect { + pub(crate) fn new(dgc: Dgc, limits: IndirectCommandLimits) -> Indirect { + Indirect { + dgc, + limits, + templates: Mutex::new(Lru::new(TEMPLATES)), + layouts: Mutex::new(Lru::new(LAYOUTS)), + shapes: Mutex::new(Lru::new(SHAPES)), + regions: Mutex::new(Vec::new()), + } + } + + /// The shape of an execution of `capacity` commands of `layout` with `compiled`'s + /// `pipeline`, made under `raster`: the device's, or one made now, its layout the device's for + /// its tokens ([`tokens`]) or one made now, and its preprocess requirements queried with the + /// pipeline, which an execution with another of the content's pipelines does not reuse. + /// + /// Err: [`Gap::IndirectCommandBuffers`] where [`tokens`] answers a kind, and of + /// [`IndirectCommandsKind::Tokens`] for more tokens than the device takes; [`Error::Vulkan`] + /// where the layout cannot be made. + pub(crate) fn shape( + &self, + core: &Core, + (compiled, raster, pipeline): (&RenderCompiled, Raster, vk::Pipeline), + layout: IndirectDrawLayout, + capacity: u32, + ) -> Result { + let key = (compiled.id, raster, layout, capacity); + if let Some(shape) = lock(&self.shapes).get(&key) { + return Ok(shape); + } + let refuse = |kind| Error::Unsupported(Gap::IndirectCommandBuffers { kind }); + let tokens = tokens(&compiled.draws, layout).map_err(refuse)?; + if tokens.count() > self.limits.tokens { + return Err(refuse(IndirectCommandsKind::Tokens)); + } + let commands = self.layout(core, &tokens)?; + let info = dgc::PipelineInfo::new(pipeline); + let asked = dgc::MemoryInfo::new(&info, commands.handle, capacity); + let mut requirements: vk::MemoryRequirements2<'static> = vk::MemoryRequirements2::default(); + // SAFETY: the layout and the pipeline are the device's, and the structures are valid for + // the call. + unsafe { (self.dgc.memory_requirements)(core.device.handle(), &asked, &mut requirements) }; + let shape = Shape { + layout: commands, + base: tokens.base, + preprocess: requirements.memory_requirements, + }; + let (kept, gone) = lock(&self.shapes).keep(key, shape); + drop(gone); + Ok(kept) + } + + /// The command layout of `tokens`: the device's, or one made now, through the device's + /// pipeline layout, for vertex and fragment stages, its push tokens' ranges of + /// [`PUSH_STAGES`], the layout's one push range's stages. + fn layout(&self, core: &Core, tokens: &Tokens) -> Result, Error> { + if let Some(layout) = lock(&self.layouts).get(tokens) { + return Ok(layout); + } + let range = |offset, size| dgc::PushConstantToken { + update_range: vk::PushConstantRange { + stage_flags: PUSH_STAGES, + offset, + size, + }, + }; + let pushes: Vec = (tokens.pushes.iter()) + .map(|&(_, push, bytes)| range(push, bytes)) + .collect(); + let sequence = range(tokens.sequence, 4); + let index = dgc::IndexBufferToken { + mode: dgc::INPUT_MODE_VULKAN, + }; + let records = tokens.layout; + let mut list: Vec = (tokens.pushes.iter().zip(&pushes)) + .map(|(&(at, ..), push)| { + dgc::LayoutToken::new( + dgc::TOKEN_PUSH_CONSTANT, + std::ptr::from_ref(push).cast(), + at, + ) + }) + .collect(); + list.push(dgc::LayoutToken::new( + dgc::TOKEN_INDEX_BUFFER, + std::ptr::from_ref(&index).cast(), + records.index(), + )); + list.push(dgc::LayoutToken::new( + dgc::TOKEN_SEQUENCE_INDEX, + std::ptr::from_ref(&sequence).cast(), + records.sequence(), + )); + list.push(dgc::LayoutToken::new( + dgc::TOKEN_DRAW_INDEXED, + std::ptr::null(), + records.draw(), + )); + let info = dgc::LayoutCreateInfo::new(records.stride(), core.layout, &list); + let mut handle = 0; + let device = core.device.handle(); + // SAFETY: the structures, and every token's data, live for the call; the pipeline layout + // is the device's. + let result = + unsafe { (self.dgc.create_layout)(device, &info, std::ptr::null(), &mut handle) }; + if result != vk::Result::SUCCESS { + return Err(Error::Vulkan { + call: "vkCreateIndirectCommandsLayoutEXT", + result, + }); + } + let made = Arc::new(CommandsLayout { + handle, + device, + destroy: self.dgc.destroy_layout, + }); + let (kept, gone) = lock(&self.layouts).keep(tokens.clone(), made); + drop(gone); + Ok(kept) + } + + /// A preprocess region for `parts` parts of `shape`, one after another + /// ([`Shape::part_stride`]), held by what the call answers until the command buffer it + /// records into retires: an idle one that holds it at most twice over, or one made now of its + /// bytes rounded up to 64 KiB, in a memory type its requirements and the buffer's allow, a + /// device-local one first. None where the shape needs no bytes. Nothing waits and no legal + /// execution is refused for the pool's sake: only the device's memory bounds what is in use. + /// + /// Err: [`Error::Vulkan`] where the buffer or its memory cannot be made; + /// [`Limit::MemoryAllocations`](crate::Limit::MemoryAllocations). + pub(crate) fn executed( + &self, + core: &Arc, + shape: &Shape, + parts: u32, + ) -> Result<(Executed, u64), Error> { + let need = vk::MemoryRequirements { + size: shape.part_stride() * u64::from(parts), + ..shape.preprocess + }; + let region = match need.size { + 0 => None, + _ => Some(self.take(core, &need)?), + }; + let address = (region.as_ref()).map_or(0, |region| { + region.address.next_multiple_of(need.alignment.max(1)) + }); + let executed = Executed { + core: Arc::clone(core), + _layout: Arc::clone(&shape.layout), + region, + }; + Ok((executed, address)) + } + + /// [`executed`](Self::executed)'s region. + fn take(&self, core: &Core, need: &vk::MemoryRequirements) -> Result { + let most = need.size.saturating_mul(2).max(REGION_GRANULE); + let found = { + let mut idle = lock(&self.regions); + let best = (idle.iter().enumerate()) + .filter(|(_, region)| region.holds(need) && region.size <= most) + .min_by_key(|(_, region)| region.size) + .map(|(at, _)| at); + best.map(|at| idle.swap_remove(at)) + }; + let region = match found { + Some(region) => { + core.counters + .fall_by(Gauge::PreprocessIdleBytes, region.size); + region + } + None => { + let size = (need.size + need.alignment).next_multiple_of(REGION_GRANULE); + // SAFETY: the device is live. + unsafe { make_region(core, size, need.memory_type_bits) }? + } + }; + core.counters + .rise_by(Gauge::PreprocessUsedBytes, region.size); + Ok(region) + } + + /// Takes back `region` from a retired command buffer: idle, the oldest idle regions freed + /// while the idle bytes pass [`IDLE_BYTES`]. + fn give_back(&self, core: &Core, region: Region) { + core.counters + .fall_by(Gauge::PreprocessUsedBytes, region.size); + core.counters + .rise_by(Gauge::PreprocessIdleBytes, region.size); + let mut idle = lock(&self.regions); + idle.push(region); + let mut bytes: u64 = idle.iter().map(|region| region.size).sum(); + let mut freed = Vec::new(); + while bytes > IDLE_BYTES && !idle.is_empty() { + let oldest = idle.remove(0); + bytes -= oldest.size; + freed.push(oldest); + } + drop(idle); + for region in freed { + core.counters + .fall_by(Gauge::PreprocessIdleBytes, region.size); + // SAFETY: an idle region is in no pending work. + unsafe { region.destroy(core) }; + } + } + + /// The template of reset commands of `layout`: the device's, or one made now, written in the + /// next commit's upload, as many commands of the layout as [`TEMPLATE_BYTES`] holds (one at + /// least). Each command's slot words are the nil buffer's (`Ring::nil`), and its index token + /// binds the zero range (`Ring::zero`) with no bytes. + /// + /// Err: what taking its block, the ring's two ranges or the upload return. + pub(crate) fn template( + &self, + core: &Arc, + layout: IndirectDrawLayout, + ) -> Result, Error> { + if let Some(template) = lock(&self.templates).get(&layout) { + return Ok(template); + } + let stride = layout.stride(); + let commands = (TEMPLATE_BYTES / stride).max(1); + let memory = core.take_memory( + MemoryClass::Private, + u64::from(commands * stride), + Site::PrivateTake, + )?; + let block = Arc::new(Block::new(memory, Arc::clone(core))); + let nil = address_word(core.ring.nil(core)?); + let command = layout.reset_command(nil, core.ring.zero(core)?); + let bytes = command.repeat(commands as usize); + let (buffer, base) = block.memory.range(0); + let held = [Held::Block(Arc::clone(&block))]; + core.work.upload(core, None, held, |device, upload| { + // SAFETY: the upload is recording; the block holds the bytes, at most 65,536 of + // them, a multiple of 8 at a multiple of 4. + unsafe { device.cmd_update_buffer(upload, buffer, base, &bytes) }; + })?; + let template = Arc::new(Template { block, commands }); + // A template another thread kept first is the one kept; this one goes once its upload + // retires. + let (kept, gone) = lock(&self.templates).keep(layout, template); + drop(gone); + Ok(kept) + } + + /// Forgets every template, shape and layout, and frees every idle region, at the device's + /// end, once no command buffer holds any. + pub(crate) fn clear(&self, core: &Core) { + let templates = lock(&self.templates).clear(); + let shapes = lock(&self.shapes).clear(); + let layouts = lock(&self.layouts).clear(); + drop((templates, shapes, layouts)); + let idle: Vec = lock(&self.regions).drain(..).collect(); + for region in idle { + core.counters + .fall_by(Gauge::PreprocessIdleBytes, region.size); + // SAFETY: the device's threads are joined and its command buffers retired. + unsafe { region.destroy(core) }; + } + } + + /// For the tests: the templates, shapes and layouts held. + #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] + pub(crate) fn held(&self) -> (usize, usize, usize) { + ( + lock(&self.templates).len(), + lock(&self.shapes).len(), + lock(&self.layouts).len(), + ) + } +} + +/// The tokens of an execution of `draws`' content's commands of `layout`: a push constant token +/// for each run of the slot words the content pushes at consecutive offsets for consecutive slots +/// of a command, the slots the command holds alone, then the index buffer, the sequence index at +/// the content's `IndirectSequence` field and the indexed draw; the part's first command goes at +/// its `IndirectBase` field. +/// +/// Err: [`IndirectCommandsKind::UnflaggedState`] for a content whose vertex function reads no +/// execution range; [`IndirectCommandsKind::DrawInput`] for one that reads a slot the command +/// binds outside its push constants, its command outside them, a fixed-function vertex binding, +/// or that must draw at base instance 0. +pub(crate) fn tokens( + draws: &Draws, + layout: IndirectDrawLayout, +) -> Result { + let mut words = Vec::new(); + let (mut sequence, mut base, mut range) = (None, None, false); + for &(place, table, value) in &draws.fields { + match value { + FieldValue::BufferAddress { slot, .. } => { + let (count, at) = match table { + VERTEX => (layout.vertex_slots(), layout.vertex_slot(slot)), + _ => (layout.fragment_slots(), layout.fragment_slot(slot)), + }; + if slot >= count { + continue; + } + match place { + DrawPlace::Push(push) => words.push((at, push)), + DrawPlace::Block(..) => return Err(IndirectCommandsKind::DrawInput), + } + } + FieldValue::IndirectSequence => match place { + DrawPlace::Push(push) => sequence = Some(push), + DrawPlace::Block(..) => return Err(IndirectCommandsKind::DrawInput), + }, + FieldValue::IndirectBase => match place { + DrawPlace::Push(push) => base = Some(push), + DrawPlace::Block(..) => return Err(IndirectCommandsKind::DrawInput), + }, + FieldValue::IndirectRange => range = true, + _ => {} + } + } + let (Some(sequence), Some(base), true) = (sequence, base, range) else { + return Err(IndirectCommandsKind::UnflaggedState); + }; + if !draws.bindings.is_empty() || draws.first_instance_zero { + return Err(IndirectCommandsKind::DrawInput); + } + words.sort_unstable(); + let mut pushes: Vec<(u32, u32, u32)> = Vec::new(); + for (at, push) in words { + match pushes.last_mut() { + Some((first, pushed, bytes)) if *first + *bytes == at && *pushed + *bytes == push => { + *bytes += 8 + } + _ => pushes.push((at, push, 8)), + } + } + Ok(Tokens { + layout, + pushes, + sequence, + base, + }) +} + +/// The copies of `template`'s commands over commands `range` of `records` of `layout`: one +/// region for each run of as many commands as the template holds. +pub(crate) fn reset_regions( + template: &Template, + layout: IndirectDrawLayout, + records: &Block, + range: Range, +) -> (vk::Buffer, vk::Buffer, Vec) { + let (source, source_base) = template.block.memory.range(0); + let (destination, base) = records.memory.range(0); + let stride = u64::from(layout.stride()); + let regions = (range.clone()) + .step_by(template.commands as usize) + .map(|first| { + let commands = (range.end - first).min(template.commands); + vk::BufferCopy { + src_offset: source_base, + dst_offset: base + layout.command(first), + size: u64::from(commands) * stride, + } + }) + .collect(); + (source, destination, regions) +} + +impl Template { + /// Its block, which a copy from it keeps. + pub(crate) fn block(&self) -> &Arc { + &self.block + } +} + +/// A preprocess region of `size` bytes in a memory type of `bits` and the buffer's own. +/// +/// # Safety +/// +/// The device is live. +unsafe fn make_region(core: &Core, size: u64, bits: u32) -> Result { + let device = &core.device; + let mut usage = vk::BufferUsageFlags2CreateInfoKHR::default() + .usage(dgc::PREPROCESS_USAGE | vk::BufferUsageFlags2KHR::SHADER_DEVICE_ADDRESS); + let info = vk::BufferCreateInfo::default() + .size(size) + .sharing_mode(vk::SharingMode::EXCLUSIVE) + .push_next(&mut usage); + // SAFETY: the device is live, and the create info valid. + let buffer = + unsafe { device.create_buffer(&info, None) }.map_err(Error::vulkan("vkCreateBuffer"))?; + // SAFETY: the buffer is the device's. + let requirements = unsafe { device.get_buffer_memory_requirements(buffer) }; + let allowed = bits & requirements.memory_type_bits; + let types = (0..u32::BITS).filter(|&index| allowed & (1 << index) != 0); + let Some(memory_type) = types.min_by_key(|&index| core.device_local & (1 << index) == 0) else { + // SAFETY: the buffer is unused. + unsafe { device.destroy_buffer(buffer, None) }; + return Err(Error::Vulkan { + call: "vkGetGeneratedCommandsMemoryRequirementsEXT", + result: vk::Result::ERROR_OUT_OF_DEVICE_MEMORY, + }); + }; + let mut flags = + vk::MemoryAllocateFlagsInfo::default().flags(vk::MemoryAllocateFlags::DEVICE_ADDRESS); + let allocate = vk::MemoryAllocateInfo::default() + .allocation_size(requirements.size.max(size)) + .memory_type_index(memory_type) + .push_next(&mut flags); + // SAFETY: the memory type is one the buffer allows, and `bufferDeviceAddress` is enabled. + let memory = match unsafe { + memory::allocate( + device, + &core.counters, + core.max_allocations, + &allocate, + None, + ) + } { + Ok(memory) => memory, + Err(error) => { + // SAFETY: the buffer is unused. + unsafe { device.destroy_buffer(buffer, None) }; + return Err(error); + } + }; + let region = Region { + buffer, + memory, + memory_type, + address: 0, + size, + }; + // SAFETY: the memory is the buffer's type and size, and unbound. + if let Err(result) = unsafe { device.bind_buffer_memory(buffer, memory, 0) } { + // SAFETY: nothing uses it. + unsafe { region.destroy(core) }; + return Err(Error::Vulkan { + call: "vkBindBufferMemory", + result, + }); + } + let address_info = vk::BufferDeviceAddressInfo::default().buffer(buffer); + // SAFETY: the buffer is bound and of `SHADER_DEVICE_ADDRESS` usage. + let address = unsafe { device.get_buffer_device_address(&address_info) }; + Ok(Region { address, ..region }) +} + +impl Device { + /// `newIndirectCommandBufferWithDescriptor:maxCommandCount:options:`: a buffer of + /// `max_command_count` indexed draw commands, its records in a Private block the runtime + /// takes (the options' storage mode is not read: the CPU encodes no command). Its commands are + /// reset, each drawing nothing, by copies from the device's template of its layout in the + /// upload of the next commit, ahead of every command buffer committed after the call; its + /// header is written there too. + /// + /// Err: [`Gap::IndirectCommandBuffers`] of [`IndirectCommandsKind::Extension`] on a device + /// without the extension, [`IndirectCommandsKind::CommandTypes`] for types other than indexed + /// draws alone, [`IndirectCommandsKind::CommandPipelines`] for commands that set their own + /// pipeline state, [`IndirectCommandsKind::InheritedBuffers`] for commands that draw with the + /// encoder's buffers, [`IndirectCommandsKind::BindCount`] for more than 31 vertex or fragment + /// buffers, [`IndirectCommandsKind::Capacity`] for a count of 0 or past the device's + /// `maxIndirectSequenceCount`; [`Refusal::InScheduledHandler`](crate::Refusal::InScheduledHandler); + /// [`Error::Quiesced`]; what taking the records' block returns; [`Error::Vulkan`] where the + /// upload's command buffer cannot be made. + pub fn new_indirect_command_buffer( + &self, + descriptor: &IndirectCommandBufferDescriptor, + max_command_count: u32, + ) -> Result { + let core = self.core(); + if core.closed() { + return Err(Error::Quiesced); + } + crate::command::not_in_scheduled_handler()?; + let refuse = |kind| Err(Error::Unsupported(Gap::IndirectCommandBuffers { kind })); + let Some(indirect) = &core.indirect else { + return refuse(IndirectCommandsKind::Extension); + }; + if descriptor.command_types != IndirectCommandType::DRAW_INDEXED { + return refuse(IndirectCommandsKind::CommandTypes); + } + if !descriptor.inherit_pipeline_state { + return refuse(IndirectCommandsKind::CommandPipelines); + } + if descriptor.inherit_buffers { + return refuse(IndirectCommandsKind::InheritedBuffers); + } + let Some(layout) = IndirectDrawLayout::new( + descriptor.max_vertex_buffer_bind_count, + descriptor.max_fragment_buffer_bind_count, + ) else { + return refuse(IndirectCommandsKind::BindCount); + }; + if max_command_count == 0 || max_command_count > indirect.limits.sequences { + return refuse(IndirectCommandsKind::Capacity); + } + let template = indirect.template(core, layout)?; + let memory = core.take_memory( + MemoryClass::Private, + layout.bytes(max_command_count), + Site::PrivateTake, + )?; + let records = Arc::new(Block::new(memory, Arc::clone(core))); + let header = layout.header(max_command_count, core.ring.zero(core)?); + let (source, destination, regions) = + reset_regions(&template, layout, &records, 0..max_command_count); + let (_, base) = records.memory.range(0); + let held = [ + Held::Block(Arc::clone(&records)), + Held::Block(Arc::clone(template.block())), + ]; + core.work.upload(core, None, held, |device, upload| { + // SAFETY: the upload is recording; the header and every region lie in their blocks, + // which it keeps. The barrier orders the template's own write, in this upload or an + // earlier one, before the copies read it. + unsafe { + device.cmd_update_buffer(upload, destination, base, &header); + record::barrier(device, upload, Reach::Commands); + core.counters.count(Metric::Barriers); + device.cmd_copy_buffer(upload, source, destination, ®ions); + } + })?; + core.counters.rise(Gauge::IndirectCommandBuffers); + Ok(IndirectCommandBuffer { + inner: Arc::new(IcbInner { + core: Arc::clone(core), + records, + layout, + capacity: max_command_count, + }), + }) + } +} diff --git a/crates/metal2vulkan-runtime/src/lib.rs b/crates/metal2vulkan-runtime/src/lib.rs index 3de364294..e81535dd1 100644 --- a/crates/metal2vulkan-runtime/src/lib.rs +++ b/crates/metal2vulkan-runtime/src/lib.rs @@ -23,6 +23,7 @@ mod counters; mod d3d11; mod depth_stencil; mod device; +mod dgc; mod encoder; mod error; mod event; @@ -35,6 +36,7 @@ pub mod floor; mod hazard; mod host_bytes; mod import; +mod indirect; mod instance; mod kept; mod kernel_map; @@ -74,8 +76,8 @@ pub use depth_stencil::DepthStencilState; pub use device::{Device, DeviceOptions, RawDevice}; pub use encoder::{ComputeCommandEncoder, Dispatch, DispatchType, Resource, ResourceUsage}; pub use error::{ - DrawKind, Error, Gap, KernelInputKind, Limit, LinearPlanePassKind, Refusal, RenderPassKind, - RenderPipelineKind, TextureViewKind, + DrawKind, Error, Gap, IndirectCommandsKind, KernelInputKind, Limit, LinearPlanePassKind, + Refusal, RenderPassKind, RenderPipelineKind, TextureViewKind, }; pub use event::{Event, SharedEvent}; pub use export::{Export, ExportHandle}; @@ -84,6 +86,7 @@ pub use fault::{DeviceFault, FaultAddress}; pub use fence::Fence; pub use host_bytes::HostBytes; pub use import::ImportHandle; +pub use indirect::{IndirectCommandBuffer, IndirectCommandBufferDescriptor, IndirectCommandType}; pub use instance::{Instance, PhysicalDevice}; pub use memory::{AllocationId, AllocationInfo, BlockId, BlockInfo, BlockMappings, MemoryClass}; /// `MTLLibrary`: the translator's, read from AIR or a metallib. diff --git a/crates/metal2vulkan-runtime/src/pipeline.rs b/crates/metal2vulkan-runtime/src/pipeline.rs index d519e3ef7..a21294c21 100644 --- a/crates/metal2vulkan-runtime/src/pipeline.rs +++ b/crates/metal2vulkan-runtime/src/pipeline.rs @@ -54,7 +54,7 @@ use crate::device::{lock, Core}; use crate::encoder::{ decide, size_checked, threadgroup_memory, Dispatch, Lengths, Module, BUFFER_SLOTS, }; -use crate::error::{Error, Gap, KernelInputKind, Refusal}; +use crate::error::{Error, Gap, IndirectCommandsKind, KernelInputKind, Refusal}; use crate::hazard::Access; use crate::kernel_map::KernelKey; use crate::reaper::{Free, Job}; @@ -751,6 +751,18 @@ pub(crate) enum FieldValue { /// past which a vertex function's `[[viewport_array_index]]` stores `ViewportIndex` 0 /// (`PushField::ViewportCount`). ViewportCount, + /// A `u64`: the address of the execution range the vertex function of a state made for + /// indirect command buffers tests its command against (`PushField::IndirectRange`): the + /// ring's range of every command (`Ring::whole`) for a direct draw and an execution over a + /// range the CPU gives, the range buffer's address plus its offset for an execution over a + /// range read from a buffer. + IndirectRange, + /// A `u32`: the command of an execution the draw is (`PushField::IndirectSequence`), 0 for a + /// direct draw; an execution's sequence index token pushes each command's own. + IndirectSequence, + /// A `u32`: the first command of the part of an execution the draw is + /// (`PushField::IndirectBase`), 0 for a direct draw; an execution pushes each part's own. + IndirectBase, } /// A `VkPipeline`'s specialization: the threadgroup size, the threadgroup memory lengths in the @@ -822,7 +834,9 @@ impl crate::Device { /// answered, a failing call holds none of the indices. /// /// Err: [`Error::Translation`], the translator's typed refusal or a descriptor Metal refuses, - /// naming the kernel; [`Gap::IndirectCommandBuffers`]; [`Gap::KernelInput`] for a kernel that + /// naming the kernel; [`Gap::IndirectCommandBuffers`] of + /// [`IndirectCommandsKind::ComputeCommands`] for a descriptor that sets + /// `supportIndirectCommandBuffers`; [`Gap::KernelInput`] for a kernel that /// reads what the compute encoder does not supply yet; [`Refusal::SamplerIds`] where /// `sampler_ids` answers another count; [`Refusal::IndicesNotGranted`] for a constexpr /// sampler's index; [`Limit::DeviceSamplers`](crate::Limit::DeviceSamplers); [`Error::Vulkan`]. @@ -843,7 +857,9 @@ impl crate::Device { sampler_ids: impl FnOnce(&[NumberedSampler]) -> Result, Error>, ) -> Result { if descriptor.support_indirect_command_buffers { - return Err(Error::Unsupported(Gap::IndirectCommandBuffers)); + return Err(Error::Unsupported(Gap::IndirectCommandBuffers { + kind: IndirectCommandsKind::ComputeCommands, + })); } let core = self.core(); let key = KernelKey { @@ -1251,10 +1267,6 @@ fn interface( translated.needs_handle_translation, KernelInputKind::HandleTranslation, ), - ( - translated.reaches_command_buffers, - KernelInputKind::CommandBuffers, - ), (!translated.stage_in.is_empty(), KernelInputKind::StageIn), ( !pipeline.layout.sets.iter().all(of_the_device), @@ -1729,7 +1741,7 @@ impl ComputePipelineState { /// `supportIndirectCommandBuffers`: false on every state the runtime makes, as a descriptor /// that asks for indirect command buffers is refused at the making - /// ([`Gap::IndirectCommandBuffers`]). + /// ([`Gap::IndirectCommandBuffers`] of [`IndirectCommandsKind::ComputeCommands`]). pub fn support_indirect_command_buffers(&self) -> bool { false } diff --git a/crates/metal2vulkan-runtime/src/render.rs b/crates/metal2vulkan-runtime/src/render.rs index ac054d98b..287accaab 100644 --- a/crates/metal2vulkan-runtime/src/render.rs +++ b/crates/metal2vulkan-runtime/src/render.rs @@ -240,13 +240,18 @@ pub(crate) struct RenderCompiled { imageblock_sample: Option, /// The descriptor's `rasterSampleCount`. samples: u32, + /// The descriptor's `supportIndirectCommandBuffers`. + indirect: bool, + /// The content's number, which no other content of the process takes: the key of its + /// executions' shapes (`crate::indirect`), which outlive no content they name. + pub(crate) id: u64, } /// What the render encoder sets that a `VkPipeline` bakes: `setDepthClipMode:` and /// `setTriangleFillMode:`, in `VkPipelineRasterizationStateCreateInfo`, which only /// `VK_EXT_extended_dynamic_state3` makes dynamic, and the floor does not require it. The default /// is Metal's, `Clip` and `Fill`. -#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] pub(crate) struct Raster { /// `MTLDepthClipModeClamp`: `depthClampEnable`. pub(crate) clamp: bool, @@ -254,6 +259,9 @@ pub(crate) struct Raster { pub(crate) lines: bool, } +/// The next content's [`RenderCompiled::id`]. +static CONTENT_IDS: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0); + /// One stage's shader module and what a `VkPipeline` of it takes. pub(crate) struct Module { pub(crate) module: vk::ShaderModule, @@ -383,7 +391,7 @@ impl crate::Device { /// has at its index before the call returns, and every draw pushes the index. /// /// Err: [`Error::Translation`], the translator's typed refusal or a descriptor Metal refuses, - /// naming the vertex and the fragment function; [`Gap::IndirectCommandBuffers`]; + /// naming the vertex and the fragment function; /// [`Gap::RenderPipeline`] for what the runtime does not build, naming it; /// [`Refusal::PointSizeTopology`] for a vertex function that writes `[[point_size]]` under /// the line or the triangle class; [`Refusal::SamplerIds`] where `sampler_ids` answers another @@ -696,6 +704,11 @@ fn draws( // The encoder's viewport count, below which the vertex function's index selects // its viewport. PushField::ViewportCount if at == VERTEX => FieldValue::ViewportCount, + // The execution range and the command a vertex function of a state made for + // indirect command buffers reads (`crate::indirect`). + PushField::IndirectRange if at == VERTEX => FieldValue::IndirectRange, + PushField::IndirectSequence if at == VERTEX => FieldValue::IndirectSequence, + PushField::IndirectBase if at == VERTEX => FieldValue::IndirectBase, _ => return Err(draw_input()), }; fields.push((offset, at, value)); @@ -752,9 +765,7 @@ fn draws( /// among them: Metal reads it only for a post-tessellation vertex function, and ignores it for any /// other, as the translator does; the translation states such a function (`unbuilt`). fn refuse(d: &RenderPipelineDescriptor) -> Result<(), Error> { - let kind = if d.support_indirect_command_buffers { - return Err(Error::Unsupported(Gap::IndirectCommandBuffers)); - } else if !(d.raster_sample_count.is_power_of_two() && d.raster_sample_count <= 64) { + let kind = if !(d.raster_sample_count.is_power_of_two() && d.raster_sample_count <= 64) { RenderPipelineKind::SampleCount } else if d.max_vertex_amplification_count != 1 { RenderPipelineKind::VertexAmplification @@ -1090,6 +1101,8 @@ impl RenderCompiled { constexprs, imageblock_sample, samples, + indirect: lowered.support_indirect_command_buffers, + id: CONTENT_IDS.fetch_add(1, std::sync::atomic::Ordering::Relaxed), }; // Made whole before the `VkPipeline`, so dropping it releases what was made. let class = match compiled.draws.patches { @@ -1385,11 +1398,12 @@ impl RenderPipelineState { .saturating_mul(samples)) } - /// `supportIndirectCommandBuffers`: false on every state the runtime makes, as a descriptor - /// that asks for indirect command buffers is refused at the making - /// ([`Gap::IndirectCommandBuffers`]). + /// `supportIndirectCommandBuffers`: the descriptor's. A state made with it pulls every vertex + /// attribute its vertex function reads, and its vertex function tests its command against an + /// execution's range, which a direct draw pushes as every command + /// ([`RenderCommandEncoder::execute_commands_in_buffer`](crate::RenderCommandEncoder::execute_commands_in_buffer)). pub fn support_indirect_command_buffers(&self) -> bool { - false + self.inner.compiled.indirect } /// Whether two handles are one state. diff --git a/crates/metal2vulkan-runtime/src/render_encoder.rs b/crates/metal2vulkan-runtime/src/render_encoder.rs index 04878eee3..dac3f2c06 100644 --- a/crates/metal2vulkan-runtime/src/render_encoder.rs +++ b/crates/metal2vulkan-runtime/src/render_encoder.rs @@ -82,10 +82,12 @@ use crate::encoder::{ check_alignment, merge, Declared, Resource, ResourceUsage, BUFFER_SLOTS, SAMPLER_SLOTS, TEXTURE_SLOTS, }; -use crate::error::{DrawKind, Error, Gap, Limit, Refusal, RenderPassKind}; +use crate::error::{DrawKind, Error, Gap, IndirectCommandsKind, Limit, Refusal, RenderPassKind}; use crate::fence::Fence; use crate::hazard::Access; +use crate::indirect::{IndirectCommandBuffer, PART, UNCHECKED_BOUNDS}; use crate::kept::{Handle, Lent, Uncounted}; +use crate::memory::BlockId; use crate::over::{self, Reached}; use crate::pass::{ layout_barrier, ops, resolving, LoadAction, Pass, RenderPassDescriptor, StoreAction, Target, @@ -253,9 +255,10 @@ struct Facts { /// texture over one, or through an address outside the draw's resources. host: bool, /// The nil buffer's address where a buffer argument the draw reaches is bound to nothing - /// (`Ring::nil`), else 0, and the zero range's where the draw checks a load (`Ring::zero`), - /// else 0. - nil: (u64, u64), + /// (`Ring::nil`), else 0, the zero range's where the draw checks a load (`Ring::zero`), else + /// 0, and the whole execution range's where the vertex function reads an execution range + /// (`Ring::whole`), else 0. + nil: (u64, u64, u64), } impl Facts { @@ -515,6 +518,16 @@ enum Call<'a> { indices: Option>, patches: bool, }, + /// An execution of `sequences` commands of an indirect command buffer from command `first` + /// (`crate::indirect`), each a sequence of triangles: over the range the CPU gave, or, where + /// `range` holds a buffer and an offset, over the range that buffer holds there, from command + /// 0 through every command. + Commands { + buffer: &'a IndirectCommandBuffer, + first: u32, + sequences: u32, + range: Option<(&'a Buffer, u64)>, + }, } /// The bytes of a draw's indirect arguments: `VkDrawIndexedIndirectCommand`'s 20 for an indexed @@ -558,10 +571,11 @@ struct Declarations { /// blend color, the line width (lines drawn at 1 alone: a draw of lines at another width is /// [`DrawKind::LineWidth`]), the store actions an encoder sets for an attachment whose pass left /// them unknown, memory barriers, fences, draws of points, lines and triangles, indexed or not, -/// draws of patches with a tessellation factor buffer, each direct or indirect, and the `Disabled` -/// visibility result mode (`Boolean` and `Counting` are [`DrawKind::VisibilityResults`]). Not -/// built, and so not methods: the store action options setters, tile functions, the -/// `setVertexBuffer:offset:attributeStride:atIndex:` family, +/// draws of patches with a tessellation factor buffer, each direct or indirect, executions of an +/// indirect command buffer's indexed triangle draws, `useResource:`, `useHeap:`, and the +/// `Disabled` visibility result mode (`Boolean` and `Counting` are +/// [`DrawKind::VisibilityResults`]). Not built, and so not methods: the store action options +/// setters, tile functions, the `setVertexBuffer:offset:attributeStride:atIndex:` family, /// `setTessellationFactorScale:` (read by a pipeline that enables the scale, which is refused), /// and indexed patch draws (`drawIndexedPatches:`, read by a pipeline of a control-point index /// type, which is refused). A draw of what the runtime does not build is [`Gap::Draw`], naming @@ -1706,6 +1720,9 @@ impl RenderCommandEncoder { /// there, and the runtime would drop the writes. A draw whose functions have no such access /// draws. /// + /// An indirect command buffer's records are kept and declare no access, as a heap's block + /// ([`use_heap`](Self::use_heap)). + /// /// Err: [`Refusal::OtherDevice`] for another device's resource. pub fn use_resource( &mut self, @@ -1738,6 +1755,13 @@ impl RenderCommandEncoder { None, ) } + Resource::IndirectCommandBuffer(commands) => { + if !commands.is_of(building.device.core()) { + return Err(Error::Refused(Refusal::OtherDevice)); + } + building.keep_block(commands.records()); + return Ok(()); + } }; let Some(access) = usage.access() else { return Ok(()); @@ -1758,6 +1782,22 @@ impl RenderCommandEncoder { Ok(()) } + /// `useHeap:stages:` (`useHeaps:count:stages:` is a loop of it, as is the deprecated form + /// without stages), for the heap whose memory is block `heap`: a + /// [`HeapRange`](crate::HeapRange)'s block, or the block a placement heap's buffers sit in. + /// The command buffer keeps the block until it retires, as + /// [`ComputeCommandEncoder::use_heap`](crate::ComputeCommandEncoder::use_heap) does. It + /// records nothing and declares no access, and the stages are not read: the pass's barriers + /// order its draws after every earlier command and before every later one. + /// + /// Err: [`Error::NoSuchBlock`] for a number no handle names. + pub fn use_heap(&mut self, heap: BlockId) -> Result<(), Error> { + let building = self.building(); + let block = building.device.block(heap)?; + building.keep_block(&block); + Ok(()) + } + /// `updateFence:afterStages:`: encoders that wait on `fence` after this one, of any queue, /// see what this encoder and the ones before it wrote. It records nothing ([`Fence`]): the /// pass's second barrier, recorded or owed, already reaches every command submitted after it. @@ -2072,7 +2112,7 @@ impl RenderCommandEncoder { // draw's count is the GPU's, so its indices are checked to start inside the buffer: one // index there. let indexed = match call { - Call::Direct { .. } | Call::Patches { .. } => None, + Call::Direct { .. } | Call::Patches { .. } | Call::Commands { .. } => None, Call::Indexed { index_count, indices, @@ -2143,7 +2183,7 @@ impl RenderCommandEncoder { if !self.facts.held { // A buffer argument bound to nothing reads the nil buffer (`Ring::nil`), and a checked // load outside its buffer the zero range (`Ring::zero`). - let (mut nil, mut zero) = (0, 0); + let (mut nil, mut zero, mut whole) = (0, 0, 0); for &(_, table, value) in &draws.fields { match value { FieldValue::BufferAddress { slot, mask } => { @@ -2156,10 +2196,11 @@ impl RenderCommandEncoder { } } FieldValue::ZeroAddress => zero = self.core.ring.zero(&self.core)?, + FieldValue::IndirectRange => whole = self.core.ring.whole(&self.core)?, _ => {} } } - self.facts.nil = (nil, zero); + self.facts.nil = (nil, zero, whole); self.facts.held = true; } let count = match call { @@ -2167,6 +2208,7 @@ impl RenderCommandEncoder { Call::Indexed { index_count, .. } => Some(index_count), Call::Patches { patch_count, .. } => Some(patch_count), Call::Indirect { .. } => None, + Call::Commands { sequences, .. } => Some(sequences), }; let [instance_count, base_instance] = instances.unwrap_or([1, 0]); if count == Some(0) || instance_count == 0 { @@ -2190,21 +2232,47 @@ impl RenderCommandEncoder { let writes_memory = draws.writes_memory; let building = (self.building.as_ref()) .expect("an encoder holds its command buffer's recording until it ends"); + // An execution's shape and its preprocess region, before anything is recorded. + let execution = match call { + Call::Commands { + buffer, sequences, .. + } => { + let Some(indirect) = &self.core.indirect else { + return Err(Error::Unsupported(Gap::IndirectCommandBuffers { + kind: IndirectCommandsKind::Extension, + })); + }; + let shape = (indirect).shape( + &self.core, + (compiled, self.raster, pipeline), + buffer.layout(), + PART, + )?; + let parts = sequences.div_ceil(PART); + let (executed, preprocess) = + indirect.executed(building.device.core(), &shape, parts)?; + Some((shape, executed, preprocess)) + } + _ => None, + }; + let commands = execution.is_some(); // What a draw reaches that each draw looks at again: an attachment of its pass through a // texture, a Managed buffer's device copy or a texture over one, or, while a texture over // a buffer in an image of its own lives (`crate::over`), such a texture bound, memory // reached through an address outside its resources, or buffers read while such a texture // the segment used has its image ahead of its buffer. let index_buffer = index.map(|(buffer, ..)| buffer); - // An indirect draw's arguments, and a patch draw's factor buffer, are its reads as an - // index buffer is an indexed draw's. + // An indirect draw's arguments, an execution's range buffer and a patch draw's factor + // buffer are its reads as an index buffer is an indexed draw's. let arguments = match call { Call::Indirect { arguments, .. } => Some(arguments), + Call::Commands { range, .. } => range.map(|(buffer, _)| buffer), _ => None, }; let factors = (self.factors.as_ref()).filter(|_| patches); let overs = building.copies_over() && (draws.reads_unbound + || commands || draws.writes_unbound || self.tables.iter().any(|tables| tables.copied > 0) || self.declared.copied > 0 @@ -2216,14 +2284,14 @@ impl RenderCommandEncoder { || factors.is_some_and(|(buffer, _)| buffer.managed_overs().is_some()) || overs; match each { - true => self.draw_reaches(reads, [index_buffer, arguments], overs)?, + true => self.draw_reaches(reads, [index_buffer, arguments], overs, commands)?, false => { if !self.shadow_slots.is_empty() { self.shadow_slots.clear(); self.push_filled = false; } self.loop_reads(false); - self.overs_after(); + self.overs_after(commands); } } let building = (self.building.as_mut()) @@ -2237,7 +2305,7 @@ impl RenderCommandEncoder { self.wrote |= writes_memory; (self.drew, self.pass_drew) = (true, true); let (bind, first) = building.bind_graphics(pipeline); - if !self.push_filled { + if !self.push_filled || commands { if let Some(state) = &self.pipeline { let factors = (self.factors.as_ref()).map_or(0, |(buffer, offset)| { buffer.gpu_address().wrapping_add(*offset) @@ -2249,6 +2317,22 @@ impl RenderCommandEncoder { (&self.moved, &self.shadow_slots, &self.pass), state, ); + // An execution's commands bind their own slots, which go unchecked, and read their + // range where it lies. + if let Call::Commands { + buffer, + first, + range, + .. + } = call + { + let range = range.map_or(self.facts.nil.2, |(buffer, offset)| { + buffer.gpu_address().wrapping_add(offset) + }); + let draws = &state.inner.compiled.draws; + let places = (&mut self.push, &mut self.blocks); + commands_push(places, draws, (buffer, first), range); + } // Each spilled function's block into the ring, and its address into the range. let made = &state.inner.compiled.draws.blocks; for (block, made) in self.blocks.iter().zip(made) { @@ -2259,7 +2343,8 @@ impl RenderCommandEncoder { } } } - self.push_filled = true; + // An execution's push bytes are its own: the next draw fills its own again. + self.push_filled = !commands; } let push = !self.push.is_empty() && building.push_needed(&self.push); let core = &*self.core; @@ -2296,7 +2381,10 @@ impl RenderCommandEncoder { .expect("an encoder holds its command buffer's recording until it ends"); // SAFETY: as above; the push bytes lie in the layout's one push range, of `PUSH_STAGES`; // every vertex binding the pipeline reads is bound inside its buffer, the ones the - // command buffer holds already as they are. + // command buffer holds already as they are. An execution's sequences lie in its records, + // at most the shape's capacity, and the command buffer keeps the records, the command + // layout and the preprocess region, which holds the shape's bytes at their alignment, + // until it retires (below). unsafe { for &(binding, buffer, offset) in &self.facts.vertex { if building.vertex_needed(binding, buffer, offset) { @@ -2373,12 +2461,144 @@ impl RenderCommandEncoder { None => device.cmd_draw_indirect(command, reached, at + offset, 1, stride), } } + ( + Call::Commands { + buffer, + first, + sequences, + .. + }, + _, + ) => { + if let (Some(indirect), Some((shape, _, preprocess))) = + (&core.indirect, &execution) + { + // One execution of each part, in order, each part's first command pushed + // at the base field; the first part's push is the draw's own. + let layout = buffer.layout(); + let info = crate::dgc::PipelineInfo::new(pipeline); + let base = shape.base as usize; + for (part, from) in (0..sequences).step_by(PART as usize).enumerate() { + let count = (sequences - from).min(PART); + if part > 0 { + let command_index = first + from; + self.push[base..base + 4] + .copy_from_slice(&command_index.to_le_bytes()); + device.cmd_push_constants( + command, + core.layout, + PUSH_STAGES, + 0, + &self.push, + ); + } + let stream = + buffer.records().memory.address + layout.command(first + from); + let size = u64::from(count) * u64::from(layout.stride()); + let at = *preprocess + shape.part_stride() * part as u64; + let generated = crate::dgc::CommandsInfo::new( + &info, + shape.layout.handle(), + (stream, size), + (at, shape.preprocess_size()), + count, + ); + (indirect.dgc.execute)(command, vk::FALSE, &generated); + } + } + } (Call::Indexed { .. }, None) => {} } } + // An execution holds its records, layout and region until the command buffer retires, + // and leaves the push bytes undefined (and the index buffer, which every indexed draw + // binds again). + if let (Call::Commands { buffer, .. }, Some((_, executed, _))) = (call, execution) { + building.keep_block(buffer.records()); + building.keep_executed(executed); + building.pushes_lost(); + } Ok(()) } + /// `executeCommandsInBuffer:withRange:`: commands `range` of `buffer`, drawn as triangles with + /// the encoder's pipeline state and every render state it set, each command with the buffers + /// its encoding bound (the command buffer keeps `buffer`'s records until it retires): one + /// `vkCmdExecuteGeneratedCommandsEXT` for each part of 64 commands from the range's first, in + /// order, each command a sequence of the content's command layout ([`IndirectCommandBuffer`]), + /// each part its own preprocess in the execution's region and its first command pushed before + /// it. Metal runs one execution; the parts cost GPU and recording time (the README's known + /// gaps). A command's buffers are read through its vertex and fragment + /// slots unchecked: an access of one reads and writes at the address the kernel's encoding + /// wrote plus its offset, as an access through a pointer loaded from memory does + /// (`docs/API.md`, section 5). An execution leaves the encoder's state as it was: the next + /// draw pushes its own fields again. An empty range records nothing. + /// + /// Err: [`Refusal::NoPipeline`]; [`Refusal::OtherDevice`]; [`Refusal::CommandRange`] for a + /// range past the buffer's commands; [`Refusal::PatchDraw`] for a state whose vertex function + /// is post-tessellation; [`Gap::IndirectCommandBuffers`] of + /// [`IndirectCommandsKind::UnflaggedState`] for a state made without + /// `supportIndirectCommandBuffers`, of [`IndirectCommandsKind::Tokens`] for one whose slots + /// take more tokens than the device does, of [`IndirectCommandsKind::DrawInput`] for one that + /// reads what a command cannot carry; as [`draw_primitives`](Self::draw_primitives) + /// otherwise. + pub fn execute_commands_in_buffer( + &mut self, + buffer: &IndirectCommandBuffer, + range: std::ops::Range, + ) -> Result<(), Error> { + if !buffer.is_of(self.building().device.core()) { + return Err(Error::Refused(Refusal::OtherDevice)); + } + if range.start > range.end || range.end > buffer.size() { + return Err(Error::Refused(Refusal::CommandRange)); + } + let call = Call::Commands { + buffer, + first: range.start, + sequences: range.end - range.start, + range: None, + }; + self.draw(primitives(PrimitiveType::Triangle), call, Some([1, 0])) + } + + /// `executeCommandsInBuffer:indirectBuffer:indirectBufferOffset:`: the commands of `buffer` in + /// the range (`MTLIndirectCommandBufferExecutionRange`: a `u32` location, then a `u32` + /// length) `range_buffer` holds at `offset` when the command runs, as + /// [`execute_commands_in_buffer`](Self::execute_commands_in_buffer) draws them. The execution + /// runs every command of the buffer, and the vertex function of each command outside the + /// range returns before its body, drawing nothing; a command past the buffer's is none. The + /// range buffer counts as a read, and the command buffer keeps it until it retires. + /// + /// Err: as [`execute_commands_in_buffer`](Self::execute_commands_in_buffer); + /// [`Refusal::OtherDevice`] for another device's range buffer; [`Refusal::CommandRange`] + /// for an offset that is not a multiple of 4 or a range whose 8 bytes leave the buffer. + pub fn execute_commands_in_buffer_with_range( + &mut self, + buffer: &IndirectCommandBuffer, + range_buffer: &Buffer, + offset: u64, + ) -> Result<(), Error> { + let device = self.building().device.core(); + if !buffer.is_of(device) || !range_buffer.is_of(device) { + return Err(Error::Refused(Refusal::OtherDevice)); + } + if offset % 4 != 0 + || offset + .checked_add(8) + .is_none_or(|end| end > range_buffer.length()) + { + return Err(Error::Refused(Refusal::CommandRange)); + } + let call = Call::Commands { + buffer, + first: 0, + sequences: buffer.size(), + range: Some((range_buffer, offset)), + }; + self.draw(primitives(PrimitiveType::Triangle), call, Some([1, 0])) + } + /// What a draw of `draws` reads of its pass's attachments through textures. A texture whose /// image the pass renders and that reaches the attachment's level and layer reads the /// attachment: from the fragment function, never written, of an image a draw may read so that @@ -2529,13 +2749,16 @@ impl RenderCommandEncoder { /// hold copied; then the copies it needs first, its textures over a buffer in an image of /// their own (`crate::over`), where `overs`, and the textures over a Managed buffer's device /// copy it reaches (`crate::over::ManagedOvers`), each recorded between the rendering's end - /// and its new beginning. `index` is its index buffer and its indirect arguments' buffer; a - /// patch draw reads the tessellation factor buffer as such. + /// and its new beginning. `index` is its index buffer and its indirect arguments' buffer, an + /// execution's range buffer among them; a patch draw reads the tessellation factor buffer as + /// such. An execution's (`commands`) reaches memory outside its resources through its + /// commands' slots. fn draw_reaches( &mut self, reads: Option, index: [Option<&Buffer>; 2], overs: bool, + commands: bool, ) -> Result<(), Error> { let reads_attachment = match reads { Some(found) => { @@ -2584,7 +2807,7 @@ impl RenderCommandEncoder { true => { // The buffers it reads owe copies back only where it reaches memory outside its // resources or such an image is ahead of its buffer. - let unbound = draws.reads_unbound || draws.writes_unbound; + let unbound = draws.reads_unbound || draws.writes_unbound || commands; let buffers = unbound || building.overs_ahead(); let vertex = (vertex_reads.clone()) .filter(|_| buffers) @@ -2620,13 +2843,14 @@ impl RenderCommandEncoder { building.managed_backs(backs) })?; } - self.overs_after(); + self.overs_after(commands); Ok(()) } /// After a draw of the pipeline state: what it wrote, for the textures over a buffer in an - /// image of their own (`crate::over`). - fn overs_after(&mut self) { + /// image of their own (`crate::over`). An execution's (`commands`) writes where its commands' + /// slots reach, outside its resources, where the state writes memory. + fn overs_after(&mut self, commands: bool) { let Some(state) = &self.pipeline else { return; }; @@ -2635,7 +2859,7 @@ impl RenderCommandEncoder { .expect("an encoder holds its command buffer's recording until it ends") .overs_after( slots(draws, &self.tables, &self.declared.each, true, true), - draws.writes_unbound, + draws.writes_unbound || (commands && draws.writes_memory), ); } @@ -2942,7 +3166,7 @@ fn primitives(primitive_type: PrimitiveType) -> (vk::PrimitiveTopology, bool) { /// element; the alpha test's code and the encoder's viewport count are the encoder's. fn fill_push( (push, blocks): (&mut Vec, &mut [Vec; 2]), - (tables, (nil, zero), factors): (&[Tables; 2], (u64, u64), u64), + (tables, (nil, zero, whole), factors): (&[Tables; 2], (u64, u64, u64), u64), [alpha_test, viewports]: [u32; 2], (moved, shadow_slots, pass): (&[Moved], &[(usize, u32)], &Pass), state: &RenderPipelineState, @@ -3026,12 +3250,46 @@ fn fill_push( FieldValue::ViewportCount => { bytes[at..at + 4].copy_from_slice(&viewports.to_le_bytes()); } + // A direct draw is every command's: the whole range, and command 0. + FieldValue::IndirectRange => bytes[at..at + 8].copy_from_slice(&whole.to_le_bytes()), + FieldValue::IndirectSequence | FieldValue::IndirectBase => bytes[at..at + 4].fill(0), // A render content has no dispatch or stage-in region (`render::draws`). FieldValue::DispatchRegion | FieldValue::StageInRegion | FieldValue::PrivateArena => {} } } } +/// Patches `push` and `blocks`, as [`fill_push`] filled them for `draws`, for an execution of +/// `buffer`'s commands from command `first`: the bounds of each slot a command holds are unchecked +/// ([`UNCHECKED_BOUNDS`]), as its address is the command's own, the execution range is read at +/// `range`, and the first part's first command is `first`. +fn commands_push( + (push, blocks): (&mut Vec, &mut [Vec; 2]), + draws: &Draws, + (buffer, first): (&IndirectCommandBuffer, u32), + range: u64, +) { + let layout = buffer.layout(); + for &(place, table, value) in &draws.fields { + let (bytes, at) = match place { + DrawPlace::Push(offset) => (&mut *push, offset as usize), + DrawPlace::Block(of, offset) => (&mut blocks[of], offset as usize), + }; + let held = match table { + VERTEX => layout.vertex_slots(), + _ => layout.fragment_slots(), + }; + match value { + FieldValue::BufferBounds(slot) if slot < held => { + bytes[at..at + 8].copy_from_slice(&UNCHECKED_BOUNDS); + } + FieldValue::IndirectRange => bytes[at..at + 8].copy_from_slice(&range.to_le_bytes()), + FieldValue::IndirectBase => bytes[at..at + 4].copy_from_slice(&first.to_le_bytes()), + _ => {} + } + } +} + /// The copy of `area` from an image into its shadow, of `aspects`, at the same place in both. fn region(area: &Area, aspects: vk::ImageAspectFlags) -> vk::ImageCopy { let layers = vk::ImageSubresourceLayers { diff --git a/crates/metal2vulkan-runtime/src/ring.rs b/crates/metal2vulkan-runtime/src/ring.rs index 3398d59e1..cb61d6562 100644 --- a/crates/metal2vulkan-runtime/src/ring.rs +++ b/crates/metal2vulkan-runtime/src/ring.rs @@ -27,6 +27,12 @@ //! Another, taken the same way, is the zero range ([`Ring::zero`]): zeros that no command and no //! buffer argument reaches, which a checked load of a buffer argument outside its buffer reads //! (the translator's `PushField::ZeroAddress`), so it reads zero. +//! +//! A third is the whole execution range ([`Ring::whole`]): Metal's +//! `MTLIndirectCommandBufferExecutionRange` of every command, location 0 and length `u32::MAX`, +//! which a direct draw of a state made for indirect command buffers, and an execution over a range +//! the CPU gives, point the vertex function's range at (the translator's +//! `PushField::IndirectRange`). Nothing writes it after its first ask. use crate::counters::{Gauge, Metric, Site}; use crate::device::{lock, Core}; @@ -54,6 +60,8 @@ pub(crate) struct Ring { nil: OnceLock, /// The zero range's address, once asked ([`Ring::zero`]), read with no lock. zero: OnceLock, + /// The whole execution range's address, once asked ([`Ring::whole`]), read with no lock. + whole: OnceLock, /// A block made, or chunks given back, while a block was being made. changed: Condvar, /// For the device tests: where set, the making of a block, the block-maker thread's or a @@ -116,6 +124,7 @@ impl Ring { }), nil: OnceLock::new(), zero: OnceLock::new(), + whole: OnceLock::new(), changed: Condvar::new(), #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] park: Mutex::new(None), @@ -193,26 +202,37 @@ impl Ring { /// The nil buffer's address (the module docs): a chunk of zeros, taken and zeroed at the /// first ask and never given back, so no command buffer writes it. pub(crate) fn nil(&self, core: &Core) -> Result { - self.kept(core, &self.nil) + self.kept(core, &self.nil, &[]) } /// The zero range's address (the module docs): a chunk of zeros taken as the nil buffer's /// is, which nothing is bound to, so nothing writes it. A multiple of 16. pub(crate) fn zero(&self, core: &Core) -> Result { - self.kept(core, &self.zero) + self.kept(core, &self.zero, &[]) } - /// The address of the chunk of zeros `which` holds, taken and zeroed at its first ask and - /// never given back. Every later ask reads it with no lock and no locked instruction: a draw - /// or a dispatch whose bindings changed asks again (the lock budget, `crate::tests::locks`). - fn kept(&self, core: &Core, which: &OnceLock) -> Result { + /// The whole execution range's address (the module docs): a chunk taken as the nil buffer's + /// is, its first 8 bytes location 0 and length `u32::MAX`, the rest zeros. + pub(crate) fn whole(&self, core: &Core) -> Result { + self.kept(core, &self.whole, &[0, 0, 0, 0, 0xff, 0xff, 0xff, 0xff]) + } + + /// The address of the chunk `which` holds, taken at its first ask, its bytes `head` and zeros + /// after them, and never given back. Every later ask reads it with no lock and no locked + /// instruction: a draw or a dispatch whose bindings changed asks again (the lock budget, + /// `crate::tests::locks`). + fn kept(&self, core: &Core, which: &OnceLock, head: &[u8]) -> Result { if let Some(&address) = which.get() { return Ok(address); } let chunk = self.take(core)?; // SAFETY: the chunk is out of every command buffer's hands and no pending work reads it: - // the host alone writes it, once. - unsafe { std::ptr::write_bytes(chunk.host.at(0).as_ptr(), 0, CHUNK as usize) }; + // the host alone writes it, once; `head` is shorter than a chunk. + unsafe { + let at = chunk.host.at(0).as_ptr(); + std::ptr::write_bytes(at, 0, CHUNK as usize); + std::ptr::copy_nonoverlapping(head.as_ptr(), at, head.len()); + } let address = *which.get_or_init(|| chunk.address); if address != chunk.address { // Another thread's ask made it first: the chunk goes back. diff --git a/crates/metal2vulkan-runtime/src/tests/floor.rs b/crates/metal2vulkan-runtime/src/tests/floor.rs index 0d3ddc1bd..db66eba69 100644 --- a/crates/metal2vulkan-runtime/src/tests/floor.rs +++ b/crates/metal2vulkan-runtime/src/tests/floor.rs @@ -3,13 +3,13 @@ //! what the code checks, and, under a device cfg, every device the loader lists is above the floor. use crate::floor::{ - choose, decide, flag_names, limits, vulkan_name, BelowFloor, Features, MemoryTypes, Missing, - Queried, ATTACHMENT_READS, ATTACHMENT_READ_EXTENSIONS, BARYCENTRICS, BARYCENTRIC_EXTENSIONS, - BORDER_SWIZZLE, BORDER_SWIZZLE_EXTENSIONS, DEVICE_EXTENSIONS, FAULT_REPORTS, FILL_MODES, - INSTANCE_EXTENSIONS, LINEAR_ATTACHMENTS, MEMORY_FLAG_NAMES, MIN_LOD_CLAMPS, OPTIONAL, - OPTIONAL_EXTENSIONS, OPTIONAL_INSTANCE_EXTENSIONS, PIXEL_INTERLOCK, PORTABILITY, - PRIVATE_MEMORY, QUAD_CONTROL, REQUIRED, RING_MEMORY, SHARED_MEMORY, STEP_RATES, TIMESTAMP_BITS, - TIME_DOMAINS, VERSION, + choose, decide, flag_names, limits, vulkan_name, BelowFloor, Features, IndirectCommandLimits, + MemoryTypes, Missing, Queried, ATTACHMENT_READS, ATTACHMENT_READ_EXTENSIONS, BARYCENTRICS, + BARYCENTRIC_EXTENSIONS, BORDER_SWIZZLE, BORDER_SWIZZLE_EXTENSIONS, DEVICE_EXTENSIONS, + FAULT_REPORTS, FILL_MODES, INDIRECT_COMMANDS, INSTANCE_EXTENSIONS, LINEAR_ATTACHMENTS, + MEMORY_FLAG_NAMES, MIN_LOD_CLAMPS, OPTIONAL, OPTIONAL_EXTENSIONS, OPTIONAL_INSTANCE_EXTENSIONS, + PIXEL_INTERLOCK, PORTABILITY, PRIVATE_MEMORY, QUAD_CONTROL, REQUIRED, RING_MEMORY, + SHARED_MEMORY, STEP_RATES, TIMESTAMP_BITS, TIME_DOMAINS, VERSION, }; use ash::vk; use std::collections::BTreeSet; @@ -138,6 +138,83 @@ fn at_the_floor() -> Queried { }], memory: memory(&[DEVICE_LOCAL, SHARED_MEMORY, RING_MEMORY]), time_domains: TIME_DOMAINS.to_vec(), + generated_commands: crate::dgc::DgcProperties::default(), + } +} + +/// A device at the floor that lists both extensions of indirect command buffers, reports both +/// features, and offers an execution of the runtime's largest command: lavapipe's limits. +fn with_indirect_commands() -> Queried { + let mut device = at_the_floor(); + (device.extensions).extend(INDIRECT_COMMANDS.iter().map(|&name| name.to_owned())); + device.features.generated_commands.device_generated_commands = vk::TRUE; + device.features.maintenance5.maintenance5 = vk::TRUE; + let offered = &mut device.generated_commands; + offered.max_indirect_sequence_count = 1 << 20; + offered.max_indirect_commands_token_count = 16; + offered.max_indirect_commands_token_offset = 2047; + offered.max_indirect_commands_indirect_stride = 2048; + offered.supported_input_modes = crate::dgc::INPUT_MODE_VULKAN; + offered.supported_shader_stages = crate::dgc::STAGES; + device +} + +/// Indirect command buffers come with both extensions and both features, enabled together, and +/// the device's limits; a device short of either feature, of the Vulkan index buffer input mode or +/// of a command's 536 bytes gets neither extension and neither feature, and stays above the floor. +#[test] +fn indirect_commands_take_both_extensions_or_neither() { + let capabilities = decide(&with_indirect_commands()).expect("above the floor"); + assert_eq!( + capabilities.indirect_commands, + Some(IndirectCommandLimits { + sequences: 1 << 20, + tokens: 16, + token_offset: 2047, + stride: 2048, + }) + ); + for name in INDIRECT_COMMANDS { + assert!(capabilities.extensions.contains(name), "{name:?} enabled"); + } + let features = &capabilities.features; + assert_eq!( + ( + features.generated_commands.device_generated_commands, + features.maintenance5.maintenance5 + ), + (vk::TRUE, vk::TRUE) + ); + let short: [fn(&mut Queried); 4] = [ + |device| device.features.maintenance5.maintenance5 = vk::FALSE, + |device| device.features.generated_commands.device_generated_commands = vk::FALSE, + |device| device.generated_commands.supported_input_modes = 0, + |device| { + device + .generated_commands + .max_indirect_commands_indirect_stride = 512 + }, + ]; + for (at, shorten) in short.into_iter().enumerate() { + let mut device = with_indirect_commands(); + shorten(&mut device); + let capabilities = decide(&device).expect("above the floor"); + assert_eq!(capabilities.indirect_commands, None, "short of item {at}"); + for name in INDIRECT_COMMANDS { + assert!( + !capabilities.extensions.contains(name), + "{name:?} with item {at} short" + ); + } + let features = &capabilities.features; + assert_eq!( + ( + features.generated_commands.device_generated_commands, + features.maintenance5.maintenance5 + ), + (vk::FALSE, vk::FALSE), + "short of item {at}" + ); } } @@ -1661,6 +1738,11 @@ fn the_readme_states_the_floor() { .iter() .map(|name| (name, "device, where reported")), ) + .chain( + INDIRECT_COMMANDS + .iter() + .map(|name| (name, "device, with indirect command buffers")), + ) .map(|(name, place)| (name.to_string_lossy().into_owned(), place.to_string())) .collect(); assert_eq!(stated, code, "the README's extensions"); @@ -1885,6 +1967,8 @@ fn every_device_the_loader_lists_is_above_the_floor() { mut linear_attachment, mut fault, mut line_rasterization, + mut generated_commands, + mut maintenance5, } = capabilities.features; let mut features = vk::PhysicalDeviceFeatures2::default() .features(core) @@ -1931,6 +2015,11 @@ fn every_device_the_loader_lists_is_above_the_floor() { if enabled(ash::ext::device_fault::NAME) { features = features.push_next(&mut fault); } + if capabilities.indirect_commands.is_some() { + features = features + .push_next(&mut generated_commands) + .push_next(&mut maintenance5); + } let extensions: Vec<*const c_char> = capabilities .extensions .iter() diff --git a/crates/metal2vulkan-runtime/src/tests/indirect.rs b/crates/metal2vulkan-runtime/src/tests/indirect.rs new file mode 100644 index 000000000..78b349e2d --- /dev/null +++ b/crates/metal2vulkan-runtime/src/tests/indirect.rs @@ -0,0 +1,943 @@ +//! Indirect command buffers (`crate::indirect`). +//! +//! - The bounds an execution pushes for a command's slot are the widest a checked access passes, +//! and not the all-ones pair of a slot bound to nothing. +//! - An execution's tokens: one push constant token for each run of slot words a content pushes +//! at consecutive offsets for consecutive places of a command, none for a slot past the +//! command's count; a content that reads no execution range, a slot word outside its push bytes +//! or a fixed-function vertex binding is refused. Fourteen slots apart take 17 tokens. +//! - Under a device cfg, on every device of the cfg's kind that enables +//! `VK_EXT_device_generated_commands`, with the owned fixtures `engine/icb_merged_indexed.ll` +//! and `engine/icb_indexed_extras.ll`; a device without the extension refuses a buffer +//! (`IndirectCommandsKind::Extension`), which each test prints and stops at: +//! - four commands a kernel encodes (indexed triangles of 16-bit indices, three vertex and one +//! fragment buffer each, base vertices and instances of their own) draw what the same draws +//! direct draw: an execution of all four; of commands 1 and 2, a range the CPU gives from a +//! non-zero location; of commands 2 and 3, the range a buffer holds at an offset; and of +//! commands 0 and 1, then a direct draw of command 2, then command 3, the direct draw drawing +//! after an execution as it does alone. A range past the commands and a range buffer's offset +//! off a multiple of 4 are refused. +//! - a kernel's reset of command 1 and a blit's reset of command 3 leave commands 0 and 2 to +//! draw; an optimize records nothing; a blit reset past the commands is refused. +//! - a command's slots go unchecked on both sides: a vertex function that reads four elements +//! before its slot's address, inside the buffer, reads the buffer's bytes there, and one that +//! reads past the end of the buffer its command named reads the bytes past it, each drawing +//! as the same draw direct, through the buffer bound at that offset, draws. +//! - a state whose fourteen slots apart take 17 tokens is `IndirectCommandsKind::Tokens` on a +//! device that takes fewer (lavapipe's 16), and executes on one that takes as many. +//! - the device's caches hold at most their capacities past them: 16 templates, 256 execution +//! shapes and 64 command layouts. +//! - the preprocess pool: regions held past 128 MiB in use all go back, the idle bytes at most +//! 128 MiB after them; 200 executions keep the regions' bytes flat between the 100th and the +//! 200th; every indirect gauge is zero once the device is dropped. +//! +//! `llvm-as` assembles the fixtures; without it a device test skips visibly. + +use crate::indirect::{tokens, UNCHECKED_BOUNDS}; +use crate::pipeline::FieldValue; +use crate::render::{DrawPlace, Draws, FRAGMENT, VERTEX}; +use crate::IndirectCommandsKind; +use metal2vulkan::pipeline::IndirectDrawLayout; + +/// A content of `fields`, reading nothing else. +fn draws(fields: Vec<(DrawPlace, usize, FieldValue)>) -> Draws { + Draws { + buffers: Vec::new(), + textures: Vec::new(), + storage_reads: Vec::new(), + own_pixel: Vec::new(), + fetched: Vec::new(), + bicubic: Vec::new(), + bindings: Vec::new(), + reads_unbound: false, + writes_unbound: false, + unbound_storage: false, + writes_memory: false, + push_len: 128, + fields, + blocks: [None, None], + first_instance_zero: false, + patches: false, + selects_viewport: false, + } +} + +fn slot(slot: u32) -> FieldValue { + FieldValue::BufferAddress { slot, mask: 0 } +} + +/// The execution range at push byte 96, the command at 104 and its part's first at 108, a vertex +/// function's. +fn ranged(mut fields: Vec<(DrawPlace, usize, FieldValue)>) -> Vec<(DrawPlace, usize, FieldValue)> { + fields.push((DrawPlace::Push(96), VERTEX, FieldValue::IndirectRange)); + fields.push((DrawPlace::Push(104), VERTEX, FieldValue::IndirectSequence)); + fields.push((DrawPlace::Push(108), VERTEX, FieldValue::IndirectBase)); + fields +} + +#[test] +fn a_commands_slots_are_pushed_with_the_widest_bounds() { + assert_eq!( + UNCHECKED_BOUNDS, + crate::encoder::bounds(u64::from(u32::MAX), 0x7fff_ffff) + ); + assert_ne!(UNCHECKED_BOUNDS, [0xff; 8], "not a slot bound to nothing"); +} + +#[test] +fn an_executions_tokens_are_its_runs_of_slot_words() { + let layout = IndirectDrawLayout::new(3, 2).expect("a layout"); + // Vertex slots 0 to 2 and fragment slot 0 lie at consecutive offsets of both the push bytes + // and the command: one run. Fragment slot 1 follows in the command but not in the push bytes, + // and vertex slot 3 is past the command's count. + let fields = ranged(vec![ + (DrawPlace::Push(0), VERTEX, slot(0)), + (DrawPlace::Push(8), VERTEX, slot(1)), + (DrawPlace::Push(16), VERTEX, slot(2)), + (DrawPlace::Push(24), FRAGMENT, slot(0)), + (DrawPlace::Push(40), FRAGMENT, slot(1)), + (DrawPlace::Push(48), VERTEX, slot(3)), + ]); + let found = tokens(&draws(fields), layout).expect("tokens"); + assert_eq!(found.pushes, [(0, 0, 32), (32, 40, 8)]); + assert_eq!((found.sequence, found.base, found.count()), (104, 108, 5)); + + // Fourteen slots, two apart in the command and consecutive in the push bytes: a run each. + let wide = IndirectDrawLayout::new(27, 0).expect("a layout"); + let fields = ranged( + (0..14) + .map(|n| (DrawPlace::Push(8 * n), VERTEX, slot(2 * n))) + .collect(), + ); + assert_eq!(tokens(&draws(fields), wide).expect("tokens").count(), 17); + + let refused = |fields, why| { + assert_eq!(tokens(&draws(fields), layout).err(), Some(why)); + }; + // No execution range: a state made without `supportIndirectCommandBuffers`. + refused( + vec![(DrawPlace::Push(0), VERTEX, slot(0))], + IndirectCommandsKind::UnflaggedState, + ); + // A slot word the command holds in a parameter block. + refused( + ranged(vec![(DrawPlace::Block(VERTEX, 0), VERTEX, slot(1))]), + IndirectCommandsKind::DrawInput, + ); + let mut bound = draws(ranged(vec![(DrawPlace::Push(0), VERTEX, slot(0))])); + bound.bindings.push((0, 0)); + assert_eq!( + tokens(&bound, layout).err(), + Some(IndirectCommandsKind::DrawInput), + "a fixed-function vertex binding" + ); +} + +#[cfg(any(m2v_gpu, m2v_cpu_icd))] +mod on_device { + use crate::indirect::{IDLE_BYTES, LAYOUTS, PART, SHAPES, TEMPLATES}; + use crate::render::Raster; + use crate::tests::command::on_device::each_device; + use crate::tests::draw::on_device::{library, pass, read, run, state, target, Buffers}; + use crate::{ + Buffer, ColorAttachmentDescriptor, ComputePipelineDescriptor, ComputePipelineState, + CullMode, Device, DispatchType, Error, FunctionDescriptor, Gap, IndexBuffer, IndexType, + IndirectCommandBuffer, IndirectCommandBufferDescriptor, IndirectCommandType, + IndirectCommandsKind, Library, MemoryClass, PixelFormat, PrimitiveType, Refusal, + RenderCommandEncoder, RenderPipelineDescriptor, RenderPipelineState, Resource, + ResourceUsage, StageSource, TextureUsage, + }; + use ash::vk; + use metal2vulkan::pipeline::IndirectDrawLayout; + use metal2vulkan_devtools::engine_dir; + + /// The commands the scene's kernel encodes. + const N: u32 = 4; + /// Each command's mark and tint: its index plus these. + const MARK: u32 = 10; + const TINT: u32 = 20; + + fn ok(name: &str, result: Result) -> T { + result.unwrap_or_else(|error| panic!("{name}: {error}")) + } + + /// Commands of indexed draws that inherit the pipeline state and bind `vertex` vertex and + /// `fragment` fragment buffers each. + fn descriptor(vertex: u32, fragment: u32) -> IndirectCommandBufferDescriptor { + let mut d = IndirectCommandBufferDescriptor::new(); + d.command_types = IndirectCommandType::DRAW_INDEXED; + d.inherit_pipeline_state = true; + d.max_vertex_buffer_bind_count = vertex; + d.max_fragment_buffer_bind_count = fragment; + d + } + + /// A buffer of `count` commands of `d`, or `None` (printed) on a device without the extension, + /// which refuses it by name. + fn commands( + name: &str, + device: &Device, + d: &IndirectCommandBufferDescriptor, + count: u32, + ) -> Option { + match device.new_indirect_command_buffer(d, count) { + Ok(commands) => Some(commands), + Err(Error::Unsupported(Gap::IndirectCommandBuffers { + kind: IndirectCommandsKind::Extension, + })) => { + assert!(device.core().indirect.is_none(), "{name}"); + println!("{name}: no VK_EXT_device_generated_commands: refused by name"); + None + } + Err(error) => panic!("{name}: {error}"), + } + } + + fn function(library: &Library, name: &str) -> StageSource { + StageSource::Function(FunctionDescriptor::new( + library.function(name).expect("the function"), + )) + } + + /// A state of `vertex` and `fragment` of `library` into an `RGBA32Uint` target, made for + /// indirect command buffers. + fn flagged( + name: &str, + device: &Device, + library: &Library, + (vertex, fragment): (&str, &str), + ) -> RenderPipelineState { + let mut d = RenderPipelineDescriptor::new(function(library, vertex)); + d.fragment = Some(function(library, fragment)); + d.color_attachments[0] = Some(ColorAttachmentDescriptor::new(PixelFormat::RGBA32Uint)); + d.support_indirect_command_buffers = true; + let made = state(name, device, &d); + assert!(made.support_indirect_command_buffers(), "{name}"); + made + } + + fn kernel(name: &str, device: &Device, library: &Library, entry: &str) -> ComputePipelineState { + let d = ComputePipelineDescriptor::new(function(library, entry)); + ok( + name, + device.new_compute_pipeline_state(&d, |samplers| Ok(vec![0; samplers.len()])), + ) + } + + fn words(values: &[u32]) -> Vec { + values.iter().flat_map(|v| v.to_le_bytes()).collect() + } + + fn floats(values: &[f32]) -> Vec { + values.iter().flat_map(|v| v.to_le_bytes()).collect() + } + + /// The pixel corners of the quad over rows `2 * band` and `2 * band + 1` of the target. + fn quad(band: u32) -> [f32; 8] { + let (top, bottom) = ((2 * band) as f32, (2 * band + 2) as f32); + [0.0, top, 8.0, top, 0.0, bottom, 8.0, bottom] + } + + /// The scene's buffers: the argument buffer holding the commands' `gpuResourceID`, each + /// command's draw (first index, count, instances, base vertex, base instance), mark and tint, + /// the frame, the four quads' corners and two copies of a quad's six 16-bit indices. + struct Scene { + arguments: Buffer, + draws: Buffer, + marks: Buffer, + frame: Buffer, + xy: Buffer, + tints: Buffer, + indices: Buffer, + } + + /// Command `i`'s first index: the second copy of the indices for an odd one. + fn first(i: u32) -> u32 { + 6 * (i % 2) + } + + impl Scene { + fn new(device: &Device, buffers: &mut Buffers, commands: &IndirectCommandBuffer) -> Scene { + Scene::of(device, buffers, commands, N) + } + + /// The scene of `count` commands, command `i` drawing band `i % 4` with mark `MARK + i` + /// and tint `TINT + i`. + fn of( + device: &Device, + buffers: &mut Buffers, + commands: &IndirectCommandBuffer, + count: u32, + ) -> Scene { + let draws: Vec = (0..count) + .flat_map(|i| [first(i), 6, 1, 4 * i, i]) + .collect(); + let xy: Vec = (0..count).flat_map(|i| quad(i % 4)).collect(); + let marks: Vec = (0..count).map(|i| MARK + i).collect(); + let tints: Vec = (0..count).map(|i| TINT + i).collect(); + let indices: Vec = [0u16, 1, 2, 2, 1, 3] + .repeat(2) + .iter() + .flat_map(|i| i.to_le_bytes()) + .collect(); + Scene { + arguments: buffers.of(device, &commands.gpu_resource_id().to_le_bytes()), + draws: buffers.of(device, &words(&draws)), + marks: buffers.of(device, &words(&marks)), + frame: buffers.of(device, &floats(&[8.0, 8.0, 0.0, 0.0])), + xy: buffers.of(device, &floats(&xy)), + tints: buffers.of(device, &words(&tints)), + indices: buffers.of(device, &indices), + } + } + } + + /// `threads` threads of `kernel` (`icb_indexed_16`) encode the scene's commands into + /// `commands`, the vertex positions those of `xy` at `xy_offset`. + fn encode( + name: &str, + device: &Device, + kernel: &ComputePipelineState, + commands: &IndirectCommandBuffer, + (s, xy, xy_offset): (&Scene, &Buffer, u64), + threads: u32, + ) { + let queue = device.new_command_queue(4).expect("a queue"); + let command_buffer = queue.command_buffer().expect("a command buffer"); + let mut e = ok( + name, + command_buffer.compute_command_encoder(DispatchType::Serial), + ); + ok(name, e.set_compute_pipeline_state(kernel)); + let bound = [ + &s.arguments, + &s.draws, + &s.marks, + &s.frame, + xy, + &s.tints, + &s.indices, + ]; + for (index, buffer) in bound.into_iter().enumerate() { + let offset = if index == 4 { xy_offset } else { 0 }; + ok(name, e.set_buffer(Some(buffer), offset, index as u32)); + } + ok( + name, + e.use_resource( + Resource::IndirectCommandBuffer(commands), + ResourceUsage::WRITE, + ), + ); + ok(name, e.dispatch_threadgroups([1, 1, 1], [threads, 1, 1])); + e.end_encoding(); + run(name, &command_buffer); + } + + /// Command `i` drawn direct, its positions those of `xy` at `xy_offset` from base vertex + /// `base`. + fn direct( + name: &str, + e: &mut RenderCommandEncoder, + (s, xy, xy_offset): (&Scene, &Buffer, u64), + i: u32, + base: i32, + ) { + ok( + name, + e.set_vertex_buffer(Some(&s.marks), 4 * u64::from(i), 0), + ); + ok(name, e.set_vertex_buffer(Some(&s.frame), 0, 1)); + ok(name, e.set_vertex_buffer(Some(xy), xy_offset, 2)); + ok( + name, + e.set_fragment_buffer(Some(&s.tints), 4 * u64::from(i), 0), + ); + let indices = IndexBuffer { + buffer: &s.indices, + offset: 2 * u64::from(first(i)), + index_type: IndexType::UInt16, + }; + ok( + name, + e.draw_indexed_primitives(PrimitiveType::Triangle, 6, indices, 1, base, i), + ); + } + + /// The `RGBA32Uint` texels a pass of `state` that `body` records draws, from opaque black. + fn drawn( + name: &str, + device: &Device, + state: &RenderPipelineState, + body: impl FnOnce(&mut RenderCommandEncoder), + ) -> Vec { + let color = target(device, PixelFormat::RGBA32Uint, TextureUsage::RENDER_TARGET); + let queue = device.new_command_queue(4).expect("a queue"); + let command_buffer = queue.command_buffer().expect("a command buffer"); + let mut e = ok( + name, + command_buffer.render_command_encoder(&pass(&color, None)), + ); + ok(name, e.set_render_pipeline_state(state)); + e.set_cull_mode(CullMode::None); + body(&mut e); + e.end_encoding(); + run(name, &command_buffer); + read(&color, 16) + } + + /// The mark of each row of `texels`, every pixel of a row holding the same mark (its first + /// word; the second is the provoking vertex's `vid`, which differs between a quad's two + /// triangles). + fn marks(name: &str, texels: &[u8]) -> Vec { + let mark = |pixel: &[u8]| u32::from_le_bytes(pixel[..4].try_into().expect("a word")); + (texels.chunks(16 * 8).enumerate()) + .map(|(row, pixels)| { + assert!( + pixels.chunks(16).all(|p| mark(p) == mark(pixels)), + "{name}: row {row} holds one mark" + ); + mark(pixels) + }) + .collect() + } + + /// The marks of rows whose commands in `drawn` drew, 0 where they did not. + fn want(drawn: &[u32]) -> Vec { + (0..2 * N) + .map(|row| { + let i = row / 2; + if drawn.contains(&i) { + MARK + i + } else { + 0 + } + }) + .collect() + } + + #[test] + fn every_device_draws_encoded_commands_as_their_draws_direct() { + let Some(indexed) = library(&engine_dir().join("icb_merged_indexed.ll")) else { + return; + }; + each_device("icb_encoded_draws", |name, _, device| { + let Some(commands) = commands(name, &device, &descriptor(3, 1), N) else { + return; + }; + let state = flagged( + name, + &device, + &indexed, + ("icb_indexed_vertex", "icb_indexed_fragment"), + ); + let kernel = kernel(name, &device, &indexed, "icb_indexed_16"); + let mut buffers = Buffers::new(&device); + let s = Scene::new(&device, &mut buffers, &commands); + let at = (&s, &s.xy, 0); + encode(name, &device, &kernel, &commands, at, N); + let direct_of = |range: std::ops::Range| { + drawn(name, &device, &state, |e| { + for i in range { + direct(name, e, at, i, 4 * i as i32); + } + }) + }; + let all = drawn(name, &device, &state, |e| { + ok(name, e.execute_commands_in_buffer(&commands, 0..N)) + }); + assert_eq!(all, direct_of(0..N), "{name}: all four"); + assert_eq!(marks(name, &all), want(&[0, 1, 2, 3]), "{name}"); + let middle = drawn(name, &device, &state, |e| { + ok(name, e.execute_commands_in_buffer(&commands, 1..3)) + }); + assert_eq!(middle, direct_of(1..3), "{name}: commands 1 and 2"); + assert_eq!(marks(name, &middle), want(&[1, 2]), "{name}"); + // The range a buffer holds 8 bytes in: location 2, length 2. + let range = buffers.of(&device, &words(&[7, 7, 2, 2])); + let held = drawn(name, &device, &state, |e| { + ok( + name, + e.execute_commands_in_buffer_with_range(&commands, &range, 8), + ) + }); + assert_eq!(held, direct_of(2..N), "{name}: the range the buffer holds"); + assert_eq!(marks(name, &held), want(&[2, 3]), "{name}"); + // A direct draw between two executions pushes and binds its own. + let mixed = drawn(name, &device, &state, |e| { + ok(name, e.execute_commands_in_buffer(&commands, 0..2)); + direct(name, e, at, 2, 8); + ok(name, e.execute_commands_in_buffer(&commands, 3..N)); + }); + assert_eq!(mixed, all, "{name}: a direct draw after an execution"); + drawn(name, &device, &state, |e| { + match e.execute_commands_in_buffer(&commands, 3..N + 1) { + Err(Error::Refused(Refusal::CommandRange)) => {} + other => panic!("{name}: a range past the commands: {other:?}"), + } + match e.execute_commands_in_buffer_with_range(&commands, &range, 6) { + Err(Error::Refused(Refusal::CommandRange)) => {} + other => panic!("{name}: a range buffer offset of 6: {other:?}"), + } + }); + println!( + "{name}: four encoded commands, commands 1 and 2, the range 2 and 3 a buffer \ + holds, and executions around a direct draw each draw as their draws direct" + ); + }); + } + + /// An execution of more commands than one part holds runs its parts in order, each command + /// tested against the range as its own: whole, over a CPU range and over a range a buffer + /// holds, each across parts, against the same draws direct. + #[test] + fn every_device_draws_an_execution_of_several_parts_as_its_draws_direct() { + const MANY: u32 = 3 * PART + 8; + let Some(indexed) = library(&engine_dir().join("icb_merged_indexed.ll")) else { + return; + }; + each_device("icb_parts", |name, _, device| { + let Some(commands) = commands(name, &device, &descriptor(3, 1), MANY) else { + return; + }; + let state = flagged( + name, + &device, + &indexed, + ("icb_indexed_vertex", "icb_indexed_fragment"), + ); + let kernel = kernel(name, &device, &indexed, "icb_indexed_16"); + let mut buffers = Buffers::new(&device); + let s = Scene::of(&device, &mut buffers, &commands, MANY); + let at = (&s, &s.xy, 0); + encode(name, &device, &kernel, &commands, at, MANY); + let direct_of = |range: std::ops::Range| { + drawn(name, &device, &state, |e| { + for i in range { + direct(name, e, at, i, 4 * i as i32); + } + }) + }; + // Each band's mark is the last command of `range` that draws it. + let last = |range: std::ops::Range| -> Vec { + (0..8) + .map(|row| { + let band = row / 2; + range + .clone() + .rev() + .find(|i| i % 4 == band) + .map_or(0, |i| MARK + i) + }) + .collect() + }; + let all = drawn(name, &device, &state, |e| { + ok(name, e.execute_commands_in_buffer(&commands, 0..MANY)) + }); + assert_eq!(all, direct_of(0..MANY), "{name}: all {MANY}"); + assert_eq!(marks(name, &all), last(0..MANY), "{name}: all {MANY}"); + let part = drawn(name, &device, &state, |e| { + ok(name, e.execute_commands_in_buffer(&commands, 60..140)) + }); + assert_eq!(part, direct_of(60..140), "{name}: commands 60 to 139"); + assert_eq!( + marks(name, &part), + last(60..140), + "{name}: commands 60 to 139" + ); + let range = buffers.of(&device, &words(&[70, 100])); + let held = drawn(name, &device, &state, |e| { + ok( + name, + e.execute_commands_in_buffer_with_range(&commands, &range, 0), + ) + }); + assert_eq!(held, direct_of(70..170), "{name}: the range 70 to 169"); + assert_eq!( + marks(name, &held), + last(70..170), + "{name}: the range 70 to 169" + ); + println!( + "{name}: {MANY} encoded commands, commands 60 to 139 and the range 70 to 169 a \ + buffer holds, in parts of {PART}, each draw as their draws direct" + ); + }); + } + + #[test] + fn every_device_resets_commands_by_kernel_and_by_blit() { + let Some(indexed) = library(&engine_dir().join("icb_merged_indexed.ll")) else { + return; + }; + let Some(extras) = library(&engine_dir().join("icb_indexed_extras.ll")) else { + return; + }; + each_device("icb_resets", |name, _, device| { + let Some(commands) = commands(name, &device, &descriptor(3, 1), N) else { + return; + }; + let state = flagged( + name, + &device, + &indexed, + ("icb_indexed_vertex", "icb_indexed_fragment"), + ); + let encoder = kernel(name, &device, &indexed, "icb_indexed_16"); + let reset = kernel(name, &device, &extras, "icb_extras_reset"); + let mut buffers = Buffers::new(&device); + let s = Scene::new(&device, &mut buffers, &commands); + let at = (&s, &s.xy, 0); + encode(name, &device, &encoder, &commands, at, N); + let first = buffers.of(&device, &words(&[1])); + let queue = device.new_command_queue(4).expect("a queue"); + let command_buffer = queue.command_buffer().expect("a command buffer"); + let mut e = ok( + name, + command_buffer.compute_command_encoder(DispatchType::Serial), + ); + ok(name, e.set_compute_pipeline_state(&reset)); + ok(name, e.set_buffer(Some(&s.arguments), 0, 0)); + ok(name, e.set_buffer(Some(&first), 0, 1)); + ok(name, e.dispatch_threadgroups([1, 1, 1], [1, 1, 1])); + e.end_encoding(); + let mut blit = ok(name, command_buffer.blit_command_encoder()); + ok(name, blit.reset_commands_in_buffer(&commands, 3..N)); + ok(name, blit.optimize_indirect_command_buffer(&commands, 0..N)); + match blit.reset_commands_in_buffer(&commands, 3..N + 1) { + Err(Error::Refused(Refusal::CommandRange)) => {} + other => panic!("{name}: a reset past the commands: {other:?}"), + } + blit.end_encoding(); + run(name, &command_buffer); + let after = drawn(name, &device, &state, |e| { + ok(name, e.execute_commands_in_buffer(&commands, 0..N)) + }); + let direct = drawn(name, &device, &state, |e| { + for i in [0, 2] { + direct(name, e, at, i, 4 * i as i32); + } + }); + assert_eq!(after, direct, "{name}: commands 0 and 2"); + assert_eq!(marks(name, &after), want(&[0, 2]), "{name}"); + println!( + "{name}: a kernel's reset of command 1 and a blit's of command 3 leave 0 and 2" + ); + }); + } + + /// Two buffers over one block's bytes: `whole` of `bytes`, and the first `part` bytes of it. + fn aliased(device: &Device, bytes: &[u8], part: u64) -> (crate::Block, Buffer, Buffer) { + let block = (device.take_block(MemoryClass::Shared, 65536)).expect("a block"); + let len = bytes.len() as u64; + let whole = (device.new_buffer(block.id, 0, len, None)).expect("a buffer"); + let first = (device.new_buffer(block.id, 0, part, None)).expect("a buffer"); + let contents = whole.contents().expect("a Shared buffer"); + // SAFETY: the range lies in the buffer, which is alive, and no GPU work uses it. + unsafe { std::ptr::copy_nonoverlapping(bytes.as_ptr(), contents.as_ptr(), bytes.len()) }; + (block, whole, first) + } + + #[test] + fn every_device_reads_a_commands_slots_unchecked_on_both_sides() { + let Some(indexed) = library(&engine_dir().join("icb_merged_indexed.ll")) else { + return; + }; + let Some(extras) = library(&engine_dir().join("icb_indexed_extras.ll")) else { + return; + }; + each_device("icb_unchecked_slots", |name, _, device| { + let Some(before) = commands(name, &device, &descriptor(3, 1), N) else { + return; + }; + let after = (commands(name, &device, &descriptor(3, 1), N)).expect("a second buffer"); + let kernel = kernel(name, &device, &indexed, "icb_indexed_16"); + let mut buffers = Buffers::new(&device); + // Command 0's quad, then corners far outside the target. + let far = [1000.0f32; 8]; + let quad_then_far = floats(&[quad(0), far].concat()); + let far_then_quad = floats(&[far, quad(0)].concat()); + + // Before: buffer 2 starts 32 bytes into the corners, and the vertex function reads + // four elements before it, which the buffer holds. + let back = flagged( + name, + &device, + &extras, + ("icb_extras_back_vertex", "icb_extras_back_fragment"), + ); + let s = Scene::new(&device, &mut buffers, &before); + let corners = buffers.of(&device, &quad_then_far); + encode(name, &device, &kernel, &before, (&s, &corners, 32), 1); + let encoded = drawn(name, &device, &back, |e| { + ok(name, e.execute_commands_in_buffer(&before, 0..1)) + }); + let direct_back = drawn(name, &device, &back, |e| { + direct(name, e, (&s, &corners, 32), 0, 0) + }); + assert_eq!( + encoded, direct_back, + "{name}: a read before the slot's address" + ); + assert_eq!(marks(name, &encoded), want(&[0]), "{name}: before"); + + // Past: buffer 2 is the first 32 bytes of the corners, and the draw's base vertex of + // 4 reads the 32 bytes past its end, which the block holds. + let state = flagged( + name, + &device, + &indexed, + ("icb_indexed_vertex", "icb_indexed_fragment"), + ); + let s = Scene::new(&device, &mut buffers, &after); + let (_block, whole, part) = aliased(&device, &far_then_quad, 32); + // The kernel's draw 0 takes base vertex 4. + let draws = buffers.of(&device, &words(&[0, 6, 1, 4, 0])); + let s = Scene { draws, ..s }; + encode(name, &device, &kernel, &after, (&s, &part, 0), 1); + let encoded = drawn(name, &device, &state, |e| { + ok(name, e.execute_commands_in_buffer(&after, 0..1)) + }); + let direct_past = drawn(name, &device, &state, |e| { + direct(name, e, (&s, &whole, 0), 0, 4) + }); + assert_eq!( + encoded, direct_past, + "{name}: a read past the slot's buffer" + ); + assert_eq!(marks(name, &encoded), want(&[0]), "{name}: past"); + println!( + "{name}: a command's slot reads the buffer's bytes 32 before its address and \ + 32 past the end of the buffer it named, as the draws direct do" + ); + }); + } + + #[test] + fn every_device_refuses_a_state_of_more_tokens_than_it_takes() { + let Some(extras) = library(&engine_dir().join("icb_indexed_extras.ll")) else { + return; + }; + each_device("icb_tokens", |name, _, device| { + let Some(commands) = commands(name, &device, &descriptor(27, 0), 1) else { + return; + }; + let wide = flagged( + name, + &device, + &extras, + ("icb_extras_wide_vertex", "icb_extras_fragment"), + ); + let tokens = (device.core().indirect.as_ref()) + .expect("the extension") + .limits + .tokens; + drawn(name, &device, &wide, |e| { + match (e.execute_commands_in_buffer(&commands, 0..1), tokens < 17) { + ( + Err(Error::Unsupported(Gap::IndirectCommandBuffers { + kind: IndirectCommandsKind::Tokens, + })), + true, + ) + | (Ok(()), false) => {} + (other, _) => panic!("{name}: 17 tokens on a device of {tokens}: {other:?}"), + } + }); + println!("{name}: a state of 17 tokens on a device that takes {tokens}"); + }); + } + + #[test] + fn every_device_bounds_its_indirect_caches() { + let Some(indexed) = library(&engine_dir().join("icb_merged_indexed.ll")) else { + return; + }; + each_device("icb_caches", |name, _, device| { + let Some(_commands) = commands(name, &device, &descriptor(3, 1), 1) else { + return; + }; + let state = flagged( + name, + &device, + &indexed, + ("icb_indexed_vertex", "icb_indexed_fragment"), + ); + let core = device.core(); + let indirect = (core.indirect.as_ref()).expect("the extension"); + let compiled = &state.inner.compiled; + let pipeline = ok( + name, + compiled.pipeline(vk::PrimitiveTopology::TRIANGLE_LIST, Raster::default()), + ); + let layout = + |vertex, fragment| IndirectDrawLayout::new(vertex, fragment).expect("a layout"); + // A pipeline of another raster state sizes its own shape (the preprocess requirements + // are queried with the execution's pipeline). + let clamped = Raster { + clamp: true, + lines: false, + }; + let other = ok( + name, + compiled.pipeline(vk::PrimitiveTopology::TRIANGLE_LIST, clamped), + ); + let before = indirect.held().1; + ok( + name, + indirect.shape( + core, + (compiled, Raster::default(), pipeline), + layout(3, 1), + 1, + ), + ); + ok( + name, + indirect.shape(core, (compiled, clamped, other), layout(3, 1), 1), + ); + assert_eq!( + indirect.held().1, + before + 2, + "{name}: a shape for each raster state" + ); + for vertex in 0..=TEMPLATES as u32 { + ok(name, indirect.template(core, layout(vertex, 0))); + } + for capacity in 1..=SHAPES as u32 + 1 { + ok( + name, + indirect.shape( + core, + (compiled, Raster::default(), pipeline), + layout(3, 1), + capacity, + ), + ); + } + let layouts = + (3..=31).flat_map(|vertex| (1..=3).map(move |fragment| (vertex, fragment))); + for (vertex, fragment) in layouts.take(LAYOUTS + 1) { + ok( + name, + indirect.shape( + core, + (compiled, Raster::default(), pipeline), + layout(vertex, fragment), + 1, + ), + ); + } + assert_eq!(indirect.held(), (TEMPLATES, SHAPES, LAYOUTS), "{name}"); + println!("{name}: {TEMPLATES} templates, {SHAPES} shapes and {LAYOUTS} layouts held past them"); + }); + } + + #[test] + fn every_device_bounds_its_preprocess_pool_and_drops_it() { + let Some(indexed) = library(&engine_dir().join("icb_merged_indexed.ll")) else { + return; + }; + each_device("icb_pool", |name, _, device| { + let Some(commands) = commands(name, &device, &descriptor(3, 1), N) else { + return; + }; + let counters = device.counters(); + let state = flagged( + name, + &device, + &indexed, + ("icb_indexed_vertex", "icb_indexed_fragment"), + ); + { + let core = device.core(); + let indirect = (core.indirect.as_ref()).expect("the extension"); + let compiled = &state.inner.compiled; + let pipeline = ok( + name, + compiled.pipeline(vk::PrimitiveTopology::TRIANGLE_LIST, Raster::default()), + ); + let layout = IndirectDrawLayout::new(3, 1).expect("a layout"); + let shape = |capacity| { + ok( + name, + indirect.shape( + core, + (compiled, Raster::default(), pipeline), + layout, + capacity, + ), + ) + }; + // A capacity whose region is between 4 and 16 MiB, so a few dozen pass the bound. + let mut capacity = 1024; + while shape(capacity).preprocess_size() > 16 << 20 && capacity > 1 { + capacity /= 2; + } + while shape(capacity).preprocess_size() < 4 << 20 + && 2 * capacity <= indirect.limits.sequences + { + capacity *= 2; + } + let shape = shape(capacity); + let mut held = Vec::new(); + while counters.gauges().preprocess_used_bytes <= IDLE_BYTES { + held.push(ok(name, indirect.executed(core, &shape, 1)).0); + } + let regions = held.len(); + drop(held); + let g = counters.gauges(); + assert_eq!(g.preprocess_used_bytes, 0, "{name}"); + assert!( + 0 < g.preprocess_idle_bytes && g.preprocess_idle_bytes <= IDLE_BYTES, + "{name}: {} idle bytes", + g.preprocess_idle_bytes + ); + println!( + "{name}: {regions} regions of {capacity} commands held past {IDLE_BYTES} bytes \ + went back, {} bytes kept idle", + g.preprocess_idle_bytes + ); + } + let mut buffers = Buffers::new(&device); + let kernel = kernel(name, &device, &indexed, "icb_indexed_16"); + let s = Scene::new(&device, &mut buffers, &commands); + encode(name, &device, &kernel, &commands, (&s, &s.xy, 0), N); + let regions = || { + let g = counters.gauges(); + ( + g.preprocess_used_bytes + g.preprocess_idle_bytes, + g.indirect_command_buffers, + ) + }; + let mut at = Vec::new(); + for iteration in 1..=200 { + drawn(name, &device, &state, |e| { + ok(name, e.execute_commands_in_buffer(&commands, 0..N)) + }); + if iteration == 100 || iteration == 200 { + at.push(regions()); + } + } + assert_eq!( + at[0], at[1], + "{name}: the regions' bytes and the buffers, flat" + ); + drop((commands, state, kernel, s, buffers)); + drop(device); + let g = counters.gauges(); + assert_eq!( + ( + g.indirect_command_buffers, + g.preprocess_used_bytes, + g.preprocess_idle_bytes + ), + (0, 0, 0), + "{name}: at the device's drop" + ); + println!( + "{name}: 200 executions flat between the 100th and the 200th; zero at the drop" + ); + }); + } +} diff --git a/crates/metal2vulkan-runtime/src/tests/mod.rs b/crates/metal2vulkan-runtime/src/tests/mod.rs index e1b3076e5..67c05851a 100644 --- a/crates/metal2vulkan-runtime/src/tests/mod.rs +++ b/crates/metal2vulkan-runtime/src/tests/mod.rs @@ -38,6 +38,7 @@ mod import; mod import_overs; mod import_time; mod imported_aliases; +mod indirect; mod interpolation; mod kept; mod kernel_input; diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index f08f36772..420af7f90 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -43,6 +43,14 @@ assoc-const metal2vulkan-air::ir::FloatPredicate::ALL pub const ALL: [FloatPredi assoc-const metal2vulkan-air::ir::IntPredicate::ALL pub const ALL: [IntPredicate; 10] assoc-const metal2vulkan-air::metal::DataType::ALL pub const ALL: [DataType; 17] assoc-const metal2vulkan-runtime::BlitCommandEncoder::GENERATE_MIPMAPS_NOTE pub const GENERATE_MIPMAPS_NOTE: PrecisionNote +assoc-const metal2vulkan-runtime::IndirectCommandType::CONCURRENT_DISPATCH pub const CONCURRENT_DISPATCH: IndirectCommandType +assoc-const metal2vulkan-runtime::IndirectCommandType::CONCURRENT_DISPATCH_THREADS pub const CONCURRENT_DISPATCH_THREADS: IndirectCommandType +assoc-const metal2vulkan-runtime::IndirectCommandType::DRAW pub const DRAW: IndirectCommandType +assoc-const metal2vulkan-runtime::IndirectCommandType::DRAW_INDEXED pub const DRAW_INDEXED: IndirectCommandType +assoc-const metal2vulkan-runtime::IndirectCommandType::DRAW_INDEXED_PATCHES pub const DRAW_INDEXED_PATCHES: IndirectCommandType +assoc-const metal2vulkan-runtime::IndirectCommandType::DRAW_MESH_THREADGROUPS pub const DRAW_MESH_THREADGROUPS: IndirectCommandType +assoc-const metal2vulkan-runtime::IndirectCommandType::DRAW_MESH_THREADS pub const DRAW_MESH_THREADS: IndirectCommandType +assoc-const metal2vulkan-runtime::IndirectCommandType::DRAW_PATCHES pub const DRAW_PATCHES: IndirectCommandType assoc-const metal2vulkan-runtime::PixelFormatInfo::INVALID pub const INVALID: PixelFormatInfo assoc-const metal2vulkan-runtime::RenderCommandEncoder::DEPTH_BIAS_NOTE pub const DEPTH_BIAS_NOTE: PrecisionNote assoc-const metal2vulkan-runtime::ResourceUsage::READ pub const READ: ResourceUsage @@ -266,6 +274,14 @@ assoc-const-value metal2vulkan-air::ir::FloatPredicate::ALL [FloatPredicate::Fal assoc-const-value metal2vulkan-air::ir::IntPredicate::ALL [IntPredicate::Eq, IntPredicate::Ne, IntPredicate::Ugt, IntPredicate::Uge, IntPredicate::Ult, IntPredicate::Ule, IntPredicate::Sgt, IntPredicate::Sge, IntPredicate::Slt, IntPredicate::Sle] assoc-const-value metal2vulkan-air::metal::DataType::ALL [DataType::Float32, DataType::Float16, DataType::BFloat16, DataType::Int2, DataType::Int4, DataType::Int8, DataType::Int16, DataType::Int32, DataType::UInt2, DataType::UInt4, DataType::UInt8, DataType::UInt16, DataType::UInt32, DataType::Fp4E2M1, DataType::Fp8E4M3, DataType::Fp8E5M2, DataType::Fp8UE8M0] assoc-const-value metal2vulkan-runtime::BlitCommandEncoder::GENERATE_MIPMAPS_NOTE PrecisionNote::DeviceFilteredMipmaps +assoc-const-value metal2vulkan-runtime::IndirectCommandType::CONCURRENT_DISPATCH IndirectCommandType(1 <<5) +assoc-const-value metal2vulkan-runtime::IndirectCommandType::CONCURRENT_DISPATCH_THREADS IndirectCommandType(1 <<6) +assoc-const-value metal2vulkan-runtime::IndirectCommandType::DRAW IndirectCommandType(1 <<0) +assoc-const-value metal2vulkan-runtime::IndirectCommandType::DRAW_INDEXED IndirectCommandType(1 <<1) +assoc-const-value metal2vulkan-runtime::IndirectCommandType::DRAW_INDEXED_PATCHES IndirectCommandType(1 <<3) +assoc-const-value metal2vulkan-runtime::IndirectCommandType::DRAW_MESH_THREADGROUPS IndirectCommandType(1 <<7) +assoc-const-value metal2vulkan-runtime::IndirectCommandType::DRAW_MESH_THREADS IndirectCommandType(1 <<8) +assoc-const-value metal2vulkan-runtime::IndirectCommandType::DRAW_PATCHES IndirectCommandType(1 <<2) assoc-const-value metal2vulkan-runtime::PixelFormatInfo::INVALID PixelFormatInfo assoc-const-value metal2vulkan-runtime::RenderCommandEncoder::DEPTH_BIAS_NOTE PrecisionNote::DeviceDepthBias assoc-const-value metal2vulkan-runtime::ResourceUsage::READ ResourceUsage(1) @@ -490,6 +506,7 @@ const metal2vulkan-runtime::floor::BARYCENTRIC_EXTENSIONS pub const BARYCENTRIC_ const metal2vulkan-runtime::floor::BORDER_SWIZZLE_EXTENSIONS pub const BORDER_SWIZZLE_EXTENSIONS: &[&CStr] const metal2vulkan-runtime::floor::BUFFER_USAGE pub const BUFFER_USAGE: vk::BufferUsageFlags const metal2vulkan-runtime::floor::DEVICE_EXTENSIONS pub const DEVICE_EXTENSIONS: &[&CStr] +const metal2vulkan-runtime::floor::INDIRECT_COMMANDS pub const INDIRECT_COMMANDS: &[&CStr] const metal2vulkan-runtime::floor::INSTANCE_EXTENSIONS pub const INSTANCE_EXTENSIONS: &[&CStr] const metal2vulkan-runtime::floor::OPTIONAL_EXTENSIONS pub const OPTIONAL_EXTENSIONS: &[&CStr] const metal2vulkan-runtime::floor::OPTIONAL_INSTANCE_EXTENSIONS pub const OPTIONAL_INSTANCE_EXTENSIONS: &[&CStr] @@ -571,6 +588,7 @@ const-value metal2vulkan-runtime::floor::BARYCENTRIC_EXTENSIONS &[ash::khr::frag const-value metal2vulkan-runtime::floor::BORDER_SWIZZLE_EXTENSIONS &[ash::ext::custom_border_color::NAME, ash::ext::border_color_swizzle::NAME] const-value metal2vulkan-runtime::floor::BUFFER_USAGE vk::BufferUsageFlags::from_raw(vk::BufferUsageFlags::TRANSFER_SRC.as_raw() | vk::BufferUsageFlags::TRANSFER_DST.as_raw() | vk::BufferUsageFlags::UNIFORM_TEXEL_BUFFER.as_raw() | vk::BufferUsageFlags::STORAGE_TEXEL_BUFFER.as_raw() | vk::BufferUsageFlags::UNIFORM_BUFFER.as_raw() | vk::BufferUsageFlags::STORAGE_BUFFER.as_raw() | vk::BufferUsageFlags::INDEX_BUFFER.as_raw() | vk::BufferUsageFlags::VERTEX_BUFFER.as_raw() | vk::BufferUsageFlags::INDIRECT_BUFFER.as_raw() | vk::BufferUsageFlags::SHADER_DEVICE_ADDRESS.as_raw()) const-value metal2vulkan-runtime::floor::DEVICE_EXTENSIONS &[ash::khr::swapchain::NAME, ash::ext::robustness2::NAME, ash::ext::calibrated_timestamps::NAME, ash::ext::line_rasterization::NAME] +const-value metal2vulkan-runtime::floor::INDIRECT_COMMANDS &[crate::dgc::NAME, ash::khr::maintenance5::NAME] const-value metal2vulkan-runtime::floor::INSTANCE_EXTENSIONS &[ash::khr::surface::NAME] const-value metal2vulkan-runtime::floor::OPTIONAL_EXTENSIONS &[ash::khr::shader_maximal_reconvergence::NAME, ash::khr::shader_subgroup_uniform_control_flow::NAME, ash::khr::shader_quad_control::NAME, ash::ext::fragment_shader_interlock::NAME, ash::ext::shader_stencil_export::NAME, ash::khr::portability_subset::NAME, ash::khr::vertex_attribute_divisor::NAME, ash::ext::vertex_attribute_divisor::NAME, ash::ext::external_memory_host::NAME, ash::khr::external_memory_fd::NAME, ash::ext::external_memory_dma_buf::NAME, ash::khr::external_memory_win32::NAME, ash::ext::queue_family_foreign::NAME, ash::ext::image_drm_format_modifier::NAME, ash::nv::linear_color_attachment::NAME, ash::ext::device_fault::NAME] const-value metal2vulkan-runtime::floor::OPTIONAL_INSTANCE_EXTENSIONS &[ash::khr::portability_enumeration::NAME] @@ -764,6 +782,7 @@ enum metal2vulkan-runtime::ExportHandle #[derive(Clone, Copy, Debug, PartialEq, enum metal2vulkan-runtime::Gap #[derive(Clone, Copy, Debug, PartialEq, Eq)] #[non_exhaustive] pub enum Gap enum metal2vulkan-runtime::ImportHandle #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum ImportHandle enum metal2vulkan-runtime::IndexClass #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[non_exhaustive] pub enum IndexClass +enum metal2vulkan-runtime::IndirectCommandsKind #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[non_exhaustive] pub enum IndirectCommandsKind enum metal2vulkan-runtime::KernelInputKind #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[non_exhaustive] pub enum KernelInputKind enum metal2vulkan-runtime::Limit #[derive(Clone, Copy, Debug, PartialEq, Eq)] #[non_exhaustive] pub enum Limit enum metal2vulkan-runtime::LinearPlanePassKind #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[non_exhaustive] pub enum LinearPlanePassKind @@ -1508,11 +1527,14 @@ field metal2vulkan-runtime::Gauges.exports pub exports: u64 field metal2vulkan-runtime::Gauges.handles_out pub handles_out: u64 field metal2vulkan-runtime::Gauges.import_bytes pub import_bytes: u64 field metal2vulkan-runtime::Gauges.imports pub imports: u64 +field metal2vulkan-runtime::Gauges.indirect_command_buffers pub indirect_command_buffers: u64 field metal2vulkan-runtime::Gauges.kernel_entries pub kernel_entries: u64 field metal2vulkan-runtime::Gauges.kernels pub kernels: u64 field metal2vulkan-runtime::Gauges.managed_spilled_bytes pub managed_spilled_bytes: u64 field metal2vulkan-runtime::Gauges.pipeline_cache_bytes pub pipeline_cache_bytes: u64 field metal2vulkan-runtime::Gauges.pipelines pub pipelines: u64 +field metal2vulkan-runtime::Gauges.preprocess_idle_bytes pub preprocess_idle_bytes: u64 +field metal2vulkan-runtime::Gauges.preprocess_used_bytes pub preprocess_used_bytes: u64 field metal2vulkan-runtime::Gauges.private_allocation_bytes pub private_allocation_bytes: u64 field metal2vulkan-runtime::Gauges.private_buffer_bytes pub private_buffer_bytes: u64 field metal2vulkan-runtime::Gauges.private_idle_age_nanos pub private_idle_age_nanos: u64 @@ -1563,6 +1585,12 @@ field metal2vulkan-runtime::IndexBuffer.offset pub offset: u64 field metal2vulkan-runtime::IndexGrant.class pub class: IndexClass field metal2vulkan-runtime::IndexGrant.count pub count: u32 field metal2vulkan-runtime::IndexGrant.first pub first: u32 +field metal2vulkan-runtime::IndirectCommandBufferDescriptor.command_types pub command_types: IndirectCommandType +field metal2vulkan-runtime::IndirectCommandBufferDescriptor.inherit_buffers pub inherit_buffers: bool +field metal2vulkan-runtime::IndirectCommandBufferDescriptor.inherit_pipeline_state pub inherit_pipeline_state: bool +field metal2vulkan-runtime::IndirectCommandBufferDescriptor.max_fragment_buffer_bind_count pub max_fragment_buffer_bind_count: u32 +field metal2vulkan-runtime::IndirectCommandBufferDescriptor.max_kernel_buffer_bind_count pub max_kernel_buffer_bind_count: u32 +field metal2vulkan-runtime::IndirectCommandBufferDescriptor.max_vertex_buffer_bind_count pub max_vertex_buffer_bind_count: u32 field metal2vulkan-runtime::Metrics.allocation_map_refusals pub allocation_map_refusals: u64 field metal2vulkan-runtime::Metrics.allocations_freed pub allocations_freed: u64 field metal2vulkan-runtime::Metrics.allocations_mapped pub allocations_mapped: u64 @@ -1924,12 +1952,15 @@ field metal2vulkan-runtime::floor::Capabilities.features pub features: Features field metal2vulkan-runtime::floor::Capabilities.feedback_loop pub feedback_loop: bool field metal2vulkan-runtime::floor::Capabilities.float16 pub float16: bool field metal2vulkan-runtime::floor::Capabilities.float64 pub float64: bool +field metal2vulkan-runtime::floor::Capabilities.indirect_commands pub indirect_commands: Option field metal2vulkan-runtime::floor::Capabilities.maximal_reconvergence pub maximal_reconvergence: bool field metal2vulkan-runtime::floor::Capabilities.memory pub memory: vk::PhysicalDeviceMemoryProperties field metal2vulkan-runtime::floor::Capabilities.queue_family pub queue_family: u32 field metal2vulkan-runtime::floor::Capabilities.shared_int64_atomics pub shared_int64_atomics: bool field metal2vulkan-runtime::floor::Capabilities.storage_read_without_format pub storage_read_without_format: bool field metal2vulkan-runtime::floor::Capabilities.subgroup_uniform_control_flow pub subgroup_uniform_control_flow: bool +field metal2vulkan-runtime::floor::DgcFeatures.device_generated_commands pub device_generated_commands: vk::Bool32 +field metal2vulkan-runtime::floor::DgcFeatures.dynamic_generated_pipeline_layout pub dynamic_generated_pipeline_layout: vk::Bool32 field metal2vulkan-runtime::floor::Features.barycentric pub barycentric: vk::PhysicalDeviceFragmentShaderBarycentricFeaturesKHR<'static> field metal2vulkan-runtime::floor::Features.border_swizzle pub border_swizzle: vk::PhysicalDeviceBorderColorSwizzleFeaturesEXT<'static> field metal2vulkan-runtime::floor::Features.core pub core: vk::PhysicalDeviceFeatures @@ -1937,9 +1968,11 @@ field metal2vulkan-runtime::floor::Features.divisor pub divisor: vk::PhysicalDev field metal2vulkan-runtime::floor::Features.fault pub fault: vk::PhysicalDeviceFaultFeaturesEXT<'static> field metal2vulkan-runtime::floor::Features.feedback_loop pub feedback_loop: vk::PhysicalDeviceAttachmentFeedbackLoopLayoutFeaturesEXT<'static> field metal2vulkan-runtime::floor::Features.feedback_loop_dynamic pub feedback_loop_dynamic: vk::PhysicalDeviceAttachmentFeedbackLoopDynamicStateFeaturesEXT<'static> +field metal2vulkan-runtime::floor::Features.generated_commands pub generated_commands: DgcFeatures field metal2vulkan-runtime::floor::Features.interlock pub interlock: vk::PhysicalDeviceFragmentShaderInterlockFeaturesEXT<'static> field metal2vulkan-runtime::floor::Features.line_rasterization pub line_rasterization: vk::PhysicalDeviceLineRasterizationFeaturesEXT<'static> field metal2vulkan-runtime::floor::Features.linear_attachment pub linear_attachment: vk::PhysicalDeviceLinearColorAttachmentFeaturesNV<'static> +field metal2vulkan-runtime::floor::Features.maintenance5 pub maintenance5: vk::PhysicalDeviceMaintenance5FeaturesKHR<'static> field metal2vulkan-runtime::floor::Features.maximal_reconvergence pub maximal_reconvergence: vk::PhysicalDeviceShaderMaximalReconvergenceFeaturesKHR<'static> field metal2vulkan-runtime::floor::Features.portability pub portability: vk::PhysicalDevicePortabilitySubsetFeaturesKHR<'static> field metal2vulkan-runtime::floor::Features.quad_control pub quad_control: vk::PhysicalDeviceShaderQuadControlFeaturesKHR<'static> @@ -1948,6 +1981,10 @@ field metal2vulkan-runtime::floor::Features.subgroup_uniform_control_flow pub su field metal2vulkan-runtime::floor::Features.vulkan11 pub vulkan11: vk::PhysicalDeviceVulkan11Features<'static> field metal2vulkan-runtime::floor::Features.vulkan12 pub vulkan12: vk::PhysicalDeviceVulkan12Features<'static> field metal2vulkan-runtime::floor::Features.vulkan13 pub vulkan13: vk::PhysicalDeviceVulkan13Features<'static> +field metal2vulkan-runtime::floor::IndirectCommandLimits.sequences pub sequences: u32 +field metal2vulkan-runtime::floor::IndirectCommandLimits.stride pub stride: u32 +field metal2vulkan-runtime::floor::IndirectCommandLimits.token_offset pub token_offset: u32 +field metal2vulkan-runtime::floor::IndirectCommandLimits.tokens pub tokens: u32 field metal2vulkan-runtime::floor::MemoryTypes.private pub private: u32 field metal2vulkan-runtime::floor::MemoryTypes.ring pub ring: u32 field metal2vulkan-runtime::floor::MemoryTypes.shared pub shared: u32 @@ -6484,8 +6521,10 @@ method metal2vulkan-runtime::BlitCommandEncoder::copy_from_texture_to_buffer_wit method metal2vulkan-runtime::BlitCommandEncoder::end_encoding pub fn end_encoding(mut self) method metal2vulkan-runtime::BlitCommandEncoder::fill_buffer pub fn fill_buffer(&mut self, buffer: &Buffer, range: Range, value: u8) -> Result<(), Error> method metal2vulkan-runtime::BlitCommandEncoder::generate_mipmaps pub fn generate_mipmaps(&mut self, texture: &Texture) -> Result<(), Error> +method metal2vulkan-runtime::BlitCommandEncoder::optimize_indirect_command_buffer pub fn optimize_indirect_command_buffer(&mut self, buffer: &IndirectCommandBuffer, range: Range) -> Result<(), Error> method metal2vulkan-runtime::BlitCommandEncoder::release_surface_to_external pub fn release_surface_to_external(&mut self, surface: &Surface) -> Result<(), Error> method metal2vulkan-runtime::BlitCommandEncoder::release_to_external pub fn release_to_external(&mut self, buffer: &Buffer) -> Result<(), Error> +method metal2vulkan-runtime::BlitCommandEncoder::reset_commands_in_buffer pub fn reset_commands_in_buffer(&mut self, buffer: &IndirectCommandBuffer, range: Range) -> Result<(), Error> method metal2vulkan-runtime::BlitCommandEncoder::synchronize_resource pub fn synchronize_resource(&mut self, resource: Resource<'_>) -> Result<(), Error> method metal2vulkan-runtime::BlitCommandEncoder::update_fence pub fn update_fence(&mut self, fence: &Fence) -> Result<(), Error> method metal2vulkan-runtime::BlitCommandEncoder::wait_for_fence pub fn wait_for_fence(&mut self, fence: &Fence) -> Result<(), Error> @@ -6588,6 +6627,7 @@ method metal2vulkan-runtime::Device::new_fence pub fn new_fence(&self) -> Fence method metal2vulkan-runtime::Device::new_heap_buffer pub fn new_heap_buffer(&self, heap: HeapRange, offset: u64, length: u64) -> Result method metal2vulkan-runtime::Device::new_heap_texture pub fn new_heap_texture(&self, descriptor: &TextureDescriptor, index: Option, heap: HeapRange, offset: u64) -> Result method metal2vulkan-runtime::Device::new_heap_texture_for_views pub fn new_heap_texture_for_views(&self, descriptor: &TextureDescriptor, heap: HeapRange, offset: u64) -> Result +method metal2vulkan-runtime::Device::new_indirect_command_buffer pub fn new_indirect_command_buffer(&self, descriptor: &IndirectCommandBufferDescriptor, max_command_count: u32) -> Result method metal2vulkan-runtime::Device::new_managed_buffer pub fn new_managed_buffer(&self, bytes: (BlockId, u64), copy: Option<(BlockId, u64)>, length: u64, copied: u64) -> Result method metal2vulkan-runtime::Device::new_managed_texture pub fn new_managed_texture(&self, descriptor: &TextureDescriptor, index: Option, bytes: &Buffer, places: &[BytesPlace]) -> Result method metal2vulkan-runtime::Device::new_sampler_state pub fn new_sampler_state(&self, descriptor: &SamplerDescriptor, index: u32) -> Result @@ -6620,6 +6660,11 @@ method metal2vulkan-runtime::HostBytes::from_raw pub unsafe fn from_raw(start: * method metal2vulkan-runtime::HostBytes::is_empty pub fn is_empty(&self) -> bool method metal2vulkan-runtime::HostBytes::len pub fn len(&self) -> usize method metal2vulkan-runtime::IndexClass::range pub fn range(self) -> Range +method metal2vulkan-runtime::IndirectCommandBuffer::gpu_resource_id pub fn gpu_resource_id(&self) -> u64 +method metal2vulkan-runtime::IndirectCommandBuffer::size pub fn size(&self) -> u32 +method metal2vulkan-runtime::IndirectCommandBufferDescriptor::new pub fn new() -> IndirectCommandBufferDescriptor +method metal2vulkan-runtime::IndirectCommandType::bits pub const fn bits(self) -> u64 +method metal2vulkan-runtime::IndirectCommandType::from_bits pub const fn from_bits(bits: u64) -> IndirectCommandType method metal2vulkan-runtime::Instance::extensions pub fn extensions(&self) -> &[CString] method metal2vulkan-runtime::Instance::new pub fn new(extensions: &[&CStr]) -> Result method metal2vulkan-runtime::Instance::physical_devices pub fn physical_devices(&self) -> Result, Error> @@ -6652,6 +6697,8 @@ method metal2vulkan-runtime::RenderCommandEncoder::draw_patches_indirect pub fn method metal2vulkan-runtime::RenderCommandEncoder::draw_primitives pub fn draw_primitives(&mut self, primitive_type: PrimitiveType, vertex_start: u32, vertex_count: u32, instance_count: u32, base_instance: u32) -> Result<(), Error> method metal2vulkan-runtime::RenderCommandEncoder::draw_primitives_indirect pub fn draw_primitives_indirect(&mut self, primitive_type: PrimitiveType, indirect_buffer: &Buffer, indirect_buffer_offset: u64) -> Result<(), Error> method metal2vulkan-runtime::RenderCommandEncoder::end_encoding pub fn end_encoding(mut self) +method metal2vulkan-runtime::RenderCommandEncoder::execute_commands_in_buffer pub fn execute_commands_in_buffer(&mut self, buffer: &IndirectCommandBuffer, range: std::ops::Range) -> Result<(), Error> +method metal2vulkan-runtime::RenderCommandEncoder::execute_commands_in_buffer_with_range pub fn execute_commands_in_buffer_with_range(&mut self, buffer: &IndirectCommandBuffer, range_buffer: &Buffer, offset: u64) -> Result<(), Error> method metal2vulkan-runtime::RenderCommandEncoder::memory_barrier pub fn memory_barrier(&mut self) -> Result<(), Error> method metal2vulkan-runtime::RenderCommandEncoder::set_alpha_test_reference_value pub fn set_alpha_test_reference_value(&mut self, value: f32) method metal2vulkan-runtime::RenderCommandEncoder::set_blend_color pub fn set_blend_color(&mut self, red: f32, green: f32, blue: f32, alpha: f32) @@ -6687,6 +6734,7 @@ method metal2vulkan-runtime::RenderCommandEncoder::set_viewport pub fn set_viewp method metal2vulkan-runtime::RenderCommandEncoder::set_viewports pub fn set_viewports(&mut self, viewports: &[Viewport]) -> Result<(), Error> method metal2vulkan-runtime::RenderCommandEncoder::set_visibility_result_mode pub fn set_visibility_result_mode(&mut self, mode: VisibilityResultMode, offset: u64) -> Result<(), Error> method metal2vulkan-runtime::RenderCommandEncoder::update_fence pub fn update_fence(&mut self, fence: &Fence) -> Result<(), Error> +method metal2vulkan-runtime::RenderCommandEncoder::use_heap pub fn use_heap(&mut self, heap: BlockId) -> Result<(), Error> method metal2vulkan-runtime::RenderCommandEncoder::use_resource pub fn use_resource(&mut self, resource: Resource<'_>, usage: ResourceUsage) -> Result<(), Error> method metal2vulkan-runtime::RenderCommandEncoder::wait_for_fence pub fn wait_for_fence(&mut self, fence: &Fence) -> Result<(), Error> method metal2vulkan-runtime::RenderPassDescriptor::precision_note pub fn precision_note(&self) -> Option @@ -7613,6 +7661,9 @@ struct metal2vulkan-runtime::HeapRange #[derive(Clone, Copy, Debug, PartialEq, E struct metal2vulkan-runtime::HostBytes #[derive(Clone, Copy, Debug)] pub struct HostBytes<'a> struct metal2vulkan-runtime::IndexBuffer #[derive(Clone, Copy)] pub struct IndexBuffer<'a> struct metal2vulkan-runtime::IndexGrant #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub struct IndexGrant +struct metal2vulkan-runtime::IndirectCommandBuffer #[derive(Clone)] pub struct IndirectCommandBuffer +struct metal2vulkan-runtime::IndirectCommandBufferDescriptor #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] #[non_exhaustive] pub struct IndirectCommandBufferDescriptor +struct metal2vulkan-runtime::IndirectCommandType #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] pub struct IndirectCommandType(u64) struct metal2vulkan-runtime::Instance #[derive(Clone)] pub struct Instance struct metal2vulkan-runtime::Library #[derive(Clone, Debug, PartialEq, Eq)] #[non_exhaustive] pub struct Library(Arc) struct metal2vulkan-runtime::Metrics #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] #[non_exhaustive] pub struct Metrics @@ -7653,7 +7704,9 @@ struct metal2vulkan-runtime::VertexDescriptor #[cfg_attr(feature = "serde", deri struct metal2vulkan-runtime::Viewport #[derive(Clone, Copy, Debug, PartialEq)] pub struct Viewport struct metal2vulkan-runtime::floor::BelowFloor #[derive(Clone, Debug, PartialEq, Eq)] pub struct BelowFloor struct metal2vulkan-runtime::floor::Capabilities pub struct Capabilities +struct metal2vulkan-runtime::floor::DgcFeatures #[derive(Clone, Copy)] #[repr(C)] pub struct DgcFeatures struct metal2vulkan-runtime::floor::Features #[derive(Clone, Copy, Default)] pub struct Features +struct metal2vulkan-runtime::floor::IndirectCommandLimits #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct IndirectCommandLimits struct metal2vulkan-runtime::floor::MemoryTypes #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct MemoryTypes struct metal2vulkan::Budget #[derive(Clone, Debug, Default)] #[non_exhaustive] pub struct Budget struct metal2vulkan::CancelToken #[derive(Clone, Debug, Default)] pub struct CancelToken(Arc) @@ -7986,6 +8039,7 @@ trait-impl metal2vulkan-runtime::Error impl std::error::Error impl std::error::E trait-impl metal2vulkan-runtime::FaultAddress impl fmt::Debug impl fmt::Debug for FaultAddress trait-impl metal2vulkan-runtime::Gap impl fmt::Display impl fmt::Display for Gap trait-impl metal2vulkan-runtime::HostBytes impl From<&'a [u8]> impl<'a> From<&'a [u8]> for HostBytes<'a> +trait-impl metal2vulkan-runtime::IndirectCommandType impl std::ops::BitOr impl std::ops::BitOr for IndirectCommandType trait-impl metal2vulkan-runtime::Limit impl fmt::Display impl fmt::Display for Limit trait-impl metal2vulkan-runtime::Refusal impl fmt::Display impl fmt::Display for Refusal trait-impl metal2vulkan-runtime::RenderCommandEncoder impl Drop impl Drop for RenderCommandEncoder @@ -8003,6 +8057,11 @@ trait-impl metal2vulkan-runtime::Texture impl crate::kept::Handle impl crate::ke trait-impl metal2vulkan-runtime::TextureSwizzleChannels impl Default impl Default for TextureSwizzleChannels trait-impl metal2vulkan-runtime::floor::BelowFloor impl fmt::Display impl fmt::Display for BelowFloor trait-impl metal2vulkan-runtime::floor::BelowFloor impl std::error::Error impl std::error::Error for BelowFloor +trait-impl metal2vulkan-runtime::floor::DgcFeatures impl Default impl Default for DgcFeatures +trait-impl metal2vulkan-runtime::floor::DgcFeatures impl fe impl Send unsafe impl Send for DgcFeatures +trait-impl metal2vulkan-runtime::floor::DgcFeatures impl fe impl Sync unsafe impl Sync for DgcFeatures +trait-impl metal2vulkan-runtime::floor::DgcFeatures impl fe impl vk::ExtendsDeviceCreateInfo unsafe impl vk::ExtendsDeviceCreateInfo for DgcFeatures +trait-impl metal2vulkan-runtime::floor::DgcFeatures impl fe impl vk::ExtendsPhysicalDeviceFeatures2 unsafe impl vk::ExtendsPhysicalDeviceFeatures2 for DgcFeatures trait-impl metal2vulkan-runtime::floor::Missing impl fmt::Display impl fmt::Display for Missing trait-impl metal2vulkan::bind::ArgumentLayoutError impl From impl From for ArgumentLayoutError trait-impl metal2vulkan::bind::DrawCommands impl Default impl Default for DrawCommands @@ -9226,7 +9285,7 @@ variant metal2vulkan-runtime::Gap::FillAlignment FillAlignment { start: u64, end variant metal2vulkan-runtime::Gap::FloatDepthUpload FloatDepthUpload { pixel_format: PixelFormat } variant metal2vulkan-runtime::Gap::HeapTexture HeapTexture { pixel_format: PixelFormat } variant metal2vulkan-runtime::Gap::ImageblockLength ImageblockLength -variant metal2vulkan-runtime::Gap::IndirectCommandBuffers IndirectCommandBuffers +variant metal2vulkan-runtime::Gap::IndirectCommandBuffers IndirectCommandBuffers { kind: IndirectCommandsKind } variant metal2vulkan-runtime::Gap::IndirectPrivateArena IndirectPrivateArena variant metal2vulkan-runtime::Gap::KernelInput KernelInput { kind: KernelInputKind } variant metal2vulkan-runtime::Gap::LinearPlanePass LinearPlanePass { kind: LinearPlanePassKind } @@ -9253,8 +9312,17 @@ variant metal2vulkan-runtime::ImportHandle::DmaBufs DmaBufs variant metal2vulkan-runtime::ImportHandle::HostMemory HostMemory variant metal2vulkan-runtime::IndexClass::Sampler Sampler variant metal2vulkan-runtime::IndexClass::Texture Texture +variant metal2vulkan-runtime::IndirectCommandsKind::BindCount BindCount +variant metal2vulkan-runtime::IndirectCommandsKind::Capacity Capacity +variant metal2vulkan-runtime::IndirectCommandsKind::CommandPipelines CommandPipelines +variant metal2vulkan-runtime::IndirectCommandsKind::CommandTypes CommandTypes +variant metal2vulkan-runtime::IndirectCommandsKind::ComputeCommands ComputeCommands +variant metal2vulkan-runtime::IndirectCommandsKind::DrawInput DrawInput +variant metal2vulkan-runtime::IndirectCommandsKind::Extension Extension +variant metal2vulkan-runtime::IndirectCommandsKind::InheritedBuffers InheritedBuffers +variant metal2vulkan-runtime::IndirectCommandsKind::Tokens Tokens +variant metal2vulkan-runtime::IndirectCommandsKind::UnflaggedState UnflaggedState variant metal2vulkan-runtime::KernelInputKind::ArgumentBlock ArgumentBlock -variant metal2vulkan-runtime::KernelInputKind::CommandBuffers CommandBuffers variant metal2vulkan-runtime::KernelInputKind::ConstexprSampler ConstexprSampler variant metal2vulkan-runtime::KernelInputKind::DescriptorSet DescriptorSet variant metal2vulkan-runtime::KernelInputKind::EntryPoint EntryPoint @@ -9399,6 +9467,7 @@ variant metal2vulkan-runtime::Refusal::BufferOffsetAlignment BufferOffsetAlignme variant metal2vulkan-runtime::Refusal::BufferPastBlock BufferPastBlock { offset: u64, length: u64, block_len: u64 } variant metal2vulkan-runtime::Refusal::BufferTextureLayout BufferTextureLayout { offset: u64, bytes_per_row: u64, len: u64 } variant metal2vulkan-runtime::Refusal::BufferTooLong BufferTooLong { length: u64, max: u64 } +variant metal2vulkan-runtime::Refusal::CommandRange CommandRange variant metal2vulkan-runtime::Refusal::Committed Committed variant metal2vulkan-runtime::Refusal::DrawableAcquired DrawableAcquired variant metal2vulkan-runtime::Refusal::DrawableDescriptor DrawableDescriptor @@ -9487,6 +9556,7 @@ variant metal2vulkan-runtime::RenderPipelineKind::SynthesizedStages SynthesizedS variant metal2vulkan-runtime::RenderPipelineKind::Tessellation Tessellation variant metal2vulkan-runtime::RenderPipelineKind::VertexAmplification VertexAmplification variant metal2vulkan-runtime::Resource::Buffer Buffer(&'a Buffer) +variant metal2vulkan-runtime::Resource::IndirectCommandBuffer IndirectCommandBuffer(&'a IndirectCommandBuffer) variant metal2vulkan-runtime::Resource::Texture Texture(&'a Texture) variant metal2vulkan-runtime::Stage::Fragment Fragment variant metal2vulkan-runtime::Stage::Kernel Kernel diff --git a/docs/METAL-COVERAGE.md b/docs/METAL-COVERAGE.md index 6de5ee9fc..0daa88cd8 100644 --- a/docs/METAL-COVERAGE.md +++ b/docs/METAL-COVERAGE.md @@ -10,12 +10,12 @@ Every public item of the macOS 27.2 SDK (Xcode 27.2, 27B52)'s Metal headers, by | Status | Items | Of which deprecated | |---|---|---| -| implemented | 601 | 27 | -| missing | 1110 | 36 | +| implemented | 620 | 29 | +| missing | 1091 | 34 | | out of scope | 424 | 5 | | all | 2135 | 68 | -Implemented by the runtime: 245; by the translator's values: 356. Missing by size: S 187, M 205, L 342, XL 376. +Implemented by the runtime: 264; by the translator's values: 356. Missing by size: S 183, M 205, L 327, XL 376. ## Missing, in build order @@ -33,7 +33,7 @@ Cheap items a plain app calls first, then medium pieces by how often a plain app | a buffer made with bytes | S | 1 | `MTLDevice.newBufferWithBytes:length:options:` | | pipeline creation forms (from a function, with a completion handler) | S | 6 | `MTLDevice.newRenderPipelineStateWithDescriptor:options:completionHandler:`, `MTLDevice.newComputePipelineStateWithFunction:error:`, `MTLDevice.newComputePipelineStateWithFunction:options:reflection:error:`, ... | | render pass descriptor fields | S/M/L | 9 | `MTLRenderPassAttachmentDescriptor.depthPlane`, `MTLRenderPassAttachmentDescriptor.storeActionOptions`, `MTLRenderPassDescriptor.imageblockSampleLength`, ... | -| encoder calls (stride setters, indirect draws, store action options, a render encoder's heap uses) | S/M/L | 29 | `MTLBlitCommandEncoder.synchronizeTexture:slice:level:`, `MTLBlitCommandEncoder.copyFromTexture:sourceSlice:sourceLevel:toTexture:destinationSlice:destinationLevel:sliceCount:levelCount:`, `MTLBlitCommandEncoder.copyFromTexture:toTexture:`, ... | +| encoder calls (stride setters, indirect draws, store action options, a render encoder's heap uses) | S/M/L | 25 | `MTLBlitCommandEncoder.synchronizeTexture:slice:level:`, `MTLBlitCommandEncoder.copyFromTexture:sourceSlice:sourceLevel:toTexture:destinationSlice:destinationLevel:sliceCount:levelCount:`, `MTLBlitCommandEncoder.copyFromTexture:toTexture:`, ... | | `textureBarrier` and queue-stage barriers | S/M | 2 | `MTLCommandEncoder.barrierAfterQueueStages:beforeStages:`, `MTLRenderCommandEncoder.textureBarrier` | | a pipeline state's reflection after creation | S | 2 | `MTLComputePipelineState.reflection`, `MTLRenderPipelineState.reflection` | | function handles by name, and a handle's type and ID | S | 4 | `MTLComputePipelineState.functionHandleWithName:`, `MTLFunctionHandle.functionType`, `MTLFunctionHandle.gpuResourceID`, ... | @@ -52,7 +52,7 @@ Cheap items a plain app calls first, then medium pieces by how often a plain app | a function's options (`MTLFunctionOptions`) | S | 2 | `MTLFunctionDescriptor.options`, `MTLFunction.options` | | argument encoders | M | 24 | `MTLArgumentEncoder`, `MTLArgumentEncoder.device`, `MTLArgumentEncoder.encodedLength`, ... | | the resource state encoder | M | 8 | `MTLCommandBuffer.resourceStateCommandEncoder`, `MTLResourceStateCommandEncoder`, `MTLResourceStateCommandEncoder.updateTextureMappings:mode:regions:mipLevels:slices:numRegions:`, ... | -| indirect command buffers | L | 71 | `MTLArgumentEncoder.setIndirectCommandBuffer:atIndex:`, `MTLArgumentEncoder.setIndirectCommandBuffers:withRange:`, `MTLBlitCommandEncoder.resetCommandsInBuffer:withRange:`, ... | +| indirect command buffers | L | 56 | `MTLArgumentEncoder.setIndirectCommandBuffer:atIndex:`, `MTLArgumentEncoder.setIndirectCommandBuffers:withRange:`, `MTLBlitCommandEncoder.copyIndirectCommandBuffer:sourceRange:destination:destinationIndex:`, ... | | function tables, function handles and dynamic libraries | L | 38 | `MTLComputeCommandEncoder.setVisibleFunctionTable:atBufferIndex:`, `MTLComputeCommandEncoder.setVisibleFunctionTables:withBufferRange:`, `MTLComputePipelineState.functionHandleWithBinaryFunction:`, ... | | rasterization rate maps | L | 12 | `MTLDevice.supportsRasterizationRateMapWithLayerCount:`, `MTLDevice.newRasterizationRateMapWithDescriptor:`, `MTLRasterizationRateMap`, ... | | mesh render pipelines and their encoder calls | L | 33 | `MTLDevice.newRenderPipelineStateWithMeshDescriptor:options:reflection:error:`, `MTLDevice.newRenderPipelineStateWithMeshDescriptor:options:completionHandler:`, `MTLRenderCommandEncoder.setObjectBytes:length:atIndex:`, ... | @@ -1004,8 +1004,8 @@ Cheap items a plain app calls first, then medium pieces by how often a plain app | `MTLArgumentEncoder.setRenderPipelineStates:withRange:` | method | missing | M: argument encoders | | `MTLArgumentEncoder.setComputePipelineState:atIndex:` | method | missing | M: argument encoders | | `MTLArgumentEncoder.setComputePipelineStates:withRange:` | method | missing | M: argument encoders | -| `MTLArgumentEncoder.setIndirectCommandBuffer:atIndex:` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLArgumentEncoder.setIndirectCommandBuffers:withRange:` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | +| `MTLArgumentEncoder.setIndirectCommandBuffer:atIndex:` | method | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLArgumentEncoder.setIndirectCommandBuffers:withRange:` | method | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | | `MTLArgumentEncoder.setAccelerationStructure:atIndex:` | method | out of scope | ray tracing | | `MTLArgumentEncoder.newArgumentEncoderForBufferAtIndex:` | method | missing | M: argument encoders | | `MTLArgumentEncoder.setVisibleFunctionTable:atIndex:` | method | missing | M: argument encoders | @@ -1057,9 +1057,9 @@ Cheap items a plain app calls first, then medium pieces by how often a plain app | `MTLBlitCommandEncoder.optimizeContentsForGPUAccess:slice:level:` | method | missing | S: an encoder call metal2vulkan-runtime does not build | | `MTLBlitCommandEncoder.optimizeContentsForCPUAccess:` | method | missing | S: an encoder call metal2vulkan-runtime does not build | | `MTLBlitCommandEncoder.optimizeContentsForCPUAccess:slice:level:` | method | missing | S: an encoder call metal2vulkan-runtime does not build | -| `MTLBlitCommandEncoder.resetCommandsInBuffer:withRange:` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLBlitCommandEncoder.copyIndirectCommandBuffer:sourceRange:destination:destinationIndex:` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLBlitCommandEncoder.optimizeIndirectCommandBuffer:withRange:` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | +| `MTLBlitCommandEncoder.resetCommandsInBuffer:withRange:` | method | implemented | `BlitCommandEncoder::reset_commands_in_buffer` (runtime) | +| `MTLBlitCommandEncoder.copyIndirectCommandBuffer:sourceRange:destination:destinationIndex:` | method | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLBlitCommandEncoder.optimizeIndirectCommandBuffer:withRange:` | method | implemented | `BlitCommandEncoder::optimize_indirect_command_buffer` (runtime): records nothing | | `MTLBlitCommandEncoder.sampleCountersInBuffer:atSampleIndex:withBarrier:` | method | missing | M: counter sample buffers | | `MTLBlitCommandEncoder.resolveCounters:inRange:destinationBuffer:destinationOffset:` | method | missing | M: counter sample buffers | | `MTLBlitCommandEncoder.copyFromTensor:sourceOrigin:sourceDimensions:toTensor:destinationOrigin:destinationDimensions:` | method | missing | L: tensors | @@ -1255,8 +1255,8 @@ Cheap items a plain app calls first, then medium pieces by how often a plain app | `MTLComputeCommandEncoder.useResources:count:usage:` | method | implemented | `ComputeCommandEncoder::use_resource` (runtime): a loop of it | | `MTLComputeCommandEncoder.useHeap:` | method | implemented | `ComputeCommandEncoder::use_heap` (runtime) | | `MTLComputeCommandEncoder.useHeaps:count:` | method | implemented | `ComputeCommandEncoder::use_heap` (runtime): a loop of it | -| `MTLComputeCommandEncoder.executeCommandsInBuffer:withRange:` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLComputeCommandEncoder.executeCommandsInBuffer:indirectBuffer:indirectBufferOffset:` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | +| `MTLComputeCommandEncoder.executeCommandsInBuffer:withRange:` | method | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLComputeCommandEncoder.executeCommandsInBuffer:indirectBuffer:indirectBufferOffset:` | method | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | | `MTLComputeCommandEncoder.memoryBarrierWithScope:` | method | implemented | `ComputeCommandEncoder::memory_barrier` (runtime): one global memory barrier | | `MTLComputeCommandEncoder.memoryBarrierWithResources:count:` | method | implemented | `ComputeCommandEncoder::memory_barrier` (runtime): one global memory barrier | | `MTLComputeCommandEncoder.sampleCountersInBuffer:atSampleIndex:withBarrier:` | method | missing | M: counter sample buffers | @@ -1459,7 +1459,7 @@ Cheap items a plain app calls first, then medium pieces by how often a plain app | `MTLDevice.newArgumentEncoderWithArguments:` | method | missing | M: argument encoders | | `MTLDevice.supportsRasterizationRateMapWithLayerCount:` | method | missing | L: rasterization rate maps; the render pass descriptor has no field for one | | `MTLDevice.newRasterizationRateMapWithDescriptor:` | method | missing | L: rasterization rate maps; the render pass descriptor has no field for one | -| `MTLDevice.newIndirectCommandBufferWithDescriptor:maxCommandCount:options:` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | +| `MTLDevice.newIndirectCommandBufferWithDescriptor:maxCommandCount:options:` | method | implemented | `Device::new_indirect_command_buffer` (runtime): indexed triangle draws with an inherited pipeline state | | `MTLDevice.newEvent` | method | implemented | `Device::new_event` (runtime) | | `MTLDevice.newSharedEvent` | method | implemented | `Device::new_shared_event` (runtime) | | `MTLDevice.newSharedEventWithHandle:` | method | missing | M: texture and event handles shared across processes | @@ -1754,73 +1754,73 @@ Cheap items a plain app calls first, then medium pieces by how often a plain app | Item | Kind | Status | Counterpart or note | |---|---|---|---| -| `MTLIndirectCommandBufferDescriptor` | class | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectCommandBufferDescriptor.commandTypes` | property | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectCommandBufferDescriptor.inheritPipelineState` | property | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectCommandBufferDescriptor.inheritBuffers` | property | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectCommandBufferDescriptor.inheritDepthStencilState` | property | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectCommandBufferDescriptor.inheritDepthBias` | property | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectCommandBufferDescriptor.inheritDepthClipMode` | property | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectCommandBufferDescriptor.inheritCullMode` | property | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectCommandBufferDescriptor.inheritFrontFacingWinding` | property | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectCommandBufferDescriptor.inheritTriangleFillMode` | property | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectCommandBufferDescriptor.maxVertexBufferBindCount` | property | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectCommandBufferDescriptor.maxFragmentBufferBindCount` | property | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectCommandBufferDescriptor.maxKernelBufferBindCount` | property | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectCommandBufferDescriptor.maxKernelThreadgroupMemoryBindCount` | property | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectCommandBufferDescriptor.maxObjectBufferBindCount` | property | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectCommandBufferDescriptor.maxMeshBufferBindCount` | property | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectCommandBufferDescriptor.maxObjectThreadgroupMemoryBindCount` | property | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectCommandBufferDescriptor` | class | implemented | `IndirectCommandBufferDescriptor` (runtime) | +| `MTLIndirectCommandBufferDescriptor.commandTypes` | property | implemented | `IndirectCommandBufferDescriptor.command_types` (runtime) | +| `MTLIndirectCommandBufferDescriptor.inheritPipelineState` | property | implemented | `IndirectCommandBufferDescriptor.inherit_pipeline_state` (runtime): true alone | +| `MTLIndirectCommandBufferDescriptor.inheritBuffers` | property | implemented | `IndirectCommandBufferDescriptor.inherit_buffers` (runtime): false alone | +| `MTLIndirectCommandBufferDescriptor.inheritDepthStencilState` | property | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectCommandBufferDescriptor.inheritDepthBias` | property | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectCommandBufferDescriptor.inheritDepthClipMode` | property | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectCommandBufferDescriptor.inheritCullMode` | property | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectCommandBufferDescriptor.inheritFrontFacingWinding` | property | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectCommandBufferDescriptor.inheritTriangleFillMode` | property | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectCommandBufferDescriptor.maxVertexBufferBindCount` | property | implemented | `IndirectCommandBufferDescriptor.max_vertex_buffer_bind_count` (runtime) | +| `MTLIndirectCommandBufferDescriptor.maxFragmentBufferBindCount` | property | implemented | `IndirectCommandBufferDescriptor.max_fragment_buffer_bind_count` (runtime) | +| `MTLIndirectCommandBufferDescriptor.maxKernelBufferBindCount` | property | implemented | `IndirectCommandBufferDescriptor.max_kernel_buffer_bind_count` (runtime): read by no render command | +| `MTLIndirectCommandBufferDescriptor.maxKernelThreadgroupMemoryBindCount` | property | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectCommandBufferDescriptor.maxObjectBufferBindCount` | property | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectCommandBufferDescriptor.maxMeshBufferBindCount` | property | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectCommandBufferDescriptor.maxObjectThreadgroupMemoryBindCount` | property | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | | `MTLIndirectCommandBufferDescriptor.supportRayTracing` | property | out of scope | ray tracing | -| `MTLIndirectCommandBufferDescriptor.supportDynamicAttributeStride` | property | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectCommandBufferDescriptor.supportColorAttachmentMapping` | property | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectCommandBuffer` | protocol | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectCommandBuffer.size` | property | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectCommandBuffer.gpuResourceID` | property | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectCommandBuffer.resetWithRange:` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectCommandBuffer.indirectRenderCommandAtIndex:` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectCommandBuffer.indirectComputeCommandAtIndex:` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectCommandBufferExecutionRangeMake` | function | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectCommandBufferDescriptor.supportDynamicAttributeStride` | property | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectCommandBufferDescriptor.supportColorAttachmentMapping` | property | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectCommandBuffer` | protocol | implemented | `IndirectCommandBuffer` (runtime) | +| `MTLIndirectCommandBuffer.size` | property | implemented | `IndirectCommandBuffer::size` (runtime) | +| `MTLIndirectCommandBuffer.gpuResourceID` | property | implemented | `IndirectCommandBuffer::gpu_resource_id` (runtime): the records' device address | +| `MTLIndirectCommandBuffer.resetWithRange:` | method | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectCommandBuffer.indirectRenderCommandAtIndex:` | method | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectCommandBuffer.indirectComputeCommandAtIndex:` | method | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectCommandBufferExecutionRangeMake` | function | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | ### MTLIndirectCommandEncoder.h | Item | Kind | Status | Counterpart or note | |---|---|---|---| -| `MTLIndirectRenderCommand` | protocol | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectRenderCommand.setRenderPipelineState:` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectRenderCommand.setVertexBuffer:offset:atIndex:` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectRenderCommand.setFragmentBuffer:offset:atIndex:` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectRenderCommand.setVertexBuffer:offset:attributeStride:atIndex:` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectRenderCommand.drawPatches:patchStart:patchCount:patchIndexBuffer:patchIndexBufferOffset:instanceCount:baseInstance:tessellationFactorBuffer:tessellationFactorBufferOffset:tessellationFactorBufferInstanceStride:` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectRenderCommand.drawIndexedPatches:patchStart:patchCount:patchIndexBuffer:patchIndexBufferOffset:controlPointIndexBuffer:controlPointIndexBufferOffset:instanceCount:baseInstance:tessellationFactorBuffer:tessellationFactorBufferOffset:tessellationFactorBufferInstanceStride:` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectRenderCommand.drawPrimitives:vertexStart:vertexCount:instanceCount:baseInstance:` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectRenderCommand.drawIndexedPrimitives:indexCount:indexType:indexBuffer:indexBufferOffset:instanceCount:baseVertex:baseInstance:` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectRenderCommand.setObjectThreadgroupMemoryLength:atIndex:` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectRenderCommand.setObjectBuffer:offset:atIndex:` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectRenderCommand.setMeshBuffer:offset:atIndex:` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectRenderCommand.drawMeshThreadgroups:threadsPerObjectThreadgroup:threadsPerMeshThreadgroup:` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectRenderCommand.drawMeshThreads:threadsPerObjectThreadgroup:threadsPerMeshThreadgroup:` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectRenderCommand.setBarrier` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectRenderCommand.clearBarrier` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectRenderCommand.setDepthStencilState:` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectRenderCommand.setDepthBias:slopeScale:clamp:` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectRenderCommand.setDepthClipMode:` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectRenderCommand.setCullMode:` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectRenderCommand.setFrontFacingWinding:` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectRenderCommand.setTriangleFillMode:` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectRenderCommand.reset` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectComputeCommand` | protocol | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectComputeCommand.setComputePipelineState:` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectComputeCommand.setKernelBuffer:offset:atIndex:` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectComputeCommand.setKernelBuffer:offset:attributeStride:atIndex:` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectComputeCommand.concurrentDispatchThreadgroups:threadsPerThreadgroup:` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectComputeCommand.concurrentDispatchThreads:threadsPerThreadgroup:` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectComputeCommand.setBarrier` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectComputeCommand.clearBarrier` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectComputeCommand.setImageblockWidth:height:` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectComputeCommand.reset` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectComputeCommand.setThreadgroupMemoryLength:atIndex:` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLIndirectComputeCommand.setStageInRegion:` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectRenderCommand` | protocol | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectRenderCommand.setRenderPipelineState:` | method | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectRenderCommand.setVertexBuffer:offset:atIndex:` | method | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectRenderCommand.setFragmentBuffer:offset:atIndex:` | method | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectRenderCommand.setVertexBuffer:offset:attributeStride:atIndex:` | method | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectRenderCommand.drawPatches:patchStart:patchCount:patchIndexBuffer:patchIndexBufferOffset:instanceCount:baseInstance:tessellationFactorBuffer:tessellationFactorBufferOffset:tessellationFactorBufferInstanceStride:` | method | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectRenderCommand.drawIndexedPatches:patchStart:patchCount:patchIndexBuffer:patchIndexBufferOffset:controlPointIndexBuffer:controlPointIndexBufferOffset:instanceCount:baseInstance:tessellationFactorBuffer:tessellationFactorBufferOffset:tessellationFactorBufferInstanceStride:` | method | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectRenderCommand.drawPrimitives:vertexStart:vertexCount:instanceCount:baseInstance:` | method | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectRenderCommand.drawIndexedPrimitives:indexCount:indexType:indexBuffer:indexBufferOffset:instanceCount:baseVertex:baseInstance:` | method | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectRenderCommand.setObjectThreadgroupMemoryLength:atIndex:` | method | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectRenderCommand.setObjectBuffer:offset:atIndex:` | method | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectRenderCommand.setMeshBuffer:offset:atIndex:` | method | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectRenderCommand.drawMeshThreadgroups:threadsPerObjectThreadgroup:threadsPerMeshThreadgroup:` | method | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectRenderCommand.drawMeshThreads:threadsPerObjectThreadgroup:threadsPerMeshThreadgroup:` | method | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectRenderCommand.setBarrier` | method | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectRenderCommand.clearBarrier` | method | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectRenderCommand.setDepthStencilState:` | method | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectRenderCommand.setDepthBias:slopeScale:clamp:` | method | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectRenderCommand.setDepthClipMode:` | method | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectRenderCommand.setCullMode:` | method | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectRenderCommand.setFrontFacingWinding:` | method | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectRenderCommand.setTriangleFillMode:` | method | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectRenderCommand.reset` | method | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectComputeCommand` | protocol | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectComputeCommand.setComputePipelineState:` | method | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectComputeCommand.setKernelBuffer:offset:atIndex:` | method | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectComputeCommand.setKernelBuffer:offset:attributeStride:atIndex:` | method | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectComputeCommand.concurrentDispatchThreadgroups:threadsPerThreadgroup:` | method | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectComputeCommand.concurrentDispatchThreads:threadsPerThreadgroup:` | method | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectComputeCommand.setBarrier` | method | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectComputeCommand.clearBarrier` | method | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectComputeCommand.setImageblockWidth:height:` | method | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectComputeCommand.reset` | method | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectComputeCommand.setThreadgroupMemoryLength:atIndex:` | method | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | +| `MTLIndirectComputeCommand.setStageInRegion:` | method | missing | L: indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) | ### MTLIntersectionFunctionTable.h @@ -2126,12 +2126,12 @@ Cheap items a plain app calls first, then medium pieces by how often a plain app | `MTLRenderCommandEncoder.useResources:count:usage:` (deprecated) | method | implemented | `RenderCommandEncoder::use_resource` (runtime): a loop of it | | `MTLRenderCommandEncoder.useResource:usage:stages:` | method | implemented | `RenderCommandEncoder::use_resource` (runtime): the stages are not read | | `MTLRenderCommandEncoder.useResources:count:usage:stages:` | method | implemented | `RenderCommandEncoder::use_resource` (runtime): a loop of it; the stages are not read | -| `MTLRenderCommandEncoder.useHeap:` (deprecated) | method | missing | S: as the compute encoder's `ComputeCommandEncoder::use_resource` and `use_heap` | -| `MTLRenderCommandEncoder.useHeaps:count:` (deprecated) | method | missing | S: as the compute encoder's `ComputeCommandEncoder::use_resource` and `use_heap` | -| `MTLRenderCommandEncoder.useHeap:stages:` | method | missing | S: as the compute encoder's `ComputeCommandEncoder::use_resource` and `use_heap` | -| `MTLRenderCommandEncoder.useHeaps:count:stages:` | method | missing | S: as the compute encoder's `ComputeCommandEncoder::use_resource` and `use_heap` | -| `MTLRenderCommandEncoder.executeCommandsInBuffer:withRange:` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | -| `MTLRenderCommandEncoder.executeCommandsInBuffer:indirectBuffer:indirectBufferOffset:` | method | missing | L: indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) | +| `MTLRenderCommandEncoder.useHeap:` (deprecated) | method | implemented | `RenderCommandEncoder::use_heap` (runtime) | +| `MTLRenderCommandEncoder.useHeaps:count:` (deprecated) | method | implemented | `RenderCommandEncoder::use_heap` (runtime): a loop of it | +| `MTLRenderCommandEncoder.useHeap:stages:` | method | implemented | `RenderCommandEncoder::use_heap` (runtime): the stages are not read | +| `MTLRenderCommandEncoder.useHeaps:count:stages:` | method | implemented | `RenderCommandEncoder::use_heap` (runtime): a loop of it | +| `MTLRenderCommandEncoder.executeCommandsInBuffer:withRange:` | method | implemented | `RenderCommandEncoder::execute_commands_in_buffer` (runtime) | +| `MTLRenderCommandEncoder.executeCommandsInBuffer:indirectBuffer:indirectBufferOffset:` | method | implemented | `RenderCommandEncoder::execute_commands_in_buffer_with_range` (runtime) | | `MTLRenderCommandEncoder.memoryBarrierWithScope:afterStages:beforeStages:` | method | implemented | `RenderCommandEncoder::memory_barrier` (runtime): one global memory barrier | | `MTLRenderCommandEncoder.memoryBarrierWithResources:count:afterStages:beforeStages:` | method | implemented | `RenderCommandEncoder::memory_barrier` (runtime): one global memory barrier | | `MTLRenderCommandEncoder.sampleCountersInBuffer:atSampleIndex:withBarrier:` | method | missing | M: counter sample buffers | diff --git a/docs/REFUSALS.md b/docs/REFUSALS.md index 8d00bcb6c..13291ee7c 100644 --- a/docs/REFUSALS.md +++ b/docs/REFUSALS.md @@ -32,7 +32,7 @@ Columns: | Rate maps the compile layer does not compile | 5 | 5 | 0 | 0 | 4 | 1 | 0 | | The translation deadline | 1 | 1 | 0 | 0 | 0 | 1 | 0 | | Devices below the runtime's floor | 8 | 8 | 0 | 0 | 0 | 0 | 0 | -| The runtime's `Refusal` | 77 | 77 | 0 | 0 | 0 | 0 | 0 | +| The runtime's `Refusal` | 78 | 78 | 0 | 0 | 0 | 0 | 0 | | The runtime's `Limit` | 17 | 17 | 0 | 0 | 0 | 0 | 0 | | The runtime's `Gap` | 30 | 30 | 0 | 0 | 0 | 0 | 0 | @@ -46,7 +46,7 @@ Columns: | Rate maps the compile layer does not compile | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 5 | | The translation deadline | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | | Devices below the runtime's floor | 0 | 0 | 0 | 8 | 0 | 0 | 0 | 0 | -| The runtime's `Refusal` | 22 | 20 | 0 | 0 | 35 | 0 | 0 | 0 | +| The runtime's `Refusal` | 22 | 21 | 0 | 0 | 35 | 0 | 0 | 0 | | The runtime's `Limit` | 0 | 0 | 0 | 13 | 4 | 0 | 0 | 0 | | The runtime's `Gap` | 0 | 0 | 0 | 2 | 28 | 0 | 0 | 0 | @@ -272,10 +272,11 @@ Columns: | `Committed` | A call on a command buffer already committed | every device (a public call's own check of its arguments) | `metal-documented`: Metal's validation asserts "commit an already committed command buffer", "Completed handler provided after commit call" and "Scheduled handler provided after commit call" | 1: `crates/metal2vulkan-runtime/src/command.rs (open)` | `-` | | `InScheduledHandler` | A call a scheduled handler may not make (`CommandBuffer::add_scheduled_handler`) | every device (a public call's own check of its arguments) | `ours`: the consumer's scheduled handlers run on the submit thread, and the one consumer's make none of these calls; a guest's scheduled handler runs in the guest | 1: `crates/metal2vulkan-runtime/src/command.rs (not_in_scheduled_handler)` | `-` | | `WaitOnOwnThread` | A wait, in a handler or a listener, for what the runtime thread that runs it would have to do first, so it would never end | every device (a public call's own check of its arguments) | `ours`: no wait of the runtime's hangs by construction | 4: `crates/metal2vulkan-runtime/src/command.rs (wait_until_completed)`, `crates/metal2vulkan-runtime/src/command.rs (wait_until_scheduled)` (+2) | `-` | -| `OtherDevice` | An event, a buffer, a texture or a pipeline state of another device in an encode call (`CommandBuffer::encode_wait_for_event`,... | every device (a public call's own check of its arguments) | `ours`: an event's semaphore, a buffer's block, a texture's image, a pipeline and a block belong to the `VkDevice` that made them | 33: `crates/metal2vulkan-runtime/src/blit.rs (buffer_copy)`, `crates/metal2vulkan-runtime/src/blit.rs (copy_from_buffer_to_buffer)` (+28) | `-` | +| `OtherDevice` | An event, a buffer, a texture or a pipeline state of another device in an encode call (`CommandBuffer::encode_wait_for_event`,... | every device (a public call's own check of its arguments) | `ours`: an event's semaphore, a buffer's block, a texture's image, a pipeline and a block belong to the `VkDevice` that made them | 39: `crates/metal2vulkan-runtime/src/blit.rs (buffer_copy)`, `crates/metal2vulkan-runtime/src/blit.rs (copy_from_buffer_to_buffer)` (+32) | `-` | | `NoCommandBuffers` | A queue that may hold no command buffer (`Device::new_command_queue` with a count of 0) | every device (a public call's own check of its arguments) | `ours`: its first `commandBuffer` call would wait forever | 1: `crates/metal2vulkan-runtime/src/queue.rs (new_command_queue)` | `-` | | `EncoderOpen` | A second encoder, an encode call, or a commit or enqueue, while an encoder of the command buffer is open | every device (a public call's own check of its arguments) | `metal-documented`: a command buffer has one active encoder at a time, ended by `endEncoding` before another is made or the command buffer is committed | 1: `crates/metal2vulkan-runtime/src/command.rs (open)` | `-` | | `NoPipeline` | A dispatch or a draw with no pipeline state set | every device (a public call's own check of its arguments) | `metal-documented`: a compute dispatch needs a compute pipeline state set first, and a draw a render pipeline state | 3: `crates/metal2vulkan-runtime/src/encoder.rs (dispatch)`, `crates/metal2vulkan-runtime/src/render_encoder.rs (draw)` (+1) | `-` | +| `CommandRange` | A range of an indirect command buffer's commands past them, in an execution (`RenderCommandEncoder::execute_commands_in_buffer`), a reset or an... | every device (a public call's own check of its arguments) | `metal-documented`: each call names commands of the buffer, and the offset of a range a buffer holds must be a multiple of 4 bytes | 4: `crates/metal2vulkan-runtime/src/blit.rs (optimize_indirect_command_buffer)`, `crates/metal2vulkan-runtime/src/blit.rs (reset_commands_in_buffer)` (+2) | `-` | | `PatchDraw` | A draw of patches with a render pipeline state whose vertex function is not a post-tessellation one, or a draw of primitives with one whose vertex... | every device (a public call's own check of its arguments) | `metal-measured`: an M4: plain Metal stops its process over a patch draw with a pipeline that is not a tessellation one, its validation off; Metal's validation stops a draw of primitives with a tessellation pipeline | 1: `crates/metal2vulkan-runtime/src/render_encoder.rs (draw)` | `-` | | `NoTessellationFactorBuffer` | A draw of patches while the encoder has no tessellation factor buffer (`setTessellationFactorBuffer:offset:instanceStride:`) | every device (a public call's own check of its arguments) | `metal-measured`: an Apple M3 Max, macOS 27.0.1: plain Metal ends the process, SIGSEGV, at a quad patch draw with no tessellation factor buffer, where the same draw with one set runs and paints the target, the API validation layer off | 1: `crates/metal2vulkan-runtime/src/render_encoder.rs (draw)` | `-` | | `PointSizeTopology` | `Device::new_render_pipeline_state` of a vertex function that writes `[[point_size]]` under the line or the triangle input primitive topology... | every device (a public call's own check of its arguments) | `metal-measured`: an Apple M3 Max, macOS 27.0.1, every class crossed with both shapes of vertex function: Metal's pipeline creation fails with `Vertex shader writes point size but inputPrimitiveTopology is MTLPrimitiveTopologyClassLine`, and its `Triangle` counterpart; the conformance crate's `topology-class-point-size-function` compares it | 1: `crates/metal2vulkan-runtime/src/render.rs (of)` | `-` | @@ -360,7 +361,7 @@ Columns: | Variant | What it blocks | Where | Basis | Sites | Reach | |---|---|---|---|---|---| -| `IndirectCommandBuffers` | A compute pipeline state for indirect command buffers (`supportIndirectCommandBuffers`) | every device (a public call's own check of its arguments) | `ours`: indirect command buffers are not built | 2: `crates/metal2vulkan-runtime/src/pipeline.rs (compute_pipeline_state)`, `crates/metal2vulkan-runtime/src/render.rs (refuse)` | `-` | +| `IndirectCommandBuffers` | An indirect command buffer, its execution, or a compute pipeline state for one, of what the runtime does not build, `kind` naming it | every device (a public call's own check of its arguments) | `ours`: the first cut of indirect command buffers builds that alone | 4: `crates/metal2vulkan-runtime/src/indirect.rs (new_indirect_command_buffer)`, `crates/metal2vulkan-runtime/src/indirect.rs (shape)` (+2) | `-` | | `KernelInput` | A kernel that reads something the compute encoder does not supply yet, `kind` naming what | every device (a public call's own check of its arguments) | `ours`: the encoder supplies only those | 1: `crates/metal2vulkan-runtime/src/pipeline.rs (gap)` | `-` | | `ImageblockLength` | An imageblock length Metal answers that no case measures | every device (a public call's own check of its arguments) | `ours`: the length is not measured against Metal's | 2: `crates/metal2vulkan-runtime/src/pipeline.rs (imageblock_memory_length_for_dimensions)`, `crates/metal2vulkan-runtime/src/render.rs (imageblock_sample_length)` | `-` | | `PartialSimdgroups` | A dispatch whose threadgroup is not whole SIMD groups of a kernel whose tier runs each SIMD group as one subgroup of `width` threads (a pinned... | every device (a public call's own check of its arguments) | `ours`: no emulated-SIMD-group module | 1: `crates/metal2vulkan-runtime/src/encoder.rs (decide)` | `-` | @@ -568,10 +569,11 @@ Each refusal's sites, with the function that builds it. - `rt:Refusal::Committed`: `crates/metal2vulkan-runtime/src/command.rs (open)` - `rt:Refusal::InScheduledHandler`: `crates/metal2vulkan-runtime/src/command.rs (not_in_scheduled_handler)` - `rt:Refusal::WaitOnOwnThread`: `crates/metal2vulkan-runtime/src/command.rs (wait_until_completed)`; `crates/metal2vulkan-runtime/src/command.rs (wait_until_scheduled)`; `crates/metal2vulkan-runtime/src/event.rs (wait_until_signaled_value)`; `crates/metal2vulkan-runtime/src/queue.rs (command_buffer)` -- `rt:Refusal::OtherDevice`: `crates/metal2vulkan-runtime/src/blit.rs (buffer_copy)`; `crates/metal2vulkan-runtime/src/blit.rs (copy_from_buffer_to_buffer)`; `crates/metal2vulkan-runtime/src/blit.rs (copy_from_texture)`; `crates/metal2vulkan-runtime/src/blit.rs (fill_buffer)`; `crates/metal2vulkan-runtime/src/blit.rs (generate_mipmaps)`; `crates/metal2vulkan-runtime/src/blit.rs (release_surface_to_external)`; `crates/metal2vulkan-runtime/src/blit.rs (release_to_external)`; `crates/metal2vulkan-runtime/src/blit.rs (synchronize_resource)`; `crates/metal2vulkan-runtime/src/command.rs (check)`; `crates/metal2vulkan-runtime/src/command.rs (present_drawable)`; `crates/metal2vulkan-runtime/src/device.rs (release_block)`; `crates/metal2vulkan-runtime/src/encoder.rs (dispatch_threadgroups_with_indirect_buffer)`; `crates/metal2vulkan-runtime/src/encoder.rs (set_buffer)`; `crates/metal2vulkan-runtime/src/encoder.rs (set_compute_pipeline_state)`; `crates/metal2vulkan-runtime/src/encoder.rs (set_sampler_state)`; `crates/metal2vulkan-runtime/src/encoder.rs (set_texture)`; `crates/metal2vulkan-runtime/src/encoder.rs (use_resource, 2 sites)`; `crates/metal2vulkan-runtime/src/fence.rs (check)`; `crates/metal2vulkan-runtime/src/pass.rs (check, 2 sites)`; `crates/metal2vulkan-runtime/src/pass.rs (resolve)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (draw)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (indirect)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (set_buffer)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (set_depth_stencil_state)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (set_render_pipeline_state)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (set_sampler_state)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (set_tessellation_factor_buffer)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (set_texture)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (use_resource, 2 sites)`; `crates/metal2vulkan-runtime/src/texture.rs (new_managed_texture)` +- `rt:Refusal::OtherDevice`: `crates/metal2vulkan-runtime/src/blit.rs (buffer_copy)`; `crates/metal2vulkan-runtime/src/blit.rs (copy_from_buffer_to_buffer)`; `crates/metal2vulkan-runtime/src/blit.rs (copy_from_texture)`; `crates/metal2vulkan-runtime/src/blit.rs (fill_buffer)`; `crates/metal2vulkan-runtime/src/blit.rs (generate_mipmaps)`; `crates/metal2vulkan-runtime/src/blit.rs (optimize_indirect_command_buffer)`; `crates/metal2vulkan-runtime/src/blit.rs (release_surface_to_external)`; `crates/metal2vulkan-runtime/src/blit.rs (release_to_external)`; `crates/metal2vulkan-runtime/src/blit.rs (reset_commands_in_buffer)`; `crates/metal2vulkan-runtime/src/blit.rs (synchronize_resource)`; `crates/metal2vulkan-runtime/src/command.rs (check)`; `crates/metal2vulkan-runtime/src/command.rs (present_drawable)`; `crates/metal2vulkan-runtime/src/device.rs (release_block)`; `crates/metal2vulkan-runtime/src/encoder.rs (dispatch_threadgroups_with_indirect_buffer)`; `crates/metal2vulkan-runtime/src/encoder.rs (set_buffer)`; `crates/metal2vulkan-runtime/src/encoder.rs (set_compute_pipeline_state)`; `crates/metal2vulkan-runtime/src/encoder.rs (set_sampler_state)`; `crates/metal2vulkan-runtime/src/encoder.rs (set_texture)`; `crates/metal2vulkan-runtime/src/encoder.rs (use_resource, 3 sites)`; `crates/metal2vulkan-runtime/src/fence.rs (check)`; `crates/metal2vulkan-runtime/src/pass.rs (check, 2 sites)`; `crates/metal2vulkan-runtime/src/pass.rs (resolve)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (draw)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (execute_commands_in_buffer)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (execute_commands_in_buffer_with_range)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (indirect)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (set_buffer)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (set_depth_stencil_state)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (set_render_pipeline_state)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (set_sampler_state)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (set_tessellation_factor_buffer)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (set_texture)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (use_resource, 3 sites)`; `crates/metal2vulkan-runtime/src/texture.rs (new_managed_texture)` - `rt:Refusal::NoCommandBuffers`: `crates/metal2vulkan-runtime/src/queue.rs (new_command_queue)` - `rt:Refusal::EncoderOpen`: `crates/metal2vulkan-runtime/src/command.rs (open)` - `rt:Refusal::NoPipeline`: `crates/metal2vulkan-runtime/src/encoder.rs (dispatch)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (draw)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (draw_reaches)` +- `rt:Refusal::CommandRange`: `crates/metal2vulkan-runtime/src/blit.rs (optimize_indirect_command_buffer)`; `crates/metal2vulkan-runtime/src/blit.rs (reset_commands_in_buffer)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (execute_commands_in_buffer)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (execute_commands_in_buffer_with_range)` - `rt:Refusal::PatchDraw`: `crates/metal2vulkan-runtime/src/render_encoder.rs (draw)` - `rt:Refusal::NoTessellationFactorBuffer`: `crates/metal2vulkan-runtime/src/render_encoder.rs (draw)` - `rt:Refusal::PointSizeTopology`: `crates/metal2vulkan-runtime/src/render.rs (of)` @@ -646,7 +648,7 @@ Each refusal's sites, with the function that builds it. - `rt:Limit::NoExport`: `crates/metal2vulkan-runtime/src/export.rs (handle, 2 sites)`; `crates/metal2vulkan-runtime/src/export.rs (new_exported_block)`; `crates/metal2vulkan-runtime/src/surface.rs (dma_buf_in_place)`; `crates/metal2vulkan-runtime/src/surface.rs (new_exported_surface)` - `rt:Limit::ExportType`: `crates/metal2vulkan-runtime/src/export.rs (new_exported_block)`; `crates/metal2vulkan-runtime/src/import.rs (surface_import)`; `crates/metal2vulkan-runtime/src/memory.rs (export)`; `crates/metal2vulkan-runtime/src/memory.rs (surface_view)`; `crates/metal2vulkan-runtime/src/surface.rs (dma_buf_in_place)`; `crates/metal2vulkan-runtime/src/surface.rs (new_exported_surface)` - `rt:Limit::TextureSamples`: `crates/metal2vulkan-runtime/src/texture.rs (plan)` -- `rt:Gap::IndirectCommandBuffers`: `crates/metal2vulkan-runtime/src/pipeline.rs (compute_pipeline_state)`; `crates/metal2vulkan-runtime/src/render.rs (refuse)` +- `rt:Gap::IndirectCommandBuffers`: `crates/metal2vulkan-runtime/src/indirect.rs (new_indirect_command_buffer)`; `crates/metal2vulkan-runtime/src/indirect.rs (shape)`; `crates/metal2vulkan-runtime/src/pipeline.rs (compute_pipeline_state)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (draw)` - `rt:Gap::KernelInput`: `crates/metal2vulkan-runtime/src/pipeline.rs (gap)` - `rt:Gap::ImageblockLength`: `crates/metal2vulkan-runtime/src/pipeline.rs (imageblock_memory_length_for_dimensions)`; `crates/metal2vulkan-runtime/src/render.rs (imageblock_sample_length)` - `rt:Gap::PartialSimdgroups`: `crates/metal2vulkan-runtime/src/encoder.rs (decide)` diff --git a/scripts/metal-coverage/coverage.tsv b/scripts/metal-coverage/coverage.tsv index 38b8c8acc..ecd4feccb 100644 --- a/scripts/metal-coverage/coverage.tsv +++ b/scripts/metal-coverage/coverage.tsv @@ -743,8 +743,8 @@ MTLArgumentEncoder.h MTLArgumentEncoder method setRenderPipelineState:atIndex: MTLArgumentEncoder.h MTLArgumentEncoder method setRenderPipelineStates:withRange: M argument encoders M argument-encoders MTLArgumentEncoder.h MTLArgumentEncoder method setComputePipelineState:atIndex: M argument encoders M argument-encoders MTLArgumentEncoder.h MTLArgumentEncoder method setComputePipelineStates:withRange: M argument encoders M argument-encoders -MTLArgumentEncoder.h MTLArgumentEncoder method setIndirectCommandBuffer:atIndex: M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLArgumentEncoder.h MTLArgumentEncoder method setIndirectCommandBuffers:withRange: M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb +MTLArgumentEncoder.h MTLArgumentEncoder method setIndirectCommandBuffer:atIndex: M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLArgumentEncoder.h MTLArgumentEncoder method setIndirectCommandBuffers:withRange: M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb MTLArgumentEncoder.h MTLArgumentEncoder method setAccelerationStructure:atIndex: O ray tracing MTLArgumentEncoder.h MTLArgumentEncoder method newArgumentEncoderForBufferAtIndex: M argument encoders M argument-encoders MTLArgumentEncoder.h MTLArgumentEncoder method setVisibleFunctionTable:atIndex: M argument encoders M argument-encoders @@ -786,9 +786,9 @@ MTLBlitCommandEncoder.h MTLBlitCommandEncoder method optimizeContentsForGPUAcces MTLBlitCommandEncoder.h MTLBlitCommandEncoder method optimizeContentsForGPUAccess:slice:level: M an encoder call metal2vulkan-runtime does not build S encoder-calls MTLBlitCommandEncoder.h MTLBlitCommandEncoder method optimizeContentsForCPUAccess: M an encoder call metal2vulkan-runtime does not build S encoder-calls MTLBlitCommandEncoder.h MTLBlitCommandEncoder method optimizeContentsForCPUAccess:slice:level: M an encoder call metal2vulkan-runtime does not build S encoder-calls -MTLBlitCommandEncoder.h MTLBlitCommandEncoder method resetCommandsInBuffer:withRange: M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLBlitCommandEncoder.h MTLBlitCommandEncoder method copyIndirectCommandBuffer:sourceRange:destination:destinationIndex: M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLBlitCommandEncoder.h MTLBlitCommandEncoder method optimizeIndirectCommandBuffer:withRange: M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb +MTLBlitCommandEncoder.h MTLBlitCommandEncoder method resetCommandsInBuffer:withRange: I runtime BlitCommandEncoder::reset_commands_in_buffer +MTLBlitCommandEncoder.h MTLBlitCommandEncoder method copyIndirectCommandBuffer:sourceRange:destination:destinationIndex: M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLBlitCommandEncoder.h MTLBlitCommandEncoder method optimizeIndirectCommandBuffer:withRange: I runtime BlitCommandEncoder::optimize_indirect_command_buffer records nothing MTLBlitCommandEncoder.h MTLBlitCommandEncoder method sampleCountersInBuffer:atSampleIndex:withBarrier: M counter sample buffers M counters MTLBlitCommandEncoder.h MTLBlitCommandEncoder method resolveCounters:inRange:destinationBuffer:destinationOffset: M counter sample buffers M counters MTLBlitCommandEncoder.h MTLBlitCommandEncoder method copyFromTensor:sourceOrigin:sourceDimensions:toTensor:destinationOrigin:destinationDimensions: M tensors L tensor @@ -944,8 +944,8 @@ MTLComputeCommandEncoder.h MTLComputeCommandEncoder method useResource:usage: I MTLComputeCommandEncoder.h MTLComputeCommandEncoder method useResources:count:usage: I runtime ComputeCommandEncoder::use_resource a loop of it MTLComputeCommandEncoder.h MTLComputeCommandEncoder method useHeap: I runtime ComputeCommandEncoder::use_heap MTLComputeCommandEncoder.h MTLComputeCommandEncoder method useHeaps:count: I runtime ComputeCommandEncoder::use_heap a loop of it -MTLComputeCommandEncoder.h MTLComputeCommandEncoder method executeCommandsInBuffer:withRange: M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLComputeCommandEncoder.h MTLComputeCommandEncoder method executeCommandsInBuffer:indirectBuffer:indirectBufferOffset: M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb +MTLComputeCommandEncoder.h MTLComputeCommandEncoder method executeCommandsInBuffer:withRange: M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLComputeCommandEncoder.h MTLComputeCommandEncoder method executeCommandsInBuffer:indirectBuffer:indirectBufferOffset: M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb MTLComputeCommandEncoder.h MTLComputeCommandEncoder method memoryBarrierWithScope: I runtime ComputeCommandEncoder::memory_barrier one global memory barrier MTLComputeCommandEncoder.h MTLComputeCommandEncoder method memoryBarrierWithResources:count: I runtime ComputeCommandEncoder::memory_barrier one global memory barrier MTLComputeCommandEncoder.h MTLComputeCommandEncoder method sampleCountersInBuffer:atSampleIndex:withBarrier: M counter sample buffers M counters @@ -1123,7 +1123,7 @@ MTLDevice.h MTLDevice method getDefaultSamplePositions:count: M the standard MTLDevice.h MTLDevice method newArgumentEncoderWithArguments: M argument encoders M argument-encoders MTLDevice.h MTLDevice method supportsRasterizationRateMapWithLayerCount: M rasterization rate maps; the render pass descriptor has no field for one L rasterization MTLDevice.h MTLDevice method newRasterizationRateMapWithDescriptor: M rasterization rate maps; the render pass descriptor has no field for one L rasterization -MTLDevice.h MTLDevice method newIndirectCommandBufferWithDescriptor:maxCommandCount:options: M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb +MTLDevice.h MTLDevice method newIndirectCommandBufferWithDescriptor:maxCommandCount:options: I runtime Device::new_indirect_command_buffer indexed triangle draws with an inherited pipeline state MTLDevice.h MTLDevice method newEvent I runtime Device::new_event MTLDevice.h MTLDevice method newSharedEvent I runtime Device::new_shared_event MTLDevice.h MTLDevice method newSharedEventWithHandle: M texture and event handles shared across processes M sharing @@ -1343,68 +1343,68 @@ MTLIOCompressor.h function MTLIOCompressionContextDefaultChunkSize M fast re MTLIOCompressor.h function MTLIOCreateCompressionContext M fast resource loading (`MTLIOCommandQueue`) L io MTLIOCompressor.h function MTLIOCompressionContextAppendData M fast resource loading (`MTLIOCommandQueue`) L io MTLIOCompressor.h function MTLIOFlushAndDestroyCompressionContext M fast resource loading (`MTLIOCommandQueue`) L io -MTLIndirectCommandBuffer.h MTLIndirectCommandBufferDescriptor class MTLIndirectCommandBufferDescriptor M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandBuffer.h MTLIndirectCommandBufferDescriptor property commandTypes M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandBuffer.h MTLIndirectCommandBufferDescriptor property inheritPipelineState M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandBuffer.h MTLIndirectCommandBufferDescriptor property inheritBuffers M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandBuffer.h MTLIndirectCommandBufferDescriptor property inheritDepthStencilState M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandBuffer.h MTLIndirectCommandBufferDescriptor property inheritDepthBias M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandBuffer.h MTLIndirectCommandBufferDescriptor property inheritDepthClipMode M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandBuffer.h MTLIndirectCommandBufferDescriptor property inheritCullMode M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandBuffer.h MTLIndirectCommandBufferDescriptor property inheritFrontFacingWinding M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandBuffer.h MTLIndirectCommandBufferDescriptor property inheritTriangleFillMode M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandBuffer.h MTLIndirectCommandBufferDescriptor property maxVertexBufferBindCount M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandBuffer.h MTLIndirectCommandBufferDescriptor property maxFragmentBufferBindCount M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandBuffer.h MTLIndirectCommandBufferDescriptor property maxKernelBufferBindCount M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandBuffer.h MTLIndirectCommandBufferDescriptor property maxKernelThreadgroupMemoryBindCount M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandBuffer.h MTLIndirectCommandBufferDescriptor property maxObjectBufferBindCount M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandBuffer.h MTLIndirectCommandBufferDescriptor property maxMeshBufferBindCount M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandBuffer.h MTLIndirectCommandBufferDescriptor property maxObjectThreadgroupMemoryBindCount M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandBuffer.h MTLIndirectCommandBufferDescriptor class MTLIndirectCommandBufferDescriptor I runtime IndirectCommandBufferDescriptor +MTLIndirectCommandBuffer.h MTLIndirectCommandBufferDescriptor property commandTypes I runtime IndirectCommandBufferDescriptor.command_types +MTLIndirectCommandBuffer.h MTLIndirectCommandBufferDescriptor property inheritPipelineState I runtime IndirectCommandBufferDescriptor.inherit_pipeline_state true alone +MTLIndirectCommandBuffer.h MTLIndirectCommandBufferDescriptor property inheritBuffers I runtime IndirectCommandBufferDescriptor.inherit_buffers false alone +MTLIndirectCommandBuffer.h MTLIndirectCommandBufferDescriptor property inheritDepthStencilState M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandBuffer.h MTLIndirectCommandBufferDescriptor property inheritDepthBias M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandBuffer.h MTLIndirectCommandBufferDescriptor property inheritDepthClipMode M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandBuffer.h MTLIndirectCommandBufferDescriptor property inheritCullMode M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandBuffer.h MTLIndirectCommandBufferDescriptor property inheritFrontFacingWinding M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandBuffer.h MTLIndirectCommandBufferDescriptor property inheritTriangleFillMode M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandBuffer.h MTLIndirectCommandBufferDescriptor property maxVertexBufferBindCount I runtime IndirectCommandBufferDescriptor.max_vertex_buffer_bind_count +MTLIndirectCommandBuffer.h MTLIndirectCommandBufferDescriptor property maxFragmentBufferBindCount I runtime IndirectCommandBufferDescriptor.max_fragment_buffer_bind_count +MTLIndirectCommandBuffer.h MTLIndirectCommandBufferDescriptor property maxKernelBufferBindCount I runtime IndirectCommandBufferDescriptor.max_kernel_buffer_bind_count read by no render command +MTLIndirectCommandBuffer.h MTLIndirectCommandBufferDescriptor property maxKernelThreadgroupMemoryBindCount M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandBuffer.h MTLIndirectCommandBufferDescriptor property maxObjectBufferBindCount M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandBuffer.h MTLIndirectCommandBufferDescriptor property maxMeshBufferBindCount M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandBuffer.h MTLIndirectCommandBufferDescriptor property maxObjectThreadgroupMemoryBindCount M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb MTLIndirectCommandBuffer.h MTLIndirectCommandBufferDescriptor property supportRayTracing O ray tracing -MTLIndirectCommandBuffer.h MTLIndirectCommandBufferDescriptor property supportDynamicAttributeStride M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandBuffer.h MTLIndirectCommandBufferDescriptor property supportColorAttachmentMapping M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandBuffer.h MTLIndirectCommandBuffer protocol MTLIndirectCommandBuffer M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandBuffer.h MTLIndirectCommandBuffer property size M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandBuffer.h MTLIndirectCommandBuffer property gpuResourceID M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandBuffer.h MTLIndirectCommandBuffer method resetWithRange: M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandBuffer.h MTLIndirectCommandBuffer method indirectRenderCommandAtIndex: M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandBuffer.h MTLIndirectCommandBuffer method indirectComputeCommandAtIndex: M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandBuffer.h function MTLIndirectCommandBufferExecutionRangeMake M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandEncoder.h MTLIndirectRenderCommand protocol MTLIndirectRenderCommand M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method setRenderPipelineState: M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method setVertexBuffer:offset:atIndex: M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method setFragmentBuffer:offset:atIndex: M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method setVertexBuffer:offset:attributeStride:atIndex: M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method drawPatches:patchStart:patchCount:patchIndexBuffer:patchIndexBufferOffset:instanceCount:baseInstance:tessellationFactorBuffer:tessellationFactorBufferOffset:tessellationFactorBufferInstanceStride: M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method drawIndexedPatches:patchStart:patchCount:patchIndexBuffer:patchIndexBufferOffset:controlPointIndexBuffer:controlPointIndexBufferOffset:instanceCount:baseInstance:tessellationFactorBuffer:tessellationFactorBufferOffset:tessellationFactorBufferInstanceStride: M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method drawPrimitives:vertexStart:vertexCount:instanceCount:baseInstance: M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method drawIndexedPrimitives:indexCount:indexType:indexBuffer:indexBufferOffset:instanceCount:baseVertex:baseInstance: M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method setObjectThreadgroupMemoryLength:atIndex: M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method setObjectBuffer:offset:atIndex: M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method setMeshBuffer:offset:atIndex: M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method drawMeshThreadgroups:threadsPerObjectThreadgroup:threadsPerMeshThreadgroup: M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method drawMeshThreads:threadsPerObjectThreadgroup:threadsPerMeshThreadgroup: M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method setBarrier M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method clearBarrier M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method setDepthStencilState: M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method setDepthBias:slopeScale:clamp: M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method setDepthClipMode: M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method setCullMode: M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method setFrontFacingWinding: M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method setTriangleFillMode: M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method reset M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandEncoder.h MTLIndirectComputeCommand protocol MTLIndirectComputeCommand M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandEncoder.h MTLIndirectComputeCommand method setComputePipelineState: M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandEncoder.h MTLIndirectComputeCommand method setKernelBuffer:offset:atIndex: M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandEncoder.h MTLIndirectComputeCommand method setKernelBuffer:offset:attributeStride:atIndex: M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandEncoder.h MTLIndirectComputeCommand method concurrentDispatchThreadgroups:threadsPerThreadgroup: M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandEncoder.h MTLIndirectComputeCommand method concurrentDispatchThreads:threadsPerThreadgroup: M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandEncoder.h MTLIndirectComputeCommand method setBarrier M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandEncoder.h MTLIndirectComputeCommand method clearBarrier M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandEncoder.h MTLIndirectComputeCommand method setImageblockWidth:height: M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandEncoder.h MTLIndirectComputeCommand method reset M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandEncoder.h MTLIndirectComputeCommand method setThreadgroupMemoryLength:atIndex: M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLIndirectCommandEncoder.h MTLIndirectComputeCommand method setStageInRegion: M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandBuffer.h MTLIndirectCommandBufferDescriptor property supportDynamicAttributeStride M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandBuffer.h MTLIndirectCommandBufferDescriptor property supportColorAttachmentMapping M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandBuffer.h MTLIndirectCommandBuffer protocol MTLIndirectCommandBuffer I runtime IndirectCommandBuffer +MTLIndirectCommandBuffer.h MTLIndirectCommandBuffer property size I runtime IndirectCommandBuffer::size +MTLIndirectCommandBuffer.h MTLIndirectCommandBuffer property gpuResourceID I runtime IndirectCommandBuffer::gpu_resource_id the records' device address +MTLIndirectCommandBuffer.h MTLIndirectCommandBuffer method resetWithRange: M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandBuffer.h MTLIndirectCommandBuffer method indirectRenderCommandAtIndex: M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandBuffer.h MTLIndirectCommandBuffer method indirectComputeCommandAtIndex: M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandBuffer.h function MTLIndirectCommandBufferExecutionRangeMake M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandEncoder.h MTLIndirectRenderCommand protocol MTLIndirectRenderCommand M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method setRenderPipelineState: M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method setVertexBuffer:offset:atIndex: M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method setFragmentBuffer:offset:atIndex: M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method setVertexBuffer:offset:attributeStride:atIndex: M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method drawPatches:patchStart:patchCount:patchIndexBuffer:patchIndexBufferOffset:instanceCount:baseInstance:tessellationFactorBuffer:tessellationFactorBufferOffset:tessellationFactorBufferInstanceStride: M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method drawIndexedPatches:patchStart:patchCount:patchIndexBuffer:patchIndexBufferOffset:controlPointIndexBuffer:controlPointIndexBufferOffset:instanceCount:baseInstance:tessellationFactorBuffer:tessellationFactorBufferOffset:tessellationFactorBufferInstanceStride: M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method drawPrimitives:vertexStart:vertexCount:instanceCount:baseInstance: M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method drawIndexedPrimitives:indexCount:indexType:indexBuffer:indexBufferOffset:instanceCount:baseVertex:baseInstance: M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method setObjectThreadgroupMemoryLength:atIndex: M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method setObjectBuffer:offset:atIndex: M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method setMeshBuffer:offset:atIndex: M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method drawMeshThreadgroups:threadsPerObjectThreadgroup:threadsPerMeshThreadgroup: M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method drawMeshThreads:threadsPerObjectThreadgroup:threadsPerMeshThreadgroup: M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method setBarrier M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method clearBarrier M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method setDepthStencilState: M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method setDepthBias:slopeScale:clamp: M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method setDepthClipMode: M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method setCullMode: M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method setFrontFacingWinding: M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method setTriangleFillMode: M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandEncoder.h MTLIndirectRenderCommand method reset M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandEncoder.h MTLIndirectComputeCommand protocol MTLIndirectComputeCommand M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandEncoder.h MTLIndirectComputeCommand method setComputePipelineState: M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandEncoder.h MTLIndirectComputeCommand method setKernelBuffer:offset:atIndex: M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandEncoder.h MTLIndirectComputeCommand method setKernelBuffer:offset:attributeStride:atIndex: M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandEncoder.h MTLIndirectComputeCommand method concurrentDispatchThreadgroups:threadsPerThreadgroup: M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandEncoder.h MTLIndirectComputeCommand method concurrentDispatchThreads:threadsPerThreadgroup: M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandEncoder.h MTLIndirectComputeCommand method setBarrier M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandEncoder.h MTLIndirectComputeCommand method clearBarrier M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandEncoder.h MTLIndirectComputeCommand method setImageblockWidth:height: M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandEncoder.h MTLIndirectComputeCommand method reset M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandEncoder.h MTLIndirectComputeCommand method setThreadgroupMemoryLength:atIndex: M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb +MTLIndirectCommandEncoder.h MTLIndirectComputeCommand method setStageInRegion: M indirect command buffers past GPU-encoded indexed triangle draws with an inherited pipeline state (`Gap::IndirectCommandBuffers`) L icb MTLIntersectionFunctionTable.h MTLIntersectionFunctionTableDescriptor class MTLIntersectionFunctionTableDescriptor O ray tracing MTLIntersectionFunctionTable.h MTLIntersectionFunctionTableDescriptor class method intersectionFunctionTableDescriptor O ray tracing MTLIntersectionFunctionTable.h MTLIntersectionFunctionTableDescriptor property functionCount O ray tracing @@ -1670,12 +1670,12 @@ MTLRenderCommandEncoder.h MTLRenderCommandEncoder method useResource:usage: yes MTLRenderCommandEncoder.h MTLRenderCommandEncoder method useResources:count:usage: yes I runtime RenderCommandEncoder::use_resource a loop of it MTLRenderCommandEncoder.h MTLRenderCommandEncoder method useResource:usage:stages: I runtime RenderCommandEncoder::use_resource the stages are not read MTLRenderCommandEncoder.h MTLRenderCommandEncoder method useResources:count:usage:stages: I runtime RenderCommandEncoder::use_resource a loop of it; the stages are not read -MTLRenderCommandEncoder.h MTLRenderCommandEncoder method useHeap: yes M as the compute encoder's `ComputeCommandEncoder::use_resource` and `use_heap` S encoder-calls -MTLRenderCommandEncoder.h MTLRenderCommandEncoder method useHeaps:count: yes M as the compute encoder's `ComputeCommandEncoder::use_resource` and `use_heap` S encoder-calls -MTLRenderCommandEncoder.h MTLRenderCommandEncoder method useHeap:stages: M as the compute encoder's `ComputeCommandEncoder::use_resource` and `use_heap` S encoder-calls -MTLRenderCommandEncoder.h MTLRenderCommandEncoder method useHeaps:count:stages: M as the compute encoder's `ComputeCommandEncoder::use_resource` and `use_heap` S encoder-calls -MTLRenderCommandEncoder.h MTLRenderCommandEncoder method executeCommandsInBuffer:withRange: M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb -MTLRenderCommandEncoder.h MTLRenderCommandEncoder method executeCommandsInBuffer:indirectBuffer:indirectBufferOffset: M indirect command buffers; a compute state that asks for them is refused (`Gap::IndirectCommandBuffers`) L icb +MTLRenderCommandEncoder.h MTLRenderCommandEncoder method useHeap: yes I runtime RenderCommandEncoder::use_heap +MTLRenderCommandEncoder.h MTLRenderCommandEncoder method useHeaps:count: yes I runtime RenderCommandEncoder::use_heap a loop of it +MTLRenderCommandEncoder.h MTLRenderCommandEncoder method useHeap:stages: I runtime RenderCommandEncoder::use_heap the stages are not read +MTLRenderCommandEncoder.h MTLRenderCommandEncoder method useHeaps:count:stages: I runtime RenderCommandEncoder::use_heap a loop of it +MTLRenderCommandEncoder.h MTLRenderCommandEncoder method executeCommandsInBuffer:withRange: I runtime RenderCommandEncoder::execute_commands_in_buffer +MTLRenderCommandEncoder.h MTLRenderCommandEncoder method executeCommandsInBuffer:indirectBuffer:indirectBufferOffset: I runtime RenderCommandEncoder::execute_commands_in_buffer_with_range MTLRenderCommandEncoder.h MTLRenderCommandEncoder method memoryBarrierWithScope:afterStages:beforeStages: I runtime RenderCommandEncoder::memory_barrier one global memory barrier MTLRenderCommandEncoder.h MTLRenderCommandEncoder method memoryBarrierWithResources:count:afterStages:beforeStages: I runtime RenderCommandEncoder::memory_barrier one global memory barrier MTLRenderCommandEncoder.h MTLRenderCommandEncoder method sampleCountersInBuffer:atSampleIndex:withBarrier: M counter sample buffers M counters