Glad2 Vulkan support
Version/Branch of Dear ImGui:
master
Back-ends:
imgui_impl_vulkan.cpp + imgui_impl_glfw.cpp
Compiler, OS:
Arch Linux GCC 14
Full config/build information:
No response
Details:
Add Vulkan glad2 support!
When I use glad2 for Vulkan I get errors that the imgui library cannot find Vulkan functions. I created this hotfix to resolve this issue.
Error example: imgui/backends/imgui_impl_vulkan.cpp:1582:(.text+0x4936): undefined reference to vkDestroySemaphore
In imgui_impl_vulkan.h we should change 56-66 lines to:
#ifdef IMGUI_IMPL_VULKAN_USE_VOLK
#include <volk.h>
#else
#ifdef IMGUI_IMPL_VULKAN_USE_GLAD
#include <glad/vulkan.h>
#else
#include <vulkan/vulkan.h>
#endif
#endif
And also fix 96 line from VkPipelineRenderingCreateInfoKHR to VkPipelineRenderingCreateInfo
Thanks for attention!
Screenshots/Video:
No response
Minimal, Complete and Verifiable Example code:
No response
(FFS, another Vulkan loader. Vulkan is going the route of OpenGL :( )
Linking to #6582
You can actually use GLAD2 with VOLK, without touching ImGui sources. Volk has a compile time define VOLK_VULKAN_H_PATH we can use! I used the example_sdl2_vulkan with cmake as my starting point but I am sure you can make it work with glfw.
- Generate the interface with GLAD2 generator, I used vulkan 1.0 + VK_KHR_surface + VK_KHR_swapchain + VK_EXT_debug_report: https://gen.glad.sh/#generator=c&api=gl%3D4.3%2Cvulkan%3D1.0&profile=gl%3Dcore%2Cgles1%3Dcommon&extensions=VK_EXT_debug_report%2CVK_KHR_surface%2CVK_KHR_swapchain
- Add to cmake
target_include_directoriesso it includes the unzipped GLAD2 include folder - Download VOLK and add to
target_include_directoriesso it includesvolk.h. You actually have to edit the ImGui sources here a bit, but just replace<Volk/volk.h>to"volk.h"or use the specified directory name for the repo and include that, or whatever, but this should not be a problem here. - Add to cmake
target_compile_definitionsso it defines-DIMGUI_IMPL_VULKAN_USE_VOLKand-DVOLK_VULKAN_H_PATH="glad/vulkan.h" - Build with cmake, the example works without including the system
<vulkan/vulkan.h>!
Also VkPipelineRenderingCreateInfoKHR will be available with VK_KHR_dynamic_rendering extension or vulkan 1.3 (can be vulkan 1.0-1.3).
In contrast VkPipelineRenderingCreateInfo will only be available in vulkan 1.3 so if you want to reach the widest audience I would suggest to use VkPipelineRenderingCreateInfoKHR.
使用 glad2 将会方便很多