@@ -247,8 +247,9 @@ struct ImGui_ImplVulkan_ViewportData
247
247
ImGui_ImplVulkan_WindowRenderBuffers RenderBuffers; // Used by all viewports
248
248
bool WindowOwned;
249
249
bool SwapChainNeedRebuild; // Flag when viewport swapchain resized in the middle of processing a frame
250
+ bool SwapChainSuboptimal; // Flag when VK_SUBOPTIMAL_KHR was returned.
250
251
251
- ImGui_ImplVulkan_ViewportData () { WindowOwned = SwapChainNeedRebuild = false ; memset (&RenderBuffers, 0 , sizeof (RenderBuffers)); }
252
+ ImGui_ImplVulkan_ViewportData () { WindowOwned = SwapChainNeedRebuild = SwapChainSuboptimal = false ; memset (&RenderBuffers, 0 , sizeof (RenderBuffers)); }
252
253
~ImGui_ImplVulkan_ViewportData () { }
253
254
};
254
255
@@ -1808,10 +1809,10 @@ static void ImGui_ImplVulkan_RenderWindow(ImGuiViewport* viewport, void*)
1808
1809
ImGui_ImplVulkan_InitInfo* v = &bd->VulkanInitInfo ;
1809
1810
VkResult err;
1810
1811
1811
- if (vd->SwapChainNeedRebuild )
1812
+ if (vd->SwapChainNeedRebuild || vd-> SwapChainSuboptimal )
1812
1813
{
1813
1814
ImGui_ImplVulkanH_CreateOrResizeWindow (v->Instance , v->PhysicalDevice , v->Device , wd, v->QueueFamily , v->Allocator , (int )viewport->Size .x , (int )viewport->Size .y , v->MinImageCount );
1814
- vd->SwapChainNeedRebuild = false ;
1815
+ vd->SwapChainNeedRebuild = vd-> SwapChainSuboptimal = false ;
1815
1816
}
1816
1817
1817
1818
ImGui_ImplVulkanH_Frame* fd = nullptr ;
@@ -1821,11 +1822,13 @@ static void ImGui_ImplVulkan_RenderWindow(ImGuiViewport* viewport, void*)
1821
1822
err = vkAcquireNextImageKHR (v->Device , wd->Swapchain , UINT64_MAX, fsd->ImageAcquiredSemaphore , VK_NULL_HANDLE, &wd->FrameIndex );
1822
1823
if (err == VK_ERROR_OUT_OF_DATE_KHR)
1823
1824
{
1824
- // Since we are not going to swap this frame anyway, it's ok that recreation happens on next frame.
1825
- vd->SwapChainNeedRebuild = true ;
1825
+ vd->SwapChainNeedRebuild = true ; // Since we are not going to swap this frame anyway, it's ok that recreation happens on next frame.
1826
1826
return ;
1827
1827
}
1828
- check_vk_result (err);
1828
+ if (err == VK_SUBOPTIMAL_KHR)
1829
+ vd->SwapChainSuboptimal = true ;
1830
+ else
1831
+ check_vk_result (err);
1829
1832
fd = &wd->Frames [wd->FrameIndex ];
1830
1833
}
1831
1834
for (;;)
@@ -1967,11 +1970,14 @@ static void ImGui_ImplVulkan_SwapBuffers(ImGuiViewport* viewport, void*)
1967
1970
info.pSwapchains = &wd->Swapchain ;
1968
1971
info.pImageIndices = &present_index;
1969
1972
err = vkQueuePresentKHR (v->Queue , &info);
1970
- if (err == VK_ERROR_OUT_OF_DATE_KHR || err == VK_SUBOPTIMAL_KHR)
1971
- vd->SwapChainNeedRebuild = true ;
1972
1973
if (err == VK_ERROR_OUT_OF_DATE_KHR)
1974
+ {
1975
+ vd->SwapChainNeedRebuild = true ;
1973
1976
return ;
1974
- if (err != VK_SUBOPTIMAL_KHR)
1977
+ }
1978
+ if (err == VK_SUBOPTIMAL_KHR)
1979
+ vd->SwapChainSuboptimal = true ;
1980
+ else
1975
1981
check_vk_result (err);
1976
1982
wd->SemaphoreIndex = (wd->SemaphoreIndex + 1 ) % wd->SemaphoreCount ; // Now we can use the next set of semaphores
1977
1983
}
0 commit comments