diff --git a/src/core/host_display.h b/src/core/host_display.h index 7226a674f..38915f7c9 100644 --- a/src/core/host_display.h +++ b/src/core/host_display.h @@ -109,7 +109,6 @@ public: bool threaded_presentation) = 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/src/duckstation-nogui/nogui_host.cpp b/src/duckstation-nogui/nogui_host.cpp index b14408f1a..66607e08a 100644 --- a/src/duckstation-nogui/nogui_host.cpp +++ b/src/duckstation-nogui/nogui_host.cpp @@ -683,8 +683,8 @@ bool NoGUIHost::AcquireHostDisplay(RenderAPI api) { ImGuiManager::Shutdown(); CommonHost::ReleaseHostDisplayResources(); - g_host_display->DestroyRenderDevice(); g_host_display.reset(); + g_nogui_window->DestroyPlatformWindow(); return false; } @@ -718,7 +718,6 @@ void NoGUIHost::ReleaseHostDisplay() CommonHost::ReleaseHostDisplayResources(); ImGuiManager::Shutdown(); - g_host_display->DestroyRenderDevice(); g_host_display.reset(); g_nogui_window->ExecuteInMessageLoop([]() { g_nogui_window->DestroyPlatformWindow(); diff --git a/src/duckstation-qt/displaysettingswidget.cpp b/src/duckstation-qt/displaysettingswidget.cpp index 344113fd7..a4c13cd72 100644 --- a/src/duckstation-qt/displaysettingswidget.cpp +++ b/src/duckstation-qt/displaysettingswidget.cpp @@ -204,11 +204,11 @@ void DisplaySettingsWidget::populateGPUAdaptersAndResolutions() { #ifdef _WIN32 case GPURenderer::HardwareD3D11: - aml = FrontendCommon::D3D11HostDisplay::StaticGetAdapterAndModeList(); + aml = D3D11HostDisplay::StaticGetAdapterAndModeList(); break; case GPURenderer::HardwareD3D12: - aml = FrontendCommon::D3D12HostDisplay::StaticGetAdapterAndModeList(); + aml = D3D12HostDisplay::StaticGetAdapterAndModeList(); break; #endif #ifdef WITH_VULKAN diff --git a/src/duckstation-qt/qthost.cpp b/src/duckstation-qt/qthost.cpp index a2eab153c..f5ddfbcd3 100644 --- a/src/duckstation-qt/qthost.cpp +++ b/src/duckstation-qt/qthost.cpp @@ -739,9 +739,8 @@ bool EmuThread::acquireHostDisplay(RenderAPI api) { ImGuiManager::Shutdown(); CommonHost::ReleaseHostDisplayResources(); - g_host_display->DestroyRenderDevice(); - emit destroyDisplayRequested(); g_host_display.reset(); + emit destroyDisplayRequested(); return false; } @@ -811,9 +810,8 @@ void EmuThread::releaseHostDisplay() CommonHost::ReleaseHostDisplayResources(); ImGuiManager::Shutdown(); - g_host_display->DestroyRenderDevice(); - emit destroyDisplayRequested(); g_host_display.reset(); + emit destroyDisplayRequested(); m_is_fullscreen = false; } diff --git a/src/frontend-common/common_host.cpp b/src/frontend-common/common_host.cpp index ba2d1c3a6..977ccfaf0 100644 --- a/src/frontend-common/common_host.cpp +++ b/src/frontend-common/common_host.cpp @@ -142,26 +142,26 @@ std::unique_ptr Host::CreateDisplayForAPI(RenderAPI api) #ifdef WITH_OPENGL case RenderAPI::OpenGL: case RenderAPI::OpenGLES: - return std::make_unique(); + return std::make_unique(); #endif #ifdef _WIN32 case RenderAPI::D3D12: - return std::make_unique(); + return std::make_unique(); case RenderAPI::D3D11: - return std::make_unique(); + return std::make_unique(); #endif default: #if defined(_WIN32) && defined(_M_ARM64) - return std::make_unique(); + return std::make_unique(); #elif defined(_WIN32) - return std::make_unique(); + return std::make_unique(); #elif defined(WITH_OPENGL) - return std::make_unique(); + return std::make_unique(); #elif defined(WITH_VULKAN) - return std::make_unique(); + return std::make_unique(); #else return {}; #endif diff --git a/src/frontend-common/d3d11_host_display.cpp b/src/frontend-common/d3d11_host_display.cpp index 230441d4a..ca6132b32 100644 --- a/src/frontend-common/d3d11_host_display.cpp +++ b/src/frontend-common/d3d11_host_display.cpp @@ -21,8 +21,6 @@ Log_SetChannel(D3D11HostDisplay); #pragma comment(lib, "d3d11.lib") #pragma comment(lib, "dxgi.lib") -namespace FrontendCommon { - class D3D11HostDisplayTexture final : public HostDisplayTexture { public: @@ -90,8 +88,10 @@ D3D11HostDisplay::D3D11HostDisplay() = default; D3D11HostDisplay::~D3D11HostDisplay() { - AssertMsg(!m_context, "Context should have been destroyed by now"); - AssertMsg(!m_swap_chain, "Swap chain should have been destroyed by now"); + DestroyResources(); + DestroyRenderSurface(); + m_context.Reset(); + m_device.Reset(); } RenderAPI D3D11HostDisplay::GetRenderAPI() const @@ -337,14 +337,6 @@ bool D3D11HostDisplay::InitializeRenderDevice(std::string_view shader_cache_dire return true; } -void D3D11HostDisplay::DestroyRenderDevice() -{ - DestroyResources(); - DestroyRenderSurface(); - m_context.Reset(); - m_device.Reset(); -} - bool D3D11HostDisplay::MakeRenderContextCurrent() { return true; @@ -1006,7 +998,7 @@ bool D3D11HostDisplay::SetPostProcessingChain(const std::string_view& config) for (u32 i = 0; i < m_post_processing_chain.GetStageCount(); i++) { - const PostProcessingShader& shader = m_post_processing_chain.GetShaderStage(i); + const FrontendCommon::PostProcessingShader& shader = m_post_processing_chain.GetShaderStage(i); const std::string vs = shadergen.GeneratePostProcessingVertexShader(shader); const std::string ps = shadergen.GeneratePostProcessingFragmentShader(shader); @@ -1255,5 +1247,3 @@ float D3D11HostDisplay::GetAndResetAccumulatedGPUTime() m_accumulated_gpu_time = 0.0f; return value; } - -} // namespace FrontendCommon diff --git a/src/frontend-common/d3d11_host_display.h b/src/frontend-common/d3d11_host_display.h index bd15b29f5..502c00b7a 100644 --- a/src/frontend-common/d3d11_host_display.h +++ b/src/frontend-common/d3d11_host_display.h @@ -14,8 +14,6 @@ #include #include -namespace FrontendCommon { - class D3D11HostDisplay final : public HostDisplay { public: @@ -36,7 +34,6 @@ public: bool threaded_presentation) override; bool InitializeRenderDevice(std::string_view shader_cache_directory, bool debug_device, bool threaded_presentation) override; - void DestroyRenderDevice() override; bool MakeRenderContextCurrent() override; bool DoneRenderContextCurrent() override; @@ -140,7 +137,7 @@ protected: bool m_using_allow_tearing = false; bool m_vsync = true; - PostProcessingChain m_post_processing_chain; + FrontendCommon::PostProcessingChain m_post_processing_chain; D3D11::Texture m_post_processing_input_texture; std::vector m_post_processing_stages; @@ -151,5 +148,3 @@ protected: bool m_timestamp_query_started = false; float m_accumulated_gpu_time = 0.0f; }; - -} // namespace FrontendCommon diff --git a/src/frontend-common/d3d12_host_display.cpp b/src/frontend-common/d3d12_host_display.cpp index aaf01e3a3..bdaffb209 100644 --- a/src/frontend-common/d3d12_host_display.cpp +++ b/src/frontend-common/d3d12_host_display.cpp @@ -15,8 +15,6 @@ #include Log_SetChannel(D3D12HostDisplay); -namespace FrontendCommon { - static constexpr std::array(HostDisplayPixelFormat::Count)> s_display_pixel_format_mapping = {{DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_B5G6R5_UNORM, DXGI_FORMAT_B5G5R5A1_UNORM}}; @@ -66,8 +64,13 @@ D3D12HostDisplay::D3D12HostDisplay() = default; D3D12HostDisplay::~D3D12HostDisplay() { - AssertMsg(!g_d3d12_context, "Context should have been destroyed by now"); - AssertMsg(!m_swap_chain, "Swap chain should have been destroyed by now"); + if (!g_d3d12_context) + return; + + // DestroyRenderSurface() will exec the command list. + DestroyRenderSurface(); + DestroyResources(); + g_d3d12_context->Destroy(); } RenderAPI D3D12HostDisplay::GetRenderAPI() const @@ -247,16 +250,6 @@ bool D3D12HostDisplay::InitializeRenderDevice(std::string_view shader_cache_dire return true; } -void D3D12HostDisplay::DestroyRenderDevice() -{ - g_d3d12_context->ExecuteCommandList(true); - - DestroyResources(); - DestroyRenderSurface(); - if (g_d3d12_context) - g_d3d12_context->Destroy(); -} - bool D3D12HostDisplay::MakeRenderContextCurrent() { return true; @@ -889,5 +882,3 @@ bool D3D12HostDisplay::SetPostProcessingChain(const std::string_view& config) { return false; } - -} // namespace FrontendCommon diff --git a/src/frontend-common/d3d12_host_display.h b/src/frontend-common/d3d12_host_display.h index 5f59e1cd1..e4874ee01 100644 --- a/src/frontend-common/d3d12_host_display.h +++ b/src/frontend-common/d3d12_host_display.h @@ -15,8 +15,6 @@ #include #include -namespace FrontendCommon { - class D3D12HostDisplay final : public HostDisplay { public: @@ -34,10 +32,9 @@ public: bool HasRenderSurface() const override; bool CreateRenderDevice(const WindowInfo& wi, std::string_view adapter_name, bool debug_device, - bool threaded_presentation) override; + bool threaded_presentation) override; bool InitializeRenderDevice(std::string_view shader_cache_directory, bool debug_device, - bool threaded_presentation) override; - void DestroyRenderDevice() override; + bool threaded_presentation) override; bool MakeRenderContextCurrent() override; bool DoneRenderContextCurrent() override; @@ -65,7 +62,7 @@ public: bool Render(bool skip_present) override; bool RenderScreenshot(u32 width, u32 height, std::vector* out_pixels, u32* out_stride, - HostDisplayPixelFormat* out_format) override; + HostDisplayPixelFormat* out_format) override; bool SetGPUTimingEnabled(bool enabled) override; float GetAndResetAccumulatedGPUTime() override; @@ -121,5 +118,3 @@ protected: bool m_using_allow_tearing = false; bool m_vsync = true; }; - -} // namespace FrontendCommon diff --git a/src/frontend-common/opengl_host_display.cpp b/src/frontend-common/opengl_host_display.cpp index 0f10525bb..96ce53af5 100644 --- a/src/frontend-common/opengl_host_display.cpp +++ b/src/frontend-common/opengl_host_display.cpp @@ -11,8 +11,6 @@ #include Log_SetChannel(OpenGLHostDisplay); -namespace FrontendCommon { - enum : u32 { TEXTURE_STREAM_BUFFER_SIZE = 16 * 1024 * 1024, @@ -48,7 +46,13 @@ OpenGLHostDisplay::OpenGLHostDisplay() = default; OpenGLHostDisplay::~OpenGLHostDisplay() { - AssertMsg(!m_gl_context, "Context should have been destroyed by now"); + if (!m_gl_context) + return; + + DestroyResources(); + + m_gl_context->DoneCurrent(); + m_gl_context.reset(); } RenderAPI OpenGLHostDisplay::GetRenderAPI() const @@ -295,17 +299,6 @@ bool OpenGLHostDisplay::DoneRenderContextCurrent() return m_gl_context->DoneCurrent(); } -void OpenGLHostDisplay::DestroyRenderDevice() -{ - if (!m_gl_context) - return; - - DestroyResources(); - - m_gl_context->DoneCurrent(); - m_gl_context.reset(); -} - bool OpenGLHostDisplay::ChangeRenderWindow(const WindowInfo& new_wi) { Assert(m_gl_context); @@ -789,7 +782,7 @@ bool OpenGLHostDisplay::SetPostProcessingChain(const std::string_view& config) for (u32 i = 0; i < m_post_processing_chain.GetStageCount(); i++) { - const PostProcessingShader& shader = m_post_processing_chain.GetShaderStage(i); + const FrontendCommon::PostProcessingShader& shader = m_post_processing_chain.GetShaderStage(i); const std::string vs = shadergen.GeneratePostProcessingVertexShader(shader); const std::string ps = shadergen.GeneratePostProcessingFragmentShader(shader); @@ -1230,5 +1223,3 @@ bool OpenGLHostDisplayTexture::Update(u32 x, u32 y, u32 width, u32 height, const return true; } - -} // namespace FrontendCommon diff --git a/src/frontend-common/opengl_host_display.h b/src/frontend-common/opengl_host_display.h index 8bc7d58e4..51e9550d0 100644 --- a/src/frontend-common/opengl_host_display.h +++ b/src/frontend-common/opengl_host_display.h @@ -9,8 +9,6 @@ #include "postprocessing_chain.h" #include -namespace FrontendCommon { - class OpenGLHostDisplay final : public HostDisplay { public: @@ -28,7 +26,6 @@ public: bool threaded_presentation) override; bool InitializeRenderDevice(std::string_view shader_cache_directory, bool debug_device, bool threaded_presentation) override; - void DestroyRenderDevice() override; bool MakeRenderContextCurrent() override; bool DoneRenderContextCurrent() override; @@ -118,7 +115,7 @@ protected: std::unique_ptr m_texture_stream_buffer; std::vector m_texture_repack_buffer; - PostProcessingChain m_post_processing_chain; + FrontendCommon::PostProcessingChain m_post_processing_chain; GL::Texture m_post_processing_input_texture; std::unique_ptr m_post_processing_ubo; std::vector m_post_processing_stages; @@ -133,5 +130,3 @@ protected: bool m_use_gles2_draw_path = false; bool m_use_pbo_for_pixels = false; }; - -} // namespace FrontendCommon \ No newline at end of file diff --git a/src/frontend-common/vulkan_host_display.cpp b/src/frontend-common/vulkan_host_display.cpp index 76b36e738..55a2ce929 100644 --- a/src/frontend-common/vulkan_host_display.cpp +++ b/src/frontend-common/vulkan_host_display.cpp @@ -583,8 +583,6 @@ bool VulkanHostDisplay::UpdateImGuiFontTexture() return ImGui_ImplVulkan_CreateFontsTexture(); } -void VulkanHostDisplay::DestroyRenderDevice() {} - bool VulkanHostDisplay::MakeRenderContextCurrent() { return true; diff --git a/src/frontend-common/vulkan_host_display.h b/src/frontend-common/vulkan_host_display.h index 7a6afeb1a..446e4bc9b 100644 --- a/src/frontend-common/vulkan_host_display.h +++ b/src/frontend-common/vulkan_host_display.h @@ -30,8 +30,7 @@ public: bool threaded_presentation) override; bool InitializeRenderDevice(std::string_view shader_cache_directory, bool debug_device, bool threaded_presentation) override; - void DestroyRenderDevice() override; - + bool MakeRenderContextCurrent() override; bool DoneRenderContextCurrent() override;