JFLib

gpu/mtl_cmd.rs (Apple)#

Source: lib/gpu/mtl_cmd.rs

mtl_cmd -- command recording on Metal (AP6, docs/APPLE.md): CommandEncoder -> CommandBuffer

An encoder records into one MTLCommandBuffer through Metal's encoders: copies and fills in a
blit encoder, dispatches in a compute encoder, a render pass in a render encoder; switching
kinds ends the current one.  barrier / texture_barrier end the current encoder too: Metal
orders encoders that touch the same (hazard-tracked) resources itself, and the layouts mean
nothing here.  Bind groups and push constants are remembered and set before the next dispatch
or draw, at the slots the pipeline's translation gave each (group, binding) of each stage
(shader::msl: buffers, textures, samplers; push constants at PUSH_SLOT, the bound buffer sizes
at SIZES_SLOT).  fill_buffer runs a small kernel of its own (a blit fill takes one byte).
The checks are those of the Vulkan backend (vk_cmd.rs); finish() returns the first misuse.
  • struct CommandEncoder<'a> records commands; finish() makes a CommandBuffer for Queue::submit

  • struct CommandBuffer<'a> recorded commands, ready to submit (dropped unsubmitted: discarded)

impl Device

  • fn encoder(&self) -> Result<CommandEncoder<'_>> a command encoder of the device's queue

impl<'a> CommandEncoder<'a>

  • fn copy_buffer(&mut self, src: &'a Buffer, src_off: u64, dst: &'a Buffer, dst_off: u64, size: u64)
  • fn fill_buffer(&mut self, buf: &'a Buffer, offset: u64, size: u64, value: u32) fill size bytes at offset with a 32-bit value (both multiples of 4)
  • fn copy_buffer_to_texture(&mut self, src: &'a Buffer, layout: DataLayout, dst: TextureRegion<'a>) buffer data -> a texture region
  • fn copy_texture_to_buffer(&mut self, src: TextureRegion<'a>, dst: &'a Buffer, layout: DataLayout) a texture region -> buffer data
  • fn barrier(&mut self, _before: Access, _after: Access) the accesses before finish before the after ones: the next command starts a new encoder
  • fn texture_barrier(&mut self, tex: &'a Texture, before: Layout, after: Layout)
  • fn texture_barrier_range(&mut self, tex: &'a Texture, base_mip: u32, mips: u32, base_layer: u32, layers: u32, _before: Layout, after: Layout)
  • fn set_compute_pipeline(&mut self, p: &'a ComputePipeline)
  • fn set_bind_group(&mut self, index: u32, group: &'a BindGroup) bind group g (= @group(g)) of the current pipeline's layout
  • fn push_constants<T: Pod>(&mut self, offset: u32, data: &[T]) push constants at offset (bytes) for the current pipeline
  • fn dispatch(&mut self, x: u32, y: u32, z: u32)
  • fn dispatch_indirect(&mut self, buf: &'a Buffer, offset: u64) workgroup counts (3 x u32) from buf at offset
  • fn begin_render(&mut self, desc: &RenderPassDesc<'_, 'a>)
  • fn end_render(&mut self)
  • fn set_render_pipeline(&mut self, p: &'a RenderPipeline)
  • fn set_viewport(&mut self, x: f32, y: f32, w: f32, h: f32, min_depth: f32, max_depth: f32) the viewport in pixels from the top left (depth range min ..= max)
  • fn set_scissor(&mut self, x: u32, y: u32, w: u32, h: u32)
  • fn set_vertex_buffer(&mut self, slot: u32, buf: &'a Buffer, offset: u64)
  • fn set_index_buffer(&mut self, buf: &'a Buffer, offset: u64, format: IndexFormat)
  • fn draw(&mut self, vertices: u32, instances: u32, first_vertex: u32, first_instance: u32)
  • fn draw_indexed(&mut self, indices: u32, instances: u32, first_index: u32, base_vertex: i32, first_instance: u32)
  • fn draw_indirect(&mut self, buf: &'a Buffer, offset: u64) one draw: vertex count, instance count, first vertex, first instance (4 x u32)
  • fn draw_indexed_indirect(&mut self, buf: &'a Buffer, offset: u64) one indexed draw: index count, instance count, first index, base vertex (i32), first instance
  • fn draw_indexed_indirect_multi(&mut self, buf: &'a Buffer, offset: u64, count: u32, stride: u32) count indexed draws, stride bytes apart (Features::multi_draw_indirect, level Voll): Metal has no multi-draw, so a loop of single indirect draws in this encoder; DrawIndex is each one's index
  • fn draw_indexed_indirect_count(&mut self, buf: &'a Buffer, offset: u64, count_buf: &'a Buffer, count_offset: u64, max_count: u32, stride: u32) up to max_count indexed draws, their number (u32) read from count_buf at count_offset (level Voll: Features::draw_indirect_count). Metal has no such draw: the pass is suspended for a compute pass that copies the max_count draws and sets the instances of those at and after the count to 0, then goes on (everything stored and loaded again, the state set again) and draws all max_count of them (docs/APPLE.md AP6g)
  • fn reset_timestamps(&mut self, _ts: &'a Timestamps, _first: u32, _n: u32)
  • fn timestamp(&mut self, _ts: &'a Timestamps, _i: u32)
  • fn finish(mut self) -> Result<CommandBuffer<'a>> the recorded commands, or the first misuse

Source: docs/API.md in the JFLib repository.