Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to provide custom header file with vulkan function prototypes #6582

Closed
wants to merge 8 commits into from

Conversation

adalsteinnh
Copy link

When using a custom Vulkan function loader the current solution can cause symbol conflicts and runtime errors as discussed in issue #4854. This adds an option to replace the Vulkan header file with a custom header file by defining IMGUI_IMPL_VULKAN_CUSTOM_HEADER to resolve these issues.

@ocornut
Copy link
Owner

ocornut commented Apr 16, 2024

Hello,

What is the reason for also adding all those checks next to the VK_NO_PROTOTYPES checks?
If you have fine-tuned control over our loaded why defining VK_NO_PROTOTYPES at all ?

@adalsteinnh
Copy link
Author

What is the reason for also adding all those checks next to the VK_NO_PROTOTYPES checks? If you have fine-tuned control over our loaded why defining VK_NO_PROTOTYPES at all ?

This was written with Volk in mind which does define VK_NO_PROTOTYPES before including some of the Vulkan headers for everything except the function declarations and I would imagine most custom loaders would do something similar.

The proposed solution in issue #4854 where you load the function pointers separately for ImGui would also work and maybe it's not a big deal to have to do that if you want to have a custom loader. However given that Volk currently ships with the Vulkan SDK I think it's reasonable to include this simpler alternative which only requires 1 define from the usage code pointing to the Volk header file or some other custom loader.

@ocornut
Copy link
Owner

ocornut commented Apr 19, 2024

Thank you for the clarification. I have installed volk and toying with it now.
I can confirm that adding #undef VK_NO_PROTOTYPES right under #include <Volk/volk.h> works fine as well.

Basically what I am not liking is to assume that IMGUI_IMPL_VULKAN_CUSTOM_HEADER imply that those block shouldn't be compiled. It seems like a bold assumption to make when the introduced define aims to be generic.

Given that everyone who posted in those thread are using Volk, I am tempted instead to add a define explicitly named after VOLK, and if other cases manifests we can later consider to introduce a more generic version.

ocornut added a commit that referenced this pull request Apr 19, 2024
@ocornut
Copy link
Owner

ocornut commented Apr 19, 2024

I have pushed b720c0f which adds support for #define IMGUI_IMPL_VULKAN_USE_VOLK
Both GLFW+Vulkan and SDL+Vulkan also now supports Volk optionally, which will make it easier to test forward.

Thanks for your help!

@mihaly-sisak
Copy link

mihaly-sisak commented Jul 7, 2024

With the addition of VOLK this can be easily achieved.

You can actually use custom vulkan headers 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.

  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>!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants