Skip to content

Commit e4e3c2c

Browse files
committed
Backends: Vulkan: amends for docking. Add PipelineInfoForViewports and SwapChainImageUsage. (#8946, #8110, #8111, #8686)
1 parent f3e8531 commit e4e3c2c

File tree

3 files changed

+30
-18
lines changed

3 files changed

+30
-18
lines changed

backends/imgui_impl_vulkan.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,7 +1321,9 @@ bool ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo* info)
13211321
else
13221322
IM_ASSERT(info->DescriptorPoolSize > 0);
13231323
if (info->UseDynamicRendering)
1324-
IM_ASSERT(info->PipelineInfoMain.RenderPass == VK_NULL_HANDLE);
1324+
IM_ASSERT(info->PipelineInfoMain.RenderPass == VK_NULL_HANDLE && info->PipelineInfoForViewports.RenderPass == VK_NULL_HANDLE);
1325+
else if (info->PipelineInfoForViewports.RenderPass == NULL)
1326+
info->PipelineInfoForViewports.RenderPass = info->PipelineInfoMain.RenderPass;
13251327

13261328
bd->VulkanInitInfo = *info;
13271329

@@ -1975,10 +1977,11 @@ static void ImGui_ImplVulkan_CreateWindow(ImGuiViewport* viewport)
19751977
}
19761978

19771979
// Select Surface Format
1980+
ImGui_ImplVulkan_PipelineInfo* pipeline_info = &v->PipelineInfoForViewports;
19781981
ImVector<VkFormat> requestSurfaceImageFormats;
19791982
#ifdef IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING
1980-
for (uint32_t n = 0; n < v->PipelineRenderingCreateInfo.colorAttachmentCount; n++)
1981-
requestSurfaceImageFormats.push_back(v->PipelineRenderingCreateInfo.pColorAttachmentFormats[n]);
1983+
for (uint32_t n = 0; n < pipeline_info->PipelineRenderingCreateInfo.colorAttachmentCount; n++)
1984+
requestSurfaceImageFormats.push_back(pipeline_info->PipelineRenderingCreateInfo.pColorAttachmentFormats[n]);
19821985
#endif
19831986
const VkFormat defaultFormats[] = { VK_FORMAT_B8G8R8A8_UNORM, VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_B8G8R8_UNORM, VK_FORMAT_R8G8B8_UNORM };
19841987
for (VkFormat format : defaultFormats)
@@ -1996,28 +1999,25 @@ static void ImGui_ImplVulkan_CreateWindow(ImGuiViewport* viewport)
19961999
// Create SwapChain, RenderPass, Framebuffer, etc.
19972000
wd->ClearEnable = (viewport->Flags & ImGuiViewportFlags_NoRendererClear) ? false : true;
19982001
wd->UseDynamicRendering = v->UseDynamicRendering;
1999-
ImGui_ImplVulkanH_CreateOrResizeWindow(v->Instance, v->PhysicalDevice, v->Device, wd, v->QueueFamily, v->Allocator, (int)viewport->Size.x, (int)viewport->Size.y, v->MinImageCount);
2002+
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);
20002003
vd->WindowOwned = true;
20012004

20022005
// Create pipeline (shared by all secondary viewports)
20032006
if (bd->PipelineForViewports == VK_NULL_HANDLE)
20042007
{
2005-
VkPipelineRenderingCreateInfoKHR* p_rendering_info = nullptr;
20062008
#ifdef IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING
2007-
VkPipelineRenderingCreateInfoKHR rendering_info = {};
20082009
if (wd->UseDynamicRendering)
20092010
{
2010-
rendering_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO;
2011-
rendering_info.pNext = nullptr;
2012-
rendering_info.viewMask = 0;
2013-
rendering_info.colorAttachmentCount = 1;
2014-
rendering_info.pColorAttachmentFormats = &wd->SurfaceFormat.format;
2015-
rendering_info.depthAttachmentFormat = VK_FORMAT_UNDEFINED;
2016-
rendering_info.stencilAttachmentFormat = VK_FORMAT_UNDEFINED;
2017-
p_rendering_info = &rendering_info;
2011+
pipeline_info->PipelineRenderingCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO;
2012+
pipeline_info->PipelineRenderingCreateInfo.colorAttachmentCount = 1;
2013+
pipeline_info->PipelineRenderingCreateInfo.pColorAttachmentFormats = &wd->SurfaceFormat.format;
2014+
}
2015+
else
2016+
{
2017+
IM_ASSERT(pipeline_info->RenderPass != VK_NULL_HANDLE && "Did you set ImGui_ImplVulkan_InitInfo::PipelineInfoForViewports.RenderPass?"); // Since 1.92.4 it is required.
20182018
}
20192019
#endif
2020-
bd->PipelineForViewports = ImGui_ImplVulkan_CreatePipeline(v->Device, v->Allocator, VK_NULL_HANDLE, wd->UseDynamicRendering ? VK_NULL_HANDLE : wd->RenderPass, VK_SAMPLE_COUNT_1_BIT, 0, p_rendering_info);
2020+
bd->PipelineForViewports = ImGui_ImplVulkan_CreatePipeline(v->Device, v->Allocator, VK_NULL_HANDLE, &v->PipelineInfoForViewports);
20212021
}
20222022
}
20232023

