<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -",
    "macCatalyst: 26.0.0 -",
    "macOS: 26.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Metal",
  "identifier" : "/documentation/Metal/MTL4RenderCommandEncoder/writeTimestamp(granularity:after:counterHeap:index:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal"
    ],
    "preciseIdentifier" : "c:objc(pl)MTL4RenderCommandEncoder(im)writeTimestampWithGranularity:afterStage:intoHeap:atIndex:"
  },
  "title" : "writeTimestamp(granularity:after:counterHeap:index:)"
}
-->

# writeTimestamp(granularity:after:counterHeap:index:)

Writes a GPU timestamp into the given [`MTL4CounterHeap`](/documentation/Metal/MTL4CounterHeap) at `index` after `stage` completes.

```
func writeTimestamp(granularity: MTL4TimestampGranularity, after stage: MTLRenderStages, counterHeap: any MTL4CounterHeap, index: Int)
```

## Parameters

`granularity`

a [`MTL4TimestampGranularity`](/documentation/Metal/MTL4TimestampGranularity) hint.

`stage`

[`MTLRenderStages`](/documentation/Metal/MTLRenderStages) that need to complete before Metal writes the timestamp. This may also include later
stages that are related, for example [`mesh`](/documentation/Metal/MTLRenderStages/mesh) may include
[`vertex`](/documentation/Metal/MTLRenderStages/vertex).

`counterHeap`

[`MTL4CounterHeap`](/documentation/Metal/MTL4CounterHeap) into which Metal writes timestamps.

`index`

The index value into which Metal writes this timestamp.

## Discussion

This command only guarantees all draws prior to this command are complete when Metal writes the timestamp into
the counter heap you provide in the `counterHeap` parameter. The timestamp may also include subsequent operations.

If you call this method before any draw calls, Metal writes a timestamp before the stage you specify in the
`stage` parameter begins.

---

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)