KhronosGroup / Vulkan-Hpp

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

`Null non-type template argument must be cast to template parameter type` errors in vulkan_handles.hpp with SDK 1.3.283. #1913

Closed MarkCallow closed 2 months ago

MarkCallow commented 2 months ago

I'm in the process of moving from Vulkan SDK 1.3.243 where everything was working, to 1.3.283. On my first attempt to compile I am getting a large number of the subject errors. E.g,

#if ( VK_USE_64_BIT_PTR_DEFINES == 1 )
  template <>
  struct CppType<VkSurfaceKHR, VK_NULL_HANDLE>   <== Null non-type template argument must be cast to template parameter type 'VkSurfaceKHR_T *'
  {
    using Type = VULKAN_HPP_NAMESPACE::SurfaceKHR;
  };
#endif

I am compiling using Apple clang 15.0.0 (clang-1500.3.9.4) with the language set to c++11. The target is 64-bit. I am not defining any macros before the inclusion of vulkan.hpp.

Is there something I need to change or is this a vulkan.hpp issue?

asuessenbach commented 2 months ago

This construct is in there for quite a while now. Have you changed anything else, besides the vulkan version?

Besides that, it seems to be a clang issue, which makes it a Vulkan-Hpp issue as well. Could you please try to replace that VK_NULL_HANDLE there with nullptr? Or, if that does not help, with an explicit cast as the compiler's error message suggests: (VkSurfaceKHR_T *)VK_NULL_HANDLE?

MarkCallow commented 2 months ago

This construct is in there for quite a while now. Have you changed anything else, besides the vulkan version?

No. Nothing.

I'll try the things you suggest tomorrow.

MarkCallow commented 2 months ago

Could you please try to replace that VK_NULL_HANDLE there with nullptr?

This worked.

The explicit cast worked as well.

asuessenbach commented 2 months ago

This worked.

That's a little strange. According to vulkan_core.h, I would expect VK_NULL_HANDLE defined to be nullptr in your case:

#ifndef VK_USE_64_BIT_PTR_DEFINES
    #if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__) ) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(__powerpc64__) || (defined(__riscv) && __riscv_xlen == 64)
        #define VK_USE_64_BIT_PTR_DEFINES 1
    #else
        #define VK_USE_64_BIT_PTR_DEFINES 0
    #endif
#endif

#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

Could you please check, what VK_NULL_HANDLE and VK_USE_64_BIT_PTR_DEFINES are defined to on your machine?

MarkCallow commented 2 months ago

Could you please check, what VK_NULL_HANDLE and VK_USE_64_BIT_PTR_DEFINES are defined to on your machine?

Ahhh! VK_HULL_HANDLE is defined by

#ifndef VK_NULL_HANDLE
    #define VK_NULL_HANDLE 0
#endif

because VK_DEFINE_NON_DISPATCHABLE_HANDLE is defined. This is defined by SDL2/SDL_vulkan.h in a block guarded by

#ifdef VULKAN_H_

which is defined by vulkan.h. In other words the ordering of includes has suddenly become important. I have to make sure vulkan/vulkan.h is always included before SDL2/SDL_vulkan.h. I have found at least once instance where it is not. Maybe I also need to update my SDL2. I'll look into that.

Thanks for your help @asuessenbach.