Synchronization

Manage access to resources in your app to avoid data hazards.

Topics

Essentials

Use semaphores or events to coordinate actions across threads. Copy shared data to multiple buffers to avoid multi-threaded resource contention.

Synchronizing CPU and GPU Work

Avoid stalls between CPU and GPU work by using multiple instances of a resource.

About Synchronization Events

Learn how to use synchronization events in your app or game.

Fences

Use fences to control data access within a command buffer.

Image Filter Graph with Heaps and Fences

Demonstrates how to use heaps and fences to optimize a multistage image filter.

MTLFence

An object that can capture, track, and manage resource dependencies across command encoders.

Events

Use events to synchronize data access within a single device.

Image Filter Graph with Heaps and Events

Demonstrates how to use heaps and events to optimize a multistage image filter.

Synchronizing Events Within a Single Device

Use nonshareable events to synchronize your app’s work within a single device.

MTLEvent

A nonshareable event used to specify synchronization points within a single Metal device object.

Shareable Events

Use events to synchronize data access across multiple devices, processors, or processes.

Synchronizing Events Across Multiple Devices

Use shareable events to synchronize your app’s work across multiple devices.

Synchronizing Events Between a GPU and the CPU

Use shareable events to synchronize your app's work between a GPU and the CPU.

MTLSharedEvent

A shareable event used to specify synchronization points across CPUs, GPUs, and processes.

MTLSharedEventListener

A listener for shareable event notifications.

MTLSharedEventHandle

An object you use to recreate a shareable event.

See Also

Resources

Setting Resource Storage Modes

Set a storage mode that defines the memory location and access permissions of a resource.

Copying Data to a Private Resource

Use a blit command encoder to copy buffer or texture data to a private resource.

Synchronizing a Managed Resource

Synchronize the contents of a managed resource for the CPU or GPU.

Transferring Data Between Connected GPUs

Use high-speed connections between GPUs to transfer data quickly.

Reducing the Memory Footprint of Metal Apps

Learn best practices for using memory efficiently in iOS and tvOS.

MTLResource

An allocation of memory that is accessible to a GPU.

MTLBlitCommandEncoder

An encoder that encodes memory copying, filtering, and fill commands.

MTLResourceStateCommandEncoder

An encoder that encodes commands that modify resource configurations.

Beta
Buffers

Create and manipulate unstructured GPU resources.

Textures

Create and manipulate structured GPU resources.

Indirect Command Buffers

Recoup encoding time by reusing commands, or create a GPU-driven rendering pipeline by generating commands on the GPU.

Heaps

Create a single allocation of memory from which you can suballocate resources.