<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 14.0.0 -",
    "macOS: 10.14.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "Metal",
  "identifier" : "/documentation/Metal/MTLRenderCommandEncoder/memoryBarrier(resources:after:before:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal"
    ],
    "preciseIdentifier" : "s:So23MTLRenderCommandEncoderP5MetalE13memoryBarrier9resources5after6beforeySaySo11MTLResource_pG_So0A6StagesVAKtF"
  },
  "title" : "memoryBarrier(resources:after:before:)"
}
-->

# memoryBarrier(resources:after:before:)

Creates a memory barrier that enforces the order of write and read operations for specific resources.

```
func memoryBarrier(resources: [any MTLResource], after: MTLRenderStages, before: MTLRenderStages)
```

## Parameters

`resources`

An array of [`MTLResource`](/documentation/Metal/MTLResource) instances the barrier applies to.

`after`

The render stages of previous draw commands that modify `resources`.

`before`

The render stages of subsequent draw commands that read or modify `resources`.

## Discussion

Memory barriers ensure the relevant stages of prior draw commands finish modifying resources before starting the stages of subsequent commands that depend on those resources.

To determine whether a GPU supports memory barriers, see the [Metal feature set tables (PDF)](https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf).

---

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)