gpu: undef -> undefined (no longer a reserved keyword)

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2023-06-30 19:06:10 -07:00
parent a6fa17e12a
commit 709d2f9875
4 changed files with 46 additions and 50 deletions

View file

@ -217,7 +217,6 @@ The rules for translating `webgpu.h` are as follows:
* `error` -> `err` * `error` -> `err`
* `type` -> `typ` * `type` -> `typ`
* `opaque` -> `opaq` * `opaque` -> `opaq`
* Undefined in Zig commonly means _undefined memory_. WebGPU however uses _undefined_ as terminology to indicate something was not _specified_, as the optional _none value_, which Zig represents as _null_. Since _null_ is a reserved keyword in Zig, we rename all WebGPU _undefined_ terminology to "_unspecified_" instead.
* Constant names map using a few simple rules, but it's easiest to describe them with some concrete examples: * Constant names map using a few simple rules, but it's easiest to describe them with some concrete examples:
* `RG11B10Ufloat -> rg11_b10_ufloat` * `RG11B10Ufloat -> rg11_b10_ufloat`
* `Depth24PlusStencil8 -> depth24_plus_stencil8` * `Depth24PlusStencil8 -> depth24_plus_stencil8`
@ -230,6 +229,3 @@ The rules for translating `webgpu.h` are as follows:
* Regarding _"undefined"_ terminology: * Regarding _"undefined"_ terminology:
* In Zig, _undefined_ usually means _undefined memory_, _undefined behavior_, etc. * In Zig, _undefined_ usually means _undefined memory_, _undefined behavior_, etc.
* In WebGPU, _undefined_ commonly refers to JS-style undefined: _an optional value that was not specified_ * In WebGPU, _undefined_ commonly refers to JS-style undefined: _an optional value that was not specified_
* Zig refers to optional values not specified as _null_, but _null_ is a reserved keyword and so can't be used.
* We could use "_none_", but "BindingType none" and "BindingType not specified" clearly have non-equal meanings.
* As a result of all this, we translate _"undefined"_ in WebGPU to "undef" in Zig: it has no overlap with the reserved _undefined_ keyword, and distinguishes its meaning.

View file

