KhronosGroup / Vulkan-Hpp

Open-Source Vulkan C++ API
Apache License 2.0
3.08k stars 304 forks source link

Unable to compile on Windows MSVC 2022 with Clang 17.03 #1940

Closed GamerSg closed 1 week ago

GamerSg commented 4 weeks ago

Compiles fine with MSVC compiler on Windows and GCC on Linux. With Clang, im getting multiple errors which look similar,

VulkanSDK\1.3.283.0\Include\vulkan\vulkan_handles.hpp(2482,32): error : conversion from 'int' to 'VkSurfaceKHR' (aka 'VkSurfaceKHR_T *') is not allowed in a converted constant expression 2482 | struct CppType<VkSurfaceKHR, VK_NULL_HANDLE> | ^~~~~~ E:\VulkanSDK\1.3.283.0\Include\vulkan\vulkan_core.h(50,28): note: expanded from macro 'VK_NULL_HANDLE' 50 | #define VK_NULL_HANDLE 0 | ^

image

sharadhr commented 4 weeks ago

@asuessenbach we should probably use struct CppType<VkSurfaceKHR, {}> instead of VK_NULL_HANDLE in the instantiation. #1860 is relevant here.

We could also use nullptr as the second template parameter, depending on what you think makes our intentions more explicit.

asuessenbach commented 2 weeks ago

I'm a bit surprised here about

E:\VulkanSDK\1.3.283.0\Include\vulkan\vulkan_core.h(50,28): note: expanded from macro 'VK_NULL_HANDLE' 50 | #define VK_NULL_HANDLE 0

Why is VK_NULL_HANDLE defined to be 0 here? Looking at the code in vulkan_core.h, that can only be when VK_DEFINE_NON_DISPATCHABLE_HANDLE is already defined:

#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

But regularly, that's done right after that code sequence. Do you have any hint, why it's already defined in your case?

GamerSg commented 1 week ago

When i mouseover VK_NULL_HANDLE in VS, it shows that it resolves to nullptr. However, it seems when compiling, clang on Windows is resolving it to 0 and producing the error.

Could this inconsistency be due to Intellisense interpreting the code with MSVC compiler? I do not have a clue at this moment as to why it is resolving to 0 with clang.

GamerSg commented 1 week ago

Incase this is of any help, the only relevant includes before including vulkan.hpp which i think could affect the compilation are the following:

include <SDL3/SDL.h>

include <SDL3/SDL_vulkan.h>

GamerSg commented 1 week ago

I looked into the SDL includes and see that it is defining VK_DEFINE_NON_DISPATCHABLE_HANDLE which was causing the issue.

`#if defined(LP64) || defined(_WIN64) || defined(__x86_64) || defined(_M_X64) || defined(ia64) || defined (_M_IA64) || defined(aarch64) || defined(powerpc64)

define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef struct object##_T *object;

else

define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef uint64_t object;

endif`

I've moved the SDL includes after the include to vulkan.hpp and it compiles fine now.