@@ -2044,7 +2044,7 @@ static void ImGui_ImplVulkan_SetWindowSize(ImGuiViewport* viewport, ImVec2 size)
20442044
return;
20452045
ImGui_ImplVulkan_InitInfo* v = &bd->VulkanInitInfo;
20462046
vd->Window.ClearEnable = (viewport->Flags & ImGuiViewportFlags_NoRendererClear) ? false : true;
2047-
ImGui_ImplVulkanH_CreateOrResizeWindow(v->Instance, v->PhysicalDevice, v->Device, &vd->Window, v->QueueFamily, v->Allocator, (int)size.x, (int)size.y, v->MinImageCount);
2047+
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);
20482048
}
20492049

20502050
static void ImGui_ImplVulkan_RenderWindow(ImGuiViewport* viewport, void*)
@@ -2057,7 +2057,7 @@ static void ImGui_ImplVulkan_RenderWindow(ImGuiViewport* viewport, void*)
20572057

20582058
if (vd->SwapChainNeedRebuild || vd->SwapChainSuboptimal)
20592059
{
2060-
ImGui_ImplVulkanH_CreateOrResizeWindow(v->Instance, v->PhysicalDevice, v->Device, wd, v->QueueFamily, v->Allocator, (int)viewport->Size.x, (int)viewport->Size.y, v->MinImageCount);
2060+
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);
20612061
vd->SwapChainNeedRebuild = vd->SwapChainSuboptimal = false;
20622062
}
20632063

backends/imgui_impl_vulkan.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ struct ImGui_ImplVulkan_PipelineInfo
7676
#ifdef IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING
7777
VkPipelineRenderingCreateInfoKHR PipelineRenderingCreateInfo; // Optional, valid if .sType == VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO_KHR
7878
#endif
79+
80+
// For Secondary viewports only (created/managed by backend)
81+
VkImageUsageFlags SwapChainImageUsage; // 0 defaults to VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT. Add e.g. VK_IMAGE_USAGE_TRANSFER_SRC_BIT if you need to capture from viewports.
7982
};
8083

8184
// Initialization data, for ImGui_ImplVulkan_Init()
@@ -102,13 +105,14 @@ struct ImGui_ImplVulkan_InitInfo
102105

103106
// Pipeline
104107
ImGui_ImplVulkan_PipelineInfo PipelineInfoMain; // Infos for Main Viewport (created by app/user)
108+
ImGui_ImplVulkan_PipelineInfo PipelineInfoForViewports; // Infos for Secondary Viewports (created by backend)
105109
//VkRenderPass RenderPass; // --> Since 2025/09/26: set 'PipelineInfoMain.RenderPass' instead
106110
//uint32_t Subpass; // --> Since 2025/09/26: set 'PipelineInfoMain.Subpass' instead
107111
//VkSampleCountFlagBits MSAASamples; // --> Since 2025/09/26: set 'PipelineInfoMain.MSAASamples' instead
108112
//VkPipelineRenderingCreateInfoKHR PipelineRenderingCreateInfo; // Since 2025/09/26: set 'PipelineInfoMain.PipelineRenderingCreateInfo' instead
109113

110114
// (Optional) Dynamic Rendering
111-
// Need to explicitly enable VK_KHR_dynamic_rendering extension to use this, even for Vulkan 1.3 + setup PipelineInfoMain.PipelineRenderingCreateInfo.
115+
// Need to explicitly enable VK_KHR_dynamic_rendering extension to use this, even for Vulkan 1.3 + setup PipelineInfoMain.PipelineRenderingCreateInfo and PipelineInfoViewports.PipelineRenderingCreateInfo.
112116
bool UseDynamicRendering;
113117

114118
// (Optional) Allocation, Debugging

docs/CHANGELOG.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ Docking+Viewports Branch:
109109
backends have been shutdown since 1.90.4. Changed into asserts. (#7175, #8945)
110110
- Backends: DX10, DX11, DX12: Disabled DXGI's Alt+Enter default behavior on secondary
111111
viewports managed by the backend. (#4350) [@PathogenDavid]
112+
- Backends: Vulkan: Added a way to configure secondary viewport pipelinen creation
113+
by setting init_info.PipelineInfoForViewports fields. (#8946, #8110, #8111, #8686)
114+
- Backends: Vulkan: Added a way to configure secondary viewport swapchain VkImageUsageFlags
115+
to e.g. capture rendering. (#8946, #8940) [@olivier-gerard, @ocornut]
116+
Usage example:
117+
`init_info.PipelineInfoForViewports.SwapChainImageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;`
118+
- Backends: Vulkan: pipeline created for secondary viewport automatically match
119+
surface format. (#8686) [@sylmroz]
112120
- Backends: Vulkan: Added ImGui_ImplVulkanH_GetWindowDataFromViewport() accessor/helper.
113121
(#8946, #8940) [@olivier-gerard]
114122
- Examples: DX10, DX11: Disabled DXGI's Alt+Enter default behavior in examples.

0 commit comments

Comments
 (0)