@@ -887,10 +887,21 @@ static void ImGui_ImplVulkan_CreateShaderModules(VkDevice device, const VkAlloca
887
887
}
888
888
}
889
889
890
- static void ImGui_ImplVulkan_CreatePipeline (VkDevice device, const VkAllocationCallbacks* allocator, VkPipelineCache pipelineCache, VkRenderPass renderPass, VkSampleCountFlagBits MSAASamples, VkPipeline* pipeline, uint32_t subpass)
890
+ struct ImGui_ImplVulkan_PipelineCreateInfo
891
+ {
892
+ VkDevice Device = VK_NULL_HANDLE;
893
+ const VkAllocationCallbacks* Allocator = nullptr ;
894
+ VkPipelineCache PipelineCache = VK_NULL_HANDLE;
895
+ VkRenderPass RenderPass = VK_NULL_HANDLE;
896
+ uint32_t Subpass = 0 ;
897
+ VkSampleCountFlagBits MSAASamples = {};
898
+ const ImGui_ImplVulkan_PipelineRenderingInfo* pRenderingInfo = nullptr ;
899
+ };
900
+
901
+ static VkPipeline ImGui_ImplVulkan_CreatePipeline (ImGui_ImplVulkan_PipelineCreateInfo const & pci)
891
902
{
892
903
ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData ();
893
- ImGui_ImplVulkan_CreateShaderModules (device, allocator );
904
+ ImGui_ImplVulkan_CreateShaderModules (pci. Device , pci. Allocator );
894
905
895
906
VkPipelineShaderStageCreateInfo stage[2 ] = {};
896
907
stage[0 ].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
@@ -945,7 +956,7 @@ static void ImGui_ImplVulkan_CreatePipeline(VkDevice device, const VkAllocationC
945
956
946
957
VkPipelineMultisampleStateCreateInfo ms_info = {};
947
958
ms_info.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
948
- ms_info.rasterizationSamples = (MSAASamples != 0 ) ? MSAASamples : VK_SAMPLE_COUNT_1_BIT;
959
+ ms_info.rasterizationSamples = (pci. MSAASamples != 0 ) ? pci. MSAASamples : VK_SAMPLE_COUNT_1_BIT;
949
960
950
961
VkPipelineColorBlendAttachmentState color_attachment[1 ] = {};
951
962
color_attachment[0 ].blendEnable = VK_TRUE;
@@ -985,21 +996,22 @@ static void ImGui_ImplVulkan_CreatePipeline(VkDevice device, const VkAllocationC
985
996
info.pColorBlendState = &blend_info;
986
997
info.pDynamicState = &dynamic_state;
987
998
info.layout = bd->PipelineLayout ;
988
- info.renderPass = renderPass ;
989
- info.subpass = subpass ;
999
+ info.renderPass = pci. RenderPass ;
1000
+ info.subpass = pci. Subpass ;
990
1001
991
1002
#ifdef IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING
992
1003
if (bd->VulkanInitInfo .UseDynamicRendering )
993
1004
{
994
- IM_ASSERT (bd->VulkanInitInfo .PipelineRenderingCreateInfo .sType == VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO_KHR && " PipelineRenderingCreateInfo sType must be VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO_KHR" );
995
- IM_ASSERT (bd->VulkanInitInfo .PipelineRenderingCreateInfo .pNext == nullptr && " PipelineRenderingCreateInfo pNext must be NULL" );
996
- info.pNext = &bd->VulkanInitInfo .PipelineRenderingCreateInfo ;
997
1005
info.renderPass = VK_NULL_HANDLE; // Just make sure it's actually nullptr.
1006
+ IM_ASSERT (pci.pRenderingInfo ->sType == VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO_KHR && " PipelineRenderingCreateInfo::sType must be VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO_KHR" );
1007
+ IM_ASSERT (pci.pRenderingInfo ->pNext == nullptr && " PipelineRenderingCreateInfo::pNext must be NULL" );
1008
+ info.pNext = pci.pRenderingInfo ;
998
1009
}
999
1010
#endif
1000
-
1001
- VkResult err = vkCreateGraphicsPipelines (device, pipelineCache , 1 , &info, allocator, pipeline );
1011
+ VkPipeline res;
1012
+ VkResult err = vkCreateGraphicsPipelines (pci. Device , pci. PipelineCache , 1 , &info, pci. Allocator , &res );
1002
1013
check_vk_result (err);
1014
+ return res;
1003
1015
}
1004
1016
1005
1017
bool ImGui_ImplVulkan_CreateDeviceObjects ()
@@ -1058,11 +1070,43 @@ bool ImGui_ImplVulkan_CreateDeviceObjects()
1058
1070
check_vk_result (err);
1059
1071
}
1060
1072
1061
- ImGui_ImplVulkan_CreatePipeline (v->Device , v->Allocator , v->PipelineCache , v->RenderPass , v->MSAASamples , &bd->Pipeline , v->Subpass );
1062
-
1063
1073
return true ;
1064
1074
}
1065
1075
1076
+ void ImGui_ImplVulkan_ReCreateMainPipeline (ImGui_ImplVulkan_MainPipelineCreateInfo const & info)
1077
+ {
1078
+ ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData ();
1079
+ ImGui_ImplVulkan_InitInfo* v = &bd->VulkanInitInfo ;
1080
+ if (bd->Pipeline )
1081
+ {
1082
+ vkDestroyPipeline (v->Device , bd->Pipeline , v->Allocator );
1083
+ bd->Pipeline = VK_NULL_HANDLE;
1084
+ }
1085
+ v->RenderPass = info.RenderPass ;
1086
+ v->MSAASamples = info.MSAASamples ;
1087
+ v->Subpass = info.Subpass ;
1088
+
1089
+ #ifdef IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING
1090
+ if (info.pDynamicRendering )
1091
+ {
1092
+ v->PipelineRenderingCreateInfo = *info.pDynamicRendering ;
1093
+ }
1094
+ #else
1095
+ IM_ASSERT (p_dynamic_rendering == nullptr );
1096
+ #endif
1097
+
1098
+ ImGui_ImplVulkan_PipelineCreateInfo pci;
1099
+ pci.Device = v->Device ;
1100
+ pci.Allocator = v->Allocator ;
1101
+ pci.PipelineCache = v->PipelineCache ;
1102
+ pci.RenderPass = v->RenderPass ;
1103
+ pci.Subpass = v->Subpass ;
1104
+ pci.MSAASamples = v->MSAASamples ;
1105
+ pci.pRenderingInfo = info.pDynamicRendering ;
1106
+
1107
+ bd->Pipeline = ImGui_ImplVulkan_CreatePipeline (pci);
1108
+ }
1109
+
1066
1110
void ImGui_ImplVulkan_DestroyDeviceObjects ()
1067
1111
{
1068
1112
ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData ();
@@ -1145,10 +1189,11 @@ bool ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo* info)
1145
1189
IM_ASSERT (info->DescriptorPool != VK_NULL_HANDLE);
1146
1190
IM_ASSERT (info->MinImageCount >= 2 );
1147
1191
IM_ASSERT (info->ImageCount >= info->MinImageCount );
1148
- if (info->UseDynamicRendering == false )
1149
- IM_ASSERT (info->RenderPass != VK_NULL_HANDLE);
1192
+ // if (info->UseDynamicRendering == false)
1193
+ // IM_ASSERT(info->RenderPass != VK_NULL_HANDLE);
1150
1194
1151
- bd->VulkanInitInfo = *info;
1195
+ ImGui_ImplVulkan_InitInfo * v = &bd->VulkanInitInfo ;
1196
+ *v = *info;
1152
1197
1153
1198
ImGui_ImplVulkan_CreateDeviceObjects ();
1154
1199
@@ -1158,6 +1203,35 @@ bool ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo* info)
1158
1203
1159
1204
ImGui_ImplVulkan_InitMultiViewportSupport ();
1160
1205
1206
+ {
1207
+ bool create_pipeline = false ;
1208
+ const ImGui_ImplVulkan_PipelineRenderingInfo * p_dynamic_rendering = nullptr ;
1209
+ if (v->RenderPass )
1210
+ {
1211
+ create_pipeline = true ;
1212
+ }
1213
+ else
1214
+ {
1215
+ #ifdef IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING
1216
+ if (v->UseDynamicRendering && v->PipelineRenderingCreateInfo .sType == VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO_KHR)
1217
+ {
1218
+ p_dynamic_rendering = &v->PipelineRenderingCreateInfo ;
1219
+ create_pipeline = true ;
1220
+ }
1221
+ #endif
1222
+ }
1223
+ if (create_pipeline)
1224
+ {
1225
+ ImGui_ImplVulkan_MainPipelineCreateInfo mp_info = {};
1226
+ mp_info.RenderPass = v->RenderPass ;
1227
+ mp_info.Subpass = v->Subpass ;
1228
+ mp_info.MSAASamples = info->MSAASamples ;
1229
+ mp_info.pDynamicRendering = p_dynamic_rendering;
1230
+
1231
+ ImGui_ImplVulkan_ReCreateMainPipeline (mp_info);
1232
+ }
1233
+ }
1234
+
1161
1235
return true ;
1162
1236
}
1163
1237
@@ -1699,8 +1773,33 @@ static void ImGui_ImplVulkan_CreateWindow(ImGuiViewport* viewport)
1699
1773
vd->WindowOwned = true ;
1700
1774
1701
1775
// Create pipeline (shared by all secondary viewports)
1702
- if (bd->PipelineForViewports == VK_NULL_HANDLE)
1703
- ImGui_ImplVulkan_CreatePipeline (v->Device , v->Allocator , VK_NULL_HANDLE, wd->RenderPass , VK_SAMPLE_COUNT_1_BIT, &bd->PipelineForViewports , 0 );
1776
+ if (bd->PipelineForViewports == VK_NULL_HANDLE)
1777
+ {
1778
+ ImGui_ImplVulkan_PipelineCreateInfo pci;
1779
+ pci.Device = v->Device ;
1780
+ pci.Allocator = v->Allocator ;
1781
+ pci.PipelineCache = VK_NULL_HANDLE;
1782
+ pci.RenderPass = wd->RenderPass ;
1783
+ pci.Subpass = 0 ;
1784
+ pci.MSAASamples = VK_SAMPLE_COUNT_1_BIT;
1785
+ #ifdef IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING
1786
+ VkPipelineRenderingCreateInfoKHR rendering_info = {};
1787
+ if (wd->UseDynamicRendering )
1788
+ {
1789
+ rendering_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO;
1790
+ rendering_info.pNext = nullptr ;
1791
+ rendering_info.viewMask = 0 ;
1792
+ rendering_info.colorAttachmentCount = 1 ;
1793
+ rendering_info.pColorAttachmentFormats = &wd->SurfaceFormat .format ;
1794
+ rendering_info.depthAttachmentFormat = VK_FORMAT_UNDEFINED;
1795
+ rendering_info.stencilAttachmentFormat = VK_FORMAT_UNDEFINED;
1796
+ pci.RenderPass = VK_NULL_HANDLE;
1797
+ pci.pRenderingInfo = &rendering_info;
1798
+ }
1799
+ #endif
1800
+ bd->PipelineForViewports = ImGui_ImplVulkan_CreatePipeline (pci);
1801
+
1802
+ }
1704
1803
}
1705
1804
1706
1805
static void ImGui_ImplVulkan_DestroyWindow (ImGuiViewport* viewport)
0 commit comments