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 VK_DEFINE_HANDLE(object) typedef struct object##_T*
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
struct object##_T *object;
#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