1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-11-30 22:24:15 +01:00

[dxvk] Added query tracker

This commit is contained in:
Philip Rebohle 2018-02-18 20:11:05 +01:00
parent 43200010c1
commit 7ddd2500d1
10 changed files with 131 additions and 5 deletions

View File

@ -82,6 +82,7 @@ namespace dxvk {
void DxvkCommandList::reset() {
m_queryTracker.reset();
m_stagingAlloc.reset();
m_descAlloc.reset();
m_resources.reset();

View File

@ -7,7 +7,7 @@
#include "dxvk_lifetime.h"
#include "dxvk_limits.h"
#include "dxvk_pipelayout.h"
#include "dxvk_query_pool.h"
#include "dxvk_query_tracker.h"
#include "dxvk_staging.h"
namespace dxvk {
@ -81,8 +81,19 @@ namespace dxvk {
* finished executing on the GPU.
* \param [in] queries The query range
*/
void trackQueryRange(const DxvkQueryRange& queries) {
m_queryRanges.push_back(queries);
void trackQueryRange(DxvkQueryRange&& queries) {
m_queryTracker.trackQueryRange(std::move(queries));
}
/**
* \brief Writes back query results
*
* Uses the query range to write back query data
* after the command list has finished executing
* on the GPU.
*/
void writeQueryData() {
m_queryTracker.writeQueryData();
}
/**
@ -95,6 +106,7 @@ namespace dxvk {
*/
void reset();
VkDescriptorSet allocateDescriptorSet(
VkDescriptorSetLayout descriptorLayout) {
return m_descAlloc.alloc(descriptorLayout);
@ -473,8 +485,7 @@ namespace dxvk {
DxvkLifetimeTracker m_resources;
DxvkDescriptorAlloc m_descAlloc;
DxvkStagingAlloc m_stagingAlloc;
std::vector<DxvkQueryRange> m_queryRanges;
DxvkQueryTracker m_queryTracker;
};

View File

@ -58,6 +58,10 @@ namespace dxvk {
this->renderPassEnd();
this->endActiveQueries();
this->trackQueryPool(m_queryPools[VK_QUERY_TYPE_OCCLUSION]);
this->trackQueryPool(m_queryPools[VK_QUERY_TYPE_PIPELINE_STATISTICS]);
this->trackQueryPool(m_queryPools[VK_QUERY_TYPE_TIMESTAMP]);
m_cmd->endRecording();
return std::exchange(m_cmd, nullptr);
}
@ -1634,6 +1638,9 @@ namespace dxvk {
queryHandle = queryPool->allocQuery(query);
if (queryHandle.queryPool == VK_NULL_HANDLE) {
if (queryPool != nullptr)
this->trackQueryPool(queryPool);
m_queryPools[queryType] = m_device->createQueryPool(queryType, MaxNumQueryCountPerPool);
queryPool = m_queryPools[queryType];
@ -1652,6 +1659,16 @@ namespace dxvk {
}
void DxvkContext::trackQueryPool(const Rc<DxvkQueryPool>& pool) {
if (pool != nullptr) {
DxvkQueryRange range = pool->getActiveQueryRange();
if (range.queryCount > 0)
m_cmd->trackQueryRange(std::move(range));
}
}
void DxvkContext::beginActiveQueries() {
for (const DxvkQueryRevision& query : m_activeQueries) {
DxvkQueryHandle handle = this->allocQuery(query);

View File

@ -612,6 +612,9 @@ namespace dxvk {
void resetQueryPool(
const Rc<DxvkQueryPool>& pool);
void trackQueryPool(
const Rc<DxvkQueryPool>& pool);
void beginActiveQueries();
void endActiveQueries();

View File

@ -91,4 +91,16 @@ namespace dxvk {
m_queryRangeLength = 0;
}
DxvkQueryRange DxvkQueryPool::getActiveQueryRange() {
DxvkQueryRange result;
result.queryPool = this;
result.queryIndex = m_queryRangeOffset;
result.queryCount = m_queryRangeLength;
m_queryRangeOffset += m_queryRangeLength;
m_queryRangeLength = 0;
return result;
}
}

View File

@ -75,6 +75,16 @@ namespace dxvk {
void reset(
const Rc<DxvkCommandList>& cmd);
/**
* \brief Retrieves active query range
*
* This will also move the beginning of the
* new active query range to the end of the
* current active query range.
* \returns Active query range
*/
DxvkQueryRange getActiveQueryRange();
private:
Rc<vk::DeviceFn> m_vkd;

View File

@ -0,0 +1,24 @@
#include "dxvk_query_tracker.h"
namespace dxvk {
DxvkQueryTracker:: DxvkQueryTracker() { }
DxvkQueryTracker::~DxvkQueryTracker() { }
void DxvkQueryTracker::trackQueryRange(DxvkQueryRange&& queryRange) {
m_queries.push_back(std::move(queryRange));
}
void DxvkQueryTracker::writeQueryData() {
for (const DxvkQueryRange& curr : m_queries)
curr.queryPool->getData(curr.queryIndex, curr.queryCount);
}
void DxvkQueryTracker::reset() {
m_queries.clear();
}
}

View File

@ -0,0 +1,45 @@
#pragma once
#include "dxvk_query_pool.h"
namespace dxvk {
/**
* \brief Query tracker
*/
class DxvkQueryTracker {
public:
DxvkQueryTracker();
~DxvkQueryTracker();
/**
* \brief Adds a query range to track
* \param [in] queryRange The query range
*/
void trackQueryRange(DxvkQueryRange&& queryRange);
/**
* \brief Fetches query data
*
* Retrieves query data from the query pools
* and writes it back to the query objects.
*/
void writeQueryData();
/**
* \brief Resets query tracker
*
* Releases all query ranges from the tracker.
* Call this after writing back the query data.
*/
void reset();
private:
std::vector<DxvkQueryRange> m_queries;
};
}

View File

@ -56,6 +56,8 @@ namespace dxvk {
if (entry.fence != nullptr) {
entry.fence->wait(std::numeric_limits<uint64_t>::max());
entry.cmdList->writeQueryData();
entry.cmdList->reset();
m_device->recycleCommandList(entry.cmdList);
}

View File

@ -31,6 +31,7 @@ dxvk_src = files([
'dxvk_pipemanager.cpp',
'dxvk_query.cpp',
'dxvk_query_pool.cpp',
'dxvk_query_tracker.cpp',
'dxvk_queue.cpp',
'dxvk_renderpass.cpp',
'dxvk_resource.cpp',