<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -",
    "macCatalyst: -",
    "macOS: 26.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Metal",
  "identifier" : "/documentation/Metal/MTL4CommandBuffer/resolveCounterHeap(_:range:buffer:fenceToWait:fenceToUpdate:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal"
    ],
    "preciseIdentifier" : "s:So17MTL4CommandBufferP5MetalE18resolveCounterHeap_5range6buffer11fenceToWait0jK6UpdateySo0afG0_p_SnySiGSo0aC5RangeVSo8MTLFence_pSgANtF"
  },
  "title" : "resolveCounterHeap(_:range:buffer:fenceToWait:fenceToUpdate:)"
}
-->

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

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

```
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:)`](/documentation/Metal/MTLDevice/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.

> Note: Your app needs ensure the GPU places data in the heap before you resolve it by
> synchronizing this stage with other GPU operations.

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`](/documentation/Metal/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:`](/documentation/Metal/MTL4CounterHeap/resolveCounterRange:) method.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)