Contents

GPU counters and counter sample buffers

Retrieve runtime data from a GPU device by sampling one or more of its counters.

Overview

A GPU counter (MTLCounter) is typically a hardware feature that tracks a specific performance metric, such as timestamps before and after an important rendering stage. A counter set (MTLCounterSet) is a collection of related counters. A counter sample buffer (MTLCounterSampleBuffer) represents the memory where a GPU device stores the data for a specific counter set.

You can retrieve and inspect data from a GPU’s counter set with the following steps:

  1. Inspect which GPU counter sets a GPU device supports (see Confirming which counters and counter sets a GPU supports).

  2. Make a counter sample buffer to store the data (see Creating a counter sample buffer to store a GPU’s counter data during a pass).

  3. Instruct the GPU to save the counter set data to the buffer during a pass or an immediate mode command (see Sampling GPU data into counter sample buffers).

  4. Transform the counter set data into a standard type (see Converting a GPU’s counter data into a readable format).

If you’re sampling data from a timestamp counter set (timestamp), you may need to convert the timestamps from the GPU’s clock to the CPU’s clock. See Converting GPU timestamps into CPU time for more information.

Topics

Counters and counter sets

Counter sample buffers

Counter sample data output

Timestamp data

Counter sample buffer errors

See Also

Developer tools