|
26 | 26 |
|
27 | 27 | // CHANGELOG
|
28 | 28 | // (minor and older changes stripped away, please see git history for details)
|
| 29 | +// 2024-11-27: Vulkan: Make user-provided descriptor pool optional. As a convenience, when setting init_info->DescriptorPoolSize the backend will create one itself. (#8172, #4867) |
29 | 30 | // 2024-10-07: Vulkan: Changed default texture sampler to Clamp instead of Repeat/Wrap.
|
30 | 31 | // 2024-10-07: Vulkan: Expose selected render state in ImGui_ImplVulkan_RenderState, which you can access in 'void* platform_io.Renderer_RenderState' during draw callbacks.
|
31 | 32 | // 2024-10-07: Vulkan: Compiling with '#define ImTextureID=ImU64' is unnecessary now that dear imgui defaults ImTextureID to u64 instead of void*.
|
@@ -131,6 +132,7 @@ static bool g_FunctionsLoaded = true;
|
131 | 132 | IMGUI_VULKAN_FUNC_MAP_MACRO(vkCmdSetViewport) \
|
132 | 133 | IMGUI_VULKAN_FUNC_MAP_MACRO(vkCreateBuffer) \
|
133 | 134 | IMGUI_VULKAN_FUNC_MAP_MACRO(vkCreateCommandPool) \
|
| 135 | + IMGUI_VULKAN_FUNC_MAP_MACRO(vkCreateDescriptorPool) \ |
134 | 136 | IMGUI_VULKAN_FUNC_MAP_MACRO(vkCreateDescriptorSetLayout) \
|
135 | 137 | IMGUI_VULKAN_FUNC_MAP_MACRO(vkCreateFence) \
|
136 | 138 | IMGUI_VULKAN_FUNC_MAP_MACRO(vkCreateFramebuffer) \
|
@@ -221,6 +223,7 @@ struct ImGui_ImplVulkan_Data
|
221 | 223 | VkPipeline Pipeline;
|
222 | 224 | VkShaderModule ShaderModuleVert;
|
223 | 225 | VkShaderModule ShaderModuleFrag;
|
| 226 | + VkDescriptorPool DescriptorPool; |
224 | 227 |
|
225 | 228 | // Font data
|
226 | 229 | VkSampler FontSampler;
|
@@ -1010,6 +1013,20 @@ bool ImGui_ImplVulkan_CreateDeviceObjects()
|
1010 | 1013 | check_vk_result(err);
|
1011 | 1014 | }
|
1012 | 1015 |
|
| 1016 | + if (v->DescriptorPoolSize) |
| 1017 | + { |
| 1018 | + VkDescriptorPoolSize pool_size = { VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, v->DescriptorPoolSize }; |
| 1019 | + VkDescriptorPoolCreateInfo pool_info = {}; |
| 1020 | + pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 1021 | + pool_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT; |
| 1022 | + pool_info.maxSets = v->DescriptorPoolSize; |
| 1023 | + pool_info.poolSizeCount = 1; |
| 1024 | + pool_info.pPoolSizes = &pool_size; |
| 1025 | + |
| 1026 | + err = vkCreateDescriptorPool(v->Device, &pool_info, v->Allocator, &bd->DescriptorPool); |
| 1027 | + check_vk_result(err); |
| 1028 | + } |
| 1029 | + |
1013 | 1030 | if (!bd->PipelineLayout)
|
1014 | 1031 | {
|
1015 | 1032 | // Constants: we are using 'vec2 offset' and 'vec2 scale' instead of a full 3d projection matrix
|
@@ -1048,6 +1065,7 @@ void ImGui_ImplVulkan_DestroyDeviceObjects()
|
1048 | 1065 | if (bd->DescriptorSetLayout) { vkDestroyDescriptorSetLayout(v->Device, bd->DescriptorSetLayout, v->Allocator); bd->DescriptorSetLayout = VK_NULL_HANDLE; }
|
1049 | 1066 | if (bd->PipelineLayout) { vkDestroyPipelineLayout(v->Device, bd->PipelineLayout, v->Allocator); bd->PipelineLayout = VK_NULL_HANDLE; }
|
1050 | 1067 | if (bd->Pipeline) { vkDestroyPipeline(v->Device, bd->Pipeline, v->Allocator); bd->Pipeline = VK_NULL_HANDLE; }
|
| 1068 | + if (bd->DescriptorPool) { vkDestroyDescriptorPool(v->Device, bd->DescriptorPool, v->Allocator); bd->DescriptorPool = VK_NULL_HANDLE; } |
1051 | 1069 | }
|
1052 | 1070 |
|
1053 | 1071 | bool ImGui_ImplVulkan_LoadFunctions(PFN_vkVoidFunction(*loader_func)(const char* function_name, void* user_data), void* user_data)
|
@@ -1110,7 +1128,10 @@ bool ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo* info)
|
1110 | 1128 | IM_ASSERT(info->PhysicalDevice != VK_NULL_HANDLE);
|
1111 | 1129 | IM_ASSERT(info->Device != VK_NULL_HANDLE);
|
1112 | 1130 | IM_ASSERT(info->Queue != VK_NULL_HANDLE);
|
1113 |
| - IM_ASSERT(info->DescriptorPool != VK_NULL_HANDLE); |
| 1131 | + if (info->DescriptorPool != VK_NULL_HANDLE) // Either DescriptorPool or DescriptorPoolSize must be set, not both! |
| 1132 | + IM_ASSERT(info->DescriptorPoolSize == 0); |
| 1133 | + else |
| 1134 | + IM_ASSERT(info->DescriptorPoolSize > 0); |
1114 | 1135 | IM_ASSERT(info->MinImageCount >= 2);
|
1115 | 1136 | IM_ASSERT(info->ImageCount >= info->MinImageCount);
|
1116 | 1137 | if (info->UseDynamicRendering == false)
|
@@ -1159,19 +1180,20 @@ void ImGui_ImplVulkan_SetMinImageCount(uint32_t min_image_count)
|
1159 | 1180 | bd->VulkanInitInfo.MinImageCount = min_image_count;
|
1160 | 1181 | }
|
1161 | 1182 |
|
1162 |
| -// Register a texture |
| 1183 | +// Register a texture by creating a descriptor |
1163 | 1184 | // FIXME: This is experimental in the sense that we are unsure how to best design/tackle this problem, please post to https://github.com/ocornut/imgui/pull/914 if you have suggestions.
|
1164 | 1185 | VkDescriptorSet ImGui_ImplVulkan_AddTexture(VkSampler sampler, VkImageView image_view, VkImageLayout image_layout)
|
1165 | 1186 | {
|
1166 | 1187 | ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData();
|
1167 | 1188 | ImGui_ImplVulkan_InitInfo* v = &bd->VulkanInitInfo;
|
| 1189 | + VkDescriptorPool pool = bd->DescriptorPool ? bd->DescriptorPool : v->DescriptorPool; |
1168 | 1190 |
|
1169 | 1191 | // Create Descriptor Set:
|
1170 | 1192 | VkDescriptorSet descriptor_set;
|
1171 | 1193 | {
|
1172 | 1194 | VkDescriptorSetAllocateInfo alloc_info = {};
|
1173 | 1195 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
|
1174 |
| - alloc_info.descriptorPool = v->DescriptorPool; |
| 1196 | + alloc_info.descriptorPool = pool; |
1175 | 1197 | alloc_info.descriptorSetCount = 1;
|
1176 | 1198 | alloc_info.pSetLayouts = &bd->DescriptorSetLayout;
|
1177 | 1199 | VkResult err = vkAllocateDescriptorSets(v->Device, &alloc_info, &descriptor_set);
|
@@ -1199,7 +1221,8 @@ void ImGui_ImplVulkan_RemoveTexture(VkDescriptorSet descriptor_set)
|
1199 | 1221 | {
|
1200 | 1222 | ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData();
|
1201 | 1223 | ImGui_ImplVulkan_InitInfo* v = &bd->VulkanInitInfo;
|
1202 |
| - vkFreeDescriptorSets(v->Device, v->DescriptorPool, 1, &descriptor_set); |
| 1224 | + VkDescriptorPool pool = bd->DescriptorPool ? bd->DescriptorPool : v->DescriptorPool; |
| 1225 | + vkFreeDescriptorSets(v->Device, pool, 1, &descriptor_set); |
1203 | 1226 | }
|
1204 | 1227 |
|
1205 | 1228 | void ImGui_ImplVulkan_DestroyFrameRenderBuffers(VkDevice device, ImGui_ImplVulkan_FrameRenderBuffers* buffers, const VkAllocationCallbacks* allocator)
|
|
0 commit comments