Contents

addCompletedHandler(_:)

Registers a completion handler the GPU device calls immediately after the GPU finishes running the commands in the command buffer.

Declaration

func addCompletedHandler(_ block: @escaping  MTLCommandBufferHandler)

Parameters

  • block:

    A Swift closure or an Objective-C block that Metal calls after the GPU finishes running the commands in the command buffer.

Mentioned in

Discussion

You can register one or more completion handlers for the same command buffer. The GPU device’s driver (on the CPU) calls the completion handlers after the GPU finishes executing the command buffer.

For example, you can use the command buffer’s gpuEndTime and gpuStartTime properties to calculate how much time the GPU spends running the command buffer.

The completion handler is also a good place to check the status property to determine whether the GPU successfully completes the buffer’s commands. If the status is equal to MTLCommandBufferStatus.error, you can investigate further by checking the error and log properties for more details about the issue. See Command buffer debugging for more methods and properties that can help you isolate the issue.

See Also

Registering state change handlers