---
title: "updateFence(_:afterEncoderStages:)"
framework: metal
role: symbol
role_heading: Instance Method
path: "metal/mtl4commandencoder/updatefence(_:afterencoderstages:)"
---

# updateFence(_:afterEncoderStages:)

Encodes a command that instructs the GPU to update a fence after one or more stages, which can unblock other passes waiting for the fence.

## Declaration

```swift
func updateFence(_ fence: any MTLFence, afterEncoderStages: MTLStages)
```

## Parameters

- `fence`: A fence the pass updates after the stages in afterEncoderStages complete.
- `afterEncoderStages`: The encoder stages that need to complete before the pass updates fence.

## Mentioned in

Synchronizing passes with a fence Synchronizing stages within a pass

## Discussion

Discussion You can synchronize memory operations of a pass that access resources with an MTLFence. This method instructs the pass to update fence after the stages you pass to the afterEncoderStages run all their memory store operations to the resources it accesses. The fence indicates when other passes can access those resources without a race condition. For more information about synchronization with fences, see: Resource synchronization Synchronizing passes with a fence Reuse a fence by waiting first and updating second When encoding a pass that reuses a fence, wait for other passes to update the fence before repurposing that fence to notify subsequent passes with an update: Call the waitForFence(_:beforeEncoderStages:) method before encoding commands that need to wait for other passes. Call the updateFence(_:afterEncoderStages:) method after encoding commands that later passes depend on. The GPU driver evaluates the fences that apply to the pass and the commands that depend on those fences when your app commits the enclosing MTLCommandBuffer. warning: Don’t update a fence and then wait for the same fence within a pass because it can create a GPU deadlock. To synchronize different stages within a single pass, create an intrapass barrier because a fence can only synchronize memory operations between different passes. For more information, see Synchronizing stages within a pass.
