From ffd5e57a2038eecf6fc7967bba0e21d0aab0b20e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 1 Aug 2023 21:07:33 +0200 Subject: [PATCH] Vulkan: Don't use multithreaded rendering if frames-in-flight is set to 1 It has no benefit, and loses by a few percent in simple benchmarking. --- Common/GPU/thin3d.h | 1 - SDL/SDLVulkanGraphicsContext.cpp | 6 +++++- Windows/GPU/WindowsVulkanContext.cpp | 7 ++++++- android/jni/AndroidVulkanContext.cpp | 6 +++++- libretro/LibretroVulkanContext.cpp | 6 +++++- 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/Common/GPU/thin3d.h b/Common/GPU/thin3d.h index 5213726c943d..994390d36338 100644 --- a/Common/GPU/thin3d.h +++ b/Common/GPU/thin3d.h @@ -843,7 +843,6 @@ class DrawContext { // Total amount of frames rendered. Unaffected by game pause, so more robust than gpuStats.numFlips virtual int GetFrameCount() = 0; - virtual int GetFramesInFlight() { return 3; } protected: ShaderModule *vsPresets_[VS_MAX_PRESET]; diff --git a/SDL/SDLVulkanGraphicsContext.cpp b/SDL/SDLVulkanGraphicsContext.cpp index 270a8f30a1c4..f58ae422dd44 100644 --- a/SDL/SDLVulkanGraphicsContext.cpp +++ b/SDL/SDLVulkanGraphicsContext.cpp @@ -136,7 +136,11 @@ bool SDLVulkanGraphicsContext::Init(SDL_Window *&window, int x, int y, int w, in return false; } - draw_ = Draw::T3DCreateVulkanContext(vulkan_, g_Config.bRenderMultiThreading); + bool useMultiThreading = g_Config.bRenderMultiThreading; + if (g_Config.iInflightFrames == 1) { + useMultiThreading = false; + } + draw_ = Draw::T3DCreateVulkanContext(vulkan_, useMultiThreading); SetGPUBackend(GPUBackend::VULKAN); bool success = draw_->CreatePresets(); _assert_(success); diff --git a/Windows/GPU/WindowsVulkanContext.cpp b/Windows/GPU/WindowsVulkanContext.cpp index e4c31ab8e9b1..71347e8e5554 100644 --- a/Windows/GPU/WindowsVulkanContext.cpp +++ b/Windows/GPU/WindowsVulkanContext.cpp @@ -131,7 +131,12 @@ bool WindowsVulkanContext::Init(HINSTANCE hInst, HWND hWnd, std::string *error_m return false; } - draw_ = Draw::T3DCreateVulkanContext(vulkan_, g_Config.bRenderMultiThreading); + bool useMultiThreading = g_Config.bRenderMultiThreading; + if (g_Config.iInflightFrames == 1) { + useMultiThreading = false; + } + + draw_ = Draw::T3DCreateVulkanContext(vulkan_, useMultiThreading); SetGPUBackend(GPUBackend::VULKAN, vulkan_->GetPhysicalDeviceProperties(deviceNum).properties.deviceName); bool success = draw_->CreatePresets(); _assert_msg_(success, "Failed to compile preset shaders"); diff --git a/android/jni/AndroidVulkanContext.cpp b/android/jni/AndroidVulkanContext.cpp index 18ef569a1296..6a501c68f90d 100644 --- a/android/jni/AndroidVulkanContext.cpp +++ b/android/jni/AndroidVulkanContext.cpp @@ -113,7 +113,11 @@ bool AndroidVulkanContext::InitFromRenderThread(ANativeWindow *wnd, int desiredB bool success = true; if (g_Vulkan->InitSwapchain()) { - draw_ = Draw::T3DCreateVulkanContext(g_Vulkan, g_Config.bRenderMultiThreading); + bool useMultiThreading = g_Config.bRenderMultiThreading; + if (g_Config.iInflightFrames == 1) { + useMultiThreading = false; + } + draw_ = Draw::T3DCreateVulkanContext(g_Vulkan, useMultiThreading); SetGPUBackend(GPUBackend::VULKAN); success = draw_->CreatePresets(); // Doesn't fail, we ship the compiler. _assert_msg_(success, "Failed to compile preset shaders"); diff --git a/libretro/LibretroVulkanContext.cpp b/libretro/LibretroVulkanContext.cpp index c07a000bcc27..ccce6c9ad5e3 100644 --- a/libretro/LibretroVulkanContext.cpp +++ b/libretro/LibretroVulkanContext.cpp @@ -139,7 +139,11 @@ void LibretroVulkanContext::CreateDrawContext() { return; } - draw_ = Draw::T3DCreateVulkanContext(vk, true); + bool useMultiThreading = g_Config.bRenderMultiThreading; + if (g_Config.iInflightFrames == 1) { + useMultiThreading = false; + } + draw_ = Draw::T3DCreateVulkanContext(vk, useMultiThreading); ((VulkanRenderManager*)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER))->SetInflightFrames(g_Config.iInflightFrames); SetGPUBackend(GPUBackend::VULKAN); }