C Specification

To copy query statuses and numerical results directly to buffer memory, call:

// Provided by VK_VERSION_1_0
void vkCmdCopyQueryPoolResults(
    VkCommandBuffer                             commandBuffer,
    VkQueryPool                                 queryPool,
    uint32_t                                    firstQuery,
    uint32_t                                    queryCount,
    VkBuffer                                    dstBuffer,
    VkDeviceSize                                dstOffset,
    VkDeviceSize                                stride,
    VkQueryResultFlags                          flags);

Parameters

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

  • queryPool is the query pool managing the queries containing the desired results.

  • firstQuery is the initial query index.

  • queryCount is the number of queries. firstQuery and queryCount together define a range of queries.

  • dstBuffer is a VkBuffer object that will receive the results of the copy command.

  • dstOffset is an offset into dstBuffer.

  • stride is the stride in bytes between results for individual queries within dstBuffer. The required size of the backing memory for dstBuffer is determined as described above for vkGetQueryPoolResults.

  • flags is a bitmask of VkQueryResultFlagBits specifying how and when results are returned.

Description

Any results written for a query are written according to a layout dependent on the query type.

Results for any query in queryPool identified by firstQuery and queryCount that is available are copied to dstBuffer.

If VK_QUERY_RESULT_WITH_AVAILABILITY_BIT is set, results for all queries in queryPool identified by firstQuery and queryCount are copied to dstBuffer, along with an extra availability value written directly after the results of each query and interpreted as an unsigned integer. A value of zero indicates that the results are not yet available, otherwise the query is complete and results are available.

Results for any available query written by this command are final and represent the final result of the query. If VK_QUERY_RESULT_PARTIAL_BIT is set, then for any query that is unavailable, an intermediate result between zero and the final result value is written for that query. Otherwise, any result written by this command is undefined.

If VK_QUERY_RESULT_64_BIT is set, results and availability values for all queries are written as an array of 64-bit values. If the queryPool was created with VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR, results for each query are written as an array of the type indicated by VkPerformanceCounterKHR::storage for the counter being queried. Otherwise, results and availability values are written as an array of 32-bit values. If an unsigned integer query’s value overflows the result type, the value may either wrap or saturate. If a signed integer query’s value overflows the result type, the value is undefined. If a floating point query’s value is not representable as the result type, the value is undefined.

This command defines an execution dependency between other query commands that reference the same query.

The first synchronization scope includes all commands which reference the queries in queryPool indicated by query that occur earlier in submission order. If flags does not include VK_QUERY_RESULT_WAIT_BIT, vkCmdWriteTimestamp2KHR, vkCmdEndQuery, and vkCmdWriteTimestamp are excluded from this scope.

The second synchronization scope includes all commands which reference the queries in queryPool indicated by query that occur later in submission order.

The operation of this command happens after the first scope and happens before the second scope.

vkCmdCopyQueryPoolResults is considered to be a transfer operation, and its writes to buffer memory must be synchronized using VK_PIPELINE_STAGE_TRANSFER_BIT and VK_ACCESS_TRANSFER_WRITE_BIT before using the results.

Valid Usage
  • VUID-vkCmdCopyQueryPoolResults-firstQuery-09436
    firstQuery must be less than the number of queries in queryPool

  • VUID-vkCmdCopyQueryPoolResults-firstQuery-09437
    The sum of firstQuery and queryCount must be less than or equal to the number of queries in queryPool

  • VUID-vkCmdCopyQueryPoolResults-queryCount-09438
    If queryCount is greater than 1, stride must not be zero

  • VUID-vkCmdCopyQueryPoolResults-queryType-09439
    If the queryType used to create queryPool was VK_QUERY_TYPE_TIMESTAMP, flags must not contain VK_QUERY_RESULT_PARTIAL_BIT

  • VUID-vkCmdCopyQueryPoolResults-queryType-09440
    If the queryType used to create queryPool was VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR, flags must not contain VK_QUERY_RESULT_WITH_AVAILABILITY_BIT, VK_QUERY_RESULT_PARTIAL_BIT, or VK_QUERY_RESULT_64_BIT

  • VUID-vkCmdCopyQueryPoolResults-queryType-09441
    If the queryType used to create queryPool was VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR, the queryPool must have been recorded once for each pass as retrieved via a call to vkGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR

  • VUID-vkCmdCopyQueryPoolResults-None-09402
    All queries used by the command must not be uninitialized when the command is executed

  • VUID-vkCmdCopyQueryPoolResults-dstOffset-00819
    dstOffset must be less than the size of dstBuffer

  • VUID-vkCmdCopyQueryPoolResults-flags-00822
    If VK_QUERY_RESULT_64_BIT is not set in flags then dstOffset and stride must be multiples of 4

  • VUID-vkCmdCopyQueryPoolResults-flags-00823
    If VK_QUERY_RESULT_64_BIT is set in flags then dstOffset and stride must be multiples of 8

  • VUID-vkCmdCopyQueryPoolResults-dstBuffer-00824
    dstBuffer must have enough storage, from dstOffset, to contain the result of each query, as described here

  • VUID-vkCmdCopyQueryPoolResults-dstBuffer-00825
    dstBuffer must have been created with VK_BUFFER_USAGE_TRANSFER_DST_BIT usage flag

  • VUID-vkCmdCopyQueryPoolResults-dstBuffer-00826
    If dstBuffer is non-sparse then it must be bound completely and contiguously to a single VkDeviceMemory object

  • VUID-vkCmdCopyQueryPoolResults-queryType-03232
    If the queryType used to create queryPool was VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR, VkPhysicalDevicePerformanceQueryPropertiesKHR::allowCommandBufferQueryCopies must be VK_TRUE

  • VUID-vkCmdCopyQueryPoolResults-None-07429
    All queries used by the command must not be active

  • VUID-vkCmdCopyQueryPoolResults-None-08752
    All queries used by the command must have been made available by prior executed commands

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

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

  • VUID-vkCmdCopyQueryPoolResults-dstBuffer-parameter
    dstBuffer must be a valid VkBuffer handle

  • VUID-vkCmdCopyQueryPoolResults-flags-parameter
    flags must be a valid combination of VkQueryResultFlagBits values

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

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

  • VUID-vkCmdCopyQueryPoolResults-renderpass
    This command must only be called outside of a render pass instance

  • VUID-vkCmdCopyQueryPoolResults-commonparent
    Each of commandBuffer, dstBuffer, 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 Command Type

Primary
Secondary

Outside

Graphics
Compute

Action

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-2023 The Khronos Group Inc.

SPDX-License-Identifier: CC-BY-4.0