Vulkan-Hpp icon indicating copy to clipboard operation
Vulkan-Hpp copied to clipboard

MSVC with Ninja fails to compile SharedHandles sample

Open M2-TE opened this issue 2 months ago • 2 comments

When trying to compile the SharedHandle sample with MSVC (2022) using Ninja (-G Ninja), it is not able to construct a shared handle of vk::SurfaceKHR:

https://github.com/KhronosGroup/Vulkan-Hpp/blob/0a7333161db0821452ad950760e48abc35ea0fa3/samples/SharedHandles/SharedHandles.cpp#L89

fails with the following output:

FAILED: [code=2] samples/SharedHandles/CMakeFiles/SharedHandles.dir/SharedHandles.cpp.obj 
C:\PROGRA~1\MICROS~2\2022\ENTERP~1\VC\Tools\MSVC\1444~1.352\bin\Hostx86\x86\cl.exe  /nologo /TP -DVK_NO_PROTOTYPES -DVK_USE_PLATFORM_WIN32_KHR -DVULKAN_HPP_DISPATCH_LOADER_DYNAMIC -DVULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1 -ID:\a\Vulkan-Hpp\Vulkan-Hpp -ID:\a\Vulkan-Hpp\Vulkan-Hpp\Vulkan-Headers\include -ID:\a\Vulkan-Hpp\Vulkan-Hpp\glm -ID:\a\Vulkan-Hpp\Vulkan-Hpp\glfw\include -ID:\a\Vulkan-Hpp\Vulkan-Hpp\glslang\glslang\.. -ID:\a\Vulkan-Hpp\Vulkan-Hpp\build\include -ID:\a\Vulkan-Hpp\Vulkan-Hpp\glslang\SPIRV\.. /DWIN32 /D_WINDOWS /EHsc /Zi /Ob0 /Od /RTC1 -MDd /W4 /WX /showIncludes /Fosamples\SharedHandles\CMakeFiles\SharedHandles.dir\SharedHandles.cpp.obj /Fdsamples\SharedHandles\CMakeFiles\SharedHandles.dir\ /FS -c D:\a\Vulkan-Hpp\Vulkan-Hpp\samples\SharedHandles\SharedHandles.cpp
D:\a\Vulkan-Hpp\Vulkan-Hpp\samples\SharedHandles\SharedHandles.cpp(89): error C2440: 'initializing': cannot convert from 'initializer list' to 'vk::SharedHandle<vk::SurfaceKHR>'
D:\a\Vulkan-Hpp\Vulkan-Hpp\samples\SharedHandles\SharedHandles.cpp(89): note: 'vk::SharedHandle<vk::SurfaceKHR>::SharedHandle': function does not take 2 arguments
D:\a\Vulkan-Hpp\Vulkan-Hpp\vulkan/vulkan_shared.hpp(304): note: could be 'vk::SharedHandle<vk::SurfaceKHR>::SharedHandle(HandleType,vk::detail::ObjectDestroyShared<HandleType>) noexcept'
        with
        [
            HandleType=vk::SurfaceKHR
        ]
D:\a\Vulkan-Hpp\Vulkan-Hpp\vulkan/vulkan_shared.hpp(295): note: or       'vk::SharedHandle<vk::SurfaceKHR>::SharedHandle(HandleType,vk::SharedHandle<vk::Instance>,vk::SharedHandle<vk::NoDestructor>,const Dispatcher &) noexcept'
        with
        [
            HandleType=vk::SurfaceKHR
        ]
D:\a\Vulkan-Hpp\Vulkan-Hpp\vulkan/vulkan_shared.hpp(285): note: or       'vk::SharedHandle<vk::SurfaceKHR>::SharedHandle(HandleType,vk::SharedHandle<vk::Instance>,vk::detail::ObjectDestroyShared<HandleType>) noexcept'
        with
        [
            HandleType=vk::SurfaceKHR
        ]
D:\a\Vulkan-Hpp\Vulkan-Hpp\samples\SharedHandles\SharedHandles.cpp(89): note: while trying to match the argument list '(VkSurfaceKHR, vk::SharedInstance)'

M2-TE avatar Oct 27 '25 15:10 M2-TE

Could you please check what you get when you change that line 89 in samples/SharedHandles/SharedHandles.cpp to vk::SharedSurfaceKHR sharedSurface{ static_cast<vk::SurfaceKHR>(surface), instance };

asuessenbach avatar Oct 27 '25 16:10 asuessenbach

That fixes the issue. Similar error popped up in the UniqueHandleDefaultArguments test, requiring the same explicit cast.

Actually, this is because the test was run on 32-bit Windows. As the test claims at the top: https://github.com/KhronosGroup/Vulkan-Hpp/blob/0a7333161db0821452ad950760e48abc35ea0fa3/tests/UniqueHandleDefaultArguments/UniqueHandleDefaultArguments.cpp#L17

Interestingly, it compiles on 32-bit Windows just fine when using the default MSBuild instead of Ninja.

The original issue is still relevant though, as I did not change how samples are compiled at all. It is likely that, without Ninja, the final compiler commands were different. Otherwise, the current CI should have caught this long ago.

M2-TE avatar Oct 27 '25 21:10 M2-TE