<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -",
    "macCatalyst: 26.0.0 -",
    "macOS: 26.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Metal",
  "identifier" : "/documentation/Metal/MTLCommandEncoder/barrier(afterQueueStages:beforeStages:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal"
    ],
    "preciseIdentifier" : "c:objc(pl)MTLCommandEncoder(im)barrierAfterQueueStages:beforeStages:"
  },
  "title" : "barrier(afterQueueStages:beforeStages:)"
}
-->

# barrier(afterQueueStages:beforeStages:)

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

```
func barrier(afterQueueStages: MTLStages, beforeStages: MTLStages)
```

## Parameters

`afterQueueStages`

[`MTLStages`](/documentation/Metal/MTLStages) mask that represents the stages of work to wait for.
This argument applies to work corresponding to these stages you
encode in prior command encoders, and not for the current encoder.

`beforeStages`

[`MTLStages`](/documentation/Metal/MTLStages) mask that represents the stages of work that wait.
This argument applies to work you encode in the current command encoder.

## Discussion

Encode a barrier that guarantees that any subsequent work you encode in the current command encoder that corresponds
to the `beforeStages` stages doesn’t proceed until Metal completes all work prior to the current command encoder
corresponding to the `afterQueueStages` stages, completes.

Metal can reorder the exact point where it applies the barrier, so use this method for synchronizing between different passes.

If you need to synchronize work within a pass that you encode with an instance of a subclass of [`MTLCommandEncoder`](/documentation/Metal/MTLCommandEncoder),
use memory barriers instead. For subclasses of [`MTL4CommandEncoder`](/documentation/Metal/MTL4CommandEncoder), use encoder barriers.

You can specify `afterQueueStages` and `beforeStages` that contain [`MTLStages`](/documentation/Metal/MTLStages) unrelated to the current command
encoder.

---

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)