SpiecsEngine
 
Loading...
Searching...
No Matches
VulkanQueryPool.cpp
Go to the documentation of this file.
1/**
2* @file VulkanQueryPool.cpp.
3* @brief The VulkanQueryPool Class Implementation.
4* @author Spices.
5*/
6
7#include "Pchheader.h"
9
10namespace Spices {
11
13 VulkanState& vulkanState ,
14 VkQueryType type ,
15 uint32_t count ,
16 uint32_t stride ,
17 VkQueryPipelineStatisticFlags statistics
18 )
19 : VulkanObject(vulkanState)
21 , m_QueryCount(count)
22 , m_Stride(stride)
23 {
25
26 /**
27 * @brief Instance a VkQueryPoolCreateInfo.
28 */
29 VkQueryPoolCreateInfo createInfo{};
30 createInfo.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
31 createInfo.queryType = type;
32 createInfo.queryCount = count;
33
34 createInfo.flags = 0;
35 createInfo.pipelineStatistics = statistics;
36 createInfo.pNext = nullptr;
37
38 /**
39 * @brief Create Query Pool.
40 */
41 VK_CHECK(vkCreateQueryPool(vulkanState.m_Device, &createInfo, nullptr, &m_QueryPool))
42 DEBUGUTILS_SETOBJECTNAME(VK_OBJECT_TYPE_QUERY_POOL, (uint64_t)m_QueryPool, m_VulkanState.m_Device, "Query Pool")
43 }
44
46 {
48
49 /**
50 * @brief Destroy this QueryPool.
51 */
52 vkDestroyQueryPool(m_VulkanState.m_Device, m_QueryPool, nullptr);
53 }
54
55 void VulkanQueryPool::BeginQuery(VkCommandBuffer commandBuffer, uint32_t index) const
56 {
58
59 /**
60 * @brief Determine VkQueryControlFlags.
61 */
62 VkQueryControlFlags flags = 0;
63 if (m_QueryType & VK_QUERY_TYPE_OCCLUSION)
64 {
65 flags |= VK_QUERY_CONTROL_PRECISE_BIT;
66 }
67
68 assert(!(m_QueryType & VK_QUERY_TYPE_TIMESTAMP));
69
70 /**
71 * @brief Begin Query.
72 */
73 vkCmdBeginQuery(commandBuffer, m_QueryPool, index, flags);
74 }
75
76 void VulkanQueryPool::EndQuery(VkCommandBuffer commandBuffer, uint32_t index) const
77 {
79
80 assert(!(m_QueryType & VK_QUERY_TYPE_TIMESTAMP));
81
82 /**
83 * @brief EndQuery.
84 */
85 vkCmdEndQuery(commandBuffer, m_QueryPool, index);
86 }
87
88 void VulkanQueryPool::WriteTimeStamp(VkCommandBuffer commandBuffer, uint32_t index) const
89 {
91
92 assert(m_QueryType & VK_QUERY_TYPE_TIMESTAMP);
93
94 vkCmdWriteTimestamp2(commandBuffer, VK_PIPELINE_STAGE_2_NONE, m_QueryPool, index);
95 }
96
97 void VulkanQueryPool::Reset(VkCommandBuffer commandBuffer) const
98 {
100
101 /**
102 * @brief Reset query pool.
103 * Must be done outside of render pass.
104 */
105 vkCmdResetQueryPool(commandBuffer, m_QueryPool, 0, m_QueryCount);
106 }
107
108 void VulkanQueryPool::QueryResults(uint64_t* result) const
109 {
111
112 /**
113 * @brief Query all result with uint64_t.
114 */
115 VK_CHECK(vkGetQueryPoolResults(
116 m_VulkanState.m_Device ,
117 m_QueryPool ,
118 0 ,
119 m_QueryCount ,
120 m_Stride * m_QueryCount + sizeof(uint64_t) ,
121 result ,
122 m_Stride ,
123 // Store results a 64 bit values and wait until the results have been finished
124 // If you don't want to wait, you can use VK_QUERY_RESULT_WITH_AVAILABILITY_BIT
125 // which also returns the state of the result (ready) in the result
126 VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WAIT_BIT
127 ))
128 }
129}
#define SPICES_PROFILE_ZONE
#define VK_CHECK(expr)
Vulkan Check macro. Verify Vulkan API Effectiveness.
Definition VulkanUtils.h:68
VulkanObject(VulkanState &vulkanState)
Constructor Function. Init member variables.
VulkanObject Class. This class defines the basic behaves of VulkanObject. When we create an new Vulka...
void EndQuery(VkCommandBuffer commandBuffer, uint32_t index=0) const
End query previous commands.
void WriteTimeStamp(VkCommandBuffer commandBuffer, uint32_t index) const
Write a TimeStamp to queryPool.
void Reset(VkCommandBuffer commandBuffer) const
Reset QueryPool. Call it on frame start.
void QueryResults(uint64_t *result) const
Query results from Pool.
virtual ~VulkanQueryPool() override
Destructor Function.
uint32_t m_QueryCount
Query Count.
VulkanQueryPool(VulkanState &vulkanState, VkQueryType type, uint32_t count=1, uint32_t stride=8, VkQueryPipelineStatisticFlags statistics=0)
Constructor Function. Create VkQueryPool.
void BeginQuery(VkCommandBuffer commandBuffer, uint32_t index=0) const
Begin to query next commands.
uint32_t m_Stride
Data stride.
This Class is a Wrapper of VulkanQueryPool.
This struct contains all Vulkan object in used global.
Definition VulkanUtils.h:74