Protocol

MTLBlitCommandEncoder

An encoder that encodes memory copying, filtering, and fill commands.

Declaration

protocol MTLBlitCommandEncoder

Overview

The MTLBlitCommandEncoder protocol defines the interface for objects that can encode resource-copying commands into a command buffer. Use these commands to manage the contents of textures and buffers.

Data copying operations may be necessary for image processing and texture effects, such as blurring or reflections. You also use these operators to access image data that is rendered offscreen.

Your app does not define classes that implement this protocol. To create a MTLBlitCommandEncoder object, call the makeBlitCommandEncoder() method of the MTLCommandBuffer object into which you want to encode blit commands. Next, call methods on the MTLBlitCommandEncoder object to enqueue blit commands. Finally, call endEncoding() to finish the encoding process.

Topics

Copying Data Between Buffers

func copy(from: MTLBuffer, sourceOffset: Int, to: MTLBuffer, destinationOffset: Int, size: Int)

Encodes a command to copy data from a source buffer into a destination buffer.

Required.

Copying Data Between Textures

Generating Buffer and Texture Data

func fill(buffer: MTLBuffer, range: Range<Int>, value: UInt8)

Fills a buffer with a constant value in each byte.

func generateMipmaps(for: MTLTexture)

Encodes a command to generate mipmaps for a texture from the base mipmap level up to the maximum level.

Required.

Working with Indirect Command Buffers

func copyIndirectCommandBuffer(MTLIndirectCommandBuffer, sourceRange: Range<Int>, destination: MTLIndirectCommandBuffer, destinationIndex: Int)

Encodes a command to copy commands from an indirect command buffer into another indirect command buffer.

func optimizeIndirectCommandBuffer(MTLIndirectCommandBuffer, range: Range<Int>)

Encodes a command to optimize a range in the indirect command buffer to improve performance.

func resetCommandsInBuffer(MTLIndirectCommandBuffer, range: Range<Int>)

Encodes a command to reset a range of commands in an indirect command buffer.

Synchronizing Managed Resources to the CPU

func synchronize(resource: MTLResource)

Encodes a command to synchronize the contents of a managed resource from the GPU to the CPU.

Required.

func synchronize(texture: MTLTexture, slice: Int, level: Int)

Encodes a command to synchronize part of a managed texture from the GPU to the CPU.

Required.

Performing Fence Operations

func updateFence(MTLFence)

Updates the given fence to capture all GPU work enqueued by the command encoder up to this specific point.

Required.

func waitForFence(MTLFence)

Prevents further GPU commands from being enqueued by the command encoder until the given fence is reached.

Required.

Optimizing Texture Access Performance

func optimizeContentsForGPUAccess(texture: MTLTexture)

Encodes a command to optimize a texture for better performance when the GPU accesses it.

Required.

func optimizeContentsForGPUAccess(texture: MTLTexture, slice: Int, level: Int)

Encodes a command to optimize part of a texture for better performance when the GPU accesses it.

Required.

func optimizeContentsForCPUAccess(texture: MTLTexture)

Encodes a command to optimize a texture for better performance when the CPU accesses it.

Required.

func optimizeContentsForCPUAccess(texture: MTLTexture, slice: Int, level: Int)

Encodes a command to optimize part of a texture for better performance when the CPU accesses it.

Required.

Managing GPU Execution Data

func sampleCounters(sampleBuffer: MTLCounterSampleBuffer, sampleIndex: Int, barrier: Bool)

Encodes a command to sample hardware counters at this point in the blit pass and store the samples into a counter sample buffer.

Required.

Relationships

Inherits From

See Also

Resources

Setting Resource Storage Modes

Set a storage mode that defines the memory location and access permissions of a resource.

Copying Data to a Private Resource

Use a blit command encoder to copy buffer or texture data to a private resource.

Synchronizing a Managed Resource

Synchronize the contents of a managed resource for the CPU or GPU.

Transferring Data Between Connected GPUs

Use high-speed connections between GPUs to transfer data quickly.

Reducing the Memory Footprint of Metal Apps

Learn best practices for using memory efficiently in iOS and tvOS.

protocol MTLResource

An allocation of memory that is accessible to a GPU.

protocol MTLResourceStateCommandEncoder

An encoder that encodes commands that modify resource configurations.

Buffers

Create and manipulate unstructured GPU resources.

Textures

Create and manipulate structured GPU resources.

Indirect Command Buffers

Recoup encoding time by reusing commands, or create a GPU-driven rendering pipeline by generating commands on the GPU.

Heaps

Create a single allocation of memory from which you can suballocate resources.

Synchronization

Manage access to resources in your app to avoid data hazards.