mirror of
				https://github.com/ocornut/imgui.git
				synced 2025-10-26 12:27:30 +00:00 
			
		
		
		
	Backends: Vulkan: Fixed crash with using no prototypes + *BREAKING* Added ApiVersion to ImGui_ImplVulkan_LoadFunctions(). (#8326, #8365, #8400)
This commit is contained in:
		| @@ -26,6 +26,7 @@ | |||||||
|  |  | ||||||
| // CHANGELOG | // CHANGELOG | ||||||
| // (minor and older changes stripped away, please see git history for details) | // (minor and older changes stripped away, please see git history for details) | ||||||
|  | //  2025-02-14: *BREAKING CHANGE*: Added uint32_t api_version to ImGui_ImplVulkan_LoadFunctions(). | ||||||
| //  2025-02-13: Vulkan: Added ApiVersion field in ImGui_ImplVulkan_InitInfo. Default to header version if unspecified. Dynamic rendering path loads "vkCmdBeginRendering/vkCmdEndRendering" (without -KHR suffix) on API 1.3. (#8326) | //  2025-02-13: Vulkan: Added ApiVersion field in ImGui_ImplVulkan_InitInfo. Default to header version if unspecified. Dynamic rendering path loads "vkCmdBeginRendering/vkCmdEndRendering" (without -KHR suffix) on API 1.3. (#8326) | ||||||
| //  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) | //  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) | ||||||
| //  2025-01-06: Vulkan: Added more ImGui_ImplVulkanH_XXXX helper functions to simplify our examples. | //  2025-01-06: Vulkan: Added more ImGui_ImplVulkanH_XXXX helper functions to simplify our examples. | ||||||
| @@ -1081,22 +1082,34 @@ void    ImGui_ImplVulkan_DestroyDeviceObjects() | |||||||
| } | } | ||||||
|  |  | ||||||
| #ifdef IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING | #ifdef IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING | ||||||
| static void ImGui_ImplVulkan_LoadDynamicRenderingFunctions(PFN_vkVoidFunction(*loader_func)(const char* function_name, void* user_data), void* user_data) | static void ImGui_ImplVulkan_LoadDynamicRenderingFunctions(uint32_t api_version, PFN_vkVoidFunction(*loader_func)(const char* function_name, void* user_data), void* user_data) | ||||||
| { | { | ||||||
|     // Manually load those two (see #5446, #8326, #8365) |     // Manually load those two (see #5446, #8326, #8365) | ||||||
|     ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData(); |     ImGuiImplVulkanFuncs_vkCmdBeginRenderingKHR = reinterpret_cast<PFN_vkCmdBeginRenderingKHR>(loader_func(api_version < VK_API_VERSION_1_3 ? "vkCmdBeginRenderingKHR" : "vkCmdBeginRendering", user_data)); | ||||||
|     ImGui_ImplVulkan_InitInfo* v = &bd->VulkanInitInfo; |     ImGuiImplVulkanFuncs_vkCmdEndRenderingKHR = reinterpret_cast<PFN_vkCmdEndRenderingKHR>(loader_func(api_version < VK_API_VERSION_1_3 ? "vkCmdEndRenderingKHR" : "vkCmdEndRendering", user_data)); | ||||||
|     ImGuiImplVulkanFuncs_vkCmdBeginRenderingKHR = reinterpret_cast<PFN_vkCmdBeginRenderingKHR>(loader_func(v->ApiVersion < VK_API_VERSION_1_3 ? "vkCmdBeginRenderingKHR" : "vkCmdBeginRendering", user_data)); |  | ||||||
|     ImGuiImplVulkanFuncs_vkCmdEndRenderingKHR = reinterpret_cast<PFN_vkCmdEndRenderingKHR>(loader_func(v->ApiVersion < VK_API_VERSION_1_3 ? "vkCmdEndRenderingKHR" : "vkCmdEndRendering", user_data)); |  | ||||||
| } | } | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| bool    ImGui_ImplVulkan_LoadFunctions(PFN_vkVoidFunction(*loader_func)(const char* function_name, void* user_data), void* user_data) | // If unspecified by user, assume that ApiVersion == HeaderVersion | ||||||
|  |  // We don't care about other versions than 1.3 for our checks, so don't need to make this exhaustive (e.g. with all #ifdef VK_VERSION_1_X checks) | ||||||
|  | static uint32_t ImGui_ImplVulkan_GetDefaultApiVersion() | ||||||
|  | { | ||||||
|  | #ifdef VK_HEADER_VERSION_COMPLETE | ||||||
|  |     return VK_HEADER_VERSION_COMPLETE; | ||||||
|  | #else | ||||||
|  |     return VK_API_VERSION_1_0; | ||||||
|  | #endif | ||||||
|  | } | ||||||
|  |  | ||||||
|  | bool    ImGui_ImplVulkan_LoadFunctions(uint32_t api_version, PFN_vkVoidFunction(*loader_func)(const char* function_name, void* user_data), void* user_data) | ||||||
| { | { | ||||||
|     // Load function pointers |     // Load function pointers | ||||||
|     // You can use the default Vulkan loader using: |     // You can use the default Vulkan loader using: | ||||||
|     //      ImGui_ImplVulkan_LoadFunctions([](const char* function_name, void*) { return vkGetInstanceProcAddr(your_vk_isntance, function_name); }); |     //      ImGui_ImplVulkan_LoadFunctions(VK_API_VERSION_1_3, [](const char* function_name, void*) { return vkGetInstanceProcAddr(your_vk_isntance, function_name); }); | ||||||
|     // But this would be roughly equivalent to not setting VK_NO_PROTOTYPES. |     // But this would be roughly equivalent to not setting VK_NO_PROTOTYPES. | ||||||
|  |     if (api_version == 0) | ||||||
|  |         api_version = ImGui_ImplVulkan_GetDefaultApiVersion(); | ||||||
|  |  | ||||||
| #ifdef IMGUI_IMPL_VULKAN_USE_LOADER | #ifdef IMGUI_IMPL_VULKAN_USE_LOADER | ||||||
| #define IMGUI_VULKAN_FUNC_LOAD(func) \ | #define IMGUI_VULKAN_FUNC_LOAD(func) \ | ||||||
|     func = reinterpret_cast<decltype(func)>(loader_func(#func, user_data)); \ |     func = reinterpret_cast<decltype(func)>(loader_func(#func, user_data)); \ | ||||||
| @@ -1106,7 +1119,7 @@ bool    ImGui_ImplVulkan_LoadFunctions(PFN_vkVoidFunction(*loader_func)(const ch | |||||||
| #undef IMGUI_VULKAN_FUNC_LOAD | #undef IMGUI_VULKAN_FUNC_LOAD | ||||||
|  |  | ||||||
| #ifdef IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING | #ifdef IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING | ||||||
|     ImGui_ImplVulkan_LoadDynamicRenderingFunctions(loader_func, user_data); |     ImGui_ImplVulkan_LoadDynamicRenderingFunctions(api_version, loader_func, user_data); | ||||||
| #endif | #endif | ||||||
| #else | #else | ||||||
|     IM_UNUSED(loader_func); |     IM_UNUSED(loader_func); | ||||||
| @@ -1121,11 +1134,14 @@ bool    ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo* info) | |||||||
| { | { | ||||||
|     IM_ASSERT(g_FunctionsLoaded && "Need to call ImGui_ImplVulkan_LoadFunctions() if IMGUI_IMPL_VULKAN_NO_PROTOTYPES or VK_NO_PROTOTYPES are set!"); |     IM_ASSERT(g_FunctionsLoaded && "Need to call ImGui_ImplVulkan_LoadFunctions() if IMGUI_IMPL_VULKAN_NO_PROTOTYPES or VK_NO_PROTOTYPES are set!"); | ||||||
|  |  | ||||||
|  |     if (info->ApiVersion == 0) | ||||||
|  |         info->ApiVersion = ImGui_ImplVulkan_GetDefaultApiVersion(); | ||||||
|  |  | ||||||
|     if (info->UseDynamicRendering) |     if (info->UseDynamicRendering) | ||||||
|     { |     { | ||||||
| #ifdef IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING | #ifdef IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING | ||||||
| #ifndef IMGUI_IMPL_VULKAN_USE_LOADER | #ifndef IMGUI_IMPL_VULKAN_USE_LOADER | ||||||
|         ImGui_ImplVulkan_LoadDynamicRenderingFunctions([](const char* function_name, void* user_data) { return vkGetInstanceProcAddr((VkInstance)user_data, function_name); }, (void*)info->Instance); |         ImGui_ImplVulkan_LoadDynamicRenderingFunctions(info->ApiVersion, [](const char* function_name, void* user_data) { return vkGetInstanceProcAddr((VkInstance)user_data, function_name); }, (void*)info->Instance); | ||||||
| #endif | #endif | ||||||
|         IM_ASSERT(ImGuiImplVulkanFuncs_vkCmdBeginRenderingKHR != nullptr); |         IM_ASSERT(ImGuiImplVulkanFuncs_vkCmdBeginRenderingKHR != nullptr); | ||||||
|         IM_ASSERT(ImGuiImplVulkanFuncs_vkCmdEndRenderingKHR != nullptr); |         IM_ASSERT(ImGuiImplVulkanFuncs_vkCmdEndRenderingKHR != nullptr); | ||||||
| @@ -1158,15 +1174,6 @@ bool    ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo* info) | |||||||
|         IM_ASSERT(info->RenderPass != VK_NULL_HANDLE); |         IM_ASSERT(info->RenderPass != VK_NULL_HANDLE); | ||||||
|  |  | ||||||
|     bd->VulkanInitInfo = *info; |     bd->VulkanInitInfo = *info; | ||||||
|     if (bd->VulkanInitInfo.ApiVersion == 0) |  | ||||||
|     { |  | ||||||
|         // We don't care about other versions for now, so don't need to make this exhaustive (with #ifdef VK_VERSION_1_X checks) |  | ||||||
| #ifdef VK_HEADER_VERSION_COMPLETE |  | ||||||
|         bd->VulkanInitInfo.ApiVersion = VK_HEADER_VERSION_COMPLETE; |  | ||||||
| #else |  | ||||||
|         bd->VulkanInitInfo.ApiVersion = VK_API_VERSION_1_0; |  | ||||||
| #endif |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     ImGui_ImplVulkan_CreateDeviceObjects(); |     ImGui_ImplVulkan_CreateDeviceObjects(); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -124,7 +124,7 @@ IMGUI_IMPL_API void             ImGui_ImplVulkan_RemoveTexture(VkDescriptorSet d | |||||||
|  |  | ||||||
| // Optional: load Vulkan functions with a custom function loader | // Optional: load Vulkan functions with a custom function loader | ||||||
| // This is only useful with IMGUI_IMPL_VULKAN_NO_PROTOTYPES / VK_NO_PROTOTYPES | // This is only useful with IMGUI_IMPL_VULKAN_NO_PROTOTYPES / VK_NO_PROTOTYPES | ||||||
| IMGUI_IMPL_API bool             ImGui_ImplVulkan_LoadFunctions(PFN_vkVoidFunction(*loader_func)(const char* function_name, void* user_data), void* user_data = nullptr); | IMGUI_IMPL_API bool             ImGui_ImplVulkan_LoadFunctions(uint32_t api_version, PFN_vkVoidFunction(*loader_func)(const char* function_name, void* user_data), void* user_data = nullptr); | ||||||
|  |  | ||||||
| // [BETA] Selected render state data shared with callbacks. | // [BETA] Selected render state data shared with callbacks. | ||||||
| // This is temporarily stored in GetPlatformIO().Renderer_RenderState during the ImGui_ImplVulkan_RenderDrawData() call. | // This is temporarily stored in GetPlatformIO().Renderer_RenderState during the ImGui_ImplVulkan_RenderDrawData() call. | ||||||
|   | |||||||
| @@ -43,6 +43,10 @@ Breaking changes: | |||||||
|  |  | ||||||
| - Renamed ImFontConfig::GlyphExtraSpacing.x option to GlyphExtraAdvanceX. (#242) | - Renamed ImFontConfig::GlyphExtraSpacing.x option to GlyphExtraAdvanceX. (#242) | ||||||
| - Renamed style.TabMinWidthForCloseButton to style.TabCloseButtonMinWidthUnselected. | - Renamed style.TabMinWidthForCloseButton to style.TabCloseButtonMinWidthUnselected. | ||||||
|  | - Backends: Vulkan: Added 'uint32_t api_version' argument to ImGui_ImplVulkan_LoadFunctions(). | ||||||
|  |   Note that it was also added to ImGui_ImplVulkan_InitInfo but for the later it is optional. | ||||||
|  |   (#8326, #8365, #8400) | ||||||
|  |  | ||||||
|  |  | ||||||
| Other changes: | Other changes: | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 ocornut
					ocornut