From c7e8233b7b30cd59e6324d1a7f3878e63a283949 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Thu, 18 Aug 2022 23:51:43 +1000 Subject: [PATCH] System: Move present skip check to core --- src/core/host_display.h | 4 +-- src/core/system.cpp | 6 ++-- src/duckstation-qt/qthost.cpp | 35 ++++++++++++--------- src/duckstation-qt/qthost.h | 2 +- src/frontend-common/common_host.cpp | 2 +- src/frontend-common/d3d11_host_display.cpp | 4 +-- src/frontend-common/d3d11_host_display.h | 2 +- src/frontend-common/d3d12_host_display.cpp | 4 +-- src/frontend-common/d3d12_host_display.h | 2 +- src/frontend-common/opengl_host_display.cpp | 4 +-- src/frontend-common/opengl_host_display.h | 2 +- src/frontend-common/vulkan_host_display.cpp | 4 +-- src/frontend-common/vulkan_host_display.h | 2 +- 13 files changed, 39 insertions(+), 34 deletions(-) diff --git a/src/core/host_display.h b/src/core/host_display.h index 400ea3211..961844555 100644 --- a/src/core/host_display.h +++ b/src/core/host_display.h @@ -124,7 +124,7 @@ public: u32 width, u32 height, void* out_data, u32 out_data_stride) = 0; /// Returns false if the window was completely occluded. - virtual bool Render() = 0; + virtual bool Render(bool skip_present) = 0; /// Renders the display with postprocessing to the specified image. virtual bool RenderScreenshot(u32 width, u32 height, std::vector* out_pixels, u32* out_stride, @@ -318,6 +318,6 @@ void ReleaseHostDisplay(); //void EndPresentFrame(); /// Provided by the host; renders the display. -void RenderDisplay(); +void RenderDisplay(bool skip_present); void InvalidateDisplay(); } // namespace Host diff --git a/src/core/system.cpp b/src/core/system.cpp index 513439bc4..5dd175e2a 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -996,7 +996,7 @@ bool System::LoadState(const char* filename) ResetPerformanceCounters(); ResetThrottler(); - Host::RenderDisplay(); + Host::RenderDisplay(false); Log_VerbosePrintf("Loading state took %.2f msec", load_timer.GetTimeMilliseconds()); return true; } @@ -1463,7 +1463,7 @@ void System::Execute() PauseSystem(true); } - Host::RenderDisplay(); + Host::RenderDisplay(g_host_display->ShouldSkipDisplayingFrame()); System::UpdatePerformanceCounters(); @@ -1502,7 +1502,7 @@ void System::RecreateSystem() ResetPerformanceCounters(); ResetThrottler(); - Host::RenderDisplay(); + Host::RenderDisplay(false); if (was_paused) PauseSystem(true); diff --git a/src/duckstation-qt/qthost.cpp b/src/duckstation-qt/qthost.cpp index 20d779957..c6aad170b 100644 --- a/src/duckstation-qt/qthost.cpp +++ b/src/duckstation-qt/qthost.cpp @@ -502,7 +502,7 @@ void EmuThread::bootSystem(std::shared_ptr params) return; // force a frame to be drawn to repaint the window - renderDisplay(); + renderDisplay(false); } void EmuThread::bootOrLoadState(std::string path) @@ -626,7 +626,7 @@ void EmuThread::onDisplayWindowResized(int width, int height) // force redraw if we're paused if (!System::IsRunning() && !FullscreenUI::HasActiveWindow()) - renderDisplay(); + renderDisplay(false); } } @@ -641,7 +641,7 @@ void EmuThread::redrawDisplayWindow() if (!g_host_display || System::IsShutdown()) return; - renderDisplay(); + renderDisplay(false); } void EmuThread::toggleFullscreen() @@ -875,7 +875,7 @@ void Host::OnSystemPaused() emit g_emu_thread->systemPaused(); g_emu_thread->startBackgroundControllerPollTimer(); - g_emu_thread->renderDisplay(); + g_emu_thread->renderDisplay(false); } void Host::OnSystemResumed() @@ -1244,7 +1244,7 @@ void EmuThread::singleStepCPU() return; System::SingleStepCPU(); - renderDisplay(); + renderDisplay(false); } void EmuThread::dumpRAM(const QString& filename) @@ -1444,7 +1444,7 @@ void EmuThread::run() continue; } - renderDisplay(); + renderDisplay(false); } } @@ -1458,27 +1458,32 @@ void EmuThread::run() moveToThread(m_ui_thread); } -void EmuThread::renderDisplay() +void EmuThread::renderDisplay(bool skip_present) { // acquire for IO.MousePos. std::atomic_thread_fence(std::memory_order_acquire); - FullscreenUI::Render(); - ImGuiManager::RenderOverlays(); - ImGuiManager::RenderOSD(); - ImGuiManager::RenderDebugWindows(); - g_host_display->Render(); + if (!skip_present) + { + FullscreenUI::Render(); + ImGuiManager::RenderOverlays(); + ImGuiManager::RenderOSD(); + ImGuiManager::RenderDebugWindows(); + } + + g_host_display->Render(skip_present); + ImGuiManager::NewFrame(); } void Host::InvalidateDisplay() { - g_emu_thread->renderDisplay(); + g_emu_thread->renderDisplay(false); } -void Host::RenderDisplay() +void Host::RenderDisplay(bool skip_present) { - g_emu_thread->renderDisplay(); + g_emu_thread->renderDisplay(skip_present); } void EmuThread::wakeThread() diff --git a/src/duckstation-qt/qthost.h b/src/duckstation-qt/qthost.h index a12c69daa..a92b4bc99 100644 --- a/src/duckstation-qt/qthost.h +++ b/src/duckstation-qt/qthost.h @@ -94,7 +94,7 @@ public: bool acquireHostDisplay(HostDisplay::RenderAPI api); void connectDisplaySignals(DisplayWidget* widget); void releaseHostDisplay(); - void renderDisplay(); + void renderDisplay(bool skip_present); void startBackgroundControllerPollTimer(); void stopBackgroundControllerPollTimer(); diff --git a/src/frontend-common/common_host.cpp b/src/frontend-common/common_host.cpp index fbff3d3ac..ef20ed0d9 100644 --- a/src/frontend-common/common_host.cpp +++ b/src/frontend-common/common_host.cpp @@ -394,7 +394,7 @@ void Host::DisplayLoadingScreen(const char* message, int progress_min /*= -1*/, ImGui::End(); ImGui::EndFrame(); - g_host_display->Render(); + g_host_display->Render(false); ImGui::NewFrame(); } diff --git a/src/frontend-common/d3d11_host_display.cpp b/src/frontend-common/d3d11_host_display.cpp index efee1c3ea..156df9556 100644 --- a/src/frontend-common/d3d11_host_display.cpp +++ b/src/frontend-common/d3d11_host_display.cpp @@ -745,9 +745,9 @@ bool D3D11HostDisplay::UpdateImGuiFontTexture() return true; } -bool D3D11HostDisplay::Render() +bool D3D11HostDisplay::Render(bool skip_present) { - if (ShouldSkipDisplayingFrame() || !m_swap_chain) + if (skip_present || !m_swap_chain) { if (ImGui::GetCurrentContext()) ImGui::Render(); diff --git a/src/frontend-common/d3d11_host_display.h b/src/frontend-common/d3d11_host_display.h index 2d2777eb3..8a44f4791 100644 --- a/src/frontend-common/d3d11_host_display.h +++ b/src/frontend-common/d3d11_host_display.h @@ -67,7 +67,7 @@ public: void SetVSync(bool enabled) override; - bool Render() override; + bool Render(bool skip_present) override; bool RenderScreenshot(u32 width, u32 height, std::vector* out_pixels, u32* out_stride, HostDisplayPixelFormat* out_format) override; diff --git a/src/frontend-common/d3d12_host_display.cpp b/src/frontend-common/d3d12_host_display.cpp index 669436375..cae399e6e 100644 --- a/src/frontend-common/d3d12_host_display.cpp +++ b/src/frontend-common/d3d12_host_display.cpp @@ -650,9 +650,9 @@ bool D3D12HostDisplay::UpdateImGuiFontTexture() return ImGui_ImplDX12_CreateFontsTexture(); } -bool D3D12HostDisplay::Render() +bool D3D12HostDisplay::Render(bool skip_present) { - if (ShouldSkipDisplayingFrame() || !m_swap_chain) + if (skip_present || !m_swap_chain) { if (ImGui::GetCurrentContext()) ImGui::Render(); diff --git a/src/frontend-common/d3d12_host_display.h b/src/frontend-common/d3d12_host_display.h index fee706330..0b1b56a77 100644 --- a/src/frontend-common/d3d12_host_display.h +++ b/src/frontend-common/d3d12_host_display.h @@ -68,7 +68,7 @@ public: virtual void SetVSync(bool enabled) override; - virtual bool Render() override; + virtual bool Render(bool skip_present) override; virtual bool RenderScreenshot(u32 width, u32 height, std::vector* out_pixels, u32* out_stride, HostDisplayPixelFormat* out_format) override; diff --git a/src/frontend-common/opengl_host_display.cpp b/src/frontend-common/opengl_host_display.cpp index 439cb8be4..49f4330b3 100644 --- a/src/frontend-common/opengl_host_display.cpp +++ b/src/frontend-common/opengl_host_display.cpp @@ -738,9 +738,9 @@ void OpenGLHostDisplay::DestroyResources() m_display_program.Destroy(); } -bool OpenGLHostDisplay::Render() +bool OpenGLHostDisplay::Render(bool skip_present) { - if (ShouldSkipDisplayingFrame()) + if (skip_present || m_window_info.type == WindowInfo::Type::Surfaceless) { if (ImGui::GetCurrentContext()) ImGui::Render(); diff --git a/src/frontend-common/opengl_host_display.h b/src/frontend-common/opengl_host_display.h index 9ab293fad..3f0d965cc 100644 --- a/src/frontend-common/opengl_host_display.h +++ b/src/frontend-common/opengl_host_display.h @@ -58,7 +58,7 @@ public: void SetVSync(bool enabled) override; - bool Render() override; + bool Render(bool skip_present) override; bool RenderScreenshot(u32 width, u32 height, std::vector* out_pixels, u32* out_stride, HostDisplayPixelFormat* out_format) override; diff --git a/src/frontend-common/vulkan_host_display.cpp b/src/frontend-common/vulkan_host_display.cpp index 66075ef6a..34214c48e 100644 --- a/src/frontend-common/vulkan_host_display.cpp +++ b/src/frontend-common/vulkan_host_display.cpp @@ -572,9 +572,9 @@ bool VulkanHostDisplay::DoneRenderContextCurrent() return true; } -bool VulkanHostDisplay::Render() +bool VulkanHostDisplay::Render(bool skip_present) { - if (ShouldSkipDisplayingFrame() || !m_swap_chain) + if (skip_present || !m_swap_chain) { if (ImGui::GetCurrentContext()) ImGui::Render(); diff --git a/src/frontend-common/vulkan_host_display.h b/src/frontend-common/vulkan_host_display.h index c7639cd70..9dd2b12ed 100644 --- a/src/frontend-common/vulkan_host_display.h +++ b/src/frontend-common/vulkan_host_display.h @@ -63,7 +63,7 @@ public: void SetVSync(bool enabled) override; - bool Render() override; + bool Render(bool skip_present) override; bool RenderScreenshot(u32 width, u32 height, std::vector* out_pixels, u32* out_stride, HostDisplayPixelFormat* out_format) override;