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

compilation errors if include *<SDL3/SDL_vulkan.h>* before *<vulkan/vulkan.hpp>* #11328

Closed
feelamee opened this issue Oct 25, 2024 · 2 comments
Closed
Milestone

Comments

@feelamee
Copy link

feelamee commented Oct 25, 2024

The problem in compilation errors if <SDL3/SDL_vulkan.h> was included before <vulkan/vulkan.hpp>.
It reproducing only with vulkan C++ api, but not C.

compilation output
In file included from /home/missed/code/sdl-bug-with-vulkan-cpp-api/build/_deps/vulkan-headers-src/include/vulkan/vulkan.hpp:8681,
               from /home/missed/code/sdl-bug-with-vulkan-cpp-api/build/_deps/vulkan-headers-src/include/vulkan/vulkan_raii.hpp:11,
               from /home/missed/code/sdl-bug-with-vulkan-cpp-api/main.cpp:3:
/home/missed/code/sdl-bug-with-vulkan-cpp-api/build/_deps/vulkan-headers-src/include/vulkan/vulkan_handles.hpp:2613:46: error: conversion from ‘int’ to ‘VkSurfaceKHR_T*’ in a converted constant expression
 2613 |   struct CppType<VkSurfaceKHR, VK_NULL_HANDLE>
      |                                              ^
/home/missed/code/sdl-bug-with-vulkan-cpp-api/build/_deps/vulkan-headers-src/include/vulkan/vulkan_handles.hpp:2613:46: error: could not convert ‘0’ from ‘int’ to ‘VkSurfaceKHR_T*’
 2613 |   struct CppType<VkSurfaceKHR, VK_NULL_HANDLE>
      |                                              ^
      |                                              |
      |                                              int

As I explored, VK_NULL_HANDLE defined to 0 insted of nullptr in <vulkan/vulkan_core.h>

#ifndef VK_DEFINE_NON_DISPATCHABLE_HANDLE
    #if (VK_USE_64_BIT_PTR_DEFINES==1)
        #if (defined(__cplusplus) && (__cplusplus >= 201103L)) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201103L))
            #define VK_NULL_HANDLE nullptr
        #else
            #define VK_NULL_HANDLE ((void*)0)
        #endif
    #else
        #define VK_NULL_HANDLE 0ULL
    #endif
#endif
#ifndef VK_NULL_HANDLE
    #define VK_NULL_HANDLE 0
#endif

Because <SDL3/SDL_vulkan.h> defined VK_DEFINE_NON_DISPATCHABLE_HANDLE.

I also made a repo with minimal repoducible example.

So, I'm not sure that this is an SDL bug. But, probably, we need to provide workaround for this.
I'm ready to make PR, if someone will guide me to right solution/fix.

@slouken slouken added this to the 3.2.0 milestone Oct 25, 2024
@Dv-Senna
Copy link
Contributor

The issue is due to VK_NULL_HANDLE being defined to 0, which can't be implicitly converted to a pointer in C++. By looking at the way VK_NULL_HANDLE is defined, you have to not define VK_DEFINE_NON_DISPATCHABLE_HANDLE before including vulkan/vulkan_core.h, or else, #define VK_NULL_HANDLE 0 is forced. The issue is that SDL_vulkan.h need VK_DEFINE_NON_DISPATCHABLE_HANDLE and define it itself, but it's never undef. In #11361 , I added an #undef at the end of SDL_vulkan.h for VK_DEFINE_NON_DISPATCHABLE_HANDLE and one for VK_DEFINE_DISPATCHABLE (didn't check if it can work without the second one, but it's safer to add it anyway).

@Dv-Senna
Copy link
Contributor

After check, #undef VK_DEFINE_DISPATCHABLE is not necessary to allow it to compile with gcc 14.2.1

@sezero sezero closed this as completed in 149ecff Oct 29, 2024
sezero pushed a commit that referenced this issue Oct 29, 2024
…LE_HANDLE

Allows including vulkan.hpp in user code in C++ before SDL_vulkan.h w/o errors.
Fixes:  #11328 .

(cherry picked from commit 149ecff)
slouken pushed a commit that referenced this issue Oct 30, 2024
…LE_HANDLE

Allows including vulkan.hpp in user code in C++ before SDL_vulkan.h w/o errors.
Fixes:  #11328 .

(cherry picked from commit 149ecff)
(cherry picked from commit 478dff3)
sezero pushed a commit to sezero/SDL that referenced this issue Nov 11, 2024
…LE_HANDLE

Allows including vulkan.hpp in user code in C++ before SDL_vulkan.h w/o errors.
Fixes:  libsdl-org#11328 .

(cherry picked from commit 149ecff)
(cherry picked from commit 478dff3)
klukaszek pushed a commit to klukaszek/SDL that referenced this issue Nov 17, 2024
…LE_HANDLE

Allows including vulkan.hpp in user code in C++ before SDL_vulkan.h w/o errors.
Fixes:  libsdl-org#11328 .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants