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

# updateFence(_:)

Encodes a command that instructs the GPU to update a fence after the compute pass completes.

## Declaration

```swift
func updateFence(_ fence: any MTLFence)
```

## Parameters

- `fence`: A fence the pass updates after it completes.

## Discussion

Discussion You can synchronize memory operations of a compute pass that access resources with an MTLFence. This method instructs the pass to update fence after it runs all its 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 compute 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(_:) method before encoding commands that need to wait for other passes. Call the updateFence(_:) 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.

## See Also

### Preventing resource access conflicts

- [waitForFence(_:)](metal/mtlcomputecommandencoder/waitforfence(_:).md)
- [memoryBarrier(scope:)](metal/mtlcomputecommandencoder/memorybarrier(scope:).md)
- [memoryBarrier(resources:)](metal/mtlcomputecommandencoder/memorybarrier(resources:).md)
