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
### Nullability
### Optionality & nullability
* `label: ?[*:0]const u8` fields have a default `null` value added to them.
* 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:
* `next_in_chain: *const ChainedStruct` fields, which enable optional implementation-specific extensions to the WebGPU API, default to `null`.
* 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.
* Fields representing a slice with a `_count` field are nullable pointers defaulting to null and 0 by default.
### Slice helpers

View file

@ -9,20 +9,19 @@ pub const BindGroup = opaque {
pub const Entry = extern struct {
next_in_chain: ?*const ChainedStruct = null,
binding: u32,
buffer: ?*Buffer,
buffer: ?*Buffer = null,
offset: u64 = 0,
size: u64,
sampler: ?*Sampler,
texture_view: ?*TextureView,
sampler: ?*Sampler = null,
texture_view: ?*TextureView = null,
};
pub const Descriptor = extern struct {
next_in_chain: ?*const ChainedStruct = null,
label: ?[*:0]const u8 = null,
layout: *BindGroupLayout,
entry_count: u32,
// TODO: file a bug on Dawn, this is not marked as nullable but in fact is.
entries: ?[*]const Entry,
entry_count: u32 = 0,
entries: ?[*]const Entry = null,
};
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 {
next_in_chain: ?*const ChainedStruct = null,
label: ?[*:0]const u8 = null,
entry_count: u32,
// TODO: file a bug on Dawn, this is not marked as nullable but in fact is.
entries: ?[*]const Entry,
entry_count: u32 = 0,
entries: ?[*]const Entry = null,
};
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 {
next_in_chain: ?*const ChainedStruct = null,
label: ?[*:0]const u8 = null,
layout: ?*PipelineLayout,
layout: ?*PipelineLayout = null,
compute: ProgrammableStageDescriptor,
};

View file

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

View file

@ -45,9 +45,7 @@ pub const Device = opaque {
label: ?[*:0]const u8 = null,
required_features_count: u32 = 0,
required_features: ?[*]const FeatureName = null,
required_limits: ?*const RequiredLimits,
// 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.
required_limits: ?*const RequiredLimits = null,
default_queue: Queue.Descriptor = Queue.Descriptor{},
};

View file

@ -18,10 +18,10 @@ pub const ExternalTexture = opaque {
next_in_chain: ?*const ChainedStruct = null,
label: ?[*:0]const u8 = null,
plane0: *TextureView,
plane1: ?*TextureView,
plane1: ?*TextureView = null,
do_yuv_to_rgb_conversion_only: bool = false,
// 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?
src_transform_function_parameters: [*]const f32,
// 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 {
next_in_chain: ?*const ChainedStruct = null,
label: ?[*:0]const u8 = null,
bind_group_layout_count: u32,
// TODO: file a bug on Dawn, this is not marked as nullable but in fact is.
bind_group_layouts: ?[*]const *BindGroupLayout,
bind_group_layout_count: u32 = 0,
bind_group_layouts: ?[*]const *BindGroupLayout = null,
};
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,
type: QueryType,
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_count: u32 = 0,
};

View file

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

View file

