Contents

MTL4ComputeCommandEncoder

Encodes computation dispatches, resource copying commands, and acceleration structure building commands for a single pass into a command buffer.

Declaration

protocol MTL4ComputeCommandEncoder : MTL4CommandEncoder

Mentioned 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:

Function

MTLStages

Dispatchthreads(threadspergrid:threadsperthreadgroup:)

Dispatch

Dispatchthreads(indirectbuffer:)

Dispatch

Dispatchthreadgroups(threadgroupspergrid:threadsperthreadgroup:)

Dispatch

Dispatchthreadgroups(indirectbuffer:threadsperthreadgroup:)

Dispatch

Copy(sourcebuffer:sourceoffset:destinationbuffer:destinationoffset:size:)

Blit

Copy(sourcebuffer:sourceoffset:sourcebytesperrow:sourcebytesperimage:sourcesize:destinationtexture:destinationslice:destinationlevel:destinationorigin:options:)

Blit

Copy(sourcetensor:sourceorigin:sourcedimensions:destinationtensor:destinationorigin:destinationdimensions:)

Blit

Copy(sourcetexture:destinationtexture:)

Blit

Copy(sourcetexture:sourceslice:sourcelevel:destinationtexture:destinationslice:destinationlevel:slicecount:levelcount:)

Blit

Copy(sourcetexture:sourceslice:sourcelevel:sourceorigin:sourcesize:destinationbuffer:destinationoffset:destinationbytesperrow:destinationbytesperimage:options:)

Blit

Copy(sourcetexture:sourceslice:sourcelevel:sourceorigin:sourcesize:destinationtexture:destinationslice:destinationlevel:destinationorigin:)

Blit

Copycommands(sourcebuffer:sourcerange:destinationbuffer:destinationindex:)

Blit

Fill(buffer:range:value:)

Blit

Generatemipmaps(texture:)

Blit

Optimizecommands(buffer:range:)

Blit

Optimizecontents(forcpuaccess:)

Blit

Optimizecontents(forcpuaccess:slice:level:)

Blit

Optimizecontents(forgpuaccess:)

Blit

Optimizecontents(forgpuaccess:slice:level:)

Blit

Resetcommands(buffer:range:)

Blit

Build(destinationaccelerationstructure:descriptor:scratchbuffer:)

Accelerationstructure

Copy(sourceaccelerationstructure:destinationaccelerationstructure:)

Accelerationstructure

Copyandcompact(sourceaccelerationstructure:destinationaccelerationstructure:)

Accelerationstructure

Refit(sourceaccelerationstructure:descriptor:destinationaccelerationstructure:scratchbuffer:options:)

Accelerationstructure

Writecompactedsize(sourceaccelerationstructure:destinationbuffer:)

Accelerationstructure

Executecommands(buffer:range:)[Image]Executecommandsinbuffer:withrange:

None

Executecommands(buffer:indirectbuffer:)

None

Writetimestamp(granularity:counterheap:index:)

None

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

Inspecting the pass

Running dispatch commands

Encoding buffer copy commands

Encoding buffer-to-texture copy commands

Encoding texture copy commands

Encoding texture-to-buffer copy commands

Encoding indirect command buffer copy commands

Encoding buffer fill commands

Encoding mipmap generation commands

Encoding optimization commands

Encoding reset commands

Encoding acceleration structure build commands

Encoding acceleration structure copy commands

Encoding acceleration structure refit commands

Encoding indirect command buffers

Encoding performance measurement commands

See Also

Encoding a compute pass