diff --git a/gen/gen.go b/gen/gen.go index 0977c9eb..1ce0c62e 100644 --- a/gen/gen.go +++ b/gen/gen.go @@ -492,11 +492,17 @@ func (g *Generator) DefaultValue(member ParameterType, isDocString bool) string return s } } + switch { case member.Pointer != "": + if member.Default != nil { + panic("pointer type should not have a default") + } return literal("NULL") + + // Cases that may have member.Default case strings.HasPrefix(member.Type, "enum."): - if member.Default == "" { + if member.Default == nil { if member.Type == "enum.optional_bool" { // This Undefined is a special one that is not the zero-value, so that // a stdbool.h bool cast correctly to WGPUOptionalBool; this means we @@ -508,72 +514,75 @@ func (g *Generator) DefaultValue(member ParameterType, isDocString bool) string return "_wgpu_ENUM_ZERO_INIT(WGPU" + PascalCase(strings.TrimPrefix(member.Type, "enum.")) + ")" } } else { - return ref("WGPU" + PascalCase(strings.TrimPrefix(member.Type, "enum.")) + "_" + PascalCase(member.Default)) + return ref("WGPU" + PascalCase(strings.TrimPrefix(member.Type, "enum.")) + "_" + PascalCase(*member.Default)) } case strings.HasPrefix(member.Type, "bitflag."): - if member.Default == "" { + if member.Default == nil { return ref("WGPU" + PascalCase(strings.TrimPrefix(member.Type, "bitflag.")) + "_None") } else { - return ref("WGPU" + PascalCase(strings.TrimPrefix(member.Type, "bitflag.")) + "_" + PascalCase(member.Default)) - } - case strings.HasPrefix(member.Type, "struct."): - if member.Optional { - return literal("NULL") - } else { - typ := strings.TrimPrefix(member.Type, "struct.") - return ref("WGPU_" + ConstantCase(typ) + "_INIT") + return ref("WGPU" + PascalCase(strings.TrimPrefix(member.Type, "bitflag.")) + "_" + PascalCase(*member.Default)) } - case strings.HasPrefix(member.Type, "callback."): - typ := strings.TrimPrefix(member.Type, "callback.") - return ref("WGPU_" + ConstantCase(typ) + "_CALLBACK_INFO_INIT") - case strings.HasPrefix(member.Type, "object."): - return literal("NULL") - case strings.HasPrefix(member.Type, "array<"): - return literal("NULL") - case member.Type == "out_string", member.Type == "string_with_default_empty", member.Type == "nullable_string": - return ref("WGPU_STRING_VIEW_INIT") case member.Type == "uint16", member.Type == "uint32", member.Type == "uint64", member.Type == "usize", member.Type == "int32": - if member.Default == "" { + if member.Default == nil { return literal("0") - } else if strings.HasPrefix(member.Default, "constant.") { - return ref("WGPU_" + ConstantCase(strings.TrimPrefix(member.Default, "constant."))) + } else if strings.HasPrefix(*member.Default, "constant.") { + return ref("WGPU_" + ConstantCase(strings.TrimPrefix(*member.Default, "constant."))) } else { - return literal(member.Default) + return literal(*member.Default) } case member.Type == "float32": - if member.Default == "" { + if member.Default == nil { return literal("0.f") - } else if strings.HasPrefix(member.Default, "constant.") { - return ref("WGPU_" + ConstantCase(strings.TrimPrefix(member.Default, "constant."))) - } else if strings.Contains(member.Default, ".") { - return literal(member.Default + "f") + } else if strings.HasPrefix(*member.Default, "constant.") { + return ref("WGPU_" + ConstantCase(strings.TrimPrefix(*member.Default, "constant."))) + } else if strings.Contains(*member.Default, ".") { + return literal(*member.Default + "f") } else { - return literal(member.Default + ".f") + return literal(*member.Default + ".f") } case member.Type == "float64": - if member.Default == "" { + if member.Default == nil { return literal("0.") - } else if strings.HasPrefix(member.Default, "constant.") { - return ref("WGPU_" + ConstantCase(strings.TrimPrefix(member.Default, "constant."))) + } else if strings.HasPrefix(*member.Default, "constant.") { + return ref("WGPU_" + ConstantCase(strings.TrimPrefix(*member.Default, "constant."))) } else { - return literal(member.Default) + return literal(*member.Default) } case member.Type == "bool": - if member.Default == "" { + if member.Default == nil { return literal("0") - } else if strings.HasPrefix(member.Default, "constant.") { - return ref("WGPU_" + ConstantCase(strings.TrimPrefix(member.Default, "constant."))) - } else if member.Default == "true" { + } else if strings.HasPrefix(*member.Default, "constant.") { + return ref("WGPU_" + ConstantCase(strings.TrimPrefix(*member.Default, "constant."))) + } else if *member.Default == "true" { return literal("1") - } else if member.Default == "false" { + } else if *member.Default == "false" { return literal("0") } else { - return member.Default + return *member.Default } + case member.Default != nil: + panic(fmt.Errorf("type %s should not have a default", member.Type)) + + // Cases that should not have member.Default + case strings.HasPrefix(member.Type, "struct."): + if member.Optional { + return literal("NULL") + } else { + typ := strings.TrimPrefix(member.Type, "struct.") + return ref("WGPU_" + ConstantCase(typ) + "_INIT") + } + case strings.HasPrefix(member.Type, "callback."): + typ := strings.TrimPrefix(member.Type, "callback.") + return ref("WGPU_" + ConstantCase(typ) + "_CALLBACK_INFO_INIT") + case strings.HasPrefix(member.Type, "object."): + return literal("NULL") + case strings.HasPrefix(member.Type, "array<"): + return literal("NULL") + case member.Type == "out_string", member.Type == "string_with_default_empty", member.Type == "nullable_string": + return ref("WGPU_STRING_VIEW_INIT") case member.Type == "c_void": return literal("NULL") default: panic("invalid prefix: " + member.Type + " in member " + member.Name) - return "" } } diff --git a/gen/yml.go b/gen/yml.go index e9801e3b..7daa5d34 100644 --- a/gen/yml.go +++ b/gen/yml.go @@ -74,7 +74,7 @@ type ParameterType struct { Pointer PointerType `yaml:"pointer"` Optional bool `yaml:"optional"` Namespace string `yaml:"namespace"` - Default string `yaml:"default"` + Default *string `yaml:"default"` } type Callback struct { diff --git a/webgpu.h b/webgpu.h index 7e3d7ea5..390e4e96 100644 --- a/webgpu.h +++ b/webgpu.h @@ -1667,7 +1667,7 @@ typedef struct WGPUBlendComponent { typedef struct WGPUBufferBindingLayout { WGPUChainedStruct const * nextInChain; /** - * The `INIT` macro sets this to @ref WGPUBufferBindingType_Uniform. + * The `INIT` macro sets this to @ref WGPUBufferBindingType_BindingNotUsed. */ WGPUBufferBindingType type; /** @@ -1685,7 +1685,7 @@ typedef struct WGPUBufferBindingLayout { */ #define WGPU_BUFFER_BINDING_LAYOUT_INIT _wgpu_MAKE_INIT_STRUCT(WGPUBufferBindingLayout, { \ /*.nextInChain=*/NULL _wgpu_COMMA \ - /*.type=*/WGPUBufferBindingType_Uniform _wgpu_COMMA \ + /*.type=*/WGPUBufferBindingType_BindingNotUsed _wgpu_COMMA \ /*.hasDynamicOffset=*/0 _wgpu_COMMA \ /*.minBindingSize=*/0 _wgpu_COMMA \ }) diff --git a/webgpu.yml b/webgpu.yml index 88d88073..162ea6bf 100644 --- a/webgpu.yml +++ b/webgpu.yml @@ -1618,22 +1618,18 @@ structs: doc: | TODO type: struct.buffer_binding_layout - default: constant.binding_not_used - name: sampler doc: | TODO type: struct.sampler_binding_layout - default: constant.binding_not_used - name: texture doc: | TODO type: struct.texture_binding_layout - default: constant.binding_not_used - name: storage_texture doc: | TODO type: struct.storage_texture_binding_layout - default: constant.binding_not_used - name: blend_component doc: | TODO @@ -1676,7 +1672,7 @@ structs: doc: | TODO type: enum.buffer_binding_type - default: uniform + default: binding_not_used - name: has_dynamic_offset doc: | TODO