From 8fb2aea07b49d994a596adea28674d9ae14673d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Aleksander=20G=C3=B3rski?= Date: Wed, 5 Aug 2026 23:37:58 +0900 Subject: [PATCH] Vulkan: Drop public RemoveHeapTexture; heap mode uses DescriptorHeapInfo UnRegisterImage like DX12 SrvDescriptorFreeFn Fix: Rename target glsl_shader_heap file in validation command to match the existing one --- backends/imgui_impl_vulkan.cpp | 17 ++++------------- backends/imgui_impl_vulkan.h | 12 ++++++------ backends/vulkan/generate_spv.sh | 2 +- 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/backends/imgui_impl_vulkan.cpp b/backends/imgui_impl_vulkan.cpp index aad4185e1..21f190929 100644 --- a/backends/imgui_impl_vulkan.cpp +++ b/backends/imgui_impl_vulkan.cpp @@ -826,7 +826,7 @@ void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer comm // Heap-mode TexIDs are tagged (index | 0x80000000). Use ImU64 for bit ops (ImTextureID may be redefined; default is ImU64). // Push a uint32_t index (not &image_id) so size=4 is endian-safe. const ImU64 tex_id_u64 = (ImU64)image_id; - IM_ASSERT((tex_id_u64 & 0x80000000ull) != 0 && "ImTextureID is not a descriptor-heap index (do not use ImGui_ImplVulkan_AddTexture when DescriptorHeapInfo is set; use RegisterImage and tag with 0x80000000)"); + IM_ASSERT((tex_id_u64 & 0x80000000ull) != 0 && "ImTextureID is not a descriptor-heap index (do not use ImGui_ImplVulkan_AddTexture when DescriptorHeapInfo is set; use DescriptorHeapInfo::RegisterImage and tag with 0x80000000)"); uint32_t heap_index = (uint32_t)(tex_id_u64 & 0x7FFFFFFFull); VkPushDataInfoEXT push{}; push.sType = VK_STRUCTURE_TYPE_PUSH_DATA_INFO_EXT; @@ -874,8 +874,8 @@ static void ImGui_ImplVulkan_DestroyTexture(ImTextureData* tex) if (backend_tex->DescriptorSet != VK_NULL_HANDLE) ImGui_ImplVulkan_RemoveTexture(backend_tex->DescriptorSet); #ifdef IMGUI_IMPL_VULKAN_HAS_DESCRIPTOR_HEAP - else - ImGui_ImplVulkan_RemoveHeapTexture(backend_tex->DescriptorHeapIndex); + else if (v->DescriptorHeapInfo) + v->DescriptorHeapInfo->UnRegisterImage(v->DescriptorHeapInfo->UserContext, backend_tex->DescriptorHeapIndex); #endif if (backend_tex->ImageView != VK_NULL_HANDLE) vkDestroyImageView(v->Device, backend_tex->ImageView, v->Allocator); @@ -1696,7 +1696,7 @@ VkDescriptorSet ImGui_ImplVulkan_AddTexture(VkImageView image_view, VkImageLayou ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData(); ImGui_ImplVulkan_InitInfo* v = &bd->VulkanInitInfo; #ifdef IMGUI_IMPL_VULKAN_HAS_DESCRIPTOR_HEAP - IM_ASSERT(v->DescriptorHeapInfo == nullptr && "ImGui_ImplVulkan_AddTexture() is unavailable when using DescriptorHeapInfo; register via DescriptorHeapInfo::RegisterImage and set ImTextureID to (index | 0x80000000)"); + IM_ASSERT(v->DescriptorHeapInfo == nullptr && "ImGui_ImplVulkan_AddTexture() is unavailable when using DescriptorHeapInfo; use DescriptorHeapInfo::RegisterImage and set ImTextureID to (index | 0x80000000)"); #endif VkDescriptorPool pool = bd->DescriptorPool ? bd->DescriptorPool : v->DescriptorPool; @@ -1745,15 +1745,6 @@ void ImGui_ImplVulkan_RemoveTexture(VkDescriptorSet descriptor_set) vkFreeDescriptorSets(v->Device, pool, 1, &descriptor_set); } -#ifdef IMGUI_IMPL_VULKAN_HAS_DESCRIPTOR_HEAP -void ImGui_ImplVulkan_RemoveHeapTexture(uint32_t id) -{ - ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData(); - ImGui_ImplVulkan_InitInfo* v = &bd->VulkanInitInfo; - v->DescriptorHeapInfo->UnRegisterImage(v->DescriptorHeapInfo->UserContext, id); -} -#endif - void ImGui_ImplVulkan_DestroyFrameRenderBuffers(VkDevice device, ImGui_ImplVulkan_FrameRenderBuffers* buffers, const VkAllocationCallbacks* allocator) { if (buffers->VertexBuffer) diff --git a/backends/imgui_impl_vulkan.h b/backends/imgui_impl_vulkan.h index 8d8f8e0c5..331b3fd45 100644 --- a/backends/imgui_impl_vulkan.h +++ b/backends/imgui_impl_vulkan.h @@ -117,6 +117,9 @@ struct ImGui_ImplVulkan_DescriptorHeapInfo // - When using dynamic rendering, set UseDynamicRendering=true + fill PipelineInfoMain.PipelineRenderingCreateInfo structure. // - About descriptor heap (requires VK_EXT_descriptor_heap in your Vulkan headers → IMGUI_IMPL_VULKAN_HAS_DESCRIPTOR_HEAP): // - When using descriptor heaps, set DescriptorHeapInfo and leave DescriptorPool / DescriptorPoolSize unset. +// - Like DX12's SrvDescriptorAllocFn/FreeFn: the application owns heap allocation via Register*/UnRegister* callbacks. +// - ImGui_ImplVulkan_AddTexture()/RemoveTexture() are unavailable in this mode (pool path only). +// - User textures: call RegisterImage yourself and use ImTextureID = (heap_index | 0x80000000); free with UnRegisterImage. struct ImGui_ImplVulkan_InitInfo { uint32_t ApiVersion; // Fill with API version of Instance, e.g. VK_API_VERSION_1_3 or your value of VkApplicationInfo::apiVersion. May be lower than header version (VK_HEADER_VERSION_COMPLETE) @@ -154,7 +157,7 @@ struct ImGui_ImplVulkan_InitInfo VkShaderModuleCreateInfo CustomShaderFragCreateInfo; #ifdef IMGUI_IMPL_VULKAN_HAS_DESCRIPTOR_HEAP - // (Optional) If set, use VK_EXT_descriptor_heap. + // (Optional) If set, use VK_EXT_descriptor_heap (app-owned Register*/UnRegister* callbacks; see comment above). // ImTextureID must be (RegisterImage() index | 0x80000000). ImGui_ImplVulkan_AddTexture() is unavailable in this mode. const ImGui_ImplVulkan_DescriptorHeapInfo *DescriptorHeapInfo; #endif @@ -176,13 +179,10 @@ IMGUI_IMPL_API void ImGui_ImplVulkan_CreateMainPipeline(const ImGui_ IMGUI_IMPL_API void ImGui_ImplVulkan_UpdateTexture(ImTextureData* tex); // Register a texture (VkDescriptorSet for a VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE == ImTextureID) -// - Not available when InitInfo::DescriptorHeapInfo is set (asserts). In heap mode register via DescriptorHeapInfo::RegisterImage -// and use ImTextureID = (heap_index | 0x80000000). +// - Pool path only. Not available when InitInfo::DescriptorHeapInfo is set (asserts). +// - Heap mode: use DescriptorHeapInfo::RegisterImage / UnRegisterImage and ImTextureID = (heap_index | 0x80000000). IMGUI_IMPL_API VkDescriptorSet ImGui_ImplVulkan_AddTexture(VkImageView image_view, VkImageLayout image_layout); IMGUI_IMPL_API void ImGui_ImplVulkan_RemoveTexture(VkDescriptorSet descriptor_set); -#ifdef IMGUI_IMPL_VULKAN_HAS_DESCRIPTOR_HEAP -IMGUI_IMPL_API void ImGui_ImplVulkan_RemoveHeapTexture(uint32_t id); -#endif #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS IMGUI_IMPL_API VkDescriptorSet ImGui_ImplVulkan_AddTexture(VkSampler sampler, VkImageView image_view, VkImageLayout image_layout); // Ignore VkSampler diff --git a/backends/vulkan/generate_spv.sh b/backends/vulkan/generate_spv.sh index d237e7473..492e0da8b 100755 --- a/backends/vulkan/generate_spv.sh +++ b/backends/vulkan/generate_spv.sh @@ -4,4 +4,4 @@ ## -o: output file glslangValidator -V -x -o glsl_shader.frag.u32 glsl_shader.frag glslangValidator -V -x -o glsl_shader.vert.u32 glsl_shader.vert -glslangValidator -V --target-env spirv1.2 -x -o glsl_shader_heap.vert.u32 glsl_shader_heap.vert +glslangValidator -V --target-env spirv1.2 -x -o glsl_shader_heap.frag.u32 glsl_shader_heap.frag