www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - BetterC issues with ErupteD Vulkan binding typedef handles

reply ParticlePeter <ParticlePeter gmx.de> writes:
Hello,

I am experimenting with betterC and Vulkan through Erupted [0] 
binding, but unfortunately I find myself hunting down these kind 
of errors:
  ..\ErupteD\source\erupted\types.d-mixin-77(77,1): Error: 
`TypeInfo` cannot be used with -betterC

The issue is with Vulkan type handles. One such error occurs when 
a function's parameter list contains an optional slice of such 
handles, e.g.:

void queueSubmit(
     VkQueue                queue,
     VkCommandBuffer[]      command_buffers,
     VkSemaphore[]          wait_semaphores         = [],  // 
error: TypeInfo required
     VkPipelineStageFlags[] wait_dest_stage_masks   = [],  // ok, 
not a handle
     VkSemaphore[]          signal_semaphores       = []   // 
error: TypeInfo required
)  { .. }


A possible workaround which I found is:
     VkSemaphore[] wait_semaphores = ( const VkSemaphore[] ).init,

but this feels more like fighting a symptom instead of getting 
rid of the cause.
I am wondering if there is a better way to translate these C 
typedefs to D:

// from vulkan_core.h [1]
// ...

#define
object;

#if !defined(VK_DEFINE_NON_DISPATCHABLE_HANDLE)
#if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) 
&& !defined(__ILP32__) ) || defined(_M_X64) || defined(__ia64) || 
defined (_M_IA64) || defined(__aarch64__) || 
defined(__powerpc64__)
         #define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef 

#else
         #define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef 
uint64_t object;
#endif
#endif

// ...
VK_DEFINE_HANDLE(VkQueue)
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkSemaphore)
// ...


Correspondingly to the C typedefs:

// from erupted/types.d [2]
// ...

enum VK_DEFINE_HANDLE( string name ) = "struct " ~ name ~ 
"_handle; alias " ~ name ~ " = " ~ name ~ "_handle*;";

version( X86_64 ) {
     alias VK_DEFINE_NON_DISPATCHABLE_HANDLE( string name ) = 
VK_DEFINE_HANDLE!name;
     enum VK_NULL_ND_HANDLE = null;
} else {
     enum VK_DEFINE_NON_DISPATCHABLE_HANDLE( string name ) = 
"alias " ~ name ~ " = ulong;";
     enum VK_NULL_ND_HANDLE = 0uL;
}

// ...
mixin( VK_DEFINE_HANDLE!q{VkQueue} );
mixin( VK_DEFINE_NON_DISPATCHABLE_HANDLE!q{VkSemaphore} );
// ...


I am running building for x64, would anyone know a smoother 
betterC approach to these typedefs?


[0] https://github.com/ParticlePeter/ErupteD
[1] 
https://github.com/KhronosGroup/Vulkan-Headers/blob/master/include/vulkan/vulkan_core.h
[2] 
https://github.com/ParticlePeter/ErupteD/blob/master/source/erupted/types.d
Dec 20 2020
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Sunday, 20 December 2020 at 15:45:59 UTC, ParticlePeter wrote:
     VkSemaphore[]          wait_semaphores         = [],  // 
 error: TypeInfo required
does it still error if you just use = null? they work the same way but might avoid the annoying error.
Dec 20 2020
parent reply ParticlePeter <ParticlePeter gmx.de> writes:
On Sunday, 20 December 2020 at 15:52:39 UTC, Adam D. Ruppe wrote:
 On Sunday, 20 December 2020 at 15:45:59 UTC, ParticlePeter 
 wrote:
     VkSemaphore[]          wait_semaphores         = [],  // 
 error: TypeInfo required
does it still error if you just use = null? they work the same way but might avoid the annoying error.
Wow, it does, that was unexpected and unexpectedly hassle free, thanks a lot :-)
Dec 20 2020
parent ParticlePeter <ParticlePeter gmx.de> writes:
[snip]

Forgot to add another question. The mentioned error message is 
not too helpful in locating the real offended code. Is there a 
way to get more information or additional hints about the actual 
cause of the problem?
Dec 20 2020