diff --git a/Common/Vulkan/VulkanContext.cpp b/Common/Vulkan/VulkanContext.cpp index cb4dc0b33..9d5837788 100644 --- a/Common/Vulkan/VulkanContext.cpp +++ b/Common/Vulkan/VulkanContext.cpp @@ -285,6 +285,14 @@ void VulkanContext::EndFrame() { } } +void VulkanContext::UpdateInflightFrames(int n) { + assert(n >= 1 && n <= MAX_INFLIGHT_FRAMES); + inflightFrames_ = n; + if (curFrame_ >= inflightFrames_) { + curFrame_ = 0; + } +} + void VulkanContext::WaitUntilQueueIdle() { // Should almost never be used vkQueueWaitIdle(gfx_queue_); diff --git a/Common/Vulkan/VulkanContext.h b/Common/Vulkan/VulkanContext.h index fccc3dc98..40eb6a78e 100644 --- a/Common/Vulkan/VulkanContext.h +++ b/Common/Vulkan/VulkanContext.h @@ -249,6 +249,8 @@ public: int GetInflightFrames() const { return inflightFrames_; } + // Don't call while a frame is in progress. + void UpdateInflightFrames(int n); int GetCurFrame() const { return curFrame_; diff --git a/Core/Config.cpp b/Core/Config.cpp index d73c00276..e1bbe8ddb 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -772,6 +772,8 @@ static ConfigSetting graphicsSettings[] = { ConfigSetting("GfxDebugSplitSubmit", &g_Config.bGfxDebugSplitSubmit, false, false, false), ConfigSetting("LogFrameDrops", &g_Config.bLogFrameDrops, false, true, false), + ConfigSetting("UseInflightFrames", &g_Config.bUseInflightFrames, true, true, true), + ConfigSetting(false), }; diff --git a/Core/Config.h b/Core/Config.h index 68f938be7..62ee4733d 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -195,6 +195,7 @@ public: std::string sPostShaderName; // Off for off. bool bGfxDebugOutput; bool bGfxDebugSplitSubmit; + bool bUseInflightFrames; // Sound bool bEnableSound; diff --git a/Core/FileLoaders/RamCachingFileLoader.cpp b/Core/FileLoaders/RamCachingFileLoader.cpp index 9ea0c2e61..bc99ad80f 100644 --- a/Core/FileLoaders/RamCachingFileLoader.cpp +++ b/Core/FileLoaders/RamCachingFileLoader.cpp @@ -78,7 +78,7 @@ size_t RamCachingFileLoader::ReadAt(s64 absolutePos, size_t bytes, void *data, F size_t bytesFromCache = ReadFromCache(absolutePos + readSize, bytes - readSize, (u8 *)data + readSize); readSize += bytesFromCache; if (bytesFromCache == 0) { - // We can't read any more. + // We can't read any more. break; } } diff --git a/GPU/GLES/GPU_GLES.cpp b/GPU/GLES/GPU_GLES.cpp index 97b0ecf17..3fa59b525 100644 --- a/GPU/GLES/GPU_GLES.cpp +++ b/GPU/GLES/GPU_GLES.cpp @@ -97,6 +97,9 @@ GPU_GLES::GPU_GLES(GraphicsContext *gfxCtx, Draw::DrawContext *draw) textureCacheGL_->NotifyConfigChanged(); + GLRenderManager *rm = (GLRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER); + rm->UseInflightFrames(g_Config.bUseInflightFrames); + // Load shader cache. std::string discID = g_paramSFO.GetDiscID(); if (discID.size()) { @@ -355,6 +358,9 @@ void GPU_GLES::BeginHostFrame() { GPUCommon::BeginHostFrame(); UpdateCmdInfo(); if (resized_) { + GLRenderManager *rm = (GLRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER); + rm->UseInflightFrames(g_Config.bUseInflightFrames); + CheckGPUFeatures(); framebufferManager_->Resized(); drawEngine_.Resized(); diff --git a/GPU/Vulkan/GPU_Vulkan.cpp b/GPU/Vulkan/GPU_Vulkan.cpp index 3f20ec064..464adaf0b 100644 --- a/GPU/Vulkan/GPU_Vulkan.cpp +++ b/GPU/Vulkan/GPU_Vulkan.cpp @@ -28,7 +28,6 @@ #include "Core/Config.h" #include "Core/Debugger/Breakpoints.h" #include "Core/MemMapHelpers.h" -#include "Core/Config.h" #include "Core/Reporting.h" #include "Core/System.h" #include "Core/ELF/ParamSFO.h" @@ -99,6 +98,8 @@ GPU_Vulkan::GPU_Vulkan(GraphicsContext *gfxCtx, Draw::DrawContext *draw) if (vulkan_->GetDeviceFeatures().enabled.wideLines) { drawEngine_.SetLineWidth(PSP_CoreParameter().renderWidth / 480.0f); } + VulkanRenderManager *rm = (VulkanRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER); + rm->UseInflightFrames(g_Config.bUseInflightFrames); // Load shader cache. std::string discID = g_paramSFO.GetDiscID(); @@ -276,6 +277,9 @@ void GPU_Vulkan::BeginHostFrame() { UpdateCmdInfo(); if (resized_) { + VulkanRenderManager *rm = (VulkanRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER); + rm->UseInflightFrames(g_Config.bUseInflightFrames); + CheckGPUFeatures(); // In case the GPU changed. BuildReportingInfo(); diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index a6fae59fa..26a032902 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -345,6 +345,14 @@ void GameSettingsScreen::CreateViews() { graphicsSettings->Add(new CheckBox(&g_Config.bVSync, gr->T("VSync"))); #endif + if (GetGPUBackend() == GPUBackend::VULKAN || GetGPUBackend() == GPUBackend::OPENGL) { + CheckBox *inflightFrames = graphicsSettings->Add(new CheckBox(&g_Config.bUseInflightFrames, gr->T("Buffer graphics commands (faster, input lag)"))); + inflightFrames->OnClick.Add([=](EventParams &e) { + NativeMessageReceived("gpu_resized", ""); + return UI::EVENT_CONTINUE; + }); + } + CheckBox *hwTransform = graphicsSettings->Add(new CheckBox(&g_Config.bHardwareTransform, gr->T("Hardware Transform"))); hwTransform->OnClick.Handle(this, &GameSettingsScreen::OnHardwareTransform); hwTransform->SetDisabledPtr(&g_Config.bSoftwareRendering); diff --git a/ext/native/thin3d/GLRenderManager.cpp b/ext/native/thin3d/GLRenderManager.cpp index f3fe9ce65..e34168111 100644 --- a/ext/native/thin3d/GLRenderManager.cpp +++ b/ext/native/thin3d/GLRenderManager.cpp @@ -166,7 +166,7 @@ bool GLRenderManager::ThreadFrame() { do { if (nextFrame) { threadFrame_++; - if (threadFrame_ >= MAX_INFLIGHT_FRAMES) + if (threadFrame_ >= inflightFrames_) threadFrame_ = 0; } FrameData &frameData = frameData_[threadFrame_]; @@ -449,7 +449,11 @@ void GLRenderManager::Finish() { frameData.pull_condVar.notify_all(); curFrame_++; - if (curFrame_ >= MAX_INFLIGHT_FRAMES) + if (newInflightFrames_ != -1) { + inflightFrames_ = newInflightFrames_; + newInflightFrames_ = -1; + } + if (curFrame_ >= inflightFrames_) curFrame_ = 0; insideFrame_ = false; diff --git a/ext/native/thin3d/GLRenderManager.h b/ext/native/thin3d/GLRenderManager.h index d7d6f54b7..69838cc52 100644 --- a/ext/native/thin3d/GLRenderManager.h +++ b/ext/native/thin3d/GLRenderManager.h @@ -862,6 +862,10 @@ public: enum { MAX_INFLIGHT_FRAMES = 3 }; + void UseInflightFrames(bool use) { + newInflightFrames_ = use ? MAX_INFLIGHT_FRAMES : 1; + } + int GetCurFrame() const { return curFrame_; } @@ -988,6 +992,9 @@ private: std::function swapIntervalFunction_; GLBufferStrategy bufferStrategy_ = GLBufferStrategy::SUBDATA; + int inflightFrames_ = MAX_INFLIGHT_FRAMES; + int newInflightFrames_ = -1; + int swapInterval_ = 0; bool swapIntervalChanged_ = true; diff --git a/ext/native/thin3d/VulkanRenderManager.cpp b/ext/native/thin3d/VulkanRenderManager.cpp index f6c4778c6..21dd931fb 100644 --- a/ext/native/thin3d/VulkanRenderManager.cpp +++ b/ext/native/thin3d/VulkanRenderManager.cpp @@ -914,6 +914,10 @@ void VulkanRenderManager::Finish() { frameData.pull_condVar.notify_all(); } vulkan_->EndFrame(); + if (newInflightFrames_ != -1) { + vulkan_->UpdateInflightFrames(newInflightFrames_); + newInflightFrames_ = -1; + } insideFrame_ = false; } diff --git a/ext/native/thin3d/VulkanRenderManager.h b/ext/native/thin3d/VulkanRenderManager.h index c14c894a7..837e0e37b 100644 --- a/ext/native/thin3d/VulkanRenderManager.h +++ b/ext/native/thin3d/VulkanRenderManager.h @@ -240,6 +240,10 @@ public: splitSubmit_ = split; } + void UseInflightFrames(bool use) { + newInflightFrames_ = use ? VulkanContext::MAX_INFLIGHT_FRAMES : 1; + } + VulkanContext *GetVulkanContext() { return vulkan_; } @@ -302,6 +306,7 @@ private: }; FrameData frameData_[VulkanContext::MAX_INFLIGHT_FRAMES]; + int newInflightFrames_ = -1; // Submission time state int curWidth_ = -1;