1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-05 01:24:14 +01:00

[dxvk] Use small_vector to store query handles.

This commit is contained in:
Philip Rebohle 2023-03-02 17:13:03 +01:00 committed by Philip Rebohle
parent 1acf885109
commit e430ff5cfd
3 changed files with 36 additions and 27 deletions

View File

@ -18,11 +18,8 @@ namespace dxvk {
DxvkGpuQuery::~DxvkGpuQuery() { DxvkGpuQuery::~DxvkGpuQuery() {
if (m_handle.queryPool) for (size_t i = 0; i < m_handles.size(); i++)
m_handle.allocator->freeQuery(m_handle); m_handles[i].allocator->freeQuery(m_handles[i]);
for (DxvkGpuQueryHandle handle : m_handles)
handle.allocator->freeQuery(handle);
} }
@ -34,15 +31,14 @@ namespace dxvk {
DxvkGpuQueryStatus DxvkGpuQuery::getData(DxvkQueryData& queryData) const { DxvkGpuQueryStatus DxvkGpuQuery::getData(DxvkQueryData& queryData) const {
queryData = DxvkQueryData(); queryData = DxvkQueryData();
if (!m_ended) // Callers must ensure that no begin call is pending when
// calling this. Given that, once the query is ended, we
// know that no other thread will access query state.
if (!m_ended.load(std::memory_order_acquire))
return DxvkGpuQueryStatus::Invalid; return DxvkGpuQueryStatus::Invalid;
// Empty begin/end pair
if (!m_handle.queryPool)
return DxvkGpuQueryStatus::Available;
// Get query data from all associated handles // Get query data from all associated handles
DxvkGpuQueryStatus status = getDataForHandle(queryData, m_handle); DxvkGpuQueryStatus status = DxvkGpuQueryStatus::Available;
for (size_t i = 0; i < m_handles.size() for (size_t i = 0; i < m_handles.size()
&& status == DxvkGpuQueryStatus::Available; i++) && status == DxvkGpuQueryStatus::Available; i++)
@ -61,27 +57,25 @@ namespace dxvk {
void DxvkGpuQuery::begin(const Rc<DxvkCommandList>& cmd) { void DxvkGpuQuery::begin(const Rc<DxvkCommandList>& cmd) {
m_ended = false; // Not useful to enforce a memory order here since
// only the false->true transition is defined.
m_ended.store(false, std::memory_order_relaxed);
cmd->trackGpuQuery(m_handle); for (size_t i = 0; i < m_handles.size(); i++)
m_handle = DxvkGpuQueryHandle(); cmd->trackGpuQuery(m_handles[i]);
for (const auto& handle : m_handles)
cmd->trackGpuQuery(handle);
m_handles.clear(); m_handles.clear();
} }
void DxvkGpuQuery::end() { void DxvkGpuQuery::end() {
m_ended = true; // Ensure that all prior writes are made available
m_ended.store(true, std::memory_order_release);
} }
void DxvkGpuQuery::addQueryHandle(const DxvkGpuQueryHandle& handle) { void DxvkGpuQuery::addQueryHandle(const DxvkGpuQueryHandle& handle) {
if (m_handle.queryPool) m_handles.push_back(handle);
m_handles.push_back(m_handle);
m_handle = handle;
} }

View File

@ -1,8 +1,11 @@
#pragma once #pragma once
#include <atomic>
#include <mutex> #include <mutex>
#include <vector> #include <vector>
#include "../util/util_small_vector.h"
#include "dxvk_resource.h" #include "dxvk_resource.h"
namespace dxvk { namespace dxvk {
@ -149,7 +152,10 @@ namespace dxvk {
* \returns Current query handle * \returns Current query handle
*/ */
DxvkGpuQueryHandle handle() const { DxvkGpuQueryHandle handle() const {
return m_handle; if (m_handles.empty())
return DxvkGpuQueryHandle();
return m_handles.back();
} }
/** /**
@ -222,11 +228,9 @@ namespace dxvk {
VkQueryType m_type; VkQueryType m_type;
VkQueryControlFlags m_flags; VkQueryControlFlags m_flags;
uint32_t m_index; uint32_t m_index;
bool m_ended; std::atomic<bool> m_ended;
DxvkGpuQueryHandle m_handle; small_vector<DxvkGpuQueryHandle, 8> m_handles;
std::vector<DxvkGpuQueryHandle> m_handles;
DxvkGpuQueryStatus getDataForHandle( DxvkGpuQueryStatus getDataForHandle(
DxvkQueryData& queryData, DxvkQueryData& queryData,

View File

@ -90,6 +90,17 @@ namespace dxvk {
ptr(--m_size)->~T(); ptr(--m_size)->~T();
} }
void clear() {
for (size_t i = 0; i < m_size; i++)
ptr(i)->~T();
m_size = 0;
}
bool empty() const {
return m_size == 0;
}
T& operator [] (size_t idx) { return *ptr(idx); } T& operator [] (size_t idx) { return *ptr(idx); }
const T& operator [] (size_t idx) const { return *ptr(idx); } const T& operator [] (size_t idx) const { return *ptr(idx); }