diff --git a/core/rend/gui_util.h b/core/rend/gui_util.h index 25bf55641..ade64dfcd 100644 --- a/core/rend/gui_util.h +++ b/core/rend/gui_util.h @@ -39,6 +39,7 @@ static inline void ImGui_impl_RenderDrawData(ImDrawData *draw_data, bool save_ba { context->NewFrame(); context->BeginRenderPass(); + context->PresentLastFrame(); } // Record Imgui Draw Data and draw funcs into command buffer ImGui_ImplVulkan_RenderDrawData(draw_data, (VkCommandBuffer)context->GetCurrentCommandBuffer()); diff --git a/core/rend/vulkan/vulkan_context.cpp b/core/rend/vulkan/vulkan_context.cpp index 339b4b80f..f3ec2539d 100644 --- a/core/rend/vulkan/vulkan_context.cpp +++ b/core/rend/vulkan/vulkan_context.cpp @@ -692,13 +692,8 @@ void VulkanContext::Present() } } -extern Renderer *renderer; - -void VulkanContext::PresentFrame(vk::ImageView imageView, vk::Offset2D extent) +void VulkanContext::DrawFrame(vk::ImageView imageView, vk::Offset2D extent) { - NewFrame(); - BeginRenderPass(); - float marginWidth = ((float)extent.y / extent.x * width / height - 1.f) / 2.f; QuadVertex vtx[] = { { { -1, -1, 0 }, { 0 - marginWidth, 0 } }, @@ -723,12 +718,32 @@ void VulkanContext::PresentFrame(vk::ImageView imageView, vk::Offset2D extent) commandBuffer.setScissor(0, vk::Rect2D(vk::Offset2D(0, 0), vk::Extent2D(width, height))); quadBuffer->Bind(commandBuffer); quadBuffer->Draw(commandBuffer); +} + +extern Renderer *renderer; + +void VulkanContext::PresentFrame(vk::ImageView imageView, vk::Offset2D extent) +{ + NewFrame(); + BeginRenderPass(); + + DrawFrame(imageView, extent); renderer->DrawOSD(false); EndFrame(); + + lastFrameView = imageView; + lastFrameExtent = extent; +} + +void VulkanContext::PresentLastFrame() +{ + if (lastFrameView) + DrawFrame(lastFrameView, lastFrameExtent); } void VulkanContext::Term() { + lastFrameView = nullptr; ImGui_ImplVulkan_Shutdown(); gui_term(); if (device && pipelineCache) diff --git a/core/rend/vulkan/vulkan_context.h b/core/rend/vulkan/vulkan_context.h index 68bc65de9..933309d1b 100644 --- a/core/rend/vulkan/vulkan_context.h +++ b/core/rend/vulkan/vulkan_context.h @@ -47,6 +47,7 @@ public: void EndFrame(); void Present(); void PresentFrame(vk::ImageView imageView, vk::Offset2D extent); + void PresentLastFrame(); vk::PhysicalDevice GetPhysicalDevice() const { return physicalDevice; } vk::Device GetDevice() const { return *device; } @@ -91,6 +92,7 @@ private: vk::Format FindDepthFormat(); void InitImgui(); void DoSwapAutomation(); + void DrawFrame(vk::ImageView imageView, vk::Offset2D extent); vk::SurfaceKHR GetSurface() { #ifdef USE_SDL return surface; @@ -181,6 +183,9 @@ private: std::unique_ptr quadPipeline; std::unique_ptr shaderManager; + vk::ImageView lastFrameView; + vk::Offset2D lastFrameExtent; + #ifdef VK_DEBUG #ifndef __ANDROID__ vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger;