VulkanQueryPool

Package: Libraries.Game.Graphics.Vulkan · Inherits from: Libraries.Language.Object, Libraries.Game.Graphics.Vulkan.VulkanRetirable

A VulkanQueryPool is a pool of Vulkan queries: numbers the GPU writes while it works, read back afterward. There are three kinds: - TIMESTAMP: the GPU's clock when it reached a point in a command buffer (WriteTimestampCommand). Read with ReadTimestamps, in milliseconds. - OCCLUSION: how many samples passed the depth test between a BeginQueryCommand and an EndQueryCommand, such as whether an object is visible at all. Read with ReadResults. - PIPELINE_STATISTICS: how many vertices, primitives and shader runs a span of work caused, the counters chosen with SetStatistics before Create. Read with ReadResults. Not every device has them (see VulkanPhysicalDeviceFeatures:HasPipelineStatisticsQuery); Apple GPUs don't. Queries are reset with ResetQueryPoolCommand before each use. Reading never waits for the GPU: a read returns false if any query asked for isn't finished yet, so it is usually done a frame or two later. GraphicsTimer (Libraries.Game.Graphics.Timing) uses a pool of timestamps to time each part of a frame.

Example Code

use Libraries.Game.Graphics.Vulkan.VulkanQueryPool
use Libraries.Game.Graphics.Vulkan.VulkanGraphics
use Libraries.Game.GameStateManager

GameStateManager manager
VulkanGraphics graphics = cast(VulkanGraphics, manager:GetGameGraphics())
VulkanQueryPool pool
if pool:Create(graphics:GetDevice(), pool:TIMESTAMP, 16)
output "Made a pool of " + pool:GetCount() + " timestamps."
end

Variables

  • integer VERTEX_SHADER_INVOCATIONS
  • integer COMPUTE_SHADER_INVOCATIONS: How CopyQueryResultsCommand writes results (VkQueryResultFlagBits).
  • integer INPUT_ASSEMBLY_VERTICES: The counters a statistics pool can keep (VkQueryPipelineStatisticFlagBits).
  • integer GEOMETRY_SHADER_INVOCATIONS
  • integer CLIPPING_PRIMITIVES
  • integer TESSELLATION_EVALUATION_SHADER_INVOCATIONS
  • integer INPUT_ASSEMBLY_PRIMITIVES
  • integer TESSELLATION_CONTROL_SHADER_PATCHES
  • integer RESULT_PARTIAL
  • integer FRAGMENT_SHADER_INVOCATIONS
  • integer PIPELINE_STATISTICS
  • integer GEOMETRY_SHADER_PRIMITIVES
  • integer RESULT_WAIT
  • integer OCCLUSION: The kinds of query (VkQueryType).
  • integer CLIPPING_INVOCATIONS
  • integer RESULT_WITH_AVAILABILITY
  • integer TIMESTAMP: The counters a statistics pool can keep (VkQueryPipelineStatisticFlagBits).
  • integer RESULT_64_BIT: How CopyQueryResultsCommand writes results (VkQueryResultFlagBits).

Actions

Create(Libraries.Game.Graphics.Vulkan.VulkanDevice device, integer type, integer count)

This action makes the pool on a device.

Parameters

Returns

boolean: True if the pool was made

Dispose()

This action frees the pool.

GetCount()

This action returns how many queries the pool holds.

Returns

integer: The count

GetDevice()

This action returns the device the pool was made on.

Returns

Libraries.Game.Graphics.Vulkan.VulkanDevice: The device

GetStatistics()

This action returns the counters a statistics pool keeps.

Returns

integer: The counters, added together

GetType()

This action returns the kind of query the pool holds.

Returns

integer: TIMESTAMP, OCCLUSION or PIPELINE_STATISTICS

GetValuesPerQuery()

This action returns how many numbers each query of a statistics pool gives: one per counter it keeps. Other pools give one.

Returns

integer: The count

IsCreated()

This action returns true once the pool has been made.

Returns

boolean: True if made

ReadResults(integer first, integer count, Libraries.Containers.Number64BitArray into)

This action reads occlusion counts or pipeline statistics without waiting: GetValuesPerQuery numbers for each query, in order.

Parameters

Returns

boolean: True if all were finished and read; false otherwise

ReadTimestamps(integer first, integer count, Libraries.Containers.Number64BitArray into)

This action reads timestamps without waiting, as milliseconds after the first one read. into is made large enough.

Parameters

Returns

boolean: True if all were finished and read; false otherwise

Release()

This action frees the pool once VulkanGraphics:Retire knows no frame still uses it. It is the same as Dispose.

SetStatistics(integer flags)

This action sets which counters a PIPELINE_STATISTICS pool keeps, added together, such as VERTEX_SHADER_INVOCATIONS + FRAGMENT_SHADER_INVOCATIONS. Call it before Create.

Parameters

  • flags integer: The counters

SetTimestampScale(number period, integer bits)

This action sets how timestamps are turned into time: the device's nanoseconds per tick (VulkanPhysicalDeviceLimits:GetTimestampPeriod) and the queue's valid bits (VulkanQueueFamily:GetTimestampValidBits). GraphicsTimer sets them.

Parameters

  • period number: Nanoseconds per tick
  • bits integer: How many bits of a timestamp are valid

Inherited Actions

2 actions from Libraries.Game.Graphics.Vulkan.VulkanRetirable
3 actions from Libraries.Language.Object