@ -44,11 +44,11 @@ pub inline fn getProcAddress(_device: *device.Device, proc_name: [*:0]const u8)
return Impl.getProcAddress(_device, proc_name); return Impl.getProcAddress(_device, proc_name);
} }
pub const array_layer_count_undef = 0xffffffff; pub const array_layer_count_undefined = 0xffffffff;
pub const copy_stride_undef = 0xffffffff; pub const copy_stride_undefined = 0xffffffff;
pub const limit_u32_undef = 0xffffffff; pub const limit_u32_undefined = 0xffffffff;
pub const limit_u64_undef = 0xffffffffffffffff; pub const limit_u64_undefined = 0xffffffffffffffff;
pub const mip_level_count_undef = 0xffffffff; pub const mip_level_count_undefined = 0xffffffff;
pub const whole_map_size = std.math.maxInt(usize); pub const whole_map_size = std.math.maxInt(usize);
pub const whole_size = 0xffffffffffffffff; pub const whole_size = 0xffffffffffffffff;
@ -167,7 +167,7 @@ pub const BackendType = enum(u32) {
pub fn name(t: BackendType) []const u8 { pub fn name(t: BackendType) []const u8 {
return switch (t) { return switch (t) {
.undef => "Undefined", .undefined => "Undefined",
.null => "Null", .null => "Null",
.webgpu => "WebGPU", .webgpu => "WebGPU",
.d3d11 => "D3D11", .d3d11 => "D3D11",
@ -573,38 +573,38 @@ pub const Extent3D = extern struct {
}; };
pub const Limits = extern struct { pub const Limits = extern struct {
max_texture_dimension_1d: u32 = limit_u32_undef, max_texture_dimension_1d: u32 = limit_u32_undefined,
max_texture_dimension_2d: u32 = limit_u32_undef, max_texture_dimension_2d: u32 = limit_u32_undefined,
max_texture_dimension_3d: u32 = limit_u32_undef, max_texture_dimension_3d: u32 = limit_u32_undefined,
max_texture_array_layers: u32 = limit_u32_undef, max_texture_array_layers: u32 = limit_u32_undefined,
max_bind_groups: u32 = limit_u32_undef, max_bind_groups: u32 = limit_u32_undefined,
max_bind_groups_plus_vertex_buffers: u32 = limit_u32_undef, max_bind_groups_plus_vertex_buffers: u32 = limit_u32_undefined,
max_bindings_per_bind_group: u32 = limit_u32_undef, max_bindings_per_bind_group: u32 = limit_u32_undefined,
max_dynamic_uniform_buffers_per_pipeline_layout: u32 = limit_u32_undef, max_dynamic_uniform_buffers_per_pipeline_layout: u32 = limit_u32_undefined,
max_dynamic_storage_buffers_per_pipeline_layout: u32 = limit_u32_undef, max_dynamic_storage_buffers_per_pipeline_layout: u32 = limit_u32_undefined,
max_sampled_textures_per_shader_stage: u32 = limit_u32_undef, max_sampled_textures_per_shader_stage: u32 = limit_u32_undefined,
max_samplers_per_shader_stage: u32 = limit_u32_undef, max_samplers_per_shader_stage: u32 = limit_u32_undefined,
max_storage_buffers_per_shader_stage: u32 = limit_u32_undef, max_storage_buffers_per_shader_stage: u32 = limit_u32_undefined,
max_storage_textures_per_shader_stage: u32 = limit_u32_undef, max_storage_textures_per_shader_stage: u32 = limit_u32_undefined,
max_uniform_buffers_per_shader_stage: u32 = limit_u32_undef, max_uniform_buffers_per_shader_stage: u32 = limit_u32_undefined,
max_uniform_buffer_binding_size: u64 = limit_u64_undef, max_uniform_buffer_binding_size: u64 = limit_u64_undefined,
max_storage_buffer_binding_size: u64 = limit_u64_undef, max_storage_buffer_binding_size: u64 = limit_u64_undefined,
min_uniform_buffer_offset_alignment: u32 = limit_u32_undef, min_uniform_buffer_offset_alignment: u32 = limit_u32_undefined,
min_storage_buffer_offset_alignment: u32 = limit_u32_undef, min_storage_buffer_offset_alignment: u32 = limit_u32_undefined,
max_vertex_buffers: u32 = limit_u32_undef, max_vertex_buffers: u32 = limit_u32_undefined,
max_buffer_size: u64 = limit_u64_undef, max_buffer_size: u64 = limit_u64_undefined,
max_vertex_attributes: u32 = limit_u32_undef, max_vertex_attributes: u32 = limit_u32_undefined,
max_vertex_buffer_array_stride: u32 = limit_u32_undef, max_vertex_buffer_array_stride: u32 = limit_u32_undefined,
max_inter_stage_shader_components: u32 = limit_u32_undef, max_inter_stage_shader_components: u32 = limit_u32_undefined,
max_inter_stage_shader_variables: u32 = limit_u32_undef, max_inter_stage_shader_variables: u32 = limit_u32_undefined,
max_color_attachments: u32 = limit_u32_undef, max_color_attachments: u32 = limit_u32_undefined,
max_color_attachment_bytes_per_sample: u32 = limit_u32_undef, max_color_attachment_bytes_per_sample: u32 = limit_u32_undefined,
max_compute_workgroup_storage_size: u32 = limit_u32_undef, max_compute_workgroup_storage_size: u32 = limit_u32_undefined,
max_compute_invocations_per_workgroup: u32 = limit_u32_undef, max_compute_invocations_per_workgroup: u32 = limit_u32_undefined,
max_compute_workgroup_size_x: u32 = limit_u32_undef, max_compute_workgroup_size_x: u32 = limit_u32_undefined,
max_compute_workgroup_size_y: u32 = limit_u32_undef, max_compute_workgroup_size_y: u32 = limit_u32_undefined,
max_compute_workgroup_size_z: u32 = limit_u32_undef, max_compute_workgroup_size_z: u32 = limit_u32_undefined,
max_compute_workgroups_per_dimension: u32 = limit_u32_undef, max_compute_workgroups_per_dimension: u32 = limit_u32_undefined,
}; };
pub const Origin2D = extern struct { pub const Origin2D = extern struct {
@ -695,7 +695,7 @@ pub const StorageTextureBindingLayout = extern struct {
next_in_chain: ?*const ChainedStruct = null, next_in_chain: ?*const ChainedStruct = null,
access: StorageTextureAccess = .undefined, access: StorageTextureAccess = .undefined,
format: Texture.Format = .undefined, format: Texture.Format = .undefined,
view_dimension: TextureView.Dimension = .dimension_undef, view_dimension: TextureView.Dimension = .dimension_undefined,
}; };
pub const VertexAttribute = extern struct { pub const VertexAttribute = extern struct {

View file

@ -156,15 +156,15 @@ pub const Texture = opaque {
pub const BindingLayout = extern struct { pub const BindingLayout = extern struct {
next_in_chain: ?*const ChainedStruct = null, next_in_chain: ?*const ChainedStruct = null,
sample_type: SampleType = .undefined, sample_type: SampleType = .undefined,
view_dimension: TextureView.Dimension = .dimension_undef, view_dimension: TextureView.Dimension = .dimension_undefined,
multisampled: bool = false, multisampled: bool = false,
}; };
pub const DataLayout = extern struct { pub const DataLayout = extern struct {
next_in_chain: ?*const ChainedStruct = null, next_in_chain: ?*const ChainedStruct = null,
offset: u64 = 0, offset: u64 = 0,
bytes_per_row: u32 = types.copy_stride_undef, bytes_per_row: u32 = types.copy_stride_undefined,
rows_per_image: u32 = types.copy_stride_undef, rows_per_image: u32 = types.copy_stride_undefined,
}; };
pub const Descriptor = extern struct { pub const Descriptor = extern struct {

View file

@ -5,7 +5,7 @@ const types = @import("main.zig");
pub const TextureView = opaque { pub const TextureView = opaque {
pub const Dimension = enum(u32) { pub const Dimension = enum(u32) {
dimension_undef = 0x00000000, dimension_undefined = 0x00000000,
dimension_1d = 0x00000001, dimension_1d = 0x00000001,
dimension_2d = 0x00000002, dimension_2d = 0x00000002,
dimension_2d_array = 0x00000003, dimension_2d_array = 0x00000003,
@ -18,11 +18,11 @@ pub const TextureView = opaque {
next_in_chain: ?*const ChainedStruct = null, next_in_chain: ?*const ChainedStruct = null,
label: ?[*:0]const u8 = null, label: ?[*:0]const u8 = null,
format: Texture.Format = .undefined, format: Texture.Format = .undefined,
dimension: Dimension = .dimension_undef, dimension: Dimension = .dimension_undefined,
base_mip_level: u32 = 0, base_mip_level: u32 = 0,
mip_level_count: u32 = types.mip_level_count_undef, mip_level_count: u32 = types.mip_level_count_undefined,
base_array_layer: u32 = 0, base_array_layer: u32 = 0,
array_layer_count: u32 = types.array_layer_count_undef, array_layer_count: u32 = types.array_layer_count_undefined,
aspect: Texture.Aspect = .all, aspect: Texture.Aspect = .all,
}; };