An object you use to synchronize access to Metal resources.
- iOS 12.0+
- macOS 10.14+
- Mac Catalyst 13.0+
- tvOS 12.0+
Don’t implement this protocol yourself; instead, to create a
MTLEvent object, call the
make method of a
MTLDevice object. A basic event object that this method creates can be used to synchronize commands executing on a single Metal device.
An event is represented by a monotonically increasing unsigned 64-bit integer. An event starts with a value of
0. To signal a change to the event, call
encode on a command buffer, passing in the new value for this event. The new value should be larger than previous changes to the event. Metal signals the event after all scheduled commands prior to the event have finished, updating the event's value if the new value is larger than its current value.
To wait for an event to be signaled, call
encode on a command buffer, passing in the value for which to wait. When the device object executes the command buffer and reaches this wait command, it compares the event's current value to the value you passed in. If the event's current value is less than the value you passed in, the device object will not start any new commands until the event is updated to a value equal to or greater than the value you requested.
You can encode signalling and waiting on events into different command buffers, even command buffers executing on two different command queues for the same device. You can also encode these commands independently of each other, meaning, for example, that you can wait on signals you haven't encoded yet.
For more information, see Synchronizing Events Within a Single Device.