Skip to content

Commit 0b8ff4b

Browse files
committed
Backends, Examples: Vulkan: add IMGUI_IMPL_VULKAN_MINIMUM_IMAGE_SAMPLER_POOL_SIZE. use in descriptor pools sizes. (#6642)
1 parent e7fb972 commit 0b8ff4b

7 files changed

Lines changed: 31 additions & 19 deletions

File tree

‎backends/imgui_impl_vulkan.cpp‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
// CHANGELOG
2828
// (minor and older changes stripped away, please see git history for details)
29+
// 2025-01-09: Vulkan: Added IMGUI_IMPL_VULKAN_MINIMUM_IMAGE_SAMPLER_POOL_SIZE to clarify how many image sampler descriptors are expected to be available in descriptor pool. (#6642)
2930
// 2025-01-06: Vulkan: Added more ImGui_ImplVulkanH_XXXX helper functions to simplify our examples.
3031
// 2024-12-11: Vulkan: Fixed setting VkSwapchainCreateInfoKHR::preTransform for platforms not supporting VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR. (#8222)
3132
// 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)
@@ -1022,8 +1023,9 @@ bool ImGui_ImplVulkan_CreateDeviceObjects()
10221023
check_vk_result(err);
10231024
}
10241025

1025-
if (v->DescriptorPoolSize)
1026+
if (v->DescriptorPoolSize != 0)
10261027
{
1028+
IM_ASSERT(v->DescriptorPoolSize > IMGUI_IMPL_VULKAN_MINIMUM_IMAGE_SAMPLER_POOL_SIZE);
10271029
VkDescriptorPoolSize pool_size = { VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, v->DescriptorPoolSize };
10281030
VkDescriptorPoolCreateInfo pool_info = {};
10291031
pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;

‎backends/imgui_impl_vulkan.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,16 @@
6161
#define IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING
6262
#endif
6363

64+
// Current version of the backend use 1 descriptor for the font atlas + as many as additional calls done to ImGui_ImplVulkan_AddTexture().
65+
// It is expected that as early as Q1 2025 the backend will use a few more descriptors. Use this value + number of desired calls to ImGui_ImplVulkan_AddTexture().
66+
#define IMGUI_IMPL_VULKAN_MINIMUM_IMAGE_SAMPLER_POOL_SIZE (1) // Minimum per atlas
67+
6468
// Initialization data, for ImGui_ImplVulkan_Init()
6569
// [Please zero-clear before use!]
6670
// - About descriptor pool:
6771
// - A VkDescriptorPool should be created with VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT,
6872
// and must contain a pool size large enough to hold a small number of VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER descriptors.
6973
// - As an convenience, by setting DescriptorPoolSize > 0 the backend will create one for you.
70-
// - Current version of the backend use 1 descriptor for the font atlas + as many as additional calls done to ImGui_ImplVulkan_AddTexture().
71-
// - It is expected that as early as Q1 2025 the backend will use a few more descriptors, so aim at 10 + number of desierd calls to ImGui_ImplVulkan_AddTexture().
7274
// - About dynamic rendering:
7375
// - When using dynamic rendering, set UseDynamicRendering=true and fill PipelineRenderingCreateInfo structure.
7476
struct ImGui_ImplVulkan_InitInfo

‎docs/CHANGELOG.txt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ Other changes:
7979
platforms not supporting VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR. (#8222) [@Zer0xFF]
8080
- Backends: Vulkan: Added a few more ImGui_ImplVulkanH_XXX helper functions
8181
primarily for the purpose of making our examples simpler.
82+
- Backends: Vulkan: Added IMGUI_IMPL_VULKAN_MINIMUM_IMAGE_SAMPLER_POOL_SIZE to clarify
83+
how many image sampler descriptors are expected to be available in the provided
84+
descriptor pool. Current backend needs 1 but it is expected that by end of Q1 2025
85+
this number will grow (will staying a very small number). (#6642)
8286
- Backends: DX11: Expose vertex constant buffer in ImGui_ImplDX11_RenderState.
8387
Reset projection matrix in ImDrawCallback_ResetRenderState handlers. (#6969, #5834, #7468, #3590)
8488
- Backends: DX10: Expose ImGui_ImplDX10_RenderState for completeness. (#6969, #5834, #7468, #3590)

‎examples/example_glfw_vulkan/main.cpp‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,17 +189,18 @@ static void SetupVulkan(ImVector<const char*> instance_extensions)
189189
}
190190

191191
// Create Descriptor Pool
192-
// The example only requires a single combined image sampler descriptor for the font image and only uses one descriptor set (for that)
193-
// If you wish to load e.g. additional textures you may need to alter pools sizes.
192+
// If you wish to load e.g. additional textures you may need to alter pools sizes and maxSets.
194193
{
195194
VkDescriptorPoolSize pool_sizes[] =
196195
{
197-
{ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1 },
196+
{ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, IMGUI_IMPL_VULKAN_MINIMUM_IMAGE_SAMPLER_POOL_SIZE },
198197
};
199198
VkDescriptorPoolCreateInfo pool_info = {};
200199
pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
201200
pool_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
202-
pool_info.maxSets = 1;
201+
pool_info.maxSets = 0;
202+
for (VkDescriptorPoolSize& pool_size : pool_sizes)
203+
pool_info.maxSets += pool_size.descriptorCount;
203204
pool_info.poolSizeCount = (uint32_t)IM_ARRAYSIZE(pool_sizes);
204205
pool_info.pPoolSizes = pool_sizes;
205206
err = vkCreateDescriptorPool(g_Device, &pool_info, g_Allocator, &g_DescriptorPool);

‎examples/example_sdl2_vulkan/main.cpp‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,17 +177,18 @@ static void SetupVulkan(ImVector<const char*> instance_extensions)
177177
}
178178

179179
// Create Descriptor Pool
180-
// The example only requires a single combined image sampler descriptor for the font image and only uses one descriptor set (for that)
181-
// If you wish to load e.g. additional textures you may need to alter pools sizes.
180+
// If you wish to load e.g. additional textures you may need to alter pools sizes and maxSets.
182181
{
183182
VkDescriptorPoolSize pool_sizes[] =
184183
{
185-
{ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1 },
184+
{ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, IMGUI_IMPL_VULKAN_MINIMUM_IMAGE_SAMPLER_POOL_SIZE },
186185
};
187186
VkDescriptorPoolCreateInfo pool_info = {};
188187
pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
189188
pool_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
190-
pool_info.maxSets = 1;
189+
pool_info.maxSets = 0;
190+
for (VkDescriptorPoolSize& pool_size : pool_sizes)
191+
pool_info.maxSets += pool_size.descriptorCount;
191192
pool_info.poolSizeCount = (uint32_t)IM_ARRAYSIZE(pool_sizes);
192193
pool_info.pPoolSizes = pool_sizes;
193194
err = vkCreateDescriptorPool(g_Device, &pool_info, g_Allocator, &g_DescriptorPool);

‎examples/example_sdl3_vulkan/main.cpp‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,17 +182,18 @@ static void SetupVulkan(ImVector<const char*> instance_extensions)
182182
}
183183

184184
// Create Descriptor Pool
185-
// The example only requires a single combined image sampler descriptor for the font image and only uses one descriptor set (for that)
186-
// If you wish to load e.g. additional textures you may need to alter pools sizes.
185+
// If you wish to load e.g. additional textures you may need to alter pools sizes and maxSets.
187186
{
188187
VkDescriptorPoolSize pool_sizes[] =
189188
{
190-
{ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1 },
189+
{ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, IMGUI_IMPL_VULKAN_MINIMUM_IMAGE_SAMPLER_POOL_SIZE },
191190
};
192191
VkDescriptorPoolCreateInfo pool_info = {};
193192
pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
194193
pool_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
195-
pool_info.maxSets = 1;
194+
pool_info.maxSets = 0;
195+
for (VkDescriptorPoolSize& pool_size : pool_sizes)
196+
pool_info.maxSets += pool_size.descriptorCount;
196197
pool_info.poolSizeCount = (uint32_t)IM_ARRAYSIZE(pool_sizes);
197198
pool_info.pPoolSizes = pool_sizes;
198199
err = vkCreateDescriptorPool(g_Device, &pool_info, g_Allocator, &g_DescriptorPool);

‎examples/example_win32_vulkan/main.cpp‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,17 +178,18 @@ static void SetupVulkan(ImVector<const char*> instance_extensions)
178178
}
179179

180180
// Create Descriptor Pool
181-
// The example only requires a single combined image sampler descriptor for the font image and only uses one descriptor set (for that)
182-
// If you wish to load e.g. additional textures you may need to alter pools sizes.
181+
// If you wish to load e.g. additional textures you may need to alter pools sizes and maxSets.
183182
{
184183
VkDescriptorPoolSize pool_sizes[] =
185184
{
186-
{ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1 },
185+
{ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, IMGUI_IMPL_VULKAN_MINIMUM_IMAGE_SAMPLER_POOL_SIZE },
187186
};
188187
VkDescriptorPoolCreateInfo pool_info = {};
189188
pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
190189
pool_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
191-
pool_info.maxSets = 1;
190+
pool_info.maxSets = 0;
191+
for (VkDescriptorPoolSize& pool_size : pool_sizes)
192+
pool_info.maxSets += pool_size.descriptorCount;
192193
pool_info.poolSizeCount = (uint32_t)IM_ARRAYSIZE(pool_sizes);
193194
pool_info.pPoolSizes = pool_sizes;
194195
err = vkCreateDescriptorPool(g_Device, &pool_info, g_Allocator, &g_DescriptorPool);

0 commit comments

Comments
 (0)