diff --git a/Common/GPU/D3D11/thin3d_d3d11.cpp b/Common/GPU/D3D11/thin3d_d3d11.cpp index 1a15af2674..133fa9cfa4 100644 --- a/Common/GPU/D3D11/thin3d_d3d11.cpp +++ b/Common/GPU/D3D11/thin3d_d3d11.cpp @@ -139,7 +139,7 @@ public: void BeginFrame(DebugFlags debugFlags) override; void EndFrame() override; - void Present() override; + void Present(int vblanks) override; int GetFrameCount() override { return frameCount_; } @@ -426,11 +426,6 @@ void D3D11DrawContext::HandleEvent(Event ev, int width, int height, void *param1 curRTHeight_ = height; break; } - case Event::PRESENTED: - // Make sure that we don't eliminate the next time the render target is set. - curRenderTargetView_ = nullptr; - curDepthStencilView_ = nullptr; - break; } } @@ -438,7 +433,10 @@ void D3D11DrawContext::EndFrame() { curPipeline_ = nullptr; } -void D3D11DrawContext::Present() { +void D3D11DrawContext::Present(int vblanks) { + swapChain_->Present(1, 0); + curRenderTargetView_ = nullptr; + curDepthStencilView_ = nullptr; frameCount_++; } diff --git a/Common/GPU/D3D9/thin3d_d3d9.cpp b/Common/GPU/D3D9/thin3d_d3d9.cpp index 84ce9da268..a23f4220fa 100644 --- a/Common/GPU/D3D9/thin3d_d3d9.cpp +++ b/Common/GPU/D3D9/thin3d_d3d9.cpp @@ -580,7 +580,7 @@ public: } void EndFrame() override; - void Present() override; + void Present(int vblanks) override; int GetFrameCount() override { return frameCount_; } @@ -970,7 +970,16 @@ void D3D9Context::EndFrame() { curPipeline_ = nullptr; } -void D3D9Context::Present() { +void D3D9Context::Present(int vblanks) { + if (deviceEx_) { + deviceEx_->EndScene(); + deviceEx_->PresentEx(NULL, NULL, NULL, NULL, 0); + deviceEx_->BeginScene(); + } else { + device_->EndScene(); + device_->Present(NULL, NULL, NULL, NULL); + device_->BeginScene(); + } frameCount_++; } diff --git a/Common/GPU/OpenGL/thin3d_gl.cpp b/Common/GPU/OpenGL/thin3d_gl.cpp index 124a5c0583..1e261be7a0 100644 --- a/Common/GPU/OpenGL/thin3d_gl.cpp +++ b/Common/GPU/OpenGL/thin3d_gl.cpp @@ -366,7 +366,7 @@ public: void BeginFrame(DebugFlags debugFlags) override; void EndFrame() override; - void Present() override; + void Present(int vblanks) override; int GetFrameCount() override { return frameCount_; @@ -802,7 +802,7 @@ void OpenGLContext::EndFrame() { Invalidate(InvalidationFlags::CACHED_RENDER_STATE); } -void OpenGLContext::Present() { +void OpenGLContext::Present(int vblanks) { renderManager_.Present(); frameCount_++; } diff --git a/Common/GPU/Vulkan/thin3d_vulkan.cpp b/Common/GPU/Vulkan/thin3d_vulkan.cpp index e4a37eb82e..ad3a74880d 100644 --- a/Common/GPU/Vulkan/thin3d_vulkan.cpp +++ b/Common/GPU/Vulkan/thin3d_vulkan.cpp @@ -480,7 +480,7 @@ public: void BeginFrame(DebugFlags debugFlags) override; void EndFrame() override; - void Present() override; + void Present(int vblanks) override; void WipeQueue() override; @@ -1121,7 +1121,8 @@ void VKContext::EndFrame() { Invalidate(InvalidationFlags::CACHED_RENDER_STATE); } -void VKContext::Present() { +void VKContext::Present(int vblanks) { + _dbg_assert_(vblanks == 0 || vblanks == 1); renderManager_.Present(); frameCount_++; } diff --git a/Common/GPU/thin3d.h b/Common/GPU/thin3d.h index e58b6072ce..c90d8ed93d 100644 --- a/Common/GPU/thin3d.h +++ b/Common/GPU/thin3d.h @@ -815,7 +815,7 @@ public: // Frame management (for the purposes of sync and resource management, necessary with modern APIs). Default implementations here. virtual void BeginFrame(DebugFlags debugFlags) {} virtual void EndFrame() = 0; - virtual void Present() = 0; + virtual void Present(int vblanks) = 0; // NOTE: Not all backends support vblanks > 1. virtual void WipeQueue() {} diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 9fe58fa44a..7c7c89db98 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -1157,7 +1157,7 @@ void NativeFrame(GraphicsContext *graphicsContext) { ClearFailedGPUBackends(); } - g_draw->Present(); + g_draw->Present(1); if (resized) { INFO_LOG(G3D, "Resized flag set - recalculating bounds"); diff --git a/UWP/App.cpp b/UWP/App.cpp index 0d5459845e..9c07b544bc 100644 --- a/UWP/App.cpp +++ b/UWP/App.cpp @@ -198,9 +198,8 @@ void App::Run() { while (!m_windowClosed) { if (m_windowVisible) { CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent); - if (m_main->Render()) { - m_deviceResources->Present(); - } + m_main->Render(); + // TODO: Adopt some practices from m_deviceResources->Present(); } else { CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessOneAndAllPending); } diff --git a/UWP/PPSSPP_UWPMain.cpp b/UWP/PPSSPP_UWPMain.cpp index eab8c2ab7f..91fa56553a 100644 --- a/UWP/PPSSPP_UWPMain.cpp +++ b/UWP/PPSSPP_UWPMain.cpp @@ -164,8 +164,6 @@ void PPSSPP_UWPMain::CreateWindowSizeDependentResources() { // Renders the current frame according to the current application state. // Returns true if the frame was rendered and is ready to be displayed. bool PPSSPP_UWPMain::Render() { - ctx_->GetDrawContext()->HandleEvent(Draw::Event::PRESENTED, 0, 0, nullptr, nullptr); - static bool hasSetThreadName = false; if (!hasSetThreadName) { SetCurrentThreadName("UWPRenderThread"); @@ -325,10 +323,6 @@ void UWPGraphicsContext::Shutdown() { delete draw_; } -void UWPGraphicsContext::SwapInterval(int interval) { - -} - std::string System_GetProperty(SystemProperty prop) { static bool hasCheckedGPUDriverVersion = false; switch (prop) { diff --git a/UWP/PPSSPP_UWPMain.h b/UWP/PPSSPP_UWPMain.h index 3be7b25ce4..0d51f1bbf1 100644 --- a/UWP/PPSSPP_UWPMain.h +++ b/UWP/PPSSPP_UWPMain.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include @@ -19,7 +19,7 @@ public: UWPGraphicsContext(std::shared_ptr resources); void Shutdown() override; - void SwapInterval(int interval) override; + void SwapInterval(int interval) override {} void SwapBuffers() override {} void Resize() override {} Draw::DrawContext * GetDrawContext() override { @@ -70,4 +70,4 @@ private: std::unique_ptr ctx_; }; -} \ No newline at end of file +} diff --git a/Windows/GPU/D3D11Context.cpp b/Windows/GPU/D3D11Context.cpp index 0a2c5565ac..4173f9a6ac 100644 --- a/Windows/GPU/D3D11Context.cpp +++ b/Windows/GPU/D3D11Context.cpp @@ -33,11 +33,6 @@ #error This file should not be compiled for UWP. #endif -void D3D11Context::SwapBuffers() { - swapChain_->Present(swapInterval_, 0); - draw_->HandleEvent(Draw::Event::PRESENTED, 0, 0, nullptr, nullptr); -} - void D3D11Context::SwapInterval(int interval) { swapInterval_ = interval; } diff --git a/Windows/GPU/D3D11Context.h b/Windows/GPU/D3D11Context.h index f2f03b2756..b7d2baf20e 100644 --- a/Windows/GPU/D3D11Context.h +++ b/Windows/GPU/D3D11Context.h @@ -31,7 +31,7 @@ public: bool Init(HINSTANCE hInst, HWND window, std::string *error_message) override; void Shutdown() override; void SwapInterval(int interval) override; - void SwapBuffers() override; + void SwapBuffers() override {} void Resize() override; diff --git a/Windows/GPU/D3D9Context.cpp b/Windows/GPU/D3D9Context.cpp index faf5568561..776ed26fc0 100644 --- a/Windows/GPU/D3D9Context.cpp +++ b/Windows/GPU/D3D9Context.cpp @@ -21,18 +21,6 @@ #include "Common/GPU/thin3d_create.h" #include "Common/GPU/D3D9/D3DCompilerLoader.h" -void D3D9Context::SwapBuffers() { - if (has9Ex_) { - deviceEx_->EndScene(); - deviceEx_->PresentEx(NULL, NULL, NULL, NULL, 0); - deviceEx_->BeginScene(); - } else { - device_->EndScene(); - device_->Present(NULL, NULL, NULL, NULL); - device_->BeginScene(); - } -} - typedef HRESULT (__stdcall *DIRECT3DCREATE9EX)(UINT, IDirect3D9Ex**); void D3D9Context::SwapInterval(int interval) { diff --git a/Windows/GPU/D3D9Context.h b/Windows/GPU/D3D9Context.h index 9ad836d338..b916ace945 100644 --- a/Windows/GPU/D3D9Context.h +++ b/Windows/GPU/D3D9Context.h @@ -35,7 +35,7 @@ public: bool Init(HINSTANCE hInst, HWND window, std::string *error_message) override; void Shutdown() override; void SwapInterval(int interval) override; - void SwapBuffers() override; + void SwapBuffers() override {} void Resize() override;