<!--
{
  "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(afterEncoderStages:beforeEncoderStages:visibilityOptions:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal"
    ],
    "preciseIdentifier" : "s:So18MTL4CommandEncoderP5MetalE7barrier05afterC6Stages06beforecG017visibilityOptionsySo9MTLStagesV_AISo0a10VisibilityJ0VtF"
  },
  "title" : "barrier(afterEncoderStages:beforeEncoderStages:visibilityOptions:)"
}
-->

# barrier(afterEncoderStages:beforeEncoderStages:visibilityOptions:)

Encodes an intra-pass barrier.

```
func barrier(afterEncoderStages: MTLStages, beforeEncoderStages: MTLStages, visibilityOptions: MTL4VisibilityOptions = [ .device ])
```

## Parameters

`afterEncoderStages`

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

`beforeEncoderStages`

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

`visibilityOptions`

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

## Discussion

Encode a barrier that guarantees that any subsequent work you encode in the *current command encoder*,
corresponding to `beforeEncoderStages`, doesn’t begin until all prior commands in this command encoder,
corresponding to `afterEncoderStages`, completes.

When calling this method, it’s your responsibility to ensure parameters `afterEncoderStages` and `beforeEncoderStages`
contain a combination of [`MTLStages`](/documentation/Metal/MTLStages) for which this encoder can encode commands. For example, for a
[`MTL4ComputeCommandEncoder`](/documentation/Metal/MTL4ComputeCommandEncoder) instance, you can provide any combination of [`dispatch`](/documentation/Metal/MTLStages/dispatch),
[`blit`](/documentation/Metal/MTLStages/blit) and [`accelerationStructure`](/documentation/Metal/MTLStages/accelerationStructure).

---

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)