|
@@ -28,6 +28,7 @@
|
|
|
// CHANGELOG
|
|
|
// (minor and older changes stripped away, please see git history for details)
|
|
|
// 2024-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
|
|
|
+// 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*.
|
|
@@ -137,6 +138,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) \
|
|
@@ -151,6 +153,7 @@ static bool g_FunctionsLoaded = true;
|
|
|
IMGUI_VULKAN_FUNC_MAP_MACRO(vkCreateSwapchainKHR) \
|
|
|
IMGUI_VULKAN_FUNC_MAP_MACRO(vkDestroyBuffer) \
|
|
|
IMGUI_VULKAN_FUNC_MAP_MACRO(vkDestroyCommandPool) \
|
|
|
+ IMGUI_VULKAN_FUNC_MAP_MACRO(vkDestroyDescriptorPool) \
|
|
|
IMGUI_VULKAN_FUNC_MAP_MACRO(vkDestroyDescriptorSetLayout) \
|
|
|
IMGUI_VULKAN_FUNC_MAP_MACRO(vkDestroyFence) \
|
|
|
IMGUI_VULKAN_FUNC_MAP_MACRO(vkDestroyFramebuffer) \
|
|
@@ -220,6 +223,16 @@ struct ImGui_ImplVulkan_WindowRenderBuffers
|
|
|
ImGui_ImplVulkan_FrameRenderBuffers* FrameRenderBuffers;
|
|
|
};
|
|
|
|
|
|
+struct ImGui_ImplVulkan_Texture
|
|
|
+{
|
|
|
+ VkDeviceMemory Memory;
|
|
|
+ VkImage Image;
|
|
|
+ VkImageView ImageView;
|
|
|
+ VkDescriptorSet DescriptorSet;
|
|
|
+
|
|
|
+ ImGui_ImplVulkan_Texture() { memset(this, 0, sizeof(*this)); }
|
|
|
+};
|
|
|
+
|
|
|
// For multi-viewport support:
|
|
|
// Helper structure we store in the void* RendererUserData field of each ImGuiViewport to easily retrieve our backend data.
|
|
|
struct ImGui_ImplVulkan_ViewportData
|
|
@@ -229,8 +242,8 @@ struct ImGui_ImplVulkan_ViewportData
|
|
|
bool WindowOwned;
|
|
|
bool SwapChainNeedRebuild; // Flag when viewport swapchain resized in the middle of processing a frame
|
|
|
|
|
|
- ImGui_ImplVulkan_ViewportData() { WindowOwned = SwapChainNeedRebuild = false; memset(&RenderBuffers, 0, sizeof(RenderBuffers)); }
|
|
|
- ~ImGui_ImplVulkan_ViewportData() { }
|
|
|
+ ImGui_ImplVulkan_ViewportData() { WindowOwned = SwapChainNeedRebuild = false; memset(&RenderBuffers, 0, sizeof(RenderBuffers)); }
|
|
|
+ ~ImGui_ImplVulkan_ViewportData() { }
|
|
|
};
|
|
|
|
|
|
// Vulkan data
|
|
@@ -245,15 +258,13 @@ struct ImGui_ImplVulkan_Data
|
|
|
VkPipeline PipelineForViewports; // pipeline for secondary viewports (created by backend)
|
|
|
VkShaderModule ShaderModuleVert;
|
|
|
VkShaderModule ShaderModuleFrag;
|
|
|
+ VkDescriptorPool DescriptorPool;
|
|
|
|
|
|
- // Font data
|
|
|
- VkSampler FontSampler;
|
|
|
- VkDeviceMemory FontMemory;
|
|
|
- VkImage FontImage;
|
|
|
- VkImageView FontView;
|
|
|
- VkDescriptorSet FontDescriptorSet;
|
|
|
- VkCommandPool FontCommandPool;
|
|
|
- VkCommandBuffer FontCommandBuffer;
|
|
|
+ // Texture management
|
|
|
+ ImGui_ImplVulkan_Texture FontTexture;
|
|
|
+ VkSampler TexSampler;
|
|
|
+ VkCommandPool TexCommandPool;
|
|
|
+ VkCommandBuffer TexCommandBuffer;
|
|
|
|
|
|
// Render buffers for main window
|
|
|
ImGui_ImplVulkan_WindowRenderBuffers MainWindowRenderBuffers;
|
|
@@ -620,14 +631,8 @@ void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer comm
|
|
|
vkCmdSetScissor(command_buffer, 0, 1, &scissor);
|
|
|
|
|
|
// Bind DescriptorSet with font or user texture
|
|
|
- VkDescriptorSet desc_set[1] = { (VkDescriptorSet)pcmd->GetTexID() };
|
|
|
- if (sizeof(ImTextureID) < sizeof(ImU64))
|
|
|
- {
|
|
|
- // We don't support texture switches if ImTextureID hasn't been redefined to be 64-bit. Do a flaky check that other textures haven't been used.
|
|
|
- IM_ASSERT(pcmd->GetTexID() == (ImTextureID)bd->FontDescriptorSet);
|
|
|
- desc_set[0] = bd->FontDescriptorSet;
|
|
|
- }
|
|
|
- vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, bd->PipelineLayout, 0, 1, desc_set, 0, nullptr);
|
|
|
+ VkDescriptorSet desc_set = (VkDescriptorSet)pcmd->GetTexID();
|
|
|
+ vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, bd->PipelineLayout, 0, 1, &desc_set, 0, nullptr);
|
|
|
|
|
|
// Draw
|
|
|
vkCmdDrawIndexed(command_buffer, pcmd->ElemCount, 1, pcmd->IdxOffset + global_idx_offset, pcmd->VtxOffset + global_vtx_offset, 0);
|
|
@@ -657,39 +662,39 @@ bool ImGui_ImplVulkan_CreateFontsTexture()
|
|
|
VkResult err;
|
|
|
|
|
|
// Destroy existing texture (if any)
|
|
|
- if (bd->FontView || bd->FontImage || bd->FontMemory || bd->FontDescriptorSet)
|
|
|
+ if (bd->FontTexture.DescriptorSet)
|
|
|
{
|
|
|
vkQueueWaitIdle(v->Queue);
|
|
|
ImGui_ImplVulkan_DestroyFontsTexture();
|
|
|
}
|
|
|
|
|
|
// Create command pool/buffer
|
|
|
- if (bd->FontCommandPool == VK_NULL_HANDLE)
|
|
|
+ if (bd->TexCommandPool == VK_NULL_HANDLE)
|
|
|
{
|
|
|
VkCommandPoolCreateInfo info = {};
|
|
|
info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
|
|
|
info.flags = 0;
|
|
|
info.queueFamilyIndex = v->QueueFamily;
|
|
|
- vkCreateCommandPool(v->Device, &info, v->Allocator, &bd->FontCommandPool);
|
|
|
+ vkCreateCommandPool(v->Device, &info, v->Allocator, &bd->TexCommandPool);
|
|
|
}
|
|
|
- if (bd->FontCommandBuffer == VK_NULL_HANDLE)
|
|
|
+ if (bd->TexCommandBuffer == VK_NULL_HANDLE)
|
|
|
{
|
|
|
VkCommandBufferAllocateInfo info = {};
|
|
|
info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
|
|
|
- info.commandPool = bd->FontCommandPool;
|
|
|
+ info.commandPool = bd->TexCommandPool;
|
|
|
info.commandBufferCount = 1;
|
|
|
- err = vkAllocateCommandBuffers(v->Device, &info, &bd->FontCommandBuffer);
|
|
|
+ err = vkAllocateCommandBuffers(v->Device, &info, &bd->TexCommandBuffer);
|
|
|
check_vk_result(err);
|
|
|
}
|
|
|
|
|
|
// Start command buffer
|
|
|
{
|
|
|
- err = vkResetCommandPool(v->Device, bd->FontCommandPool, 0);
|
|
|
+ err = vkResetCommandPool(v->Device, bd->TexCommandPool, 0);
|
|
|
check_vk_result(err);
|
|
|
VkCommandBufferBeginInfo begin_info = {};
|
|
|
begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
|
|
|
begin_info.flags |= VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
|
|
|
- err = vkBeginCommandBuffer(bd->FontCommandBuffer, &begin_info);
|
|
|
+ err = vkBeginCommandBuffer(bd->TexCommandBuffer, &begin_info);
|
|
|
check_vk_result(err);
|
|
|
}
|
|
|
|
|
@@ -699,6 +704,7 @@ bool ImGui_ImplVulkan_CreateFontsTexture()
|
|
|
size_t upload_size = width * height * 4 * sizeof(char);
|
|
|
|
|
|
// Create the Image:
|
|
|
+ ImGui_ImplVulkan_Texture* backend_tex = &bd->FontTexture;
|
|
|
{
|
|
|
VkImageCreateInfo info = {};
|
|
|
info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
|
|
@@ -714,17 +720,17 @@ bool ImGui_ImplVulkan_CreateFontsTexture()
|
|
|
info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
|
|
|
info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
|
|
info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
|
|
- err = vkCreateImage(v->Device, &info, v->Allocator, &bd->FontImage);
|
|
|
+ err = vkCreateImage(v->Device, &info, v->Allocator, &backend_tex->Image);
|
|
|
check_vk_result(err);
|
|
|
VkMemoryRequirements req;
|
|
|
- vkGetImageMemoryRequirements(v->Device, bd->FontImage, &req);
|
|
|
+ vkGetImageMemoryRequirements(v->Device, backend_tex->Image, &req);
|
|
|
VkMemoryAllocateInfo alloc_info = {};
|
|
|
alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
|
|
|
alloc_info.allocationSize = IM_MAX(v->MinAllocationSize, req.size);
|
|
|
alloc_info.memoryTypeIndex = ImGui_ImplVulkan_MemoryType(VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, req.memoryTypeBits);
|
|
|
- err = vkAllocateMemory(v->Device, &alloc_info, v->Allocator, &bd->FontMemory);
|
|
|
+ err = vkAllocateMemory(v->Device, &alloc_info, v->Allocator, &backend_tex->Memory);
|
|
|
check_vk_result(err);
|
|
|
- err = vkBindImageMemory(v->Device, bd->FontImage, bd->FontMemory, 0);
|
|
|
+ err = vkBindImageMemory(v->Device, backend_tex->Image, backend_tex->Memory, 0);
|
|
|
check_vk_result(err);
|
|
|
}
|
|
|
|
|
@@ -732,18 +738,18 @@ bool ImGui_ImplVulkan_CreateFontsTexture()
|
|
|
{
|
|
|
VkImageViewCreateInfo info = {};
|
|
|
info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
|
|
|
- info.image = bd->FontImage;
|
|
|
+ info.image = backend_tex->Image;
|
|
|
info.viewType = VK_IMAGE_VIEW_TYPE_2D;
|
|
|
info.format = VK_FORMAT_R8G8B8A8_UNORM;
|
|
|
info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
|
|
info.subresourceRange.levelCount = 1;
|
|
|
info.subresourceRange.layerCount = 1;
|
|
|
- err = vkCreateImageView(v->Device, &info, v->Allocator, &bd->FontView);
|
|
|
+ err = vkCreateImageView(v->Device, &info, v->Allocator, &backend_tex->ImageView);
|
|
|
check_vk_result(err);
|
|
|
}
|
|
|
|
|
|
// Create the Descriptor Set:
|
|
|
- bd->FontDescriptorSet = (VkDescriptorSet)ImGui_ImplVulkan_AddTexture(bd->FontSampler, bd->FontView, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
|
|
+ backend_tex->DescriptorSet = ImGui_ImplVulkan_AddTexture(bd->TexSampler, backend_tex->ImageView, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
|
|
|
|
|
// Create the Upload Buffer:
|
|
|
VkDeviceMemory upload_buffer_memory;
|
|
@@ -793,11 +799,11 @@ bool ImGui_ImplVulkan_CreateFontsTexture()
|
|
|
copy_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
|
|
|
copy_barrier[0].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
|
|
copy_barrier[0].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
|
|
- copy_barrier[0].image = bd->FontImage;
|
|
|
+ copy_barrier[0].image = backend_tex->Image;
|
|
|
copy_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
|
|
copy_barrier[0].subresourceRange.levelCount = 1;
|
|
|
copy_barrier[0].subresourceRange.layerCount = 1;
|
|
|
- vkCmdPipelineBarrier(bd->FontCommandBuffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 0, nullptr, 1, copy_barrier);
|
|
|
+ vkCmdPipelineBarrier(bd->TexCommandBuffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 0, nullptr, 1, copy_barrier);
|
|
|
|
|
|
VkBufferImageCopy region = {};
|
|
|
region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
|
@@ -805,7 +811,7 @@ bool ImGui_ImplVulkan_CreateFontsTexture()
|
|
|
region.imageExtent.width = width;
|
|
|
region.imageExtent.height = height;
|
|
|
region.imageExtent.depth = 1;
|
|
|
- vkCmdCopyBufferToImage(bd->FontCommandBuffer, upload_buffer, bd->FontImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion);
|
|
|
+ vkCmdCopyBufferToImage(bd->TexCommandBuffer, upload_buffer, backend_tex->Image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion);
|
|
|
|
|
|
VkImageMemoryBarrier use_barrier[1] = {};
|
|
|
use_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
|
@@ -815,22 +821,22 @@ bool ImGui_ImplVulkan_CreateFontsTexture()
|
|
|
use_barrier[0].newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
|
|
use_barrier[0].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
|
|
use_barrier[0].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
|
|
- use_barrier[0].image = bd->FontImage;
|
|
|
+ use_barrier[0].image = backend_tex->Image;
|
|
|
use_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
|
|
use_barrier[0].subresourceRange.levelCount = 1;
|
|
|
use_barrier[0].subresourceRange.layerCount = 1;
|
|
|
- vkCmdPipelineBarrier(bd->FontCommandBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, use_barrier);
|
|
|
+ vkCmdPipelineBarrier(bd->TexCommandBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, use_barrier);
|
|
|
}
|
|
|
|
|
|
// Store our identifier
|
|
|
- io.Fonts->SetTexID((ImTextureID)bd->FontDescriptorSet);
|
|
|
+ io.Fonts->SetTexID((ImTextureID)backend_tex->DescriptorSet);
|
|
|
|
|
|
// End command buffer
|
|
|
VkSubmitInfo end_info = {};
|
|
|
end_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
|
|
end_info.commandBufferCount = 1;
|
|
|
- end_info.pCommandBuffers = &bd->FontCommandBuffer;
|
|
|
- err = vkEndCommandBuffer(bd->FontCommandBuffer);
|
|
|
+ end_info.pCommandBuffers = &bd->TexCommandBuffer;
|
|
|
+ err = vkEndCommandBuffer(bd->TexCommandBuffer);
|
|
|
check_vk_result(err);
|
|
|
err = vkQueueSubmit(v->Queue, 1, &end_info, VK_NULL_HANDLE);
|
|
|
check_vk_result(err);
|
|
@@ -851,16 +857,17 @@ void ImGui_ImplVulkan_DestroyFontsTexture()
|
|
|
ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData();
|
|
|
ImGui_ImplVulkan_InitInfo* v = &bd->VulkanInitInfo;
|
|
|
|
|
|
- if (bd->FontDescriptorSet)
|
|
|
+ ImGui_ImplVulkan_Texture* backend_tex = &bd->FontTexture;
|
|
|
+
|
|
|
+ if (backend_tex->DescriptorSet)
|
|
|
{
|
|
|
- ImGui_ImplVulkan_RemoveTexture(bd->FontDescriptorSet);
|
|
|
- bd->FontDescriptorSet = VK_NULL_HANDLE;
|
|
|
+ ImGui_ImplVulkan_RemoveTexture(backend_tex->DescriptorSet);
|
|
|
+ backend_tex->DescriptorSet = VK_NULL_HANDLE;
|
|
|
io.Fonts->SetTexID(0);
|
|
|
}
|
|
|
-
|
|
|
- if (bd->FontView) { vkDestroyImageView(v->Device, bd->FontView, v->Allocator); bd->FontView = VK_NULL_HANDLE; }
|
|
|
- if (bd->FontImage) { vkDestroyImage(v->Device, bd->FontImage, v->Allocator); bd->FontImage = VK_NULL_HANDLE; }
|
|
|
- if (bd->FontMemory) { vkFreeMemory(v->Device, bd->FontMemory, v->Allocator); bd->FontMemory = VK_NULL_HANDLE; }
|
|
|
+ if (backend_tex->ImageView) { vkDestroyImageView(v->Device, backend_tex->ImageView, v->Allocator); backend_tex->ImageView = VK_NULL_HANDLE; }
|
|
|
+ if (backend_tex->Image) { vkDestroyImage(v->Device, backend_tex->Image, v->Allocator); backend_tex->Image = VK_NULL_HANDLE; }
|
|
|
+ if (backend_tex->Memory) { vkFreeMemory(v->Device, backend_tex->Memory, v->Allocator); backend_tex->Memory = VK_NULL_HANDLE; }
|
|
|
}
|
|
|
|
|
|
static void ImGui_ImplVulkan_CreateShaderModules(VkDevice device, const VkAllocationCallbacks* allocator)
|
|
@@ -1008,7 +1015,7 @@ bool ImGui_ImplVulkan_CreateDeviceObjects()
|
|
|
ImGui_ImplVulkan_InitInfo* v = &bd->VulkanInitInfo;
|
|
|
VkResult err;
|
|
|
|
|
|
- if (!bd->FontSampler)
|
|
|
+ if (!bd->TexSampler)
|
|
|
{
|
|
|
// Bilinear sampling is required by default. Set 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines' or 'style.AntiAliasedLinesUseTex = false' to allow point/nearest sampling.
|
|
|
VkSamplerCreateInfo info = {};
|
|
@@ -1022,7 +1029,7 @@ bool ImGui_ImplVulkan_CreateDeviceObjects()
|
|
|
info.minLod = -1000;
|
|
|
info.maxLod = 1000;
|
|
|
info.maxAnisotropy = 1.0f;
|
|
|
- err = vkCreateSampler(v->Device, &info, v->Allocator, &bd->FontSampler);
|
|
|
+ err = vkCreateSampler(v->Device, &info, v->Allocator, &bd->TexSampler);
|
|
|
check_vk_result(err);
|
|
|
}
|
|
|
|
|
@@ -1040,6 +1047,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
|
|
@@ -1070,15 +1091,16 @@ void ImGui_ImplVulkan_DestroyDeviceObjects()
|
|
|
ImGui_ImplVulkanH_DestroyAllViewportsRenderBuffers(v->Device, v->Allocator);
|
|
|
ImGui_ImplVulkan_DestroyFontsTexture();
|
|
|
|
|
|
- if (bd->FontCommandBuffer) { vkFreeCommandBuffers(v->Device, bd->FontCommandPool, 1, &bd->FontCommandBuffer); bd->FontCommandBuffer = VK_NULL_HANDLE; }
|
|
|
- if (bd->FontCommandPool) { vkDestroyCommandPool(v->Device, bd->FontCommandPool, v->Allocator); bd->FontCommandPool = VK_NULL_HANDLE; }
|
|
|
+ if (bd->TexCommandBuffer) { vkFreeCommandBuffers(v->Device, bd->TexCommandPool, 1, &bd->TexCommandBuffer); bd->TexCommandBuffer = VK_NULL_HANDLE; }
|
|
|
+ if (bd->TexCommandPool) { vkDestroyCommandPool(v->Device, bd->TexCommandPool, v->Allocator); bd->TexCommandPool = VK_NULL_HANDLE; }
|
|
|
+ if (bd->TexSampler) { vkDestroySampler(v->Device, bd->TexSampler, v->Allocator); bd->TexSampler = VK_NULL_HANDLE; }
|
|
|
if (bd->ShaderModuleVert) { vkDestroyShaderModule(v->Device, bd->ShaderModuleVert, v->Allocator); bd->ShaderModuleVert = VK_NULL_HANDLE; }
|
|
|
if (bd->ShaderModuleFrag) { vkDestroyShaderModule(v->Device, bd->ShaderModuleFrag, v->Allocator); bd->ShaderModuleFrag = VK_NULL_HANDLE; }
|
|
|
- if (bd->FontSampler) { vkDestroySampler(v->Device, bd->FontSampler, v->Allocator); bd->FontSampler = VK_NULL_HANDLE; }
|
|
|
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->PipelineForViewports) { vkDestroyPipeline(v->Device, bd->PipelineForViewports, v->Allocator); bd->PipelineForViewports = 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)
|
|
@@ -1142,7 +1164,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)
|
|
@@ -1190,7 +1215,7 @@ void ImGui_ImplVulkan_NewFrame()
|
|
|
ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData();
|
|
|
IM_ASSERT(bd != nullptr && "Context or backend not initialized! Did you call ImGui_ImplVulkan_Init()?");
|
|
|
|
|
|
- if (!bd->FontDescriptorSet)
|
|
|
+ if (!bd->FontTexture.DescriptorSet)
|
|
|
ImGui_ImplVulkan_CreateFontsTexture();
|
|
|
}
|
|
|
|
|
@@ -1210,19 +1235,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);
|
|
@@ -1250,7 +1276,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)
|