diff --git a/Common/GPU/D3D11/thin3d_d3d11.cpp b/Common/GPU/D3D11/thin3d_d3d11.cpp index 0248c44856..e80fe6ef20 100644 --- a/Common/GPU/D3D11/thin3d_d3d11.cpp +++ b/Common/GPU/D3D11/thin3d_d3d11.cpp @@ -139,6 +139,7 @@ public: void BeginFrame() override; void EndFrame() override; + void Present() override; int GetFrameCount() override { return frameCount_; } @@ -433,6 +434,9 @@ void D3D11DrawContext::HandleEvent(Event ev, int width, int height, void *param1 void D3D11DrawContext::EndFrame() { curPipeline_ = nullptr; +} + +void D3D11DrawContext::Present() { frameCount_++; } diff --git a/Common/GPU/D3D9/thin3d_d3d9.cpp b/Common/GPU/D3D9/thin3d_d3d9.cpp index a05057d8a1..84ce9da268 100644 --- a/Common/GPU/D3D9/thin3d_d3d9.cpp +++ b/Common/GPU/D3D9/thin3d_d3d9.cpp @@ -580,6 +580,8 @@ public: } void EndFrame() override; + void Present() override; + int GetFrameCount() override { return frameCount_; } void UpdateDynamicUniformBuffer(const void *ub, size_t size) override; @@ -966,6 +968,9 @@ void D3D9Context::BindNativeTexture(int index, void *nativeTexture) { void D3D9Context::EndFrame() { curPipeline_ = nullptr; +} + +void D3D9Context::Present() { frameCount_++; } diff --git a/Common/GPU/OpenGL/thin3d_gl.cpp b/Common/GPU/OpenGL/thin3d_gl.cpp index df93103468..a1da0cc9b4 100644 --- a/Common/GPU/OpenGL/thin3d_gl.cpp +++ b/Common/GPU/OpenGL/thin3d_gl.cpp @@ -369,6 +369,7 @@ public: void BeginFrame() override; void EndFrame() override; + void Present() override; int GetFrameCount() override { return frameCount_; @@ -803,8 +804,10 @@ void OpenGLContext::EndFrame() { FrameData &frameData = frameData_[renderManager_.GetCurFrame()]; renderManager_.EndPushBuffer(frameData.push); // upload the data! renderManager_.Finish(); - Invalidate(InvalidationFlags::CACHED_RENDER_STATE); +} + +void OpenGLContext::Present() { frameCount_++; } diff --git a/Common/GPU/Vulkan/thin3d_vulkan.cpp b/Common/GPU/Vulkan/thin3d_vulkan.cpp index baca7f122e..b4d7db8012 100644 --- a/Common/GPU/Vulkan/thin3d_vulkan.cpp +++ b/Common/GPU/Vulkan/thin3d_vulkan.cpp @@ -481,6 +481,8 @@ public: void BeginFrame() override; void EndFrame() override; + void Present() override; + void WipeQueue() override; int GetFrameCount() override { @@ -1115,12 +1117,14 @@ void VKContext::BeginFrame() { } void VKContext::EndFrame() { + // Do all the work to submit the command buffers etc. renderManager_.Finish(); - renderManager_.Present(); - // Unbind stuff, to avoid accidentally relying on it across frames (and provide some protection against forgotten unbinds of deleted things). Invalidate(InvalidationFlags::CACHED_RENDER_STATE); +} +void VKContext::Present() { + renderManager_.Present(); frameCount_++; } diff --git a/Common/GPU/thin3d.h b/Common/GPU/thin3d.h index 7478a921cc..6f752708dd 100644 --- a/Common/GPU/thin3d.h +++ b/Common/GPU/thin3d.h @@ -816,6 +816,8 @@ public: // Frame management (for the purposes of sync and resource management, necessary with modern APIs). Default implementations here. virtual void BeginFrame() {} virtual void EndFrame() = 0; + virtual void Present() = 0; + virtual void WipeQueue() {} // This should be avoided as much as possible, in favor of clearing when binding a render target, which is native diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index af62a26659..1289c7839c 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -1136,16 +1136,18 @@ void NativeFrame(GraphicsContext *graphicsContext) { g_screenManager->getDrawContext()->SetDebugFlags(debugFlags); g_draw->BeginFrame(); - // All actual rendering happen in here. g_screenManager->render(); if (g_screenManager->getUIContext()->Text()) { g_screenManager->getUIContext()->Text()->OncePerFrame(); } - - // This triggers present. g_draw->EndFrame(); + // This, between EndFrame and Present, is where we should actually wait to do present time management. + // There might not be a meaningful distinction here for all backends.. + + g_draw->Present(); + if (resized) { INFO_LOG(G3D, "Resized flag set - recalculating bounds"); resized = false;