Skip to content

Commit ea33a48

Browse files
committed
Backends: Vulkan: Replaced InitInfo's PipelineInfo PipelineInfoForViewports by SecondaryViewportsInfo SecondaryViewportsInfo
- `PipelineInfoForViewports` was confusing (only one (or two) out of the five (or six) parameters was actually used). - Add `struct ImGui_ImplVulkan_SecondaryViewportsInfo` for viewports specific informations (to be extended and re-used)
1 parent 2289b62 commit ea33a48

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

backends/imgui_impl_vulkan.cpp

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,6 @@ struct ImGui_ImplVulkan_Data
282282
VkDescriptorSetLayout DescriptorSetLayout;
283283
VkPipelineLayout PipelineLayout;
284284
VkPipeline Pipeline; // pipeline for main render pass (created by app)
285-
VkPipeline PipelineForViewports; // pipeline for secondary viewports (created by backend)
286285
VkShaderModule ShaderModuleVert;
287286
VkShaderModule ShaderModuleFrag;
288287
VkDescriptorPool DescriptorPool;
@@ -296,6 +295,12 @@ struct ImGui_ImplVulkan_Data
296295
// Render buffers for main window
297296
ImGui_ImplVulkan_WindowRenderBuffers MainWindowRenderBuffers;
298297

298+
// Viewports common data
299+
// Filled during ImGui_ImplVulkan_PrepareViewportsRendering() based on ViewportsFormat and VulkanInitInfo->SecondaryViewportsInfo
300+
ImGui_ImplVulkan_PipelineInfo PipelineInfoForViewports;
301+
VkPipeline PipelineForViewports; // pipeline for secondary viewports (created by backend)
302+
303+
299304
ImGui_ImplVulkan_Data()
300305
{
301306
memset((void*)this, 0, sizeof(*this));
@@ -1321,7 +1326,7 @@ bool ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo* info)
13211326
else
13221327
IM_ASSERT(info->DescriptorPoolSize > 0);
13231328
if (info->UseDynamicRendering)
1324-
IM_ASSERT(info->PipelineInfoMain.RenderPass == VK_NULL_HANDLE && info->PipelineInfoForViewports.RenderPass == VK_NULL_HANDLE);
1329+
IM_ASSERT(info->PipelineInfoMain.RenderPass == VK_NULL_HANDLE);
13251330

13261331
bd->VulkanInitInfo = *info;
13271332

@@ -1978,18 +1983,18 @@ static void ImGui_ImplVulkan_CreateWindow(ImGuiViewport* viewport)
19781983
}
19791984

19801985
// Select Surface Format
1981-
ImGui_ImplVulkan_PipelineInfo* pipeline_info = &v->PipelineInfoForViewports;
1982-
ImVector<VkFormat> requestSurfaceImageFormats;
1983-
#ifdef IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING
1984-
for (uint32_t n = 0; n < pipeline_info->PipelineRenderingCreateInfo.colorAttachmentCount; n++)
1985-
requestSurfaceImageFormats.push_back(pipeline_info->PipelineRenderingCreateInfo.pColorAttachmentFormats[n]);
1986-
#endif
1987-
const VkFormat defaultFormats[] = { VK_FORMAT_B8G8R8A8_UNORM, VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_B8G8R8_UNORM, VK_FORMAT_R8G8B8_UNORM };
1988-
for (VkFormat format : defaultFormats)
1989-
requestSurfaceImageFormats.push_back(format);
1986+
ImGui_ImplVulkan_PipelineInfo* pipeline_info = &bd->PipelineInfoForViewports;
1987+
const VkFormat requestSurfaceImageFormats[] = { v->SecondaryViewportsInfo.DesiredFormat.format, VK_FORMAT_B8G8R8A8_UNORM, VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_B8G8R8_UNORM, VK_FORMAT_R8G8B8_UNORM };
1988+
int requestSurfaceImageFormatsCount = IM_ARRAYSIZE(requestSurfaceImageFormats);
1989+
const VkFormat* pRequestSurfaceImageFormats = requestSurfaceImageFormats;
1990+
if (pRequestSurfaceImageFormats[0] == VK_FORMAT_UNDEFINED)
1991+
{
1992+
++pRequestSurfaceImageFormats;
1993+
--requestSurfaceImageFormatsCount;
1994+
}
19901995

