Protocol

MTLCommandQueue

A queue that organizes command buffers to be executed by a GPU.

Declaration

protocol MTLCommandQueue

Overview

A MTLCommandQueue object is used to queue an ordered list of command buffers for a MTLDevice to execute. Command queues are thread-safe and allow multiple outstanding command buffers to be encoded simultaneously.

You don't define classes that implement this protocol. To create a command queue, call the makeCommandQueue() or makeCommandQueue(maxCommandBufferCount:) method of a MTLDevice object. The queue returned by makeCommandQueue(maxCommandBufferCount:) method restricts the number of uncompleted command buffers. Typically, you create one or more command queues when your app is initialized and then keep those queues around throughout the lifetime of your app.

To render images or execute compute operations, use the command queue to create one or more command buffer objects, then encode commands into those objects and commit them to the queue. There are two methods to create MTLCommandBuffer objects: makeCommandBuffer() and makeCommandBufferWithUnretainedReferences(). In most cases, you use the makeCommandBuffer() method, because it creates a command buffer that holds a strong reference to any objects that are needed to finish executing the commands encoded in the command buffer. In very rare situations, you use the makeCommandBufferWithUnretainedReferences() method to create a command buffer that does not keep strong references to these objects. In this case, you are responsible for keeping these objects alive until the commands encoded in the command buffer have finished executing.

Topics

Creating Command Buffers

func makeCommandBuffer() -> MTLCommandBuffer?

Creates a command buffer.

Required.

func makeCommandBufferWithUnretainedReferences() -> MTLCommandBuffer?

Creates a command buffer that doesn't hold strong references to any objects required to execute the command buffer.

Required.

Identifying Properties

var device: MTLDevice

The device from which the command queue was created.

Required.

var label: String?

A string that identifies the command queue.

Required.

Deprecated

func insertDebugCaptureBoundary()

Informs Xcode about when GPU Frame Capture starts and stops.

Required.

Deprecated

Relationships

Inherits From

See Also

Command Setup

Setting Up a Command Structure

Discover how Metal executes commands on a GPU.

Devices and Commands

Demonstrates how to access and interact with the GPU.

Enhancing Frame Capture by Using Labels

Assign meaningful labels to your Metal objects and commands so you can easily identify them in the call list of a captured frame.

protocol MTLCommandBuffer

A container that stores encoded commands for the GPU to execute.

protocol MTLCommandEncoder

An encoder that writes GPU commands into a command buffer.

Advanced Command Setup

Organize your commands for maximum concurrency and minimal dependencies.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software