Skip to content

Commit

Permalink
ImGui: Make ImGui work with volk loader
Browse files Browse the repository at this point in the history
ImGui defines vulkan function pointers globally and those names
conflict with function pointers defined by volk library (violation of
single definition rule).

This leads to runtime crash when some compilation units have a
chance to use imgui's version of function pointer which is not
initialized by imgui (because we use volk for initialization and do
not invoke imgui function loader functionality).
  • Loading branch information
kennyalive committed Jan 2, 2022
1 parent 4b68b54 commit 65113bf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions third-party/imgui/impl/imgui_impl_vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,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) \
Expand Down Expand Up @@ -1011,7 +1011,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<decltype(func)>(loader_func(#func, user_data)); \
if (func == NULL) \
Expand Down
2 changes: 1 addition & 1 deletion third-party/imgui/impl/imgui_impl_vulkan.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#if defined(IMGUI_IMPL_VULKAN_NO_PROTOTYPES) && !defined(VK_NO_PROTOTYPES)
#define VK_NO_PROTOTYPES
#endif
#include <vulkan/vulkan.h>
#include "volk/volk.h"

// Initialization data, for ImGui_ImplVulkan_Init()
// [Please zero-clear before use!]
Expand Down

0 comments on commit 65113bf

Please sign in to comment.