From fd38e33fb25723ae105045fe411c767605d614d9 Mon Sep 17 00:00:00 2001 From: GPUCode Date: Sun, 20 Aug 2023 16:54:08 +0300 Subject: [PATCH] vk_renderpass_cache: Bring back renderpass flushing --- src/video_core/renderer_vulkan/vk_renderpass_cache.cpp | 10 ++++++++++ src/video_core/renderer_vulkan/vk_renderpass_cache.h | 1 + 2 files changed, 11 insertions(+) diff --git a/src/video_core/renderer_vulkan/vk_renderpass_cache.cpp b/src/video_core/renderer_vulkan/vk_renderpass_cache.cpp index 845f1f279..f9fc22bc5 100644 --- a/src/video_core/renderer_vulkan/vk_renderpass_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_renderpass_cache.cpp @@ -12,6 +12,8 @@ namespace Vulkan { +constexpr u32 MIN_DRAWS_TO_FLUSH = 20; + using VideoCore::PixelFormat; using VideoCore::SurfaceType; @@ -46,6 +48,7 @@ void RenderpassCache::BeginRendering(const Framebuffer* framebuffer, void RenderpassCache::BeginRendering(const RenderPass& new_pass) { if (pass == new_pass) [[likely]] { + num_draws++; return; } @@ -111,6 +114,13 @@ void RenderpassCache::EndRendering() { vk::DependencyFlagBits::eByRegion, 0, nullptr, 0, nullptr, num_barriers, barriers.data()); }); + + // The Mali guide recommends flushing at the end of each major renderpass + // Testing has shown this has a significant effect on rendering performance + if (num_draws > MIN_DRAWS_TO_FLUSH && instance.ShouldFlush()) { + scheduler.Flush(); + num_draws = 0; + } } vk::RenderPass RenderpassCache::GetRenderpass(VideoCore::PixelFormat color, diff --git a/src/video_core/renderer_vulkan/vk_renderpass_cache.h b/src/video_core/renderer_vulkan/vk_renderpass_cache.h index 64cb960b8..64f9931a2 100644 --- a/src/video_core/renderer_vulkan/vk_renderpass_cache.h +++ b/src/video_core/renderer_vulkan/vk_renderpass_cache.h @@ -68,6 +68,7 @@ private: std::array images; std::array aspects; RenderPass pass{}; + u32 num_draws{}; }; } // namespace Vulkan