imgui icon indicating copy to clipboard operation
imgui copied to clipboard

Glad2 Vulkan support

Open CyberFlex1984 opened this issue 1 year ago • 2 comments

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

CyberFlex1984 avatar Jun 30 '24 15:06 CyberFlex1984

(FFS, another Vulkan loader. Vulkan is going the route of OpenGL :( )

Linking to #6582

ocornut avatar Jul 01 '24 10:07 ocornut

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.

  1. 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
  2. Add to cmake target_include_directories so it includes the unzipped GLAD2 include folder
  3. Download VOLK and add to target_include_directories so it includes volk.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.
  4. Add to cmake target_compile_definitions so it defines -DIMGUI_IMPL_VULKAN_USE_VOLK and -DVOLK_VULKAN_H_PATH="glad/vulkan.h"
  5. 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.

mihaly-sisak avatar Jul 07 '24 11:07 mihaly-sisak

使用 glad2 将会方便很多

redbg avatar Aug 31 '24 09:08 redbg