Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -684,15 +684,25 @@ func (g *Generator) DefaultValue(member ParameterType, isDocString bool) string
// Cases that may have member.Default
case strings.HasPrefix(member.Type, "enum."):
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
// must explicitly initialize it
return ref("WGPUOptionalBool_Undefined")
} else if isDocString {
return "(@ref " + g.CType(member.Type, "") + ")0"
_, name, _ := strings.Cut(member.Type, ".")

// Find the enum type.
idx := slices.IndexFunc(g.Enums, func(e Enum) bool { return e.Name == name })
if idx == -1 {
panic("Invalid enum type: " + name)
}

// If the enum type has an explicit "Undefined" use it, otherwise, use 0.
enumType := g.Enums[idx]
undefIdx := slices.IndexFunc(enumType.Entries, func(entry *EnumEntry) bool { return entry != nil && entry.Name == "undefined" })
if undefIdx == -1 {
if isDocString {
return "(@ref " + g.CType(member.Type, "") + ")0"
} else {
return "_wgpu_ENUM_ZERO_INIT(" + g.CType(member.Type, "") + ")"
}
} else {
Comment thread
kainino0x marked this conversation as resolved.
return "_wgpu_ENUM_ZERO_INIT(" + g.CType(member.Type, "") + ")"
return ref(g.CType(member.Type, "") + "_" + PascalCase("undefined"))
}
} else {
return ref(g.CType(member.Type, "") + "_" + PascalCase(*member.Default))
Expand Down
16 changes: 8 additions & 8 deletions webgpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -2486,7 +2486,7 @@ typedef struct WGPUPrimitiveState {
*/
WGPUPrimitiveTopology topology;
/**
* The `INIT` macro sets this to (@ref WGPUIndexFormat)0.
* The `INIT` macro sets this to @ref WGPUIndexFormat_Undefined.
*/
WGPUIndexFormat stripIndexFormat;
/**
Expand Down Expand Up @@ -2515,7 +2515,7 @@ typedef struct WGPUPrimitiveState {
#define WGPU_PRIMITIVE_STATE_INIT _wgpu_MAKE_INIT_STRUCT(WGPUPrimitiveState, { \
/*.nextInChain=*/NULL _wgpu_COMMA \
/*.topology=*/WGPUPrimitiveTopology_Undefined _wgpu_COMMA \
/*.stripIndexFormat=*/_wgpu_ENUM_ZERO_INIT(WGPUIndexFormat) _wgpu_COMMA \
/*.stripIndexFormat=*/WGPUIndexFormat_Undefined _wgpu_COMMA \
/*.frontFace=*/WGPUFrontFace_Undefined _wgpu_COMMA \
/*.cullMode=*/WGPUCullMode_Undefined _wgpu_COMMA \
/*.unclippedDepth=*/WGPU_FALSE _wgpu_COMMA \
Expand Down Expand Up @@ -3834,7 +3834,7 @@ typedef struct WGPUDepthStencilState {
*/
WGPUOptionalBool depthWriteEnabled;
/**
* The `INIT` macro sets this to (@ref WGPUCompareFunction)0.
* The `INIT` macro sets this to @ref WGPUCompareFunction_Undefined.
*/
WGPUCompareFunction depthCompare;
/**
Expand Down Expand Up @@ -3882,7 +3882,7 @@ typedef struct WGPUDepthStencilState {
/*.nextInChain=*/NULL _wgpu_COMMA \
/*.format=*/WGPUTextureFormat_Undefined _wgpu_COMMA \
/*.depthWriteEnabled=*/WGPUOptionalBool_Undefined _wgpu_COMMA \
/*.depthCompare=*/_wgpu_ENUM_ZERO_INIT(WGPUCompareFunction) _wgpu_COMMA \
/*.depthCompare=*/WGPUCompareFunction_Undefined _wgpu_COMMA \
/*.stencilFront=*/WGPU_STENCIL_FACE_STATE_INIT _wgpu_COMMA \
/*.stencilBack=*/WGPU_STENCIL_FACE_STATE_INIT _wgpu_COMMA \
/*.stencilReadMask=*/0xFFFFFFFF _wgpu_COMMA \
Expand Down Expand Up @@ -4026,11 +4026,11 @@ typedef struct WGPURenderPassColorAttachment {
*/
WGPU_NULLABLE WGPUTextureView resolveTarget;
/**
* The `INIT` macro sets this to (@ref WGPULoadOp)0.
* The `INIT` macro sets this to @ref WGPULoadOp_Undefined.
*/
WGPULoadOp loadOp;
/**
* The `INIT` macro sets this to (@ref WGPUStoreOp)0.
* The `INIT` macro sets this to @ref WGPUStoreOp_Undefined.
*/
WGPUStoreOp storeOp;
/**
Expand All @@ -4047,8 +4047,8 @@ typedef struct WGPURenderPassColorAttachment {
/*.view=*/NULL _wgpu_COMMA \
/*.depthSlice=*/WGPU_DEPTH_SLICE_UNDEFINED _wgpu_COMMA \
/*.resolveTarget=*/NULL _wgpu_COMMA \
/*.loadOp=*/_wgpu_ENUM_ZERO_INIT(WGPULoadOp) _wgpu_COMMA \
/*.storeOp=*/_wgpu_ENUM_ZERO_INIT(WGPUStoreOp) _wgpu_COMMA \
/*.loadOp=*/WGPULoadOp_Undefined _wgpu_COMMA \
/*.storeOp=*/WGPUStoreOp_Undefined _wgpu_COMMA \
/*.clearValue=*/WGPU_COLOR_INIT _wgpu_COMMA \
})

Expand Down
Loading