1991-
const VkColorSpaceKHR requestSurfaceColorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR;
1992-
wd->SurfaceFormat = ImGui_ImplVulkanH_SelectSurfaceFormat(v->PhysicalDevice, wd->Surface, requestSurfaceImageFormats.Data, (size_t)requestSurfaceImageFormats.Size, requestSurfaceColorSpace);
1996+
const VkColorSpaceKHR requestSurfaceColorSpace = v->SecondaryViewportsInfo.DesiredFormat.colorSpace;
1997+
wd->SurfaceFormat = ImGui_ImplVulkanH_SelectSurfaceFormat(v->PhysicalDevice, wd->Surface, pRequestSurfaceImageFormats, requestSurfaceImageFormatsCount, requestSurfaceColorSpace);
19931998

19941999
// Select Present Mode
19952000
// 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)
@@ -2000,7 +2005,7 @@ static void ImGui_ImplVulkan_CreateWindow(ImGuiViewport* viewport)
20002005
// Create SwapChain, RenderPass, Framebuffer, etc.
20012006
wd->ClearEnable = (viewport->Flags & ImGuiViewportFlags_NoRendererClear) ? false : true;
20022007
wd->UseDynamicRendering = v->UseDynamicRendering;
2003-
ImGui_ImplVulkanH_CreateOrResizeWindow(v->Instance, v->PhysicalDevice, v->Device, wd, v->QueueFamily, v->Allocator, (int)viewport->Size.x, (int)viewport->Size.y, v->MinImageCount, pipeline_info->SwapChainImageUsage);
2008+
ImGui_ImplVulkanH_CreateOrResizeWindow(v->Instance, v->PhysicalDevice, v->Device, wd, v->QueueFamily, v->Allocator, (int)viewport->Size.x, (int)viewport->Size.y, v->MinImageCount, v->SecondaryViewportsInfo.SwapChainImageUsage);
20042009
vd->WindowOwned = true;
20052010

20062011
// Create pipeline (shared by all secondary viewports)
@@ -2018,7 +2023,7 @@ static void ImGui_ImplVulkan_CreateWindow(ImGuiViewport* viewport)
20182023
pipeline_info->RenderPass = wd->RenderPass;
20192024
}
20202025
#endif
2021-
bd->PipelineForViewports = ImGui_ImplVulkan_CreatePipeline(v->Device, v->Allocator, VK_NULL_HANDLE, &v->PipelineInfoForViewports);
2026+
bd->PipelineForViewports = ImGui_ImplVulkan_CreatePipeline(v->Device, v->Allocator, VK_NULL_HANDLE, pipeline_info);
20222027
}
20232028
}
20242029

@@ -2045,7 +2050,7 @@ static void ImGui_ImplVulkan_SetWindowSize(ImGuiViewport* viewport, ImVec2 size)
20452050
return;
20462051
ImGui_ImplVulkan_InitInfo* v = &bd->VulkanInitInfo;
20472052
vd->Window.ClearEnable = (viewport->Flags & ImGuiViewportFlags_NoRendererClear) ? false : true;
2048-
ImGui_ImplVulkanH_CreateOrResizeWindow(v->Instance, v->PhysicalDevice, v->Device, &vd->Window, v->QueueFamily, v->Allocator, (int)size.x, (int)size.y, v->MinImageCount, v->PipelineInfoForViewports.SwapChainImageUsage);
2053+
ImGui_ImplVulkanH_CreateOrResizeWindow(v->Instance, v->PhysicalDevice, v->Device, &vd->Window, v->QueueFamily, v->Allocator, (int)size.x, (int)size.y, v->MinImageCount, v->SecondaryViewportsInfo.SwapChainImageUsage);
20492054
}
20502055

