Skip to content

Commit 109dd2b

Browse files
committed
Backends: Vulkan: VK_SUBOPTIMAL_KHR doesn't skip frame. (ocornut#7831, ocornut#7825)
1 parent 507cdba commit 109dd2b

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

backends/imgui_impl_vulkan.cpp

+15-9
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,9 @@ struct ImGui_ImplVulkan_ViewportData
247247
ImGui_ImplVulkan_WindowRenderBuffers RenderBuffers; // Used by all viewports
248248
bool WindowOwned;
249249
bool SwapChainNeedRebuild; // Flag when viewport swapchain resized in the middle of processing a frame
250+
bool SwapChainSuboptimal; // Flag when VK_SUBOPTIMAL_KHR was returned.
250251

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)); }
252253
~ImGui_ImplVulkan_ViewportData() { }
253254
};
254255

@@ -1808,10 +1809,10 @@ static void ImGui_ImplVulkan_RenderWindow(ImGuiViewport* viewport, void*)
18081809
ImGui_ImplVulkan_InitInfo* v = &bd->VulkanInitInfo;
18091810
VkResult err;
18101811

1811-
if (vd->SwapChainNeedRebuild)
1812+
if (vd->SwapChainNeedRebuild || vd->SwapChainSuboptimal)
18121813
{
18131814
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;
18151816
}
18161817

18171818
ImGui_ImplVulkanH_Frame* fd = nullptr;
@@ -1821,11 +1822,13 @@ static void ImGui_ImplVulkan_RenderWindow(ImGuiViewport* viewport, void*)
18211822
err = vkAcquireNextImageKHR(v->Device, wd->Swapchain, UINT64_MAX, fsd->ImageAcquiredSemaphore, VK_NULL_HANDLE, &wd->FrameIndex);
18221823
if (err == VK_ERROR_OUT_OF_DATE_KHR)
18231824
{
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.
18261826
return;
18271827
}
1828-
check_vk_result(err);
1828+
if (err == VK_SUBOPTIMAL_KHR)
1829+
vd->SwapChainSuboptimal = true;
1830+
else
1831+
check_vk_result(err);
18291832
fd = &wd->Frames[wd->FrameIndex];
18301833
}
18311834
for (;;)
@@ -1967,11 +1970,14 @@ static void ImGui_ImplVulkan_SwapBuffers(ImGuiViewport* viewport, void*)
19671970
info.pSwapchains = &wd->Swapchain;
19681971
info.pImageIndices = &present_index;
19691972
err = vkQueuePresentKHR(v->Queue, &info);
1970-
if (err == VK_ERROR_OUT_OF_DATE_KHR || err == VK_SUBOPTIMAL_KHR)
1971-
vd->SwapChainNeedRebuild = true;
19721973
if (err == VK_ERROR_OUT_OF_DATE_KHR)
1974+
{
1975+
vd->SwapChainNeedRebuild = true;
19731976
return;
1974-
if (err != VK_SUBOPTIMAL_KHR)
1977+
}
1978+
if (err == VK_SUBOPTIMAL_KHR)
1979+
vd->SwapChainSuboptimal = true;
1980+
else
19751981
check_vk_result(err);
19761982
wd->SemaphoreIndex = (wd->SemaphoreIndex + 1) % wd->SemaphoreCount; // Now we can use the next set of semaphores
19771983
}

docs/CHANGELOG.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,13 @@ Other changes:
4646
- ImDrawList: texture baked storage for thick line reduced from ~64x64 to ~32x32. (#3245)
4747
- Examples: DirectX12: Reduced number of frame in flight from 3 to 2 in
4848
provided example, to reduce latency.
49-
- Examples: Vulkan: better handle VK_SUBOPTIMAL_KHR being returned by
49+
- Backends+Examples: Vulkan: better handle VK_SUBOPTIMAL_KHR being returned by
5050
vkAcquireNextImageKHR() or vkQueuePresentKHR(). (#7825, #7831) [@NostraMagister]
5151
- Backends: DirectX12: Texture upload use the command queue provided in
5252
ImGui_ImplDX12_InitInfo instead of creating its own.
5353

54+
Docking+Viewports Branch:
55+
5456

5557
-----------------------------------------------------------------------
5658
VERSION 1.91.7 (Released 2025-01-14)

0 commit comments

Comments
 (0)