Contents

MTLBlitCommandEncoder

Encodes commands that copy and modify resources for a single blit pass.

Declaration

protocol MTLBlitCommandEncoder : MTLCommandEncoder

Mentioned in

Overview

Create a blit encoder by calling one of the factory methods on an MTLCommandBuffer instance, such as makeBlitCommandEncoder().

A blit command encoder adds commands to a command buffer that modify resources in various ways, including:

  • Filling buffers with repeating bytes

  • Generating mipmaps for textures

  • Copying data between buffers

  • Copying data between textures

  • Copying data between a texture and a buffer

  • Managing the contents of indirect command buffers

  • Synchronizing buffers, textures, and other resources between the CPU and GPU

  • Improving runtime performance for resources by optimizing their memory layout for the GPU or CPU

You typically use these commands to move data between a resource that uses private storage and another resource that uses CPU-accessible storage. Some apps also use them to apply image-processing and texture effects, such as blurring or reflections, or to render and work with offscreen image data.

When you finish encoding blit commands, finalize the blit pass into the command buffer by calling the encoder’s endEncoding() method.

Command stages

Most blit commands apply to one stage within a pass. The following table shows which stages apply to each command:

Function

MTLStages

Fill(buffer:range:value:)

Blit

Generatemipmaps(for:)

Blit

Copy(from:sourceoffset:to:destinationoffset:size:)

Blit

Copy(from:to:)

Blit

Copy(from:sourceslice:sourcelevel:to:destinationslice:destinationlevel:slicecount:levelcount:)

Blit

Copy(from:sourceslice:sourcelevel:sourceorigin:sourcesize:to:destinationslice:destinationlevel:destinationorigin:)

Blit

Copy(from:sourceorigin:sourcedimensions:to:destinationorigin:destinationdimensions:)

Blit

Copy(from:sourceoffset:sourcebytesperrow:sourcebytesperimage:sourcesize:to:destinationslice:destinationlevel:destinationorigin:)

Blit

Copy(from:sourceoffset:sourcebytesperrow:sourcebytesperimage:sourcesize:to:destinationslice:destinationlevel:destinationorigin:options:)

Blit

Copy(from:sourceslice:sourcelevel:sourceorigin:sourcesize:to:destinationoffset:destinationbytesperrow:destinationbytesperimage:)

Blit

Copy(from:sourceslice:sourcelevel:sourceorigin:sourcesize:to:destinationoffset:destinationbytesperrow:destinationbytesperimage:options:)

Blit

Optimizecontentsforgpuaccess(texture:)

Blit

Optimizecontentsforgpuaccess(texture:slice:level:)

Blit

Optimizecontentsforcpuaccess(texture:)

Blit

Optimizecontentsforcpuaccess(texture:slice:level:)

Blit

Synchronize(resource:)

None

Synchronize(texture:slice:level:)

None

Copyindirectcommandbuffer(_:sourcerange:destination:destinationindex:)

Blit

Resetcommandsinbuffer(_:range:)

Blit

Optimizeindirectcommandbuffer(_:range:)

Blit

Samplecounters(samplebuffer:sampleindex:barrier:)

None

Resolvecounters(_:range:destinationbuffer:destinationoffset:)

Blit

Gettextureaccesscounters(_:region:miplevel:slice:resetcounters:countersbuffer:countersbufferoffset:)

Blit

Resettextureaccesscounters(_:region:miplevel:slice:)

Blit

For more information about stages and synchronization, see MTLStages and Resource synchronization.

Topics

Filling buffers

Generating texture mipmaps

Copying buffer data to another buffer

Copying texture data to another texture

Copying buffer data to a texture

Copying texture data to a buffer

Optimizing textures for GPU access

Optimizing textures for CPU access

Synchronizing managed resources

Preventing resource access conflicts

Managing indirect command buffers

Sampling counters

Managing sparse texture access counters

See Also

Encoding a blit pass