Skip to content

Commit

Permalink
[dxvk] Rework HUD to use a GPU query directly
Browse files Browse the repository at this point in the history
Allows us to leverage the global timestamp query pool now that queries
are reference-counted properly.
  • Loading branch information
doitsujin committed Oct 17, 2024
1 parent fb6e0ad commit c860fda
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 51 deletions.
6 changes: 6 additions & 0 deletions src/dxvk/dxvk_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ namespace dxvk {
}


Rc<DxvkGpuQuery> DxvkDevice::createRawQuery(
VkQueryType type) {
return m_objects.queryPool().allocQuery(type);
}


Rc<DxvkFence> DxvkDevice::createFence(
const DxvkFenceCreateInfo& fenceInfo) {
return new DxvkFence(this, fenceInfo);
Expand Down
11 changes: 10 additions & 1 deletion src/dxvk/dxvk_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<DxvkGpuQuery> createRawQuery(
VkQueryType type);

/**
* \brief Creates new fence
*
Expand Down
31 changes: 6 additions & 25 deletions src/dxvk/hud/dxvk_hud_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,25 +211,6 @@ namespace dxvk::hud {
}


HudFrameTimeQueryPool::HudFrameTimeQueryPool(
const Rc<DxvkDevice>& 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<DxvkDevice>& device, HudRenderer* renderer)
: m_device (device),
m_gfxSetLayout (createDescriptorSetLayout()),
Expand Down Expand Up @@ -298,16 +279,17 @@ namespace dxvk::hud {
HudPos maxPos) {
// Write current time stamp to the buffer
DxvkBufferSliceHandle sliceHandle = m_gpuBuffer->getSliceHandle();
std::pair<VkQueryPool, uint32_t> 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);

Expand Down Expand Up @@ -392,7 +374,7 @@ namespace dxvk::hud {

// Make sure GPU resources are being kept alive as necessary
ctx.cmd->trackResource<DxvkAccess::Write>(m_gpuBuffer->getAllocation());
ctx.cmd->trackResource<DxvkAccess::Write>(m_queryPool);
ctx.cmd->trackQuery(m_query);
}


Expand Down Expand Up @@ -493,8 +475,7 @@ namespace dxvk::hud {
ctx.cmd->cmdPipelineBarrier(DxvkCmdBuffer::InitBuffer, &depInfo);
ctx.cmd->trackResource<DxvkAccess::Write>(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);
}


Expand Down
28 changes: 3 additions & 25 deletions src/dxvk/hud/dxvk_hud_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include "../../util/util_time.h"

#include "../dxvk_gpu_query.h"

#include "dxvk_hud_renderer.h"

namespace dxvk::hud {
Expand Down Expand Up @@ -229,30 +231,6 @@ namespace dxvk::hud {
};


/**
* \brief Trackable GPU query pool
*/
class HudFrameTimeQueryPool : public DxvkResource {

public:

HudFrameTimeQueryPool(
const Rc<DxvkDevice>& device);

~HudFrameTimeQueryPool();

VkQueryPool handle() const {
return m_pool;
}

private:

Rc<vk::DeviceFn> m_vkd;
VkQueryPool m_pool = VK_NULL_HANDLE;

};


/**
* \brief HUD item to display the frame rate
*/
Expand Down Expand Up @@ -308,7 +286,7 @@ namespace dxvk::hud {
Rc<DxvkDevice> m_device;
Rc<DxvkBuffer> m_gpuBuffer;
Rc<DxvkBufferView> m_textView;
Rc<HudFrameTimeQueryPool> m_queryPool;
Rc<DxvkGpuQuery> m_query;

VkDescriptorSetLayout m_computeSetLayout = VK_NULL_HANDLE;
VkPipelineLayout m_computePipelineLayout = VK_NULL_HANDLE;
Expand Down

0 comments on commit c860fda

Please sign in to comment.