From 9199f48a3c4d681b395c7e99ebebc6b8e35239aa Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Mon, 20 Jun 2022 20:03:15 +1000 Subject: [PATCH] HostDisplay: Remove DestroyRenderDevice()/move to destructor Saves having to remember to call this any time you destroy the display object. --- pcsx2-qt/EmuThread.cpp | 6 +----- pcsx2/Frontend/D3D11HostDisplay.cpp | 12 +++--------- pcsx2/Frontend/D3D11HostDisplay.h | 1 - pcsx2/Frontend/D3D12HostDisplay.cpp | 17 ++++++----------- pcsx2/Frontend/D3D12HostDisplay.h | 1 - pcsx2/Frontend/MetalHostDisplay.h | 1 - pcsx2/Frontend/MetalHostDisplay.mm | 10 +++------- pcsx2/Frontend/OpenGLHostDisplay.cpp | 15 +++++---------- pcsx2/Frontend/OpenGLHostDisplay.h | 1 - pcsx2/Frontend/VulkanHostDisplay.cpp | 23 ++++++++--------------- pcsx2/Frontend/VulkanHostDisplay.h | 1 - pcsx2/HostDisplay.h | 1 - pcsx2/gui/AppHost.cpp | 4 ---- 13 files changed, 26 insertions(+), 67 deletions(-) diff --git a/pcsx2-qt/EmuThread.cpp b/pcsx2-qt/EmuThread.cpp index 9e5d533230..1186591775 100644 --- a/pcsx2-qt/EmuThread.cpp +++ b/pcsx2-qt/EmuThread.cpp @@ -687,12 +687,8 @@ void EmuThread::releaseHostDisplay() { ImGuiManager::Shutdown(); - if (s_host_display) - s_host_display->DestroyRenderDevice(); - - emit onDestroyDisplayRequested(); - s_host_display.reset(); + emit onDestroyDisplayRequested(); } HostDisplay* Host::GetHostDisplay() diff --git a/pcsx2/Frontend/D3D11HostDisplay.cpp b/pcsx2/Frontend/D3D11HostDisplay.cpp index d62a97cfa8..45d097c189 100644 --- a/pcsx2/Frontend/D3D11HostDisplay.cpp +++ b/pcsx2/Frontend/D3D11HostDisplay.cpp @@ -95,8 +95,9 @@ D3D11HostDisplay::D3D11HostDisplay() = default; D3D11HostDisplay::~D3D11HostDisplay() { - pxAssertMsg(!m_context, "Context should have been destroyed by now"); - pxAssertMsg(!m_swap_chain, "Swap chain should have been destroyed by now"); + D3D11HostDisplay::DestroyRenderSurface(); + m_context.Reset(); + m_device.Reset(); } HostDisplay::RenderAPI D3D11HostDisplay::GetRenderAPI() const @@ -332,13 +333,6 @@ bool D3D11HostDisplay::InitializeRenderDevice(std::string_view shader_cache_dire return true; } -void D3D11HostDisplay::DestroyRenderDevice() -{ - DestroyRenderSurface(); - m_context.Reset(); - m_device.Reset(); -} - bool D3D11HostDisplay::MakeRenderContextCurrent() { return true; diff --git a/pcsx2/Frontend/D3D11HostDisplay.h b/pcsx2/Frontend/D3D11HostDisplay.h index b16461901f..9040284f4f 100644 --- a/pcsx2/Frontend/D3D11HostDisplay.h +++ b/pcsx2/Frontend/D3D11HostDisplay.h @@ -45,7 +45,6 @@ public: bool CreateRenderDevice(const WindowInfo& wi, std::string_view adapter_name, VsyncMode vsync, bool threaded_presentation, bool debug_device) override; bool InitializeRenderDevice(std::string_view shader_cache_directory, bool debug_device) override; - void DestroyRenderDevice() override; bool MakeRenderContextCurrent() override; bool DoneRenderContextCurrent() override; diff --git a/pcsx2/Frontend/D3D12HostDisplay.cpp b/pcsx2/Frontend/D3D12HostDisplay.cpp index c1e591c0af..a1fec8f147 100644 --- a/pcsx2/Frontend/D3D12HostDisplay.cpp +++ b/pcsx2/Frontend/D3D12HostDisplay.cpp @@ -51,8 +51,12 @@ D3D12HostDisplay::D3D12HostDisplay() = default; D3D12HostDisplay::~D3D12HostDisplay() { - pxAssertMsg(!g_d3d12_context, "Context should have been destroyed by now"); - pxAssertMsg(!m_swap_chain, "Swap chain should have been destroyed by now"); + if (g_d3d12_context) + { + g_d3d12_context->WaitForGPUIdle(); + D3D12HostDisplay::DestroyRenderSurface(); + g_d3d12_context->Destroy(); + } } HostDisplay::RenderAPI D3D12HostDisplay::GetRenderAPI() const @@ -204,15 +208,6 @@ bool D3D12HostDisplay::InitializeRenderDevice(std::string_view shader_cache_dire return true; } -void D3D12HostDisplay::DestroyRenderDevice() -{ - g_d3d12_context->ExecuteCommandList(true); - - DestroyRenderSurface(); - if (g_d3d12_context) - g_d3d12_context->Destroy(); -} - bool D3D12HostDisplay::MakeRenderContextCurrent() { return true; diff --git a/pcsx2/Frontend/D3D12HostDisplay.h b/pcsx2/Frontend/D3D12HostDisplay.h index 777fd6d05f..7003131abf 100644 --- a/pcsx2/Frontend/D3D12HostDisplay.h +++ b/pcsx2/Frontend/D3D12HostDisplay.h @@ -51,7 +51,6 @@ public: bool CreateRenderDevice(const WindowInfo& wi, std::string_view adapter_name, VsyncMode vsync, bool threaded_presentation, bool debug_device) override; bool InitializeRenderDevice(std::string_view shader_cache_directory, bool debug_device) override; - void DestroyRenderDevice() override; bool MakeRenderContextCurrent() override; bool DoneRenderContextCurrent() override; diff --git a/pcsx2/Frontend/MetalHostDisplay.h b/pcsx2/Frontend/MetalHostDisplay.h index 83d630abf0..4f6a306eb1 100644 --- a/pcsx2/Frontend/MetalHostDisplay.h +++ b/pcsx2/Frontend/MetalHostDisplay.h @@ -56,7 +56,6 @@ public: bool InitializeRenderDevice(std::string_view shader_cache_directory, bool debug_device) override; bool MakeRenderContextCurrent() override; bool DoneRenderContextCurrent() override; - void DestroyRenderDevice() override; void DestroyRenderSurface() override; bool ChangeRenderWindow(const WindowInfo& wi) override; bool SupportsFullscreen() const override; diff --git a/pcsx2/Frontend/MetalHostDisplay.mm b/pcsx2/Frontend/MetalHostDisplay.mm index 6e257ea48d..87751c349e 100644 --- a/pcsx2/Frontend/MetalHostDisplay.mm +++ b/pcsx2/Frontend/MetalHostDisplay.mm @@ -49,6 +49,9 @@ MetalHostDisplay::MetalHostDisplay() MetalHostDisplay::~MetalHostDisplay() { + MetalHostDisplay::DestroyRenderSurface(); + m_queue = nullptr; + m_dev.Reset(); } HostDisplay::AdapterAndModeList GetMetalAdapterAndModeList() @@ -158,13 +161,6 @@ bool MetalHostDisplay::InitializeRenderDevice(std::string_view shader_cache_dire bool MetalHostDisplay::MakeRenderContextCurrent() { return true; } bool MetalHostDisplay::DoneRenderContextCurrent() { return true; } -void MetalHostDisplay::DestroyRenderDevice() -{ - DestroyRenderSurface(); - m_queue = nullptr; - m_dev.Reset(); -} - void MetalHostDisplay::DestroyRenderSurface() { if (!m_layer) diff --git a/pcsx2/Frontend/OpenGLHostDisplay.cpp b/pcsx2/Frontend/OpenGLHostDisplay.cpp index 27e4d26062..80bc5cf3de 100644 --- a/pcsx2/Frontend/OpenGLHostDisplay.cpp +++ b/pcsx2/Frontend/OpenGLHostDisplay.cpp @@ -53,7 +53,11 @@ OpenGLHostDisplay::OpenGLHostDisplay() = default; OpenGLHostDisplay::~OpenGLHostDisplay() { - pxAssertMsg(!m_gl_context, "Context should have been destroyed by now"); + if (m_gl_context) + { + m_gl_context->DoneCurrent(); + m_gl_context.reset(); + } } HostDisplay::RenderAPI OpenGLHostDisplay::GetRenderAPI() const @@ -239,15 +243,6 @@ bool OpenGLHostDisplay::DoneRenderContextCurrent() return m_gl_context->DoneCurrent(); } -void OpenGLHostDisplay::DestroyRenderDevice() -{ - if (!m_gl_context) - return; - - m_gl_context->DoneCurrent(); - m_gl_context.reset(); -} - bool OpenGLHostDisplay::ChangeRenderWindow(const WindowInfo& new_wi) { pxAssert(m_gl_context); diff --git a/pcsx2/Frontend/OpenGLHostDisplay.h b/pcsx2/Frontend/OpenGLHostDisplay.h index 26e4ccde9f..c87146b05b 100644 --- a/pcsx2/Frontend/OpenGLHostDisplay.h +++ b/pcsx2/Frontend/OpenGLHostDisplay.h @@ -40,7 +40,6 @@ public: bool CreateRenderDevice(const WindowInfo& wi, std::string_view adapter_name, VsyncMode vsync, bool threaded_presentation, bool debug_device) override; bool InitializeRenderDevice(std::string_view shader_cache_directory, bool debug_device) override; - void DestroyRenderDevice() override; bool MakeRenderContextCurrent() override; bool DoneRenderContextCurrent() override; diff --git a/pcsx2/Frontend/VulkanHostDisplay.cpp b/pcsx2/Frontend/VulkanHostDisplay.cpp index 62aecfd579..2f21702aee 100644 --- a/pcsx2/Frontend/VulkanHostDisplay.cpp +++ b/pcsx2/Frontend/VulkanHostDisplay.cpp @@ -51,8 +51,14 @@ VulkanHostDisplay::VulkanHostDisplay() = default; VulkanHostDisplay::~VulkanHostDisplay() { - pxAssertRel(!g_vulkan_context, "Context should have been destroyed by now"); - pxAssertRel(!m_swap_chain, "Swap chain should have been destroyed by now"); + if (g_vulkan_context) + { + g_vulkan_context->WaitForGPUIdle(); + m_swap_chain.reset(); + + Vulkan::ShaderCache::Destroy(); + Vulkan::Context::Destroy(); + } } HostDisplay::RenderAPI VulkanHostDisplay::GetRenderAPI() const @@ -163,7 +169,6 @@ HostDisplay::AdapterAndModeList VulkanHostDisplay::GetAdapterAndModeList() void VulkanHostDisplay::DestroyRenderSurface() { - m_window_info = {}; g_vulkan_context->WaitForGPUIdle(); m_swap_chain.reset(); } @@ -320,18 +325,6 @@ bool VulkanHostDisplay::UpdateImGuiFontTexture() return ImGui_ImplVulkan_CreateFontsTexture(); } -void VulkanHostDisplay::DestroyRenderDevice() -{ - if (!g_vulkan_context) - return; - - g_vulkan_context->WaitForGPUIdle(); - m_swap_chain.reset(); - - Vulkan::ShaderCache::Destroy(); - Vulkan::Context::Destroy(); -} - bool VulkanHostDisplay::MakeRenderContextCurrent() { return true; diff --git a/pcsx2/Frontend/VulkanHostDisplay.h b/pcsx2/Frontend/VulkanHostDisplay.h index 8e2bed555e..90d0a4f42d 100644 --- a/pcsx2/Frontend/VulkanHostDisplay.h +++ b/pcsx2/Frontend/VulkanHostDisplay.h @@ -29,7 +29,6 @@ public: bool CreateRenderDevice(const WindowInfo& wi, std::string_view adapter_name, VsyncMode vsync, bool threaded_presentation, bool debug_device) override; bool InitializeRenderDevice(std::string_view shader_cache_directory, bool debug_device) override; - void DestroyRenderDevice() override; bool MakeRenderContextCurrent() override; bool DoneRenderContextCurrent() override; diff --git a/pcsx2/HostDisplay.h b/pcsx2/HostDisplay.h index 7a82875165..b79ec42bd4 100644 --- a/pcsx2/HostDisplay.h +++ b/pcsx2/HostDisplay.h @@ -101,7 +101,6 @@ public: virtual bool InitializeRenderDevice(std::string_view shader_cache_directory, bool debug_device) = 0; virtual bool MakeRenderContextCurrent() = 0; virtual bool DoneRenderContextCurrent() = 0; - virtual void DestroyRenderDevice() = 0; virtual void DestroyRenderSurface() = 0; virtual bool ChangeRenderWindow(const WindowInfo& wi) = 0; virtual bool SupportsFullscreen() const = 0; diff --git a/pcsx2/gui/AppHost.cpp b/pcsx2/gui/AppHost.cpp index 71cb97598d..294356e6c1 100644 --- a/pcsx2/gui/AppHost.cpp +++ b/pcsx2/gui/AppHost.cpp @@ -121,7 +121,6 @@ HostDisplay* Host::AcquireHostDisplay(HostDisplay::RenderAPI api) !s_host_display->InitializeRenderDevice(EmuFolders::Cache, GSConfig.UseDebugDevice) || !ImGuiManager::Initialize()) { - s_host_display->DestroyRenderDevice(); s_host_display.reset(); return nullptr; } @@ -137,10 +136,7 @@ void Host::ReleaseHostDisplay() ImGuiManager::Shutdown(); if (s_host_display) - { - s_host_display->DestroyRenderDevice(); s_host_display.reset(); - } sApp.CloseGsPanel(); }