From 4dee13795c3a64ab8e32ab8b5dc3dced652800e8 Mon Sep 17 00:00:00 2001 From: Kai Ninomiya Date: Wed, 27 Nov 2024 18:08:10 -0800 Subject: [PATCH] fix C++ build --- gen/cheader.tmpl | 2 ++ gen/gen.go | 2 +- webgpu.h | 10 ++++++---- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/gen/cheader.tmpl b/gen/cheader.tmpl index 898dacb5..0aa67fcc 100644 --- a/gen/cheader.tmpl +++ b/gen/cheader.tmpl @@ -70,6 +70,7 @@ #define _wgpu_COMMA , #if defined(__cplusplus) # define _wgpu_ENUM_ZERO_INIT(type) type(0) +# define _wgpu_STRUCT_ZERO_INIT {} # if __cplusplus >= 201103L # define _wgpu_MAKE_INIT_STRUCT(type, value) (type value) # else @@ -77,6 +78,7 @@ # endif #else # define _wgpu_ENUM_ZERO_INIT(type) (type)0 +# define _wgpu_STRUCT_ZERO_INIT {0} # if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L # define _wgpu_MAKE_INIT_STRUCT(type, value) ((type) value) # else diff --git a/gen/gen.go b/gen/gen.go index 1e75c7e6..2e0332c3 100644 --- a/gen/gen.go +++ b/gen/gen.go @@ -570,7 +570,7 @@ func (g *Generator) DefaultValue(member ParameterType, isDocString bool) string if isDocString { return "zero (so the entry is `BindingNotUsed`)" } else { - return literal("{0}") + return literal("_wgpu_STRUCT_ZERO_INIT") } } else { panic("unknown default for struct type") diff --git a/webgpu.h b/webgpu.h index 25980580..161fe908 100644 --- a/webgpu.h +++ b/webgpu.h @@ -59,6 +59,7 @@ #define _wgpu_COMMA , #if defined(__cplusplus) # define _wgpu_ENUM_ZERO_INIT(type) type(0) +# define _wgpu_STRUCT_ZERO_INIT {} # if __cplusplus >= 201103L # define _wgpu_MAKE_INIT_STRUCT(type, value) (type value) # else @@ -66,6 +67,7 @@ # endif #else # define _wgpu_ENUM_ZERO_INIT(type) (type)0 +# define _wgpu_STRUCT_ZERO_INIT {0} # if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L # define _wgpu_MAKE_INIT_STRUCT(type, value) ((type) value) # else @@ -3445,10 +3447,10 @@ typedef struct WGPUBindGroupLayoutEntry { /*.nextInChain=*/NULL _wgpu_COMMA \ /*.binding=*/0 _wgpu_COMMA \ /*.visibility=*/WGPUShaderStage_None _wgpu_COMMA \ - /*.buffer=*/{0} _wgpu_COMMA \ - /*.sampler=*/{0} _wgpu_COMMA \ - /*.texture=*/{0} _wgpu_COMMA \ - /*.storageTexture=*/{0} _wgpu_COMMA \ + /*.buffer=*/_wgpu_STRUCT_ZERO_INIT _wgpu_COMMA \ + /*.sampler=*/_wgpu_STRUCT_ZERO_INIT _wgpu_COMMA \ + /*.texture=*/_wgpu_STRUCT_ZERO_INIT _wgpu_COMMA \ + /*.storageTexture=*/_wgpu_STRUCT_ZERO_INIT _wgpu_COMMA \ }) /**