|
@@ -26,6 +26,7 @@
|
|
|
|
|
|
// CHANGELOG
|
|
|
// (minor and older changes stripped away, please see git history for details)
|
|
|
+// 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)
|
|
|
// 2024-10-07: Vulkan: Changed default texture sampler to Clamp instead of Repeat/Wrap.
|
|
|
// 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.
|
|
|
// 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;
|
|
|
IMGUI_VULKAN_FUNC_MAP_MACRO(vkCmdSetViewport) \
|
|
|
IMGUI_VULKAN_FUNC_MAP_MACRO(vkCreateBuffer) \
|
|
|
IMGUI_VULKAN_FUNC_MAP_MACRO(vkCreateCommandPool) \
|
|
|
+ IMGUI_VULKAN_FUNC_MAP_MACRO(vkCreateDescriptorPool) \
|
|
|
IMGUI_VULKAN_FUNC_MAP_MACRO(vkCreateDescriptorSetLayout) \
|
|
|
IMGUI_VULKAN_FUNC_MAP_MACRO(vkCreateFence) \
|
|
|
IMGUI_VULKAN_FUNC_MAP_MACRO(vkCreateFramebuffer) \
|
|
@@ -221,6 +223,7 @@ struct ImGui_ImplVulkan_Data
|
|
|
VkPipeline Pipeline;
|
|
|
VkShaderModule ShaderModuleVert;
|
|
|
VkShaderModule ShaderModuleFrag;
|
|
|
+ VkDescriptorPool DescriptorPool;
|
|
|
|
|
|
// Font data
|
|
|
VkSampler FontSampler;
|
|
@@ -1010,6 +1013,20 @@ bool ImGui_ImplVulkan_CreateDeviceObjects()
|
|
|
check_vk_result(err);
|
|
|
}
|
|
|
|
|
|
+ if (v->DescriptorPoolSize)
|
|
|
+ {
|
|
|
+ VkDescriptorPoolSize pool_size = { VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, v->DescriptorPoolSize };
|
|
|
+ VkDescriptorPoolCreateInfo pool_info = {};
|
|
|
+ pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
|
|
|
+ pool_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
|
|
|
+ pool_info.maxSets = v->DescriptorPoolSize;
|
|
|
+ pool_info.poolSizeCount = 1;
|
|
|
+ pool_info.pPoolSizes = &pool_size;
|
|
|
+
|
|
|
+ err = vkCreateDescriptorPool(v->Device, &pool_info, v->Allocator, &bd->DescriptorPool);
|
|
|
+ check_vk_result(err);
|
|
|
+ }
|
|
|
+
|
|
|
if (!bd->PipelineLayout)
|
|
|
{
|
|
|
// Constants: we are using 'vec2 offset' and 'vec2 scale' instead of a full 3d projection matrix
|
|
@@ -1048,6 +1065,7 @@ void ImGui_ImplVulkan_DestroyDeviceObjects()
|
|
|
if (bd->DescriptorSetLayout) { vkDestroyDescriptorSetLayout(v->Device, bd->DescriptorSetLayout, v->Allocator); bd->DescriptorSetLayout = VK_NULL_HANDLE; }
|
|
|
if (bd->PipelineLayout) { vkDestroyPipelineLayout(v->Device, bd->PipelineLayout, v->Allocator); bd->PipelineLayout = VK_NULL_HANDLE; }
|
|
|
if (bd->Pipeline) { vkDestroyPipeline(v->Device, bd->Pipeline, v->Allocator); bd->Pipeline = VK_NULL_HANDLE; }
|
|
|
+ if (bd->DescriptorPool) { vkDestroyDescriptorPool(v->Device, bd->DescriptorPool, v->Allocator); bd->DescriptorPool = VK_NULL_HANDLE; }
|
|
|
}
|
|
|
|
|
|
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)
|
|
|
IM_ASSERT(info->PhysicalDevice != VK_NULL_HANDLE);
|
|
|
IM_ASSERT(info->Device != VK_NULL_HANDLE);
|
|
|
IM_ASSERT(info->Queue != VK_NULL_HANDLE);
|
|
|
- IM_ASSERT(info->DescriptorPool != VK_NULL_HANDLE);
|
|
|
+ if (info->DescriptorPool != VK_NULL_HANDLE) // Either DescriptorPool or DescriptorPoolSize must be set, not both!
|
|
|
+ IM_ASSERT(info->DescriptorPoolSize == 0);
|
|
|
+ else
|
|
|
+ IM_ASSERT(info->DescriptorPoolSize > 0);
|
|
|
IM_ASSERT(info->MinImageCount >= 2);
|
|
|
IM_ASSERT(info->ImageCount >= info->MinImageCount);
|
|
|
if (info->UseDynamicRendering == false)
|
|
@@ -1159,19 +1180,20 @@ void ImGui_ImplVulkan_SetMinImageCount(uint32_t min_image_count)
|
|
|
bd->VulkanInitInfo.MinImageCount = min_image_count;
|
|
|
}
|
|
|
|
|
|
-// Register a texture
|
|
|
+// Register a texture by creating a descriptor
|
|
|
// 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.
|
|
|
VkDescriptorSet ImGui_ImplVulkan_AddTexture(VkSampler sampler, VkImageView image_view, VkImageLayout image_layout)
|
|
|
{
|
|
|
ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData();
|
|
|
ImGui_ImplVulkan_InitInfo* v = &bd->VulkanInitInfo;
|
|
|
+ VkDescriptorPool pool = bd->DescriptorPool ? bd->DescriptorPool : v->DescriptorPool;
|
|
|
|
|
|
// Create Descriptor Set:
|
|
|
VkDescriptorSet descriptor_set;
|
|
|
{
|
|
|
VkDescriptorSetAllocateInfo alloc_info = {};
|
|
|
alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
|
|
|
- alloc_info.descriptorPool = v->DescriptorPool;
|
|
|
+ alloc_info.descriptorPool = pool;
|
|
|
alloc_info.descriptorSetCount = 1;
|
|
|
alloc_info.pSetLayouts = &bd->DescriptorSetLayout;
|
|
|
VkResult err = vkAllocateDescriptorSets(v->Device, &alloc_info, &descriptor_set);
|
|
@@ -1199,7 +1221,8 @@ void ImGui_ImplVulkan_RemoveTexture(VkDescriptorSet descriptor_set)
|
|
|
{
|
|
|
ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData();
|
|
|
ImGui_ImplVulkan_InitInfo* v = &bd->VulkanInitInfo;
|
|
|
- vkFreeDescriptorSets(v->Device, v->DescriptorPool, 1, &descriptor_set);
|
|
|
+ VkDescriptorPool pool = bd->DescriptorPool ? bd->DescriptorPool : v->DescriptorPool;
|
|
|
+ vkFreeDescriptorSets(v->Device, pool, 1, &descriptor_set);
|
|
|
}
|
|
|
|
|
|
void ImGui_ImplVulkan_DestroyFrameRenderBuffers(VkDevice device, ImGui_ImplVulkan_FrameRenderBuffers* buffers, const VkAllocationCallbacks* allocator)
|