From 1d3b9fdec2c8ed73ec9af95e390a6b86a699cf6f Mon Sep 17 00:00:00 2001 From: JosJuice Date: Fri, 21 May 2021 12:48:27 +0200 Subject: [PATCH] Fix perf query regression When trying to do a small optimization in 8a0f5ea, I failed to take into account that WeakFlush and FlushOne update m_query_count. Only D3D11 and OGL had this problem, not D3D12 and Vulkan. --- Source/Core/VideoBackends/D3D/D3DPerfQuery.cpp | 6 +++++- Source/Core/VideoBackends/OGL/OGLPerfQuery.cpp | 13 +++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Source/Core/VideoBackends/D3D/D3DPerfQuery.cpp b/Source/Core/VideoBackends/D3D/D3DPerfQuery.cpp index cf0e66aed5..84f341ab7a 100644 --- a/Source/Core/VideoBackends/D3D/D3DPerfQuery.cpp +++ b/Source/Core/VideoBackends/D3D/D3DPerfQuery.cpp @@ -27,16 +27,20 @@ PerfQuery::~PerfQuery() = default; void PerfQuery::EnableQuery(PerfQueryGroup type) { - const u32 query_count = m_query_count.load(std::memory_order_relaxed); + u32 query_count = m_query_count.load(std::memory_order_relaxed); // Is this sane? if (query_count > m_query_buffer.size() / 2) + { WeakFlush(); + query_count = m_query_count.load(std::memory_order_relaxed); + } if (m_query_buffer.size() == query_count) { // TODO FlushOne(); + query_count = m_query_count.load(std::memory_order_relaxed); ERROR_LOG_FMT(VIDEO, "Flushed query buffer early!"); } diff --git a/Source/Core/VideoBackends/OGL/OGLPerfQuery.cpp b/Source/Core/VideoBackends/OGL/OGLPerfQuery.cpp index 2718dd49af..12d28082c6 100644 --- a/Source/Core/VideoBackends/OGL/OGLPerfQuery.cpp +++ b/Source/Core/VideoBackends/OGL/OGLPerfQuery.cpp @@ -99,15 +99,19 @@ PerfQueryGL::~PerfQueryGL() void PerfQueryGL::EnableQuery(PerfQueryGroup type) { - const u32 query_count = m_query_count.load(std::memory_order_relaxed); + u32 query_count = m_query_count.load(std::memory_order_relaxed); // Is this sane? if (query_count > m_query_buffer.size() / 2) + { WeakFlush(); + query_count = m_query_count.load(std::memory_order_relaxed); + } if (m_query_buffer.size() == query_count) { FlushOne(); + query_count = m_query_count.load(std::memory_order_relaxed); // ERROR_LOG_FMT(VIDEO, "Flushed query buffer early!"); } @@ -195,14 +199,19 @@ PerfQueryGLESNV::~PerfQueryGLESNV() void PerfQueryGLESNV::EnableQuery(PerfQueryGroup type) { - const u32 query_count = m_query_count.load(std::memory_order_relaxed); + u32 query_count = m_query_count.load(std::memory_order_relaxed); + // Is this sane? if (query_count > m_query_buffer.size() / 2) + { WeakFlush(); + query_count = m_query_count.load(std::memory_order_relaxed); + } if (m_query_buffer.size() == query_count) { FlushOne(); + query_count = m_query_count.load(std::memory_order_relaxed); // ERROR_LOG_FMT(VIDEO, "Flushed query buffer early!"); }