From 5534f55eefd050f98052dc19190cac843210906c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=C3=B0alsteinn=20Hj=C3=B6rleifsson?= Date: Fri, 7 Jul 2023 00:50:42 +0200 Subject: [PATCH 1/4] changed #defines to avoid double definitions --- backends/imgui_impl_vulkan.cpp | 8 ++++---- backends/imgui_impl_vulkan.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/backends/imgui_impl_vulkan.cpp b/backends/imgui_impl_vulkan.cpp index 6d1792b515ac..ebd089f37908 100644 --- a/backends/imgui_impl_vulkan.cpp +++ b/backends/imgui_impl_vulkan.cpp @@ -155,12 +155,12 @@ void ImGui_ImplVulkanH_CreateWindowCommandBuffers(VkPhysicalDevice physical_devi // Vulkan prototypes for use with custom loaders // (see description of IMGUI_IMPL_VULKAN_NO_PROTOTYPES in imgui_impl_vulkan.h -#ifdef VK_NO_PROTOTYPES +#if defined(VK_NO_PROTOTYPES) && !defined(VOLK_HEADER_VERSION) static bool g_FunctionsLoaded = false; #else static bool g_FunctionsLoaded = true; #endif -#ifdef VK_NO_PROTOTYPES +#if defined(VK_NO_PROTOTYPES) && !defined(VOLK_HEADER_VERSION) #define IMGUI_VULKAN_FUNC_MAP(IMGUI_VULKAN_FUNC_MAP_MACRO) \ IMGUI_VULKAN_FUNC_MAP_MACRO(vkAllocateCommandBuffers) \ IMGUI_VULKAN_FUNC_MAP_MACRO(vkAllocateDescriptorSets) \ @@ -997,7 +997,7 @@ bool ImGui_ImplVulkan_LoadFunctions(PFN_vkVoidFunction(*loader_func)(const ch // You can use the default Vulkan loader using: // ImGui_ImplVulkan_LoadFunctions([](const char* function_name, void*) { return vkGetInstanceProcAddr(your_vk_isntance, function_name); }); // But this would be equivalent to not setting VK_NO_PROTOTYPES. -#ifdef VK_NO_PROTOTYPES +#if defined(VK_NO_PROTOTYPES) && !defined(VOLK_HEADER_VERSION) #define IMGUI_VULKAN_FUNC_LOAD(func) \ func = reinterpret_cast(loader_func(#func, user_data)); \ if (func == nullptr) \ @@ -1026,7 +1026,7 @@ bool ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo* info, VkRenderPass rend if (info->UseDynamicRendering) { #ifdef IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING -#ifndef VK_NO_PROTOTYPES +#if defined(VK_NO_PROTOTYPES) && !defined(VOLK_HEADER_VERSION) ImGuiImplVulkanFuncs_vkCmdBeginRenderingKHR = reinterpret_cast(vkGetInstanceProcAddr(info->Instance, "vkCmdBeginRenderingKHR")); ImGuiImplVulkanFuncs_vkCmdEndRenderingKHR = reinterpret_cast(vkGetInstanceProcAddr(info->Instance, "vkCmdEndRenderingKHR")); #endif diff --git a/backends/imgui_impl_vulkan.h b/backends/imgui_impl_vulkan.h index e2ce3b437466..d72a7d42bd1f 100644 --- a/backends/imgui_impl_vulkan.h +++ b/backends/imgui_impl_vulkan.h @@ -43,7 +43,7 @@ #if defined(IMGUI_IMPL_VULKAN_NO_PROTOTYPES) && !defined(VK_NO_PROTOTYPES) #define VK_NO_PROTOTYPES #endif -#include +#include // Initialization data, for ImGui_ImplVulkan_Init() // [Please zero-clear before use!] From 5819cf7acb00ae1ade9ef6e00e573ae4b2fafe58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=C3=B0alsteinn=20Hj=C3=B6rleifsson?= Date: Fri, 7 Jul 2023 22:18:54 +0200 Subject: [PATCH 2/4] add option to provide custom vulkan prototypes --- backends/imgui_impl_vulkan.cpp | 8 ++++---- backends/imgui_impl_vulkan.h | 10 +++++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/backends/imgui_impl_vulkan.cpp b/backends/imgui_impl_vulkan.cpp index ebd089f37908..f14ce1b10be2 100644 --- a/backends/imgui_impl_vulkan.cpp +++ b/backends/imgui_impl_vulkan.cpp @@ -155,12 +155,12 @@ void ImGui_ImplVulkanH_CreateWindowCommandBuffers(VkPhysicalDevice physical_devi // Vulkan prototypes for use with custom loaders // (see description of IMGUI_IMPL_VULKAN_NO_PROTOTYPES in imgui_impl_vulkan.h -#if defined(VK_NO_PROTOTYPES) && !defined(VOLK_HEADER_VERSION) +#if defined(VK_NO_PROTOTYPES) && !defined(IMGUI_IMPL_VULKAN_CUSTOM_HEADER) static bool g_FunctionsLoaded = false; #else static bool g_FunctionsLoaded = true; #endif -#if defined(VK_NO_PROTOTYPES) && !defined(VOLK_HEADER_VERSION) +#if defined(VK_NO_PROTOTYPES) && !defined(IMGUI_IMPL_VULKAN_CUSTOM_HEADER) #define IMGUI_VULKAN_FUNC_MAP(IMGUI_VULKAN_FUNC_MAP_MACRO) \ IMGUI_VULKAN_FUNC_MAP_MACRO(vkAllocateCommandBuffers) \ IMGUI_VULKAN_FUNC_MAP_MACRO(vkAllocateDescriptorSets) \ @@ -997,7 +997,7 @@ bool ImGui_ImplVulkan_LoadFunctions(PFN_vkVoidFunction(*loader_func)(const ch // You can use the default Vulkan loader using: // ImGui_ImplVulkan_LoadFunctions([](const char* function_name, void*) { return vkGetInstanceProcAddr(your_vk_isntance, function_name); }); // But this would be equivalent to not setting VK_NO_PROTOTYPES. -#if defined(VK_NO_PROTOTYPES) && !defined(VOLK_HEADER_VERSION) +#if defined(VK_NO_PROTOTYPES) && !defined(IMGUI_IMPL_VULKAN_CUSTOM_HEADER) #define IMGUI_VULKAN_FUNC_LOAD(func) \ func = reinterpret_cast(loader_func(#func, user_data)); \ if (func == nullptr) \ @@ -1026,7 +1026,7 @@ bool ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo* info, VkRenderPass rend if (info->UseDynamicRendering) { #ifdef IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING -#if defined(VK_NO_PROTOTYPES) && !defined(VOLK_HEADER_VERSION) +#if defined(VK_NO_PROTOTYPES) && !defined(IMGUI_IMPL_VULKAN_CUSTOM_HEADER) ImGuiImplVulkanFuncs_vkCmdBeginRenderingKHR = reinterpret_cast(vkGetInstanceProcAddr(info->Instance, "vkCmdBeginRenderingKHR")); ImGuiImplVulkanFuncs_vkCmdEndRenderingKHR = reinterpret_cast(vkGetInstanceProcAddr(info->Instance, "vkCmdEndRenderingKHR")); #endif diff --git a/backends/imgui_impl_vulkan.h b/backends/imgui_impl_vulkan.h index d72a7d42bd1f..cfac3cc511cf 100644 --- a/backends/imgui_impl_vulkan.h +++ b/backends/imgui_impl_vulkan.h @@ -38,12 +38,20 @@ // (2) Call ImGui_ImplVulkan_LoadFunctions() before ImGui_ImplVulkan_Init() with your custom function. // If you have no idea what this is, leave it alone! //#define IMGUI_IMPL_VULKAN_NO_PROTOTYPES +// Alternatively provide a custom header file with prototype definitions. This is useful to avoid symbol collisions if +// your loader defines vulkan function prototypes in the global scope with default names. +// This definition must be visible in imgui_impl_vulkan.cpp as described above. +//#define IMGUI_IMPL_VULKAN_CUSTOM_HEADER // Vulkan includes +#if defined(IMGUI_IMPL_VULKAN_CUSTOM_HEADER) +#include IMGUI_IMPL_VULKAN_CUSTOM_HEADER +#else #if defined(IMGUI_IMPL_VULKAN_NO_PROTOTYPES) && !defined(VK_NO_PROTOTYPES) #define VK_NO_PROTOTYPES #endif -#include +#include +#endif // Initialization data, for ImGui_ImplVulkan_Init() // [Please zero-clear before use!] From 816b0d7cfae9c8a35d0ceaffe4dc45c49642efcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=C3=B0alsteinn=20Hj=C3=B6rleifsson?= Date: Fri, 7 Jul 2023 00:50:42 +0200 Subject: [PATCH 3/4] changed #defines to avoid double definitions --- backends/imgui_impl_vulkan.cpp | 8 ++++---- backends/imgui_impl_vulkan.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/backends/imgui_impl_vulkan.cpp b/backends/imgui_impl_vulkan.cpp index 6d1792b515ac..ebd089f37908 100644 --- a/backends/imgui_impl_vulkan.cpp +++ b/backends/imgui_impl_vulkan.cpp @@ -155,12 +155,12 @@ void ImGui_ImplVulkanH_CreateWindowCommandBuffers(VkPhysicalDevice physical_devi // Vulkan prototypes for use with custom loaders // (see description of IMGUI_IMPL_VULKAN_NO_PROTOTYPES in imgui_impl_vulkan.h -#ifdef VK_NO_PROTOTYPES +#if defined(VK_NO_PROTOTYPES) && !defined(VOLK_HEADER_VERSION) static bool g_FunctionsLoaded = false; #else static bool g_FunctionsLoaded = true; #endif -#ifdef VK_NO_PROTOTYPES +#if defined(VK_NO_PROTOTYPES) && !defined(VOLK_HEADER_VERSION) #define IMGUI_VULKAN_FUNC_MAP(IMGUI_VULKAN_FUNC_MAP_MACRO) \ IMGUI_VULKAN_FUNC_MAP_MACRO(vkAllocateCommandBuffers) \ IMGUI_VULKAN_FUNC_MAP_MACRO(vkAllocateDescriptorSets) \ @@ -997,7 +997,7 @@ bool ImGui_ImplVulkan_LoadFunctions(PFN_vkVoidFunction(*loader_func)(const ch // You can use the default Vulkan loader using: // ImGui_ImplVulkan_LoadFunctions([](const char* function_name, void*) { return vkGetInstanceProcAddr(your_vk_isntance, function_name); }); // But this would be equivalent to not setting VK_NO_PROTOTYPES. -#ifdef VK_NO_PROTOTYPES +#if defined(VK_NO_PROTOTYPES) && !defined(VOLK_HEADER_VERSION) #define IMGUI_VULKAN_FUNC_LOAD(func) \ func = reinterpret_cast(loader_func(#func, user_data)); \ if (func == nullptr) \ @@ -1026,7 +1026,7 @@ bool ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo* info, VkRenderPass rend if (info->UseDynamicRendering) { #ifdef IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING -#ifndef VK_NO_PROTOTYPES +#if defined(VK_NO_PROTOTYPES) && !defined(VOLK_HEADER_VERSION) ImGuiImplVulkanFuncs_vkCmdBeginRenderingKHR = reinterpret_cast(vkGetInstanceProcAddr(info->Instance, "vkCmdBeginRenderingKHR")); ImGuiImplVulkanFuncs_vkCmdEndRenderingKHR = reinterpret_cast(vkGetInstanceProcAddr(info->Instance, "vkCmdEndRenderingKHR")); #endif diff --git a/backends/imgui_impl_vulkan.h b/backends/imgui_impl_vulkan.h index e2ce3b437466..d72a7d42bd1f 100644 --- a/backends/imgui_impl_vulkan.h +++ b/backends/imgui_impl_vulkan.h @@ -43,7 +43,7 @@ #if defined(IMGUI_IMPL_VULKAN_NO_PROTOTYPES) && !defined(VK_NO_PROTOTYPES) #define VK_NO_PROTOTYPES #endif -#include +#include // Initialization data, for ImGui_ImplVulkan_Init() // [Please zero-clear before use!] From 40aad688348c33e91365815eafe5295803aa4009 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=C3=B0alsteinn=20Hj=C3=B6rleifsson?= Date: Fri, 7 Jul 2023 22:18:54 +0200 Subject: [PATCH 4/4] add option to provide custom vulkan prototypes --- backends/imgui_impl_vulkan.cpp | 8 ++++---- backends/imgui_impl_vulkan.h | 10 +++++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/backends/imgui_impl_vulkan.cpp b/backends/imgui_impl_vulkan.cpp index ebd089f37908..f14ce1b10be2 100644 --- a/backends/imgui_impl_vulkan.cpp +++ b/backends/imgui_impl_vulkan.cpp @@ -155,12 +155,12 @@ void ImGui_ImplVulkanH_CreateWindowCommandBuffers(VkPhysicalDevice physical_devi // Vulkan prototypes for use with custom loaders // (see description of IMGUI_IMPL_VULKAN_NO_PROTOTYPES in imgui_impl_vulkan.h -#if defined(VK_NO_PROTOTYPES) && !defined(VOLK_HEADER_VERSION) +#if defined(VK_NO_PROTOTYPES) && !defined(IMGUI_IMPL_VULKAN_CUSTOM_HEADER) static bool g_FunctionsLoaded = false; #else static bool g_FunctionsLoaded = true; #endif -#if defined(VK_NO_PROTOTYPES) && !defined(VOLK_HEADER_VERSION) +#if defined(VK_NO_PROTOTYPES) && !defined(IMGUI_IMPL_VULKAN_CUSTOM_HEADER) #define IMGUI_VULKAN_FUNC_MAP(IMGUI_VULKAN_FUNC_MAP_MACRO) \ IMGUI_VULKAN_FUNC_MAP_MACRO(vkAllocateCommandBuffers) \ IMGUI_VULKAN_FUNC_MAP_MACRO(vkAllocateDescriptorSets) \ @@ -997,7 +997,7 @@ bool ImGui_ImplVulkan_LoadFunctions(PFN_vkVoidFunction(*loader_func)(const ch // You can use the default Vulkan loader using: // ImGui_ImplVulkan_LoadFunctions([](const char* function_name, void*) { return vkGetInstanceProcAddr(your_vk_isntance, function_name); }); // But this would be equivalent to not setting VK_NO_PROTOTYPES. -#if defined(VK_NO_PROTOTYPES) && !defined(VOLK_HEADER_VERSION) +#if defined(VK_NO_PROTOTYPES) && !defined(IMGUI_IMPL_VULKAN_CUSTOM_HEADER) #define IMGUI_VULKAN_FUNC_LOAD(func) \ func = reinterpret_cast(loader_func(#func, user_data)); \ if (func == nullptr) \ @@ -1026,7 +1026,7 @@ bool ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo* info, VkRenderPass rend if (info->UseDynamicRendering) { #ifdef IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING -#if defined(VK_NO_PROTOTYPES) && !defined(VOLK_HEADER_VERSION) +#if defined(VK_NO_PROTOTYPES) && !defined(IMGUI_IMPL_VULKAN_CUSTOM_HEADER) ImGuiImplVulkanFuncs_vkCmdBeginRenderingKHR = reinterpret_cast(vkGetInstanceProcAddr(info->Instance, "vkCmdBeginRenderingKHR")); ImGuiImplVulkanFuncs_vkCmdEndRenderingKHR = reinterpret_cast(vkGetInstanceProcAddr(info->Instance, "vkCmdEndRenderingKHR")); #endif diff --git a/backends/imgui_impl_vulkan.h b/backends/imgui_impl_vulkan.h index d72a7d42bd1f..cfac3cc511cf 100644 --- a/backends/imgui_impl_vulkan.h +++ b/backends/imgui_impl_vulkan.h @@ -38,12 +38,20 @@ // (2) Call ImGui_ImplVulkan_LoadFunctions() before ImGui_ImplVulkan_Init() with your custom function. // If you have no idea what this is, leave it alone! //#define IMGUI_IMPL_VULKAN_NO_PROTOTYPES +// Alternatively provide a custom header file with prototype definitions. This is useful to avoid symbol collisions if +// your loader defines vulkan function prototypes in the global scope with default names. +// This definition must be visible in imgui_impl_vulkan.cpp as described above. +//#define IMGUI_IMPL_VULKAN_CUSTOM_HEADER // Vulkan includes +#if defined(IMGUI_IMPL_VULKAN_CUSTOM_HEADER) +#include IMGUI_IMPL_VULKAN_CUSTOM_HEADER +#else #if defined(IMGUI_IMPL_VULKAN_NO_PROTOTYPES) && !defined(VK_NO_PROTOTYPES) #define VK_NO_PROTOTYPES #endif -#include +#include +#endif // Initialization data, for ImGui_ImplVulkan_Init() // [Please zero-clear before use!]