diff --git a/src/dxvk/dxvk_device.cpp b/src/dxvk/dxvk_device.cpp index 4bc1ea6ba8f..81f9f5eac8c 100644 --- a/src/dxvk/dxvk_device.cpp +++ b/src/dxvk/dxvk_device.cpp @@ -151,6 +151,12 @@ namespace dxvk { } + Rc DxvkDevice::createRawQuery( + VkQueryType type) { + return m_objects.queryPool().allocQuery(type); + } + + Rc DxvkDevice::createFence( const DxvkFenceCreateInfo& fenceInfo) { return new DxvkFence(this, fenceInfo); diff --git a/src/dxvk/dxvk_device.h b/src/dxvk/dxvk_device.h index 20cc2cf7fc8..64cf3ff2c1c 100644 --- a/src/dxvk/dxvk_device.h +++ b/src/dxvk/dxvk_device.h @@ -301,7 +301,16 @@ namespace dxvk { VkQueryType type, VkQueryControlFlags flags, uint32_t index); - + + /** + * \brief Creates a raw GPU query + * + * \param [in] type Query type + * \returns New query + */ + Rc createRawQuery( + VkQueryType type); + /** * \brief Creates new fence * diff --git a/src/dxvk/hud/dxvk_hud_item.cpp b/src/dxvk/hud/dxvk_hud_item.cpp index 3e88d0bb664..87a65d4266c 100644 --- a/src/dxvk/hud/dxvk_hud_item.cpp +++ b/src/dxvk/hud/dxvk_hud_item.cpp @@ -211,25 +211,6 @@ namespace dxvk::hud { } - HudFrameTimeQueryPool::HudFrameTimeQueryPool( - const Rc& device) - : m_vkd(device->vkd()) { - VkQueryPoolCreateInfo info = { VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO }; - info.queryType = VK_QUERY_TYPE_TIMESTAMP; - info.queryCount = 1; - - VkResult vr = m_vkd->vkCreateQueryPool(m_vkd->device(), &info, nullptr, &m_pool); - - if (vr != VK_SUCCESS) - throw DxvkError(str::format("Failed to create frame time query pool: ", vr)); - } - - - HudFrameTimeQueryPool::~HudFrameTimeQueryPool() { - m_vkd->vkDestroyQueryPool(m_vkd->device(), m_pool, nullptr); - } - - HudFrameTimeItem::HudFrameTimeItem(const Rc& device, HudRenderer* renderer) : m_device (device), m_gfxSetLayout (createDescriptorSetLayout()), @@ -298,16 +279,17 @@ namespace dxvk::hud { HudPos maxPos) { // Write current time stamp to the buffer DxvkBufferSliceHandle sliceHandle = m_gpuBuffer->getSliceHandle(); + std::pair query = m_query->getQuery(); ctx.cmd->cmdResetQueryPool(DxvkCmdBuffer::InitBuffer, - m_queryPool->handle(), 0, 1); + query.first, query.second, 1); ctx.cmd->cmdWriteTimestamp(DxvkCmdBuffer::InitBuffer, VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT, - m_queryPool->handle(), 0); + query.first, query.second); ctx.cmd->cmdCopyQueryPoolResults(DxvkCmdBuffer::InitBuffer, - m_queryPool->handle(), 0, 1, sliceHandle.handle, + query.first, query.second, 1, sliceHandle.handle, sliceHandle.offset + (dataPoint & 1u) * sizeof(uint64_t), sizeof(uint64_t), VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WAIT_BIT); @@ -392,7 +374,7 @@ namespace dxvk::hud { // Make sure GPU resources are being kept alive as necessary ctx.cmd->trackResource(m_gpuBuffer->getAllocation()); - ctx.cmd->trackResource(m_queryPool); + ctx.cmd->trackQuery(Rc(m_query)); } @@ -493,8 +475,7 @@ namespace dxvk::hud { ctx.cmd->cmdPipelineBarrier(DxvkCmdBuffer::InitBuffer, &depInfo); ctx.cmd->trackResource(m_gpuBuffer->getAllocation()); - // We'll use and initialize this later as necessary - m_queryPool = new HudFrameTimeQueryPool(m_device); + m_query = m_device->createRawQuery(VK_QUERY_TYPE_TIMESTAMP); } diff --git a/src/dxvk/hud/dxvk_hud_item.h b/src/dxvk/hud/dxvk_hud_item.h index 44a4c0df956..a33b937894c 100644 --- a/src/dxvk/hud/dxvk_hud_item.h +++ b/src/dxvk/hud/dxvk_hud_item.h @@ -7,6 +7,8 @@ #include "../../util/util_time.h" +#include "../dxvk_gpu_query.h" + #include "dxvk_hud_renderer.h" namespace dxvk::hud { @@ -229,30 +231,6 @@ namespace dxvk::hud { }; - /** - * \brief Trackable GPU query pool - */ - class HudFrameTimeQueryPool : public DxvkResource { - - public: - - HudFrameTimeQueryPool( - const Rc& device); - - ~HudFrameTimeQueryPool(); - - VkQueryPool handle() const { - return m_pool; - } - - private: - - Rc m_vkd; - VkQueryPool m_pool = VK_NULL_HANDLE; - - }; - - /** * \brief HUD item to display the frame rate */ @@ -308,7 +286,7 @@ namespace dxvk::hud { Rc m_device; Rc m_gpuBuffer; Rc m_textView; - Rc m_queryPool; + Rc m_query; VkDescriptorSetLayout m_computeSetLayout = VK_NULL_HANDLE; VkPipelineLayout m_computePipelineLayout = VK_NULL_HANDLE;