Skip to content

Commit 764a775

Browse files
committed
Backends: Vulkan: Add viewports desired present mode (at init)
- Add `ImGui_ImplVulkan_SelectPresentMode(ImGuiViewport*)` for later re-use
1 parent ea33a48 commit 764a775

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

backends/imgui_impl_vulkan.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1960,6 +1960,26 @@ ImGui_ImplVulkanH_Window* ImGui_ImplVulkanH_GetWindowDataFromViewport(ImGuiViewp
19601960
// If you are new to dear imgui or creating a new binding for dear imgui, it is recommended that you completely ignore this section first..
19611961
//--------------------------------------------------------------------------------------------------------
19621962

1963+
static void ImGui_ImplVulkan_SelectPresentMode(ImGuiViewport* viewport)
1964+
{
1965+
ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData();
1966+
ImGui_ImplVulkan_InitInfo* v = &bd->VulkanInitInfo;
1967+
ImGui_ImplVulkan_ViewportData* vd = (ImGui_ImplVulkan_ViewportData*)viewport->RendererUserData;
1968+
ImGui_ImplVulkanH_Window* wd = &vd->Window;
1969+
1970+
// FIXME-VULKAN: Even thought mailbox seems to get us maximum framerate with a single window, it halves framerate with a second window etc. (w/ Nvidia and SDK 1.82.1)
1971+
const VkPresentModeKHR presentModes[] = { v->SecondaryViewportsInfo.DesiredPresentMode, VK_PRESENT_MODE_MAILBOX_KHR, VK_PRESENT_MODE_IMMEDIATE_KHR, VK_PRESENT_MODE_FIFO_KHR };
1972+
int presentModesCount = IM_ARRAYSIZE(presentModes);
1973+
const VkPresentModeKHR* pPresentModes = presentModes;
1974+
if (pPresentModes[0] == VK_PRESENT_MODE_MAX_ENUM_KHR)
1975+
{
1976+
++pPresentModes;
1977+
--presentModesCount;
1978+
}
1979+
wd->PresentMode = ImGui_ImplVulkanH_SelectPresentMode(v->PhysicalDevice, wd->Surface, presentModes, presentModesCount);
1980+
//printf("[vulkan] Secondary window selected PresentMode = %d\n", wd->PresentMode);
1981+
}
1982+
19631983
static void ImGui_ImplVulkan_CreateWindow(ImGuiViewport* viewport)
19641984
{
19651985
ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData();
@@ -1997,10 +2017,7 @@ static void ImGui_ImplVulkan_CreateWindow(ImGuiViewport* viewport)
19972017
wd->SurfaceFormat = ImGui_ImplVulkanH_SelectSurfaceFormat(v->PhysicalDevice, wd->Surface, pRequestSurfaceImageFormats, requestSurfaceImageFormatsCount, requestSurfaceColorSpace);
19982018

19992019
// Select Present Mode
2000-
// FIXME-VULKAN: Even thought mailbox seems to get us maximum framerate with a single window, it halves framerate with a second window etc. (w/ Nvidia and SDK 1.82.1)
2001-
VkPresentModeKHR present_modes[] = { VK_PRESENT_MODE_MAILBOX_KHR, VK_PRESENT_MODE_IMMEDIATE_KHR, VK_PRESENT_MODE_FIFO_KHR };
2002-
wd->PresentMode = ImGui_ImplVulkanH_SelectPresentMode(v->PhysicalDevice, wd->Surface, &present_modes[0], IM_ARRAYSIZE(present_modes));
2003-
//printf("[vulkan] Secondary window selected PresentMode = %d\n", wd->PresentMode);
2020+
ImGui_ImplVulkan_SelectPresentMode(viewport);
20042021

20052022
// Create SwapChain, RenderPass, Framebuffer, etc.
20062023
wd->ClearEnable = (viewport->Flags & ImGuiViewportFlags_NoRendererClear) ? false : true;

backends/imgui_impl_vulkan.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ struct ImGui_ImplVulkan_SecondaryViewportsInfo
8484
{
8585
// Ignored if .format == VK_FORMAT_UNDEFINED
8686
VkSurfaceFormatKHR DesiredFormat;
87+
// Ignored if set to VK_PRESENT_MODE_MAX_ENUM_KHR
88+
// Warning: The default zero initialized value is VK_PRESENT_MODE_IMMEDIATE_KHR!
89+
VkPresentModeKHR DesiredPresentMode;
8790

8891
VkImageUsageFlags SwapChainImageUsage; // Extra flags for vkCreateSwapchainKHR() calls for secondary viewports. We automatically add VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT. You can add e.g. VK_IMAGE_USAGE_TRANSFER_SRC_BIT if you need to capture from viewports.
8992
};

0 commit comments

Comments
 (0)