diff --git a/Common/GPU/Vulkan/VulkanRenderManager.cpp b/Common/GPU/Vulkan/VulkanRenderManager.cpp index 9a33896d0f..4f580d5f26 100644 --- a/Common/GPU/Vulkan/VulkanRenderManager.cpp +++ b/Common/GPU/Vulkan/VulkanRenderManager.cpp @@ -433,7 +433,7 @@ void VulkanRenderManager::StopThreads() { // Not sure this is a sensible check - should be ok even if not. // _dbg_assert_(steps_.empty()); - _dbg_assert_(renderThread_.joinable()); + _dbg_assert_(!useRenderThread_ || renderThread_.joinable()); if (useRenderThread_ && renderThread_.joinable()) { // Tell the render thread to quit when it's done. VKRRenderThreadTask *task = new VKRRenderThreadTask(VKRRunType::EXIT); diff --git a/Windows/EmuThread.cpp b/Windows/EmuThread.cpp index fcbe2c42ba..edebbd644f 100644 --- a/Windows/EmuThread.cpp +++ b/Windows/EmuThread.cpp @@ -11,15 +11,12 @@ #include "Common/Log.h" #include "Common/StringUtils.h" #include "Common/GraphicsContext.h" -#include "Common/TimeUtil.h" #include "Common/Thread/ThreadUtil.h" #include "Windows/EmuThread.h" #include "Windows/W32Util/Misc.h" #include "Windows/MainWindow.h" -#include "Windows/resource.h" #include "Core/Reporting.h" -#include "Core/MemMap.h" #include "Core/Core.h" #include "Core/System.h" #include "Core/Config.h" @@ -166,7 +163,6 @@ void MainThreadFunc(int argc, const char *argv[]) { const bool performingRestart = NativeIsRestarting(); NativeInit(argc, argv, "", "", nullptr); - if (g_Config.sFailedGPUBackends.find("ALL") != std::string::npos) { Reporting::ReportMessage("Graphics init error: %s", "ALL"); diff --git a/headless/Headless.cpp b/headless/Headless.cpp index f2e984c67e..a70910d47a 100644 --- a/headless/Headless.cpp +++ b/headless/Headless.cpp @@ -262,7 +262,7 @@ bool RunAutoTest(HeadlessHost *headlessHost, CoreParameter &coreParameter, const } if (draw) { - draw->BindFramebufferAsRenderTarget(nullptr, { Draw::RPAction::CLEAR, Draw::RPAction::DONT_CARE, Draw::RPAction::DONT_CARE }, "Backbuffer"); + draw->BindFramebufferAsRenderTarget(nullptr, { Draw::RPAction::CLEAR, Draw::RPAction::DONT_CARE, Draw::RPAction::DONT_CARE }, "BackBuffer"); // Vulkan may get angry if we don't do a final present. if (gpu) { gpu->SetCurFramebufferDirty(true); diff --git a/headless/WindowsHeadlessHost.cpp b/headless/WindowsHeadlessHost.cpp index 76f1d1ceca..b58dad31bd 100644 --- a/headless/WindowsHeadlessHost.cpp +++ b/headless/WindowsHeadlessHost.cpp @@ -29,6 +29,7 @@ #include "Common/Log.h" #include "Common/File/FileUtil.h" #include "Common/TimeUtil.h" +#include "Common/Thread/ThreadUtil.h" #include "Core/CoreParameter.h" #include "Core/System.h" @@ -81,13 +82,11 @@ bool WindowsHeadlessHost::InitGraphics(std::string *error_message, GraphicsConte } WindowsGraphicsContext *graphicsContext = nullptr; - bool needRenderThread = false; switch (gpuCore_) { case GPUCORE_GLES: #if PPSSPP_API(ANY_GL) case GPUCORE_SOFTWARE: graphicsContext = new WindowsGLContext(); - needRenderThread = true; break; #endif case GPUCORE_DIRECTX11: @@ -112,8 +111,11 @@ bool WindowsHeadlessHost::InitGraphics(std::string *error_message, GraphicsConte return false; } + bool needRenderThread = gpuCore_ == GPUCORE_GLES; + if (needRenderThread) { - std::thread th([&]{ + renderThread_ = std::thread([this]{ + SetCurrentThreadName("RenderThread"); while (threadState_ == RenderThreadState::IDLE) sleep_ms(1, "render-thread-idle-poll"); threadState_ = RenderThreadState::STARTING; @@ -127,7 +129,7 @@ bool WindowsHeadlessHost::InitGraphics(std::string *error_message, GraphicsConte threadState_ = RenderThreadState::STARTED; while (threadState_ != RenderThreadState::STOP_REQUESTED) { - if (!gfx_->ThreadFrame(true)) { + if (!gfx_->ThreadFrame(false)) { break; } } @@ -137,7 +139,6 @@ bool WindowsHeadlessHost::InitGraphics(std::string *error_message, GraphicsConte gfx_->ShutdownFromRenderThread(); threadState_ = RenderThreadState::STOPPED; }); - th.detach(); } if (needRenderThread) { @@ -155,6 +156,10 @@ void WindowsHeadlessHost::ShutdownGraphics() { while (threadState_ != RenderThreadState::STOPPED && threadState_ != RenderThreadState::IDLE) sleep_ms(1, "render-thread-stop-poll"); + if (renderThread_.joinable()) { + renderThread_.join(); + } + gfx_->Shutdown(); delete gfx_; gfx_ = nullptr; diff --git a/headless/WindowsHeadlessHost.h b/headless/WindowsHeadlessHost.h index 5d5bd0d956..8282cea874 100644 --- a/headless/WindowsHeadlessHost.h +++ b/headless/WindowsHeadlessHost.h @@ -25,8 +25,7 @@ #include "Common/CommonWindows.h" -class WindowsHeadlessHost : public HeadlessHost -{ +class WindowsHeadlessHost : public HeadlessHost { public: bool InitGraphics(std::string *error_message, GraphicsContext **ctx, GPUCore core) override; void ShutdownGraphics() override; @@ -51,4 +50,5 @@ protected: HDC hDC; HGLRC hRC; volatile RenderThreadState threadState_ = RenderThreadState::IDLE; + std::thread renderThread_; };