ClangSharp icon indicating copy to clipboard operation
ClangSharp copied to clipboard

ClangSharpPInvokeGenerator does not correctly generate VK_NULL_HANDLE

Open Exanite opened this issue 7 months ago • 0 comments

This issue was discussed in the Silk.NET Discord: https://discord.com/channels/521092042781229087/1376331581198827520/1376639064366645450

The Silk.NET generator uses ClangSharpPInvokeGenerator to generate Vulkan bindings, however, VK_NULL_HANDLE from Vulkan is generated as the following:

[NativeTypeName("#define VK_NULL_HANDLE nullptr")]
    public static ref readonly  null  VK_NULL_HANDLE {
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    get { null
} }

This was generated with Silk specific modifiers disabled, so the output here should all be from ClangSharpPInvokeGenerator.

VK_NULL_HANDLE is defined here: https://github.com/KhronosGroup/Vulkan-Headers/blob/75ad707a587e1469fb53a901b9b68fe9f6fbc11f/include/vulkan/vulkan_core.h#L38-L51

#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

Exanite avatar May 26 '25 19:05 Exanite