Instance Method

sampleCounters(sampleBuffer:sampleIndex:barrier:)

Encodes a command to sample hardware counters at this point in the blit pass and store the samples into a counter sample buffer.

Required.

Declaration

func sampleCounters(sampleBuffer: MTLCounterSampleBuffer, sampleIndex: Int, barrier: Bool)

Parameters

sampleBuffer

The sample buffer to sample into.

sampleIndex

The index in the counter buffer to write the sample.

barrier

A Boolean value that states whether to insert a barrier before taking the sample.

Discussion

Inserting a barrier ensures that any work you encoded with this encoder is complete before the GPU samples the hardware counters. If you don't insert a barrier, the GPU can sample the counters concurrently with other commands encoded by this encoder. Using a barrier leads to more repeatable counter results but can negatively impact performance.

Regardless of whether you set a barrier, the GPU does not isolate the sampling from work encoded by other encoders.