20512056
static void ImGui_ImplVulkan_RenderWindow(ImGuiViewport* viewport, void*)
@@ -2058,7 +2063,7 @@ static void ImGui_ImplVulkan_RenderWindow(ImGuiViewport* viewport, void*)
20582063

20592064
if (vd->SwapChainNeedRebuild || vd->SwapChainSuboptimal)
20602065
{
2061-
ImGui_ImplVulkanH_CreateOrResizeWindow(v->Instance, v->PhysicalDevice, v->Device, wd, v->QueueFamily, v->Allocator, (int)viewport->Size.x, (int)viewport->Size.y, v->MinImageCount, v->PipelineInfoForViewports.SwapChainImageUsage);
2066+
ImGui_ImplVulkanH_CreateOrResizeWindow(v->Instance, v->PhysicalDevice, v->Device, wd, v->QueueFamily, v->Allocator, (int)viewport->Size.x, (int)viewport->Size.y, v->MinImageCount, v->SecondaryViewportsInfo.SwapChainImageUsage);
20622067
vd->SwapChainNeedRebuild = vd->SwapChainSuboptimal = false;
20632068
}
20642069

backends/imgui_impl_vulkan.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
// Backend uses a small number of descriptors per font atlas + as many as additional calls done to ImGui_ImplVulkan_AddTexture().
6767
#define IMGUI_IMPL_VULKAN_MINIMUM_IMAGE_SAMPLER_POOL_SIZE (8) // Minimum per atlas
6868

69-
// Specify settings to create pipeline and swapchain
69+
// Specify settings to create pipeline
7070
struct ImGui_ImplVulkan_PipelineInfo
7171
{
7272
// For Main viewport only
@@ -78,8 +78,13 @@ struct ImGui_ImplVulkan_PipelineInfo
7878
#ifdef IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING
7979
VkPipelineRenderingCreateInfoKHR PipelineRenderingCreateInfo; // Optional, valid if .sType == VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO_KHR
8080
#endif
81+
};
82+
83+
struct ImGui_ImplVulkan_SecondaryViewportsInfo
84+
{
85+
// Ignored if .format == VK_FORMAT_UNDEFINED
86+
VkSurfaceFormatKHR DesiredFormat;
8187

82-
// For Secondary viewports only (created/managed by backend)
8388
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.
8489
};
8590

@@ -107,7 +112,6 @@ struct ImGui_ImplVulkan_InitInfo
107112

108113
// Pipeline
109114
ImGui_ImplVulkan_PipelineInfo PipelineInfoMain; // Infos for Main Viewport (created by app/user)
110-
ImGui_ImplVulkan_PipelineInfo PipelineInfoForViewports; // Infos for Secondary Viewports (created by backend)
111115
//VkRenderPass RenderPass; // --> Since 2025/09/26: set 'PipelineInfoMain.RenderPass' instead
112116
//uint32_t Subpass; // --> Since 2025/09/26: set 'PipelineInfoMain.Subpass' instead
113117
//VkSampleCountFlagBits MSAASamples; // --> Since 2025/09/26: set 'PipelineInfoMain.MSAASamples' instead
@@ -117,6 +121,9 @@ struct ImGui_ImplVulkan_InitInfo
117121
// Need to explicitly enable VK_KHR_dynamic_rendering extension to use this, even for Vulkan 1.3 + setup PipelineInfoMain.PipelineRenderingCreateInfo and PipelineInfoViewports.PipelineRenderingCreateInfo.
118122
bool UseDynamicRendering;
119123

124+
// Optional
125+
ImGui_ImplVulkan_SecondaryViewportsInfo SecondaryViewportsInfo;
126+
120127
// (Optional) Allocation, Debugging
121128
const VkAllocationCallbacks* Allocator;
122129
void (*CheckVkResultFn)(VkResult err);

0 commit comments

Comments
 (0)