Contents

resolveCounterHeap(_:range:buffer:fenceToWait:fenceToUpdate:)

Encodes a command that resolves an opaque counter heap into a buffer.

Declaration

func resolveCounterHeap(_ counterHeap: any MTL4CounterHeap, range: Range<Int>, buffer: MTL4BufferRange, fenceToWait: (any MTLFence)? = nil, fenceToUpdate: (any MTLFence)? = nil)

Parameters

  • counterHeap:

    A heap the command resolves.

  • range:

    A range of index values within the heap the command resolves.

  • buffer:

    A buffer the command saves the data it resolves into.

  • fenceToWait:

    A fence the GPU waits for before starting, if applicable; otherwise nil.

  • fenceToUpdate:

    A fence the system updates after the command finishes resolving the data; otherwise nil.

Discussion

The command this method encodes converts the data within a counter heap into a common format and stores it into the buffer parameter.

The command places each entry in the counter heap within range sequentially, starting at offset. Each entry needs to be a fixed size that you can query by calling the size(ofCounterHeapEntry:) method.

This command runs during the MTLStageBlit stage of the GPU timeline. Barrier against this stage to ensure the data is present in the resolve buffer parameter before you access it.

Similarly, your app needs to synchronize any GPU accesses to buffer after the command completes with barrier.

If your app needs to access buffer from the CPU, signal an MTLSharedEvent to notify the CPU when it’s ready. Alternatively, you can resolve the heap’s data from the CPU by calling the heap’s resolveCounterRange: method.