From 0ccd29f2ba0fe6a6163d93207fbf32eea7c6b8f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 12 Aug 2023 13:35:21 +0200 Subject: [PATCH] Revert "OpenGL: Separate submit/present for this backend as well" This reverts commit 0143d67f9ba8f76b60a019a09292aa94caa127fb. --- Common/GPU/OpenGL/GLRenderManager.cpp | 87 ++++++++++++--------------- Common/GPU/OpenGL/GLRenderManager.h | 4 +- Common/GPU/OpenGL/thin3d_gl.cpp | 1 - libretro/libretro.cpp | 1 - 4 files changed, 39 insertions(+), 54 deletions(-) diff --git a/Common/GPU/OpenGL/GLRenderManager.cpp b/Common/GPU/OpenGL/GLRenderManager.cpp index 80dfe6d565..1e06d2ac83 100644 --- a/Common/GPU/OpenGL/GLRenderManager.cpp +++ b/Common/GPU/OpenGL/GLRenderManager.cpp @@ -377,7 +377,7 @@ void GLRenderManager::Finish() { frameData_[curFrame].deleter.Take(deleter_); VLOG("PUSH: Finish, pushing task. curFrame = %d", curFrame); - GLRRenderThreadTask *task = new GLRRenderThreadTask(GLRRunType::SUBMIT); + GLRRenderThreadTask *task = new GLRRenderThreadTask(GLRRunType::PRESENT); task->frame = curFrame; { @@ -414,56 +414,10 @@ void GLRenderManager::Finish() { insideFrame_ = false; } -void GLRenderManager::Present() { - int curFrame = GetCurFrame(); - GLRRenderThreadTask *task = new GLRRenderThreadTask(GLRRunType::PRESENT); - task->frame = curFrame; - std::unique_lock lock(pushMutex_); - renderThreadQueue_.push(task); -} - // Render thread. Returns true if the caller should handle a swap. bool GLRenderManager::Run(GLRRenderThreadTask &task) { GLFrameData &frameData = frameData_[task.frame]; - if (task.runType == GLRRunType::PRESENT) { - bool swapRequest = false; - if (!frameData.skipSwap) { - if (swapIntervalChanged_) { - swapIntervalChanged_ = false; - if (swapIntervalFunction_) { - swapIntervalFunction_(swapInterval_); - } - } - // This is the swapchain framebuffer flip. - if (swapFunction_) { - VLOG(" PULL: SwapFunction()"); - swapFunction_(); - if (!retainControl_) { - // get out of here. - swapRequest = true; - } - } else { - VLOG(" PULL: SwapRequested"); - swapRequest = true; - } - } else { - frameData.skipSwap = false; - } - frameData.hasBegun = false; - - VLOG(" PULL: Frame %d.readyForFence = true", task.frame); - - { - std::lock_guard lock(frameData.fenceMutex); - frameData.readyForFence = true; - frameData.fenceCondVar.notify_one(); - // At this point, we're done with this framedata (for now). - } - - return swapRequest; - } - if (!frameData.hasBegun) { frameData.hasBegun = true; @@ -507,8 +461,43 @@ bool GLRenderManager::Run(GLRRenderThreadTask &task) { } } + bool swapRequest = false; + switch (task.runType) { - case GLRRunType::SUBMIT: + case GLRRunType::PRESENT: + if (!frameData.skipSwap) { + if (swapIntervalChanged_) { + swapIntervalChanged_ = false; + if (swapIntervalFunction_) { + swapIntervalFunction_(swapInterval_); + } + } + // This is the swapchain framebuffer flip. + if (swapFunction_) { + VLOG(" PULL: SwapFunction()"); + swapFunction_(); + if (!retainControl_) { + // get out of here. + swapRequest = true; + } + } else { + VLOG(" PULL: SwapRequested"); + swapRequest = true; + } + } else { + frameData.skipSwap = false; + } + frameData.hasBegun = false; + + VLOG(" PULL: Frame %d.readyForFence = true", task.frame); + + { + std::lock_guard lock(frameData.fenceMutex); + frameData.readyForFence = true; + frameData.fenceCondVar.notify_one(); + // At this point, we're done with this framedata (for now). + } + break; case GLRRunType::SYNC: @@ -527,7 +516,7 @@ bool GLRenderManager::Run(GLRRenderThreadTask &task) { _assert_(false); } VLOG(" PULL: ::Run(): Done running tasks"); - return false; + return swapRequest; } void GLRenderManager::FlushSync() { diff --git a/Common/GPU/OpenGL/GLRenderManager.h b/Common/GPU/OpenGL/GLRenderManager.h index c714fb2d61..5cfc5711ed 100644 --- a/Common/GPU/OpenGL/GLRenderManager.h +++ b/Common/GPU/OpenGL/GLRenderManager.h @@ -198,7 +198,6 @@ public: }; enum class GLRRunType { - SUBMIT, PRESENT, SYNC, EXIT, @@ -254,8 +253,7 @@ public: // Makes sure that the GPU has caught up enough that we can start writing buffers of this frame again. void BeginFrame(bool enableProfiling); // Can run on a different thread! - void Finish(); - void Present(); + void Finish(); // Creation commands. These were not needed in Vulkan since there we can do that on the main thread. // We pass in width/height here even though it's not strictly needed until we support glTextureStorage diff --git a/Common/GPU/OpenGL/thin3d_gl.cpp b/Common/GPU/OpenGL/thin3d_gl.cpp index 1e261be7a0..a25644ea7f 100644 --- a/Common/GPU/OpenGL/thin3d_gl.cpp +++ b/Common/GPU/OpenGL/thin3d_gl.cpp @@ -803,7 +803,6 @@ void OpenGLContext::EndFrame() { } void OpenGLContext::Present(int vblanks) { - renderManager_.Present(); frameCount_++; } diff --git a/libretro/libretro.cpp b/libretro/libretro.cpp index 707418c62d..69d3f237fa 100644 --- a/libretro/libretro.cpp +++ b/libretro/libretro.cpp @@ -1174,7 +1174,6 @@ namespace Libretro if (ctx->GetDrawContext()) { ctx->GetDrawContext()->EndFrame(); - ctx->GetDrawContext()->Present(1); } }