summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineVulkan
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2020-01-04 07:40:25 +0000
committerassiduous <assiduous@diligentgraphics.com>2020-01-04 07:40:25 +0000
commit583cbc597b68de462b9b629be493e57db91df3a5 (patch)
treef43e27f7a3908778525aa2b99bfdaf1e3bc32fc5 /Graphics/GraphicsEngineVulkan
parentD3D12 backend: renamed QueryManager to QueryManagerD3D12 (diff)
downloadDiligentCore-583cbc597b68de462b9b629be493e57db91df3a5.tar.gz
DiligentCore-583cbc597b68de462b9b629be493e57db91df3a5.zip
Vulkan utilities: added query manipulation functions
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
-rw-r--r--Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanCommandBuffer.h48
-rw-r--r--Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanDebug.h1
-rw-r--r--Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanLogicalDevice.h18
-rw-r--r--Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanDebug.cpp13
-rw-r--r--Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanLogicalDevice.cpp15
5 files changed, 91 insertions, 4 deletions
diff --git a/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanCommandBuffer.h b/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanCommandBuffer.h
index 96563a7c..b1497ef1 100644
--- a/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanCommandBuffer.h
+++ b/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanCommandBuffer.h
@@ -441,6 +441,54 @@ public:
vkCmdResolveImage(m_VkCmdBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
}
+ __forceinline void BeginQuery(VkQueryPool queryPool,
+ uint32_t query,
+ VkQueryControlFlags flags)
+ {
+ // A query must either begin and end inside the same subpass of a render
+ // pass instance, or must both begin and end outside of a render pass instance
+ // (i.e. contain entire render pass instances) (17.2).
+ VERIFY_EXPR(m_VkCmdBuffer != VK_NULL_HANDLE);
+ vkCmdBeginQuery(m_VkCmdBuffer, queryPool, query, flags);
+ }
+
+ __forceinline void EndQuery(VkQueryPool queryPool,
+ uint32_t query)
+ {
+ VERIFY_EXPR(m_VkCmdBuffer != VK_NULL_HANDLE);
+ vkCmdEndQuery(m_VkCmdBuffer, queryPool, query);
+ }
+
+ __forceinline void ResetQueryPool(VkQueryPool queryPool,
+ uint32_t firstQuery,
+ uint32_t queryCount)
+ {
+ if (m_State.RenderPass != VK_NULL_HANDLE)
+ {
+ // Query pool reset must be performed outside of render pass (17.2).
+ EndRenderPass();
+ }
+ vkCmdResetQueryPool(m_VkCmdBuffer, queryPool, firstQuery, queryCount);
+ }
+
+ __forceinline void CopyQueryPoolResults(VkQueryPool queryPool,
+ uint32_t firstQuery,
+ uint32_t queryCount,
+ VkBuffer dstBuffer,
+ VkDeviceSize dstOffset,
+ VkDeviceSize stride,
+ VkQueryResultFlags flags)
+ {
+ VERIFY_EXPR(m_VkCmdBuffer != VK_NULL_HANDLE);
+ if (m_State.RenderPass != VK_NULL_HANDLE)
+ {
+ // Copy query results must be performed outside of render pass (17.2).
+ EndRenderPass();
+ }
+ vkCmdCopyQueryPoolResults(m_VkCmdBuffer, queryPool, firstQuery, queryCount,
+ dstBuffer, dstOffset, stride, flags);
+ }
+
void FlushBarriers();
__forceinline void SetVkCmdBuffer(VkCommandBuffer VkCmdBuffer)
diff --git a/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanDebug.h b/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanDebug.h
index 35f8826b..ee812f08 100644
--- a/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanDebug.h
+++ b/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanDebug.h
@@ -91,6 +91,7 @@ void SetDescriptorPoolName (VkDevice device, VkDescriptorPool descript
void SetSemaphoreName (VkDevice device, VkSemaphore semaphore, const char * name);
void SetFenceName (VkDevice device, VkFence fence, const char * name);
void SetEventName (VkDevice device, VkEvent _event, const char * name);
+void SetQueryPoolName (VkDevice device, VkQueryPool queryPool, const char * name);
enum class VulkanHandleTypeId : uint32_t;
diff --git a/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanLogicalDevice.h b/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanLogicalDevice.h
index f53af000..b580eb45 100644
--- a/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanLogicalDevice.h
+++ b/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanLogicalDevice.h
@@ -56,7 +56,8 @@ enum class VulkanHandleTypeId : uint32_t
DescriptorSet,
Semaphore,
Queue,
- Event
+ Event,
+ QueryPool
};
template <typename VulkanObjectType, VulkanHandleTypeId>
@@ -79,6 +80,7 @@ using FramebufferWrapper = DEFINE_VULKAN_OBJECT_WRAPPER(Framebuffer);
using DescriptorPoolWrapper = DEFINE_VULKAN_OBJECT_WRAPPER(DescriptorPool);
using DescriptorSetLayoutWrapper = DEFINE_VULKAN_OBJECT_WRAPPER(DescriptorSetLayout);
using SemaphoreWrapper = DEFINE_VULKAN_OBJECT_WRAPPER(Semaphore);
+using QueryPoolWrapper = DEFINE_VULKAN_OBJECT_WRAPPER(QueryPool);
#undef DEFINE_VULKAN_OBJECT_WRAPPER
class VulkanLogicalDevice : public std::enable_shared_from_this<VulkanLogicalDevice>
@@ -137,6 +139,7 @@ public:
DescriptorSetLayoutWrapper CreateDescriptorSetLayout(const VkDescriptorSetLayoutCreateInfo& LayoutCI, const char* DebugName = "") const;
SemaphoreWrapper CreateSemaphore(const VkSemaphoreCreateInfo& SemaphoreCI, const char* DebugName = "") const;
+ QueryPoolWrapper CreateQueryPool(const VkQueryPoolCreateInfo& QueryPoolCI, const char* DebugName = "") const;
VkCommandBuffer AllocateVkCommandBuffer(const VkCommandBufferAllocateInfo& AllocInfo, const char* DebugName = "") const;
VkDescriptorSet AllocateVkDescriptorSet(const VkDescriptorSetAllocateInfo& AllocInfo, const char* DebugName = "") const;
@@ -157,6 +160,7 @@ public:
void ReleaseVulkanObject(DescriptorPoolWrapper&& DescriptorPool) const;
void ReleaseVulkanObject(DescriptorSetLayoutWrapper&& DescriptorSetLayout) const;
void ReleaseVulkanObject(SemaphoreWrapper&& Semaphore) const;
+ void ReleaseVulkanObject(QueryPoolWrapper&& QueryPool) const;
void FreeDescriptorSet(VkDescriptorPool Pool, VkDescriptorSet Set) const;
@@ -191,6 +195,18 @@ public:
VkResult ResetDescriptorPool(VkDescriptorPool descriptorPool,
VkDescriptorPoolResetFlags flags = 0) const;
+ VkResult GetQueryPoolResults(VkQueryPool queryPool,
+ uint32_t firstQuery,
+ uint32_t queryCount,
+ size_t dataSize,
+ void* pData,
+ VkDeviceSize stride,
+ VkQueryResultFlags flags) const
+ {
+ return vkGetQueryPoolResults(m_VkDevice, queryPool, firstQuery, queryCount,
+ dataSize, pData, stride, flags);
+ }
+
VkPipelineStageFlags GetEnabledGraphicsShaderStages() const { return m_EnabledGraphicsShaderStages; }
private:
diff --git a/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanDebug.cpp b/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanDebug.cpp
index 776135d1..90202b89 100644
--- a/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanDebug.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanDebug.cpp
@@ -395,6 +395,11 @@ void SetEventName(VkDevice device, VkEvent _event, const char* name)
SetObjectName(device, (uint64_t)_event, VK_OBJECT_TYPE_EVENT, name);
}
+void SetQueryPoolName(VkDevice device, VkQueryPool queryPool, const char* name)
+{
+ SetObjectName(device, (uint64_t)queryPool, VK_OBJECT_TYPE_QUERY_POOL, name);
+}
+
template <>
void SetVulkanObjectName<VkCommandPool, VulkanHandleTypeId::CommandPool>(VkDevice device, VkCommandPool cmdPool, const char* name)
@@ -516,6 +521,12 @@ void SetVulkanObjectName<VkEvent, VulkanHandleTypeId::Event>(VkDevice device, Vk
SetEventName(device, _event, name);
}
+template <>
+void SetVulkanObjectName<VkQueryPool, VulkanHandleTypeId::QueryPool>(VkDevice device, VkQueryPool queryPool, const char* name)
+{
+ SetQueryPoolName(device, queryPool, name);
+}
+
const char* VkResultToString(VkResult errorCode)
@@ -665,7 +676,7 @@ const char* VkObjectTypeToString(VkObjectType ObjectType)
case VK_OBJECT_TYPE_INDIRECT_COMMANDS_LAYOUT_NVX: return "indirect cmd layout NVX";
case VK_OBJECT_TYPE_DEBUG_UTILS_MESSENGER_EXT: return "debug utils messenger";
case VK_OBJECT_TYPE_VALIDATION_CACHE_EXT: return "validation cache";
- case VK_OBJECT_TYPE_ACCELERATION_STRUCTURE_NVX: return "acceleration structure NVX";
+ case VK_OBJECT_TYPE_ACCELERATION_STRUCTURE_NV: return "acceleration structure NVX";
default: return "unknown";
// clang-format on
}
diff --git a/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanLogicalDevice.cpp b/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanLogicalDevice.cpp
index 0f500c96..23fd559e 100644
--- a/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanLogicalDevice.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanLogicalDevice.cpp
@@ -57,9 +57,9 @@ VulkanLogicalDevice::VulkanLogicalDevice(VkPhysicalDevice vkPhysical
m_EnabledGraphicsShaderStages = VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
if (DeviceCI.pEnabledFeatures->geometryShader)
- m_EnabledGraphicsShaderStages = VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT;
+ m_EnabledGraphicsShaderStages |= VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT;
if (DeviceCI.pEnabledFeatures->tessellationShader)
- m_EnabledGraphicsShaderStages = VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT | VK_PIPELINE_STAGE_TESSELLATION_EVALUATION_SHADER_BIT;
+ m_EnabledGraphicsShaderStages |= VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT | VK_PIPELINE_STAGE_TESSELLATION_EVALUATION_SHADER_BIT;
}
VkQueue VulkanLogicalDevice::GetQueue(uint32_t queueFamilyIndex, uint32_t queueIndex)
@@ -251,6 +251,12 @@ SemaphoreWrapper VulkanLogicalDevice::CreateSemaphore(const VkSemaphoreCreateInf
return CreateVulkanObject<VkSemaphore, VulkanHandleTypeId::Semaphore>(vkCreateSemaphore, SemaphoreCI, DebugName, "semaphore");
}
+QueryPoolWrapper VulkanLogicalDevice::CreateQueryPool(const VkQueryPoolCreateInfo& QueryPoolCI, const char* DebugName) const
+{
+ VERIFY_EXPR(QueryPoolCI.sType == VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO);
+ return CreateVulkanObject<VkQueryPool, VulkanHandleTypeId::QueryPool>(vkCreateQueryPool, QueryPoolCI, DebugName, "query pool");
+}
+
VkCommandBuffer VulkanLogicalDevice::AllocateVkCommandBuffer(const VkCommandBufferAllocateInfo& AllocInfo, const char* DebugName) const
{
VERIFY_EXPR(AllocInfo.sType == VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO);
@@ -386,6 +392,11 @@ void VulkanLogicalDevice::ReleaseVulkanObject(SemaphoreWrapper&& Semaphore) cons
Semaphore.m_VkObject = VK_NULL_HANDLE;
}
+void VulkanLogicalDevice::ReleaseVulkanObject(QueryPoolWrapper&& QueryPool) const
+{
+ vkDestroyQueryPool(m_VkDevice, QueryPool.m_VkObject, m_VkAllocator);
+ QueryPool.m_VkObject = VK_NULL_HANDLE;
+}
void VulkanLogicalDevice::FreeDescriptorSet(VkDescriptorPool Pool, VkDescriptorSet Set) const
{