C Specification

To request a timestamp, call:

// Provided by VK_KHR_synchronization2
void vkCmdWriteTimestamp2KHR(
    VkCommandBuffer                             commandBuffer,
    VkPipelineStageFlags2KHR                    stage,
    VkQueryPool                                 queryPool,
    uint32_t                                    query);

Parameters

  • commandBuffer is the command buffer into which the command will be recorded.

  • stage specifies a stage of the pipeline.

  • queryPool is the query pool that will manage the timestamp.

  • query is the query within the query pool that will contain the timestamp.

Description

When vkCmdWriteTimestamp2KHR is submitted to a queue, it defines an execution dependency on commands that were submitted before it, and writes a timestamp to a query pool.

The first synchronization scope includes all commands that occur earlier in submission order. The synchronization scope is limited to operations on the pipeline stage specified by stage.

The second synchronization scope includes only the timestamp write operation.

When the timestamp value is written, the availability status of the query is set to available.

Note

If an implementation is unable to detect completion and latch the timer at any specific stage of the pipeline, it may instead do so at any logically later stage.

Comparisons between timestamps are not meaningful if the timestamps are written by commands submitted to different queues.

Note

An example of such a comparison is subtracting an older timestamp from a newer one to determine the execution time of a sequence of commands.

If vkCmdWriteTimestamp2KHR is called while executing a render pass instance that has multiview enabled, the timestamp uses N consecutive query indices in the query pool (starting at query) where N is the number of bits set in the view mask of the subpass the command is executed in. The resulting query values are determined by an implementation-dependent choice of one of the following behaviors:

  • The first query is a timestamp value and (if more than one bit is set in the view mask) zero is written to the remaining queries. If two timestamps are written in the same subpass, the sum of the execution time of all views between those commands is the difference between the first query written by each command.

  • All N queries are timestamp values. If two timestamps are written in the same subpass, the sum of the execution time of all views between those commands is the sum of the difference between corresponding queries written by each command. The difference between corresponding queries may be the execution time of a single view.

In either case, the application can sum the differences between all N queries to determine the total execution time.

Valid Usage
  • VUID-vkCmdWriteTimestamp2KHR-stage-03929
    If the geometry shaders feature is not enabled, stage must not contain VK_PIPELINE_STAGE_2_GEOMETRY_SHADER_BIT_KHR

  • VUID-vkCmdWriteTimestamp2KHR-stage-03930
    If the tessellation shaders feature is not enabled, stage must not contain VK_PIPELINE_STAGE_2_TESSELLATION_CONTROL_SHADER_BIT_KHR or VK_PIPELINE_STAGE_2_TESSELLATION_EVALUATION_SHADER_BIT_KHR

  • VUID-vkCmdWriteTimestamp2KHR-synchronization2-03858
    The synchronization2 feature must be enabled

  • VUID-vkCmdWriteTimestamp2KHR-stage-03859
    stage must only include a single pipeline stage

  • VUID-vkCmdWriteTimestamp2KHR-stage-03860
    stage must only include stages valid for the queue family that was used to create the command pool that commandBuffer was allocated from

  • VUID-vkCmdWriteTimestamp2KHR-queryPool-03861
    queryPool must have been created with a queryType of VK_QUERY_TYPE_TIMESTAMP

  • VUID-vkCmdWriteTimestamp2KHR-queryPool-03862
    The query identified by queryPool and query must be unavailable

  • VUID-vkCmdWriteTimestamp2KHR-timestampValidBits-03863
    The command pool’s queue family must support a non-zero timestampValidBits

  • VUID-vkCmdWriteTimestamp2KHR-query-04903
    query must be less than the number of queries in queryPool

  • VUID-vkCmdWriteTimestamp2KHR-None-03864
    All queries used by the command must be unavailable

  • VUID-vkCmdWriteTimestamp2KHR-query-03865
    If vkCmdWriteTimestamp2KHR is called within a render pass instance, the sum of query and the number of bits set in the current subpass’s view mask must be less than or equal to the number of queries in queryPool

Valid Usage (Implicit)
  • VUID-vkCmdWriteTimestamp2KHR-commandBuffer-parameter
    commandBuffer must be a valid VkCommandBuffer handle

  • VUID-vkCmdWriteTimestamp2KHR-stage-parameter
    stage must be a valid combination of VkPipelineStageFlagBits2KHR values

  • VUID-vkCmdWriteTimestamp2KHR-queryPool-parameter
    queryPool must be a valid VkQueryPool handle

  • VUID-vkCmdWriteTimestamp2KHR-commandBuffer-recording
    commandBuffer must be in the recording state

  • VUID-vkCmdWriteTimestamp2KHR-commandBuffer-cmdpool
    The VkCommandPool that commandBuffer was allocated from must support transfer, graphics, or compute operations

  • VUID-vkCmdWriteTimestamp2KHR-commonparent
    Both of commandBuffer, and queryPool must have been created, allocated, or retrieved from the same VkDevice

Host Synchronization
  • Host access to commandBuffer must be externally synchronized

  • Host access to the VkCommandPool that commandBuffer was allocated from must be externally synchronized

Command Properties
Command Buffer Levels Render Pass Scope Supported Queue Types

Primary
Secondary

Both

Transfer
Graphics
Compute

See Also

Document Notes

For more information, see the Vulkan Specification

This page is extracted from the Vulkan Specification. Fixes and changes should be made to the Specification, not directly.

Copyright 2014-2021 The Khronos Group Inc.

SPDX-License-Identifier: CC-BY-4.0