From 3435702719d5c1be321562dc478f587f173c3b6e Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Thu, 6 Sep 2018 12:50:44 +0200 Subject: [PATCH] [dxvk] Add basic support for indexed queries --- src/dxvk/dxvk_query.cpp | 12 +++++- src/dxvk/dxvk_query.h | 25 ++++++++++- src/dxvk/dxvk_query_manager.cpp | 76 ++++++++++++++++++++------------- src/dxvk/dxvk_query_manager.h | 8 ++++ src/dxvk/dxvk_query_pool.cpp | 1 + 5 files changed, 88 insertions(+), 34 deletions(-) diff --git a/src/dxvk/dxvk_query.cpp b/src/dxvk/dxvk_query.cpp index 0b054913..c8da6576 100644 --- a/src/dxvk/dxvk_query.cpp +++ b/src/dxvk/dxvk_query.cpp @@ -4,8 +4,11 @@ namespace dxvk { DxvkQuery::DxvkQuery( VkQueryType type, - VkQueryControlFlags flags) - : m_type(type), m_flags(flags) { + VkQueryControlFlags flags, + uint32_t index) + : m_type (type), + m_flags (flags), + m_index (index) { } @@ -15,6 +18,11 @@ namespace dxvk { } + bool DxvkQuery::isIndexed() const { + return false; + } + + uint32_t DxvkQuery::reset() { std::unique_lock lock(m_mutex); diff --git a/src/dxvk/dxvk_query.h b/src/dxvk/dxvk_query.h index 4f735b7f..a62c0952 100644 --- a/src/dxvk/dxvk_query.h +++ b/src/dxvk/dxvk_query.h @@ -81,6 +81,7 @@ namespace dxvk { VkQueryPool queryPool = VK_NULL_HANDLE; uint32_t queryId = 0; VkQueryControlFlags flags = 0; + uint32_t index = 0; }; /** @@ -91,12 +92,13 @@ namespace dxvk { * submissions, we need to */ class DxvkQuery : public RcObject { - + public: DxvkQuery( VkQueryType type, - VkQueryControlFlags flags); + VkQueryControlFlags flags, + uint32_t index = ~0u); ~DxvkQuery(); /** @@ -117,6 +119,24 @@ namespace dxvk { VkQueryControlFlags flags() const { return m_flags; } + + /** + * \brief Query type index + * + * The query type index. Will be undefined if the + * query type is not indexed. Not to be confused + * with the query index within the query pool. + * \returns Query type index + */ + uint32_t index() const { + return m_index; + } + + /** + * \brief Checks whether the query type is indexed + * \returns \c true if the query type is indexed + */ + bool isIndexed() const; /** * \brief Resets the query object @@ -188,6 +208,7 @@ namespace dxvk { const VkQueryType m_type; const VkQueryControlFlags m_flags; + const uint32_t m_index; std::mutex m_mutex; diff --git a/src/dxvk/dxvk_query_manager.cpp b/src/dxvk/dxvk_query_manager.cpp index a1a28d1c..3aa4fb67 100644 --- a/src/dxvk/dxvk_query_manager.cpp +++ b/src/dxvk/dxvk_query_manager.cpp @@ -44,14 +44,8 @@ namespace dxvk { const DxvkQueryRevision& query) { m_activeQueries.push_back(query); - if (m_activeTypes & getDxvkQueryTypeBit(query.query->type())) { - DxvkQueryHandle handle = this->allocQuery(cmd, query); - - cmd->cmdBeginQuery( - handle.queryPool, - handle.queryId, - handle.flags); - } + if (m_activeTypes & getDxvkQueryTypeBit(query.query->type())) + this->beginVulkanQuery(cmd, query); } @@ -69,13 +63,8 @@ namespace dxvk { } if (iter != m_activeQueries.end()) { - if (m_activeTypes & getDxvkQueryTypeBit(iter->query->type())) { - DxvkQueryHandle handle = iter->query->getHandle(); - - cmd->cmdEndQuery( - handle.queryPool, - handle.queryId); - } + if (m_activeTypes & getDxvkQueryTypeBit(iter->query->type())) + this->endVulkanQuery(cmd, query); m_activeQueries.erase(iter); } @@ -88,14 +77,8 @@ namespace dxvk { m_activeTypes |= getDxvkQueryTypeBit(type); for (const DxvkQueryRevision& query : m_activeQueries) { - if (type == query.query->type()) { - DxvkQueryHandle handle = this->allocQuery(cmd, query); - - cmd->cmdBeginQuery( - handle.queryPool, - handle.queryId, - handle.flags); - } + if (type == query.query->type()) + this->beginVulkanQuery(cmd, query); } } @@ -106,13 +89,8 @@ namespace dxvk { m_activeTypes &= ~getDxvkQueryTypeBit(type); for (const DxvkQueryRevision& query : m_activeQueries) { - if (type == query.query->type()) { - DxvkQueryHandle handle = query.query->getHandle(); - - cmd->cmdEndQuery( - handle.queryPool, - handle.queryId); - } + if (type == query.query->type()) + this->endVulkanQuery(cmd, query); } } @@ -136,6 +114,44 @@ namespace dxvk { } + void DxvkQueryManager::beginVulkanQuery( + const Rc& cmd, + const DxvkQueryRevision& query) { + DxvkQueryHandle handle = this->allocQuery(cmd, query); + + if (query.query->isIndexed()) { + cmd->cmdBeginQueryIndexed( + handle.queryPool, + handle.queryId, + handle.flags, + handle.index); + } else { + cmd->cmdBeginQuery( + handle.queryPool, + handle.queryId, + handle.flags); + } + } + + + void DxvkQueryManager::endVulkanQuery( + const Rc& cmd, + const DxvkQueryRevision& query) { + DxvkQueryHandle handle = query.query->getHandle(); + + if (query.query->isIndexed()) { + cmd->cmdEndQueryIndexed( + handle.queryPool, + handle.queryId, + handle.index); + } else { + cmd->cmdEndQuery( + handle.queryPool, + handle.queryId); + } + } + + Rc& DxvkQueryManager::getQueryPool(VkQueryType type) { switch (type) { case VK_QUERY_TYPE_OCCLUSION: diff --git a/src/dxvk/dxvk_query_manager.h b/src/dxvk/dxvk_query_manager.h index 5d8216f1..3674d29a 100644 --- a/src/dxvk/dxvk_query_manager.h +++ b/src/dxvk/dxvk_query_manager.h @@ -108,6 +108,14 @@ namespace dxvk { const Rc& cmd, const Rc& pool); + void beginVulkanQuery( + const Rc& cmd, + const DxvkQueryRevision& query); + + void endVulkanQuery( + const Rc& cmd, + const DxvkQueryRevision& query); + Rc& getQueryPool( VkQueryType type); diff --git a/src/dxvk/dxvk_query_pool.cpp b/src/dxvk/dxvk_query_pool.cpp index b0a5972c..0fb17cb0 100644 --- a/src/dxvk/dxvk_query_pool.cpp +++ b/src/dxvk/dxvk_query_pool.cpp @@ -54,6 +54,7 @@ namespace dxvk { result.queryPool = m_queryPool; result.queryId = queryIndex; result.flags = query.query->flags(); + result.index = query.query->index(); query.query->associateQuery(query.revision, result); m_queries.at(queryIndex) = query;