From e2b931d6d82f08298746b2707fd599f2e5a2834c Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Fri, 15 Nov 2024 20:33:57 +0100 Subject: [PATCH] ImguiSystem: perform atomic exchange before acquiring snapshot lock Significantly improves performance when none of the imgui surfaces are being drawn. --- src/gameui/imgui_system.cpp | 5 ++--- src/gameui/imgui_system.h | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/gameui/imgui_system.cpp b/src/gameui/imgui_system.cpp index cbc480c6..2d5d4bd0 100644 --- a/src/gameui/imgui_system.cpp +++ b/src/gameui/imgui_system.cpp @@ -155,13 +155,12 @@ void CImguiSystem::SwapBuffers() void CImguiSystem::RenderFrame() { Assert(IsInitialized()); - AUTO_LOCK(m_snapshotBufferMutex); - if (!m_hasNewFrame) + if (!m_hasNewFrame.exchange(false)) return; + AUTO_LOCK(m_snapshotBufferMutex); ImGui_ImplDX11_RenderDrawData(&m_snapshotData.DrawData); - m_hasNewFrame = false; } //----------------------------------------------------------------------------- diff --git a/src/gameui/imgui_system.h b/src/gameui/imgui_system.h index 7759b86f..ddc7fd74 100644 --- a/src/gameui/imgui_system.h +++ b/src/gameui/imgui_system.h @@ -46,7 +46,7 @@ private: mutable CThreadMutex m_inputEventQueueMutex; bool m_initialized; - bool m_hasNewFrame; + std::atomic_bool m_hasNewFrame; }; CImguiSystem* ImguiSystem();