From ed6f7bd14fc5b140ab9dc9369e22b8e8cd614906 Mon Sep 17 00:00:00 2001 From: crueter Date: Sun, 3 Aug 2025 12:23:44 -0400 Subject: [PATCH] [video_core] optimized fence management Co-authored-by: Pavel Barabanov Signed-off-by: crueter --- src/video_core/fence_manager.h | 96 ++++++++++++++-------------------- 1 file changed, 40 insertions(+), 56 deletions(-) diff --git a/src/video_core/fence_manager.h b/src/video_core/fence_manager.h index 4ead784c00..0f927159ba 100644 --- a/src/video_core/fence_manager.h +++ b/src/video_core/fence_manager.h @@ -11,14 +11,11 @@ #include #include #include -#include #include #include #include #include "common/common_types.h" -#include "common/microprofile.h" -#include "common/scope_exit.h" #include "common/settings.h" #include "common/thread.h" #include "video_core/delayed_destruction_ring.h" @@ -75,18 +72,41 @@ public: } void SignalFence(std::function&& func) { - bool delay_fence = Settings::IsGPULevelHigh(); - HandleAndroidPreFenceOperations(delay_fence); + const bool delay_fence = Settings::IsGPULevelHigh(); + + #ifdef __ANDROID__ + const bool use_optimized = Settings::values.early_release_fences.GetValue(); + #else + constexpr bool use_optimized = false; + #endif const bool should_flush = ShouldFlush(); CommitAsyncFlushes(); TFence new_fence = CreateFence(!should_flush); - LockGuardIfNeeded(delay_fence); + if (use_optimized) { + if (!delay_fence) { + TryReleasePendingFences(); + } - if (delay_fence) { - uncommitted_operations.emplace_back(std::move(func)); + if (delay_fence) { + guard.lock(); + uncommitted_operations.emplace_back(std::move(func)); + } + } else { + if constexpr (!can_async_check) { + TryReleasePendingFences(); + } + + if constexpr (can_async_check) { + guard.lock(); + } + + if (delay_fence) { + uncommitted_operations.emplace_back(std::move(func)); + } } + pending_operations.emplace_back(std::move(uncommitted_operations)); QueueFence(new_fence); @@ -100,7 +120,18 @@ public: rasterizer.FlushCommands(); } - UnlockGuardAndNotifyIfNeeded(delay_fence); + if (use_optimized) { + if (delay_fence) { + guard.unlock(); + cv.notify_all(); + } + } else { + if constexpr (can_async_check) { + guard.unlock(); + cv.notify_all(); + } + } + rasterizer.InvalidateGPUCache(); } @@ -197,14 +228,6 @@ private: void ReleaseThreadFunc(std::stop_token stop_token) { std::string name = "GPUFencingThread"; - MicroProfileOnThreadCreate(name.c_str()); - - // Cleanup -#if MICROPROFILE_ENABLED - SCOPE_EXIT { - MicroProfileOnThreadExit(); - }; -#endif Common::SetCurrentThreadName(name.c_str()); Common::SetCurrentThreadPriority(Common::ThreadPriority::High); @@ -266,46 +289,7 @@ private: } query_cache.CommitAsyncFlushes(); } - void HandleAndroidPreFenceOperations(bool delay_fence) - { -#ifdef __ANDROID__ - if (!delay_fence && Settings::values.early_release_fences.GetValue()) { - TryReleasePendingFences(); - } -#else - if constexpr (!can_async_check) { - TryReleasePendingFences(); - } -#endif - } - - void LockGuardIfNeeded(bool delay_fence) - { -#ifdef __ANDROID__ - if (delay_fence && Settings::values.early_release_fences.GetValue()) { - guard.lock(); - } -#else - if constexpr (can_async_check) { - guard.lock(); - } -#endif - } - void UnlockGuardAndNotifyIfNeeded(bool delay_fence) - { -#ifdef __ANDROID__ - if (delay_fence && Settings::values.early_release_fences.GetValue()) { - guard.unlock(); - cv.notify_all(); - } -#else - if constexpr (can_async_check) { - guard.unlock(); - cv.notify_all(); - } -#endif - } std::queue fences; std::deque> uncommitted_operations; std::deque>> pending_operations;