MTL4ComputeCommandEncoder
Encodes computation dispatches, resource copying commands, and acceleration structure building commands for a single pass into a command buffer.
Declaration
protocol MTL4ComputeCommandEncoder : MTL4CommandEncoderMentioned in
Overview
Each Metal 4 compute encoder combines compute dispatch commands, blit commands, and acceleration structure commands into a single pass. The unified nature of this encoder type eliminates the overhead from creating separate encoders like MTLComputeCommandEncoder, MTLBlitCommandEncoder, and MTLAccelerationStructureCommandEncoder, and then encoding separate passes with them.
Create a compute encoder by calling a factory method of an MTL4CommandBuffer instance, such as makeComputeCommandEncoder().
Command stages
Most compute commands apply to one stage within a pass. The following table shows which stage applies to each command:
The executeCommands(buffer:range:) and executeCommands(buffer:indirectBuffer:) commands don’t apply to any stage, which means you can’t use a barrier to wait for all commands in an indirect command buffer to complete. However, each command within the MTLIndirectCommandBuffer applies to the same stages as when you encode the equivalent command directly.
For more information about stages and synchronization, see MTLStages and Resource synchronization.
Topics
Configuring the pass
setComputePipelineState(_:)setArgumentTable(_:)setThreadgroupMemoryLength(_:index:)setImageblockSize(width:height:)
Inspecting the pass
Running dispatch commands
dispatchThreads(threadsPerGrid:threadsPerThreadgroup:)dispatchThreads(indirectBuffer:)dispatchThreadgroups(threadgroupsPerGrid:threadsPerThreadgroup:)dispatchThreadgroups(indirectBuffer:threadsPerThreadgroup:)
Encoding buffer copy commands
Encoding buffer-to-texture copy commands
Encoding texture copy commands
copy(sourceTensor:sourceOrigin:sourceDimensions:destinationTensor:destinationOrigin:destinationDimensions:)copy(sourceTexture:destinationTexture:)copy(sourceTexture:sourceSlice:sourceLevel:destinationTexture:destinationSlice:destinationLevel:sliceCount:levelCount:)copy(sourceTexture:sourceSlice:sourceLevel:sourceOrigin:sourceSize:destinationTexture:destinationSlice:destinationLevel:destinationOrigin:)
Encoding texture-to-buffer copy commands
Encoding indirect command buffer copy commands
Encoding buffer fill commands
Encoding mipmap generation commands
Encoding optimization commands
optimizeCommands(buffer:range:)optimizeContents(forCPUAccess:)optimizeContents(forCPUAccess:slice:level:)optimizeContents(forGPUAccess:)optimizeContents(forGPUAccess:slice:level:)
Encoding reset commands
Encoding acceleration structure build commands
Encoding acceleration structure copy commands
copy(sourceAccelerationStructure:destinationAccelerationStructure:)copyAndCompact(sourceAccelerationStructure:destinationAccelerationStructure:)writeCompactedSize(sourceAccelerationStructure:destinationBuffer:)