---
title: "memoryBarrier(scope:after:before:)"
framework: metal
role: symbol
role_heading: Instance Method
path: "metal/mtlrendercommandencoder/memorybarrier(scope:after:before:)"
---

# memoryBarrier(scope:after:before:)

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

## Declaration

```swift
func memoryBarrier(scope: MTLBarrierScope, after: MTLRenderStages, before: MTLRenderStages)
```

## Parameters

- `scope`: An doc://com.apple.metal/documentation/Metal/MTLBarrierScope instance that represents the resource types the barrier synchronizes operations on.
- `after`: The render stages of previous draw commands that modify resources of the types that scope defines.
- `before`: The render stages of subsequent draw commands that read or modify resources of the types that scope defines.

## Discussion

Discussion Memory barriers ensure the relevant stages of prior draw commands finish updating 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).

## See Also

### Preventing resource access conflicts

- [waitForFence(_:before:)](metal/mtlrendercommandencoder/waitforfence(_:before:).md)
- [updateFence(_:after:)](metal/mtlrendercommandencoder/updatefence(_:after:).md)
- [memoryBarrier(resources:after:before:)](metal/mtlrendercommandencoder/memorybarrier(resources:after:before:).md)
