mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-01-31 23:52:20 +01:00
[dxvk] Rework HUD to use a GPU query directly
Allows us to leverage the global timestamp query pool now that queries are reference-counted properly.
This commit is contained in:
parent
fb6e0ad6c1
commit
990c7f562a
@ -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);
|
||||
|
@ -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
|
||||
*
|
||||
|
@ -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()),
|
||||
@ -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);
|
||||
|
||||
@ -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(Rc<DxvkGpuQuery>(m_query));
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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<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
|
||||
*/
|
||||
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user