@ -12,12 +12,12 @@ pub const RenderPipeline = opaque {
pub const Descriptor = extern struct {
next_in_chain: ?*const ChainedStruct = null,
label: ?[*:0]const u8 = null,
layout: ?*PipelineLayout,
layout: ?*PipelineLayout = null,
vertex: VertexState,
primitive: PrimitiveState,
depth_stencil: ?*const DepthStencilState,
multisample: MultisampleState,
fragment: ?*const FragmentState,
primitive: PrimitiveState = .{},
depth_stencil: ?*const DepthStencilState = null,
multisample: MultisampleState = .{},
fragment: ?*const FragmentState = null,
};
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,
sample_count: u32 = 1,
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,
view_formats: ?[*]const Format = null,
};
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 {
// TODO: file a bug on Dawn, this is not marked as nullable but in fact is.
next_in_chain: ?*const ChainedStruct = null,
compatible_surface: ?*Surface,
compatible_surface: ?*Surface = null,
power_preference: PowerPreference = .undef,
force_fallback_adapter: bool = false,
};
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,
label: ?[*:0]const u8 = null,
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,
};
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,
label: ?[*:0]const u8 = null,
color_attachment_count: u32,
// TODO: file a bug on Dawn, this is not marked as nullable but in fact is.
color_attachments: ?[*]const RenderPassColorAttachment,
depth_stencil_attachment: ?[*]const RenderPassDepthStencilAttachment,
color_attachment_count: u32 = 0,
color_attachments: ?[*]const RenderPassColorAttachment = null,
depth_stencil_attachment: ?[*]const RenderPassDepthStencilAttachment = null,
occlusion_query_set: ?*QuerySet = null,
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,
};
@ -500,7 +494,7 @@ pub const Origin3D = extern struct {
pub const CompilationMessage = extern struct {
next_in_chain: ?*const ChainedStruct = null,
message: ?[*:0]const u8,
message: ?[*:0]const u8 = null,
type: CompilationMessageType,
line_num: u64,
line_pos: u64,
@ -520,11 +514,11 @@ pub const CopyTextureForBrowserOptions = extern struct {
needs_color_space_conversion: bool = false,
src_alpha_mode: AlphaMode = .unpremultiplied,
// 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?
conversion_matrix: ?*const f32,
conversion_matrix: ?*const f32 = null,
// 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,
internal_usage: bool = false,
};
@ -584,8 +578,7 @@ pub const BlendState = extern struct {
pub const CompilationInfo = extern struct {
next_in_chain: ?*const ChainedStruct = null,
message_count: u32,
// TODO: file a bug on Dawn, this is not marked as nullable but in fact is.
messages: ?[*]const CompilationMessage,
messages: ?[*]const CompilationMessage = null,
};
pub const DepthStencilState = extern struct {
@ -621,13 +614,12 @@ pub const ProgrammableStageDescriptor = extern struct {
module: *ShaderModule,
entry_point: [*:0]const u8,
constant_count: u32 = 0,
// TODO: file a bug on Dawn, this is not marked as nullable but in fact is.
constants: ?[*]const ConstantEntry = null,
};
pub const RenderPassColorAttachment = extern struct {
view: ?*TextureView,
resolve_target: ?*TextureView,
view: ?*TextureView = null,
resolve_target: ?*TextureView = null,
load_op: LoadOp,
store_op: StoreOp,
/// deprecated
@ -654,14 +646,13 @@ pub const VertexBufferLayout = extern struct {
array_stride: u64,
step_mode: VertexStepMode = .vertex,
attribute_count: u32,
// TODO: file a bug on Dawn, this is not marked as nullable but in fact is.
attributes: ?[*]const VertexAttribute,
attributes: ?[*]const VertexAttribute = null,
};
pub const ColorTargetState = extern struct {
next_in_chain: ?*const ChainedStruct = null,
format: Texture.Format,
blend: ?*const BlendState,
blend: ?*const BlendState = null,
write_mask: ColorWriteMaskFlags = ColorWriteMaskFlags.all,
};
@ -670,10 +661,8 @@ pub const VertexState = extern struct {
module: *ShaderModule,
entry_point: [*:0]const u8,
constant_count: u32 = 0,
// TODO: file a bug on Dawn, this is not marked as nullable but in fact is.
constants: ?[*]const ConstantEntry = null,
buffer_count: u32 = 0,
// TODO: file a bug on Dawn, this is not marked as nullable but in fact is.
buffers: ?[*]const VertexBufferLayout = null,
};
@ -682,11 +671,9 @@ pub const FragmentState = extern struct {
module: *ShaderModule,
entry_point: [*:0]const u8,
constant_count: u32 = 0,
// TODO: file a bug on Dawn, this is not marked as nullable but in fact is.
constants: ?[*]const ConstantEntry = null,
target_count: u32,
// TODO: file a bug on Dawn, this is not marked as nullable but in fact is.
targets: ?[*]const ColorTargetState,
targets: ?[*]const ColorTargetState = null,
};
test "BackendType name" {