Contents

addScheduledHandler(_:)

Registers a completion handler the GPU device calls immediately after it schedules the command buffer to run on the GPU.

Declaration

func addScheduledHandler(_ block: @escaping  MTLCommandBufferHandler)

Parameters

  • block:

    A Swift closure or an Objective-C block that Metal calls after it schedules the command buffer to run on the GPU.

Mentioned in

Discussion

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

The GPU device schedules each command buffer — along with tasks from other command buffers — after it identifies the command buffer’s dependencies. At that time, the GPU device sets the command buffer’s status to MTLCommandBufferStatus.scheduled and calls your completion handler.

You can use the command buffer’s kernelEndTime and kernelStartTime properties to calculate how much time the CPU spends scheduling the command buffer.

See Also

Registering state change handlers