diff --git a/Core/Host.h b/Core/Host.h index 920f8f087a6b..0fc474671083 100644 --- a/Core/Host.h +++ b/Core/Host.h @@ -27,10 +27,7 @@ class Host { public: virtual ~Host() {} - virtual bool InitGraphics(std::string *error_string, GraphicsContext **ctx) = 0; - virtual void ShutdownGraphics() = 0; - - virtual void UpdateSound() {} + virtual void UpdateSound() {} // still needed for libretro, will need a proper effort. virtual void PollControllers() {} virtual void ToggleDebugConsoleVisibility() {} diff --git a/Qt/QtHost.h b/Qt/QtHost.h index 2b60498d9731..71278529e59c 100644 --- a/Qt/QtHost.h +++ b/Qt/QtHost.h @@ -31,9 +31,6 @@ class QtHost : public Host { mainWindow = mainWindow_; } - bool InitGraphics(std::string *error_message, GraphicsContext **ctx) override { return true; } - void ShutdownGraphics() override {} - void UpdateSound() override {} bool AttemptLoadSymbolMap() override { diff --git a/UI/HostTypes.h b/UI/HostTypes.h index c341a993b1fe..ede4580f5206 100644 --- a/UI/HostTypes.h +++ b/UI/HostTypes.h @@ -24,9 +24,6 @@ class NativeHost : public Host { public: NativeHost() {} - bool InitGraphics(std::string *error_message, GraphicsContext **ctx) override { return true; } - void ShutdownGraphics() override {} - void UpdateSound() override {} bool AttemptLoadSymbolMap() override {return false;} diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index d0d9746f880a..e2c05d2b31dc 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -1426,12 +1426,6 @@ void NativeShutdown() { screenManager = nullptr; } - if (host) { - host->ShutdownGraphics(); - delete host; - host = nullptr; - } - #if !PPSSPP_PLATFORM(UWP) #endif g_Config.Save("NativeShutdown"); diff --git a/UWP/UWPHost.cpp b/UWP/UWPHost.cpp index 9b50580a4c70..d620046e82fd 100644 --- a/UWP/UWPHost.cpp +++ b/UWP/UWPHost.cpp @@ -54,15 +54,6 @@ void UWPHost::SetConsolePosition() { void UWPHost::UpdateConsolePosition() { } -bool UWPHost::InitGraphics(std::string *error_message, GraphicsContext **ctx) { - // Done elsewhere - return true; -} - -void UWPHost::ShutdownGraphics() { - // Done elsewhere -} - void UWPHost::SetWindowTitle(const char *message) { } diff --git a/UWP/UWPHost.h b/UWP/UWPHost.h index 14a13b264a9a..8e13f6af2aa7 100644 --- a/UWP/UWPHost.h +++ b/UWP/UWPHost.h @@ -12,10 +12,7 @@ class UWPHost : public Host { UWPHost(); ~UWPHost(); - // If returns false, will return a null context - bool InitGraphics(std::string *error_message, GraphicsContext **ctx) override; void PollControllers() override; - void ShutdownGraphics() override; void UpdateSound() override; diff --git a/Windows/EmuThread.cpp b/Windows/EmuThread.cpp index 5c3798bc7cdc..4748557d18c8 100644 --- a/Windows/EmuThread.cpp +++ b/Windows/EmuThread.cpp @@ -26,6 +26,13 @@ #include "Core/Config.h" #include "Core/ConfigValues.h" +#if PPSSPP_API(ANY_GL) +#include "Windows/GPU/WindowsGLContext.h" +#endif +#include "Windows/GPU/WindowsVulkanContext.h" +#include "Windows/GPU/D3D9Context.h" +#include "Windows/GPU/D3D11Context.h" + enum class EmuThreadState { DISABLED, START_REQUESTED, @@ -112,6 +119,37 @@ static void EmuThreadJoin() { INFO_LOG(SYSTEM, "EmuThreadJoin - joined"); } +bool CreateGraphicsBackend(std::string *error_message, GraphicsContext **ctx) { + WindowsGraphicsContext *graphicsContext = nullptr; + switch (g_Config.iGPUBackend) { +#if PPSSPP_API(ANY_GL) + case (int)GPUBackend::OPENGL: + graphicsContext = new WindowsGLContext(); + break; +#endif + case (int)GPUBackend::DIRECT3D9: + graphicsContext = new D3D9Context(); + break; + case (int)GPUBackend::DIRECT3D11: + graphicsContext = new D3D11Context(); + break; + case (int)GPUBackend::VULKAN: + graphicsContext = new WindowsVulkanContext(); + break; + default: + return false; + } + + if (graphicsContext->Init(MainWindow::GetHInstance(), MainWindow::GetDisplayHWND(), error_message)) { + *ctx = graphicsContext; + return true; + } else { + delete graphicsContext; + *ctx = nullptr; + return false; + } +} + void MainThreadFunc() { if (useEmuThread) { // We'll start up a separate thread we'll call Emu @@ -164,7 +202,7 @@ void MainThreadFunc() { System_Notify(SystemNotification::UI); std::string error_string; - bool success = host->InitGraphics(&error_string, &g_graphicsContext); + bool success = CreateGraphicsBackend(&error_string, &g_graphicsContext); if (success) { // Main thread is the render thread. @@ -299,7 +337,8 @@ void MainThreadFunc() { g_graphicsContext->ThreadEnd(); g_graphicsContext->ShutdownFromRenderThread(); - // NativeShutdown deletes the graphics context through host->ShutdownGraphics(). + g_graphicsContext->Shutdown(); + NativeShutdown(); PostMessage(MainWindow::GetHWND(), MainWindow::WM_USER_UPDATE_UI, 0, 0); diff --git a/Windows/WindowsHost.cpp b/Windows/WindowsHost.cpp index f12f74434455..1ad4edb215b8 100644 --- a/Windows/WindowsHost.cpp +++ b/Windows/WindowsHost.cpp @@ -53,13 +53,6 @@ #include "Windows/WindowsHost.h" #include "Windows/MainWindow.h" -#if PPSSPP_API(ANY_GL) -#include "Windows/GPU/WindowsGLContext.h" -#endif -#include "Windows/GPU/WindowsVulkanContext.h" -#include "Windows/GPU/D3D9Context.h" -#include "Windows/GPU/D3D11Context.h" - #include "Windows/Debugger/DebuggerShared.h" #include "Windows/Debugger/Debugger_Disasm.h" #include "Windows/Debugger/Debugger_MemoryDlg.h" @@ -116,45 +109,6 @@ void WindowsHost::UpdateConsolePosition() { } } -bool WindowsHost::InitGraphics(std::string *error_message, GraphicsContext **ctx) { - WindowsGraphicsContext *graphicsContext = nullptr; - switch (g_Config.iGPUBackend) { -#if PPSSPP_API(ANY_GL) - case (int)GPUBackend::OPENGL: - graphicsContext = new WindowsGLContext(); - break; -#endif - case (int)GPUBackend::DIRECT3D9: - graphicsContext = new D3D9Context(); - break; - case (int)GPUBackend::DIRECT3D11: - graphicsContext = new D3D11Context(); - break; - case (int)GPUBackend::VULKAN: - graphicsContext = new WindowsVulkanContext(); - break; - default: - return false; - } - - if (graphicsContext->Init(hInstance_, displayWindow_, error_message)) { - *ctx = graphicsContext; - gfx_ = graphicsContext; - return true; - } else { - delete graphicsContext; - *ctx = nullptr; - gfx_ = nullptr; - return false; - } -} - -void WindowsHost::ShutdownGraphics() { - gfx_->Shutdown(); - delete gfx_; - gfx_ = nullptr; -} - void WindowsHost::SetWindowTitle(const char *message) { #ifdef GOLD const char *name = "PPSSPP Gold "; diff --git a/Windows/WindowsHost.h b/Windows/WindowsHost.h index 36682955a2b9..cae7f5f3ca3e 100644 --- a/Windows/WindowsHost.h +++ b/Windows/WindowsHost.h @@ -24,8 +24,6 @@ extern float g_mouseDeltaX; extern float g_mouseDeltaY; -class GraphicsContext; - class WindowsHost : public Host { public: WindowsHost(HINSTANCE hInstance, HWND mainWindow, HWND displayWindow); @@ -34,10 +32,7 @@ class WindowsHost : public Host { UpdateConsolePosition(); } - // If returns false, will return a null context - bool InitGraphics(std::string *error_message, GraphicsContext **ctx) override; void PollControllers() override; - void ShutdownGraphics() override; void UpdateSound() override; @@ -52,8 +47,6 @@ class WindowsHost : public Host { void NotifyUserMessage(const std::string &message, float duration = 1.0f, u32 color = 0x00FFFFFF, const char *id = nullptr) override; void SendUIMessage(const std::string &message, const std::string &value) override; - GraphicsContext *GetGraphicsContext() { return gfx_; } - private: void SetConsolePosition(); void UpdateConsolePosition(); @@ -61,7 +54,6 @@ class WindowsHost : public Host { HINSTANCE hInstance_; HWND displayWindow_; HWND mainWindow_; - GraphicsContext *gfx_ = nullptr; size_t numDinputDevices_ = 0; std::wstring lastTitle_; diff --git a/ext/glslang b/ext/glslang index b34f619e1c85..77551c429f86 160000 --- a/ext/glslang +++ b/ext/glslang @@ -1 +1 @@ -Subproject commit b34f619e1c85810dcb3c578107d2e48ba4ee2b37 +Subproject commit 77551c429f86c0e077f26552b7c1c0f12a9f235e diff --git a/headless/Headless.cpp b/headless/Headless.cpp index 52372f9de01f..27e0508e647c 100644 --- a/headless/Headless.cpp +++ b/headless/Headless.cpp @@ -409,12 +409,11 @@ int main(int argc, const char* argv[]) g_threadManager.Init(cpu_info.num_cores, cpu_info.logical_cpu_count); HeadlessHost *headlessHost = getHost(gpuCore); - headlessHost->SetGraphicsCore(gpuCore); host = headlessHost; std::string error_string; GraphicsContext *graphicsContext = nullptr; - bool glWorking = host->InitGraphics(&error_string, &graphicsContext); + bool glWorking = ((HeadlessHost *)host)->InitGraphics(&error_string, &graphicsContext, gpuCore); CoreParameter coreParameter; coreParameter.cpuCore = cpuCore; @@ -578,7 +577,7 @@ int main(int argc, const char* argv[]) ShutdownWebServer(); } - host->ShutdownGraphics(); + ((HeadlessHost *)host)->ShutdownGraphics(); delete host; host = nullptr; headlessHost = nullptr; diff --git a/headless/SDLHeadlessHost.cpp b/headless/SDLHeadlessHost.cpp index f26150feebfc..8aa0741782d5 100644 --- a/headless/SDLHeadlessHost.cpp +++ b/headless/SDLHeadlessHost.cpp @@ -165,7 +165,7 @@ bool GLDummyGraphicsContext::InitFromRenderThread(std::string *errorMessage) { return success; } -bool SDLHeadlessHost::InitGraphics(std::string *error_message, GraphicsContext **ctx) { +bool SDLHeadlessHost::InitGraphics(std::string *error_message, GraphicsContext **ctx, GPUCore core) { GraphicsContext *graphicsContext = new GLDummyGraphicsContext(); *ctx = graphicsContext; gfx_ = graphicsContext; diff --git a/headless/SDLHeadlessHost.h b/headless/SDLHeadlessHost.h index 47d92f509c60..afcac2e2ac24 100644 --- a/headless/SDLHeadlessHost.h +++ b/headless/SDLHeadlessHost.h @@ -30,7 +30,7 @@ typedef void *SDL_GLContext; class SDLHeadlessHost : public HeadlessHost { public: - bool InitGraphics(std::string *error_message, GraphicsContext **ctx) override; + bool InitGraphics(std::string *error_message, GraphicsContext **ctx, GPUCore core) override; void ShutdownGraphics() override; void SwapBuffers() override; diff --git a/headless/StubHost.h b/headless/StubHost.h index 67c01995f6f0..280997f4d7ed 100644 --- a/headless/StubHost.h +++ b/headless/StubHost.h @@ -23,12 +23,10 @@ #include "Core/Host.h" #include "Core/Debugger/SymbolMap.h" -// TODO: Get rid of this junk class HeadlessHost : public Host { public: - void SetGraphicsCore(GPUCore core) { gpuCore_ = core; } - bool InitGraphics(std::string *error_message, GraphicsContext **ctx) override {return false;} - void ShutdownGraphics() override {} + virtual bool InitGraphics(std::string *error_message, GraphicsContext **ctx, GPUCore core) {return false;} + virtual void ShutdownGraphics() {} void UpdateSound() override {} diff --git a/headless/WindowsHeadlessHost.cpp b/headless/WindowsHeadlessHost.cpp index c190a8872baa..6d7d58da6a56 100644 --- a/headless/WindowsHeadlessHost.cpp +++ b/headless/WindowsHeadlessHost.cpp @@ -72,8 +72,9 @@ void WindowsHeadlessHost::SendDebugOutput(const std::string &output) OutputDebugStringUTF8(output.c_str()); } -bool WindowsHeadlessHost::InitGraphics(std::string *error_message, GraphicsContext **ctx) { +bool WindowsHeadlessHost::InitGraphics(std::string *error_message, GraphicsContext **ctx, GPUCore core) { hWnd = CreateHiddenWindow(); + gpuCore_ = core; if (WINDOW_VISIBLE) { ShowWindow(hWnd, TRUE); diff --git a/headless/WindowsHeadlessHost.h b/headless/WindowsHeadlessHost.h index b0a3d3901ccc..3b67fee26a4b 100644 --- a/headless/WindowsHeadlessHost.h +++ b/headless/WindowsHeadlessHost.h @@ -29,7 +29,7 @@ class WindowsHeadlessHost : public HeadlessHost { public: - bool InitGraphics(std::string *error_message, GraphicsContext **ctx) override; + bool InitGraphics(std::string *error_message, GraphicsContext **ctx, GPUCore core) override; void ShutdownGraphics() override; void SwapBuffers() override; diff --git a/libretro/libretro.cpp b/libretro/libretro.cpp index 657e79635c2f..05b13dcdbff1 100644 --- a/libretro/libretro.cpp +++ b/libretro/libretro.cpp @@ -386,8 +386,6 @@ class LibretroHost : public Host { public: LibretroHost() {} - bool InitGraphics(std::string *error_message, GraphicsContext **ctx) override { return true; } - void ShutdownGraphics() override {} void UpdateSound() override { int hostAttemptBlockSize = __AudioGetHostAttemptBlockSize();