From 377704f195c25cfc8466d8452fbcb3fc29ba2f6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 13 Aug 2023 18:22:44 +0200 Subject: [PATCH] OpenGL: Split submit and presentation into two tasks, but schedule them together --- Common/GPU/OpenGL/GLRenderManager.cpp | 73 +++++++++++++++------------ Common/GPU/OpenGL/GLRenderManager.h | 1 + 2 files changed, 42 insertions(+), 32 deletions(-) diff --git a/Common/GPU/OpenGL/GLRenderManager.cpp b/Common/GPU/OpenGL/GLRenderManager.cpp index d9130dd4bb..695220d154 100644 --- a/Common/GPU/OpenGL/GLRenderManager.cpp +++ b/Common/GPU/OpenGL/GLRenderManager.cpp @@ -378,9 +378,8 @@ void GLRenderManager::Finish() { frameData_[curFrame].deleter.Take(deleter_); VLOG("PUSH: Finish, pushing task. curFrame = %d", curFrame); - GLRRenderThreadTask *task = new GLRRenderThreadTask(GLRRunType::PRESENT); + GLRRenderThreadTask *task = new GLRRenderThreadTask(GLRRunType::SUBMIT); task->frame = curFrame; - { std::unique_lock lock(pushMutex_); renderThreadQueue_.push(task); @@ -388,6 +387,11 @@ void GLRenderManager::Finish() { renderThreadQueue_.back()->steps = std::move(steps_); initSteps_.clear(); steps_.clear(); + + GLRRenderThreadTask *presentTask = new GLRRenderThreadTask(GLRRunType::PRESENT); + presentTask->frame = curFrame; + renderThreadQueue_.push(presentTask); + pushCondVar_.notify_one(); } @@ -417,8 +421,41 @@ void GLRenderManager::Finish() { // Render thread. Returns true if the caller should handle a swap. bool GLRenderManager::Run(GLRRenderThreadTask &task) { + _dbg_assert_(task.frame >= 0); + 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_(); + } + 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; @@ -462,36 +499,8 @@ bool GLRenderManager::Run(GLRRenderThreadTask &task) { } } - bool swapRequest = false; - switch (task.runType) { - 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_(); - } - 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). - } + case GLRRunType::SUBMIT: break; case GLRRunType::SYNC: @@ -510,7 +519,7 @@ bool GLRenderManager::Run(GLRRenderThreadTask &task) { _assert_(false); } VLOG(" PULL: ::Run(): Done running tasks"); - return swapRequest; + return false; } void GLRenderManager::FlushSync() { diff --git a/Common/GPU/OpenGL/GLRenderManager.h b/Common/GPU/OpenGL/GLRenderManager.h index 5d3457d9ac..f155c33dd9 100644 --- a/Common/GPU/OpenGL/GLRenderManager.h +++ b/Common/GPU/OpenGL/GLRenderManager.h @@ -198,6 +198,7 @@ public: }; enum class GLRRunType { + SUBMIT, PRESENT, SYNC, EXIT,