gpu: adopt new dawn.json policy for optionality of slice fields, default zero values

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2022-08-11 03:44:34 -07:00 committed by Stephen Gutekanst
parent 2b354f9226
commit 726bdf3fba
13 changed files with 40 additions and 63 deletions

View file

@ -140,11 +140,10 @@ We make the following quality of life improvements.
TODO: explain it TODO: explain it
### Nullability ### Optionality & nullability
* `label: ?[*:0]const u8` fields have a default `null` value added to them. * Optional values default to their zero value (either `null` or a struct constructor `.{}`) when specified as `optional` in `dawn.json`. This means things like `label`, `next_in_chain`, etc. do not need to be specified.
* Where a struct has a slice `_count` field, with an optional pointer, if the `_count` field defaults to zero we also enforce the optional pointer defaults to `null`. Specifically we do this for: * Fields representing a slice with a `_count` field are nullable pointers defaulting to null and 0 by default.
* `next_in_chain: *const ChainedStruct` fields, which enable optional implementation-specific extensions to the WebGPU API, default to `null`.
### Slice helpers ### Slice helpers

View file

@ -9,20 +9,19 @@ pub const BindGroup = opaque {
pub const Entry = extern struct { pub const Entry = extern struct {
next_in_chain: ?*const ChainedStruct = null, next_in_chain: ?*const ChainedStruct = null,
binding: u32, binding: u32,
buffer: ?*Buffer, buffer: ?*Buffer = null,
offset: u64 = 0, offset: u64 = 0,
size: u64, size: u64,
sampler: ?*Sampler, sampler: ?*Sampler = null,
texture_view: ?*TextureView, texture_view: ?*TextureView = null,
}; };
pub const Descriptor = extern struct { pub const Descriptor = extern struct {
next_in_chain: ?*const ChainedStruct = null, next_in_chain: ?*const ChainedStruct = null,
label: ?[*:0]const u8 = null, label: ?[*:0]const u8 = null,
layout: *BindGroupLayout, layout: *BindGroupLayout,
entry_count: u32, entry_count: u32 = 0,
// TODO: file a bug on Dawn, this is not marked as nullable but in fact is. entries: ?[*]const Entry = null,
entries: ?[*]const Entry,
}; };
pub inline fn setLabel(bind_group: *BindGroup, label: [*:0]const u8) void { pub inline fn setLabel(bind_group: *BindGroup, label: [*:0]const u8) void {

View file

@ -20,9 +20,8 @@ pub const BindGroupLayout = opaque {
pub const Descriptor = extern struct { pub const Descriptor = extern struct {
next_in_chain: ?*const ChainedStruct = null, next_in_chain: ?*const ChainedStruct = null,
label: ?[*:0]const u8 = null, label: ?[*:0]const u8 = null,
entry_count: u32, entry_count: u32 = 0,
// TODO: file a bug on Dawn, this is not marked as nullable but in fact is. entries: ?[*]const Entry = null,
entries: ?[*]const Entry,
}; };
pub inline fn setLabel(bind_group_layout: *BindGroupLayout, label: [*:0]const u8) void { pub inline fn setLabel(bind_group_layout: *BindGroupLayout, label: [*:0]const u8) void {

View file

@ -8,7 +8,7 @@ pub const ComputePipeline = opaque {
pub const Descriptor = extern struct { pub const Descriptor = extern struct {
next_in_chain: ?*const ChainedStruct = null, next_in_chain: ?*const ChainedStruct = null,
label: ?[*:0]const u8 = null, label: ?[*:0]const u8 = null,
layout: ?*PipelineLayout, layout: ?*PipelineLayout = null,
compute: ProgrammableStageDescriptor, compute: ProgrammableStageDescriptor,
}; };

View file

@ -17,9 +17,8 @@ pub const EncoderInternalUsageDescriptor = extern struct {
/// TODO: Can be chained in gpu.Instance.Descriptor /// TODO: Can be chained in gpu.Instance.Descriptor
pub const InstanceDescriptor = extern struct { pub const InstanceDescriptor = extern struct {
chain: ChainedStruct, chain: ChainedStruct,
additional_runtime_search_paths_count: u32, additional_runtime_search_paths_count: u32 = 0,
// TODO: file a bug on Dawn, this is not marked as nullable but in fact is. additional_runtime_search_paths: ?[*]const u8 = null,
additional_runtime_search_paths: ?[*]const u8,
}; };
/// TODO: Can be chained in gpu.Texture.Descriptor /// TODO: Can be chained in gpu.Texture.Descriptor

View file

@ -45,9 +45,7 @@ pub const Device = opaque {
label: ?[*:0]const u8 = null, label: ?[*:0]const u8 = null,
required_features_count: u32 = 0, required_features_count: u32 = 0,
required_features: ?[*]const FeatureName = null, required_features: ?[*]const FeatureName = null,
required_limits: ?*const RequiredLimits, required_limits: ?*const RequiredLimits = null,
// TODO: file issue on Dawn, dawn.json doesn't communicate that a zero value here is the
// acceptable default value due to internal nullability of Queue.Descriptor.
default_queue: Queue.Descriptor = Queue.Descriptor{}, default_queue: Queue.Descriptor = Queue.Descriptor{},
}; };

View file

@ -18,10 +18,10 @@ pub const ExternalTexture = opaque {
next_in_chain: ?*const ChainedStruct = null, next_in_chain: ?*const ChainedStruct = null,
label: ?[*:0]const u8 = null, label: ?[*:0]const u8 = null,
plane0: *TextureView, plane0: *TextureView,
plane1: ?*TextureView, plane1: ?*TextureView = null,
do_yuv_to_rgb_conversion_only: bool = false, do_yuv_to_rgb_conversion_only: bool = false,
// TODO: dawn.json says length 12, does it mean array length? // TODO: dawn.json says length 12, does it mean array length?
yuv_to_rgb_conversion_matrix: ?[*]const f32, yuv_to_rgb_conversion_matrix: ?[*]const f32 = null,
// TODO: dawn.json says length 7, does it mean array length? // TODO: dawn.json says length 7, does it mean array length?
src_transform_function_parameters: [*]const f32, src_transform_function_parameters: [*]const f32,
// TODO: dawn.json says length 7, does it mean array length? // TODO: dawn.json says length 7, does it mean array length?

View file

@ -6,9 +6,8 @@ pub const PipelineLayout = opaque {
pub const Descriptor = extern struct { pub const Descriptor = extern struct {
next_in_chain: ?*const ChainedStruct = null, next_in_chain: ?*const ChainedStruct = null,
label: ?[*:0]const u8 = null, label: ?[*:0]const u8 = null,
bind_group_layout_count: u32, bind_group_layout_count: u32 = 0,
// TODO: file a bug on Dawn, this is not marked as nullable but in fact is. bind_group_layouts: ?[*]const *BindGroupLayout = null,
bind_group_layouts: ?[*]const *BindGroupLayout,
}; };
pub inline fn setLabel(pipeline_layout: *PipelineLayout, label: [*:0]const u8) void { pub inline fn setLabel(pipeline_layout: *PipelineLayout, label: [*:0]const u8) void {

View file

@ -9,7 +9,6 @@ pub const QuerySet = opaque {
label: ?[*:0]const u8 = null, label: ?[*:0]const u8 = null,
type: QueryType, type: QueryType,
count: u32, count: u32,
// TODO: file a bug on Dawn, this is not marked as nullable but in fact is.
pipeline_statistics: ?[*]const PipelineStatisticName = null, pipeline_statistics: ?[*]const PipelineStatisticName = null,
pipeline_statistics_count: u32 = 0, pipeline_statistics_count: u32 = 0,
}; };

View file

@ -11,9 +11,8 @@ pub const RenderBundleEncoder = opaque {
pub const Descriptor = extern struct { pub const Descriptor = extern struct {
next_in_chain: ?*const ChainedStruct = null, next_in_chain: ?*const ChainedStruct = null,
label: ?[*:0]const u8 = null, label: ?[*:0]const u8 = null,
color_formats_count: u32, color_formats_count: u32 = 0,
// TODO: file a bug on Dawn, this is not marked as nullable but in fact is. color_formats: ?[*]const Texture.Format = null,
color_formats: ?[*]const Texture.Format,
depth_stencil_format: Texture.Format = .undef, depth_stencil_format: Texture.Format = .undef,
sample_count: u32 = 1, sample_count: u32 = 1,
depth_read_only: bool = false, depth_read_only: bool = false,

View file

@ -12,12 +12,12 @@ pub const RenderPipeline = opaque {
pub const Descriptor = extern struct { pub const Descriptor = extern struct {
next_in_chain: ?*const ChainedStruct = null, next_in_chain: ?*const ChainedStruct = null,
label: ?[*:0]const u8 = null, label: ?[*:0]const u8 = null,
layout: ?*PipelineLayout, layout: ?*PipelineLayout = null,
vertex: VertexState, vertex: VertexState,
primitive: PrimitiveState, primitive: PrimitiveState = .{},
depth_stencil: ?*const DepthStencilState, depth_stencil: ?*const DepthStencilState = null,
multisample: MultisampleState, multisample: MultisampleState = .{},
fragment: ?*const FragmentState, fragment: ?*const FragmentState = null,
}; };
pub inline fn getBindGroupLayout(render_pipeline: *RenderPipeline, group_index: u32) *BindGroupLayout { pub inline fn getBindGroupLayout(render_pipeline: *RenderPipeline, group_index: u32) *BindGroupLayout {

View file

@ -183,8 +183,7 @@ pub const Texture = opaque {
mip_level_count: u32 = 1, mip_level_count: u32 = 1,
sample_count: u32 = 1, sample_count: u32 = 1,
view_format_count: u32 = 0, view_format_count: u32 = 0,
// TODO: file a bug on Dawn, this is not marked as nullable but in fact is. view_formats: ?[*]const Format = null,
view_formats: ?[*]const Format,
}; };
pub inline fn createView(texture: *Texture, descriptor: ?*const TextureView.Descriptor) *TextureView { pub inline fn createView(texture: *Texture, descriptor: ?*const TextureView.Descriptor) *TextureView {

View file

@ -42,33 +42,27 @@ pub const RenderPassTimestampWrite = extern struct {
}; };
pub const RequestAdapterOptions = extern struct { pub const RequestAdapterOptions = extern struct {
// TODO: file a bug on Dawn, this is not marked as nullable but in fact is.
next_in_chain: ?*const ChainedStruct = null, next_in_chain: ?*const ChainedStruct = null,
compatible_surface: ?*Surface, compatible_surface: ?*Surface = null,
power_preference: PowerPreference = .undef, power_preference: PowerPreference = .undef,
force_fallback_adapter: bool = false, force_fallback_adapter: bool = false,
}; };
pub const ComputePassDescriptor = extern struct { pub const ComputePassDescriptor = extern struct {
// TODO: file a bug on Dawn, this is not marked as nullable but in fact is.
next_in_chain: ?*const ChainedStruct = null, next_in_chain: ?*const ChainedStruct = null,
label: ?[*:0]const u8 = null, label: ?[*:0]const u8 = null,
timestamp_write_count: u32 = 0, timestamp_write_count: u32 = 0,
// TODO: file a bug on Dawn, this is not marked as nullable but in fact is.
timestamp_writes: ?[*]const ComputePassTimestampWrite = null, timestamp_writes: ?[*]const ComputePassTimestampWrite = null,
}; };
pub const RenderPassDescriptor = extern struct { pub const RenderPassDescriptor = extern struct {
// TODO: file a bug on Dawn, this is not marked as nullable but in fact is.
next_in_chain: ?*const ChainedStruct = null, next_in_chain: ?*const ChainedStruct = null,
label: ?[*:0]const u8 = null, label: ?[*:0]const u8 = null,
color_attachment_count: u32, color_attachment_count: u32 = 0,
// TODO: file a bug on Dawn, this is not marked as nullable but in fact is. color_attachments: ?[*]const RenderPassColorAttachment = null,
color_attachments: ?[*]const RenderPassColorAttachment, depth_stencil_attachment: ?[*]const RenderPassDepthStencilAttachment = null,
depth_stencil_attachment: ?[*]const RenderPassDepthStencilAttachment,
occlusion_query_set: ?*QuerySet = null, occlusion_query_set: ?*QuerySet = null,
timestamp_write_count: u32 = 0, timestamp_write_count: u32 = 0,
// TODO: file a bug on Dawn, this is not marked as nullable but in fact is.
timestamp_writes: ?[*]const RenderPassTimestampWrite = null, timestamp_writes: ?[*]const RenderPassTimestampWrite = null,
}; };
@ -500,7 +494,7 @@ pub const Origin3D = extern struct {
pub const CompilationMessage = extern struct { pub const CompilationMessage = extern struct {
next_in_chain: ?*const ChainedStruct = null, next_in_chain: ?*const ChainedStruct = null,
message: ?[*:0]const u8, message: ?[*:0]const u8 = null,
type: CompilationMessageType, type: CompilationMessageType,
line_num: u64, line_num: u64,
line_pos: u64, line_pos: u64,
@ -520,11 +514,11 @@ pub const CopyTextureForBrowserOptions = extern struct {
needs_color_space_conversion: bool = false, needs_color_space_conversion: bool = false,
src_alpha_mode: AlphaMode = .unpremultiplied, src_alpha_mode: AlphaMode = .unpremultiplied,
// TODO: dawn.json says length 7, does it mean array length? // TODO: dawn.json says length 7, does it mean array length?
src_transfer_function_parameters: ?*const f32, src_transfer_function_parameters: ?*const f32 = null,
// TODO: dawn.json says length 9, does it mean array length? // TODO: dawn.json says length 9, does it mean array length?
conversion_matrix: ?*const f32, conversion_matrix: ?*const f32 = null,
// TODO: dawn.json says length 7, does it mean array length? // TODO: dawn.json says length 7, does it mean array length?
dst_transfer_function_parameters: ?*const f32, dst_transfer_function_parameters: ?*const f32 = null,
dst_alpha_mode: AlphaMode = .unpremultiplied, dst_alpha_mode: AlphaMode = .unpremultiplied,
internal_usage: bool = false, internal_usage: bool = false,
}; };
@ -584,8 +578,7 @@ pub const BlendState = extern struct {
pub const CompilationInfo = extern struct { pub const CompilationInfo = extern struct {
next_in_chain: ?*const ChainedStruct = null, next_in_chain: ?*const ChainedStruct = null,
message_count: u32, message_count: u32,
// TODO: file a bug on Dawn, this is not marked as nullable but in fact is. messages: ?[*]const CompilationMessage = null,
messages: ?[*]const CompilationMessage,
}; };
pub const DepthStencilState = extern struct { pub const DepthStencilState = extern struct {
@ -621,13 +614,12 @@ pub const ProgrammableStageDescriptor = extern struct {
module: *ShaderModule, module: *ShaderModule,
entry_point: [*:0]const u8, entry_point: [*:0]const u8,
constant_count: u32 = 0, constant_count: u32 = 0,
// TODO: file a bug on Dawn, this is not marked as nullable but in fact is.
constants: ?[*]const ConstantEntry = null, constants: ?[*]const ConstantEntry = null,
}; };
pub const RenderPassColorAttachment = extern struct { pub const RenderPassColorAttachment = extern struct {
view: ?*TextureView, view: ?*TextureView = null,
resolve_target: ?*TextureView, resolve_target: ?*TextureView = null,
load_op: LoadOp, load_op: LoadOp,
store_op: StoreOp, store_op: StoreOp,
/// deprecated /// deprecated
@ -654,14 +646,13 @@ pub const VertexBufferLayout = extern struct {
array_stride: u64, array_stride: u64,
step_mode: VertexStepMode = .vertex, step_mode: VertexStepMode = .vertex,
attribute_count: u32, attribute_count: u32,
// TODO: file a bug on Dawn, this is not marked as nullable but in fact is. attributes: ?[*]const VertexAttribute = null,
attributes: ?[*]const VertexAttribute,
}; };
pub const ColorTargetState = extern struct { pub const ColorTargetState = extern struct {
next_in_chain: ?*const ChainedStruct = null, next_in_chain: ?*const ChainedStruct = null,
format: Texture.Format, format: Texture.Format,
blend: ?*const BlendState, blend: ?*const BlendState = null,
write_mask: ColorWriteMaskFlags = ColorWriteMaskFlags.all, write_mask: ColorWriteMaskFlags = ColorWriteMaskFlags.all,
}; };
@ -670,10 +661,8 @@ pub const VertexState = extern struct {
module: *ShaderModule, module: *ShaderModule,
entry_point: [*:0]const u8, entry_point: [*:0]const u8,
constant_count: u32 = 0, constant_count: u32 = 0,
// TODO: file a bug on Dawn, this is not marked as nullable but in fact is.
constants: ?[*]const ConstantEntry = null, constants: ?[*]const ConstantEntry = null,
buffer_count: u32 = 0, buffer_count: u32 = 0,
// TODO: file a bug on Dawn, this is not marked as nullable but in fact is.
buffers: ?[*]const VertexBufferLayout = null, buffers: ?[*]const VertexBufferLayout = null,
}; };
@ -682,11 +671,9 @@ pub const FragmentState = extern struct {
module: *ShaderModule, module: *ShaderModule,
entry_point: [*:0]const u8, entry_point: [*:0]const u8,
constant_count: u32 = 0, constant_count: u32 = 0,
// TODO: file a bug on Dawn, this is not marked as nullable but in fact is.
constants: ?[*]const ConstantEntry = null, constants: ?[*]const ConstantEntry = null,
target_count: u32, target_count: u32,
// TODO: file a bug on Dawn, this is not marked as nullable but in fact is. targets: ?[*]const ColorTargetState = null,
targets: ?[*]const ColorTargetState,
}; };
test "BackendType name" { test "BackendType name" {