<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -",
    "macCatalyst: -",
    "macOS: 26.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Metal",
  "identifier" : "/documentation/Metal/MTL4CommandEncoder/barrier(afterStages:beforeQueueStages:visibilityOptions:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal"
    ],
    "preciseIdentifier" : "s:So18MTL4CommandEncoderP5MetalE7barrier11afterStages011beforeQueueG017visibilityOptionsySo9MTLStagesV_AISo0a10VisibilityK0VtF"
  },
  "title" : "barrier(afterStages:beforeQueueStages:visibilityOptions:)"
}
-->

# barrier(afterStages:beforeQueueStages:visibilityOptions:)

Encodes a producer barrier on work committed to the same command queue.

```
func barrier(afterStages: MTLStages, beforeQueueStages: MTLStages, visibilityOptions: MTL4VisibilityOptions = [ .device ])
```

## Parameters

`afterStages`

[`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
the current command encoder prior to this barrier command.

`beforeQueueStages`

[`MTLStages`](/documentation/Metal/MTLStages) mask that represents the stages of work that need to wait.
This argument applies to subsequent encoders and not to work in the current
command encoder.

`visibilityOptions`

[`MTL4VisibilityOptions`](/documentation/Metal/MTL4VisibilityOptions) of the barrier, controlling cache flush behavior.

## Discussion

This method encodes a barrier that guarantees that any work you encode using *subsequent command encoders*,
corresponding to `beforeQueueStages`, don’t begin until all commands you previously encode in the current
encoder (and prior encoders), corresponding to `afterStages`, complete.

When calling this method, you can pass any [`MTLStages`](/documentation/Metal/MTLStages) to parameters `afterStages` and `beforeQueueStages`,
even stages that don’t relate to the current or prior command encoders.

---

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)