<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.11.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Metal",
  "identifier" : "/documentation/Metal/MTLCommandEncoder",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "Metal"
    ],
    "preciseIdentifier" : "c:objc(pl)MTLCommandEncoder"
  },
  "title" : "MTLCommandEncoder"
}
-->

# MTLCommandEncoder

An encoder that writes GPU commands into a command buffer.

```
protocol MTLCommandEncoder : NSObjectProtocol
```

## Overview

Don’t implement this protocol yourself; instead you call methods on an [`MTLCommandBuffer`](/documentation/Metal/MTLCommandBuffer) instance to create command encoders. Command encoder instances are lightweight instances that you re-create every time you need to send commands to the GPU.

There are many different kinds of command encoders, each providing a different set of commands that can be encoded into the buffer.
A command encoder implements the [`MTLCommandEncoder`](/documentation/Metal/MTLCommandEncoder) protocol and an additional protocol specific to the kind of encoder being created.

|Protocol                                                                     |Task                                                  |
|-----------------------------------------------------------------------------|------------------------------------------------------|
|``doc://com.apple.metal/documentation/Metal/MTLRenderCommandEncoder``        |Graphics rendering                                    |
|``doc://com.apple.metal/documentation/Metal/MTLComputeCommandEncoder``       |Computation                                           |
|``doc://com.apple.metal/documentation/Metal/MTLBlitCommandEncoder``          |Memory management                                     |
|``doc://com.apple.metal/documentation/Metal/MTLParallelRenderCommandEncoder``|Multiple graphics rendering tasks encoded in parallel.|

While a command encoder is active, it has the exclusive right to append commands to its command buffer. Once you finish encoding commands, call the [`endEncoding()`](/documentation/Metal/MTLCommandEncoder/endEncoding()) method to finish encoding the commands. To write further commands into the same command buffer, create a new command encoder.

You can call the [`insertDebugSignpost(_:)`](/documentation/Metal/MTLCommandEncoder/insertDebugSignpost(_:)), [`pushDebugGroup(_:)`](/documentation/Metal/MTLCommandEncoder/pushDebugGroup(_:)), and [`popDebugGroup()`](/documentation/Metal/MTLCommandEncoder/popDebugGroup()) methods to put debug strings into the command buffer and to push or pop string labels used to identify groups of encoded commands. These methods don’t change the rendering or compute behavior of your app; the Xcode debugger uses them to organize your app’s rendering commands in a format that may provide insight into how your app works.

## Topics

### Ending command encoding

[`func endEncoding()`](/documentation/Metal/MTLCommandEncoder/endEncoding())

Declares that all command generation from the encoder is completed.

### Annotating the command buffer with debug information

[`func insertDebugSignpost(String)`](/documentation/Metal/MTLCommandEncoder/insertDebugSignpost(_:))

Inserts a debug string into the captured frame data.

[`func pushDebugGroup(String)`](/documentation/Metal/MTLCommandEncoder/pushDebugGroup(_:))

Pushes a specific string onto a stack of debug group strings for the command encoder.

[`func popDebugGroup()`](/documentation/Metal/MTLCommandEncoder/popDebugGroup())

Pops the latest string off of a stack of debug group strings for the command encoder.

### Identifying the command encoder

[`var device: any MTLDevice`](/documentation/Metal/MTLCommandEncoder/device)

The Metal device from which the command encoder was created.

[`var label: String?`](/documentation/Metal/MTLCommandEncoder/label)

A string that labels the command encoder.

### Instance Methods

[`func barrier(afterQueueStages: MTLStages, beforeStages: MTLStages)`](/documentation/Metal/MTLCommandEncoder/barrier(afterQueueStages:beforeStages:))

Encodes a consumer barrier on work you commit to the same command queue.

## Relationships

### Inherited By

[`MTLRenderCommandEncoder`](/documentation/Metal/MTLRenderCommandEncoder)

[`MTLAccelerationStructureCommandEncoder`](/documentation/Metal/MTLAccelerationStructureCommandEncoder)

[`MTLResourceStateCommandEncoder`](/documentation/Metal/MTLResourceStateCommandEncoder)

[`MTLComputeCommandEncoder`](/documentation/Metal/MTLComputeCommandEncoder)

[`MTLBlitCommandEncoder`](/documentation/Metal/MTLBlitCommandEncoder)

[`MTLParallelRenderCommandEncoder`](/documentation/Metal/MTLParallelRenderCommandEncoder)

### Inherits From

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)