From 709d2f9875ee544ba3231dc6870dca9f403e3347 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Fri, 30 Jun 2023 19:06:10 -0700 Subject: [PATCH] gpu: undef -> undefined (no longer a reserved keyword) Signed-off-by: Stephen Gutekanst --- libs/gpu/README.md | 4 -- libs/gpu/src/main.zig | 78 +++++++++++++++++------------------ libs/gpu/src/texture.zig | 6 +-- libs/gpu/src/texture_view.zig | 8 ++-- 4 files changed, 46 insertions(+), 50 deletions(-) diff --git a/libs/gpu/README.md b/libs/gpu/README.md index 16f895b5..95fa8b33 100644 --- a/libs/gpu/README.md +++ b/libs/gpu/README.md @@ -217,7 +217,6 @@ The rules for translating `webgpu.h` are as follows: * `error` -> `err` * `type` -> `typ` * `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: * `RG11B10Ufloat -> rg11_b10_ufloat` * `Depth24PlusStencil8 -> depth24_plus_stencil8` @@ -230,6 +229,3 @@ The rules for translating `webgpu.h` are as follows: * Regarding _"undefined"_ terminology: * 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_ - * 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. diff --git a/libs/gpu/src/main.zig b/libs/gpu/src/main.zig index d2f2c63d..27dcb32b 100644 --- a/libs/gpu/src/main.zig +++ b/libs/gpu/src/main.zig @@ -44,11 +44,11 @@ pub inline fn getProcAddress(_device: *device.Device, proc_name: [*:0]const u8) return Impl.getProcAddress(_device, proc_name); } -pub const array_layer_count_undef = 0xffffffff; -pub const copy_stride_undef = 0xffffffff; -pub const limit_u32_undef = 0xffffffff; -pub const limit_u64_undef = 0xffffffffffffffff; -pub const mip_level_count_undef = 0xffffffff; +pub const array_layer_count_undefined = 0xffffffff; +pub const copy_stride_undefined = 0xffffffff; +pub const limit_u32_undefined = 0xffffffff; +pub const limit_u64_undefined = 0xffffffffffffffff; +pub const mip_level_count_undefined = 0xffffffff; pub const whole_map_size = std.math.maxInt(usize); pub const whole_size = 0xffffffffffffffff; @@ -167,7 +167,7 @@ pub const BackendType = enum(u32) { pub fn name(t: BackendType) []const u8 { return switch (t) { - .undef => "Undefined", + .undefined => "Undefined", .null => "Null", .webgpu => "WebGPU", .d3d11 => "D3D11", @@ -573,38 +573,38 @@ pub const Extent3D = extern struct { }; pub const Limits = extern struct { - max_texture_dimension_1d: u32 = limit_u32_undef, - max_texture_dimension_2d: u32 = limit_u32_undef, - max_texture_dimension_3d: u32 = limit_u32_undef, - max_texture_array_layers: u32 = limit_u32_undef, - max_bind_groups: u32 = limit_u32_undef, - max_bind_groups_plus_vertex_buffers: u32 = limit_u32_undef, - max_bindings_per_bind_group: u32 = limit_u32_undef, - max_dynamic_uniform_buffers_per_pipeline_layout: u32 = limit_u32_undef, - max_dynamic_storage_buffers_per_pipeline_layout: u32 = limit_u32_undef, - max_sampled_textures_per_shader_stage: u32 = limit_u32_undef, - max_samplers_per_shader_stage: u32 = limit_u32_undef, - max_storage_buffers_per_shader_stage: u32 = limit_u32_undef, - max_storage_textures_per_shader_stage: u32 = limit_u32_undef, - max_uniform_buffers_per_shader_stage: u32 = limit_u32_undef, - max_uniform_buffer_binding_size: u64 = limit_u64_undef, - max_storage_buffer_binding_size: u64 = limit_u64_undef, - min_uniform_buffer_offset_alignment: u32 = limit_u32_undef, - min_storage_buffer_offset_alignment: u32 = limit_u32_undef, - max_vertex_buffers: u32 = limit_u32_undef, - max_buffer_size: u64 = limit_u64_undef, - max_vertex_attributes: u32 = limit_u32_undef, - max_vertex_buffer_array_stride: u32 = limit_u32_undef, - max_inter_stage_shader_components: u32 = limit_u32_undef, - max_inter_stage_shader_variables: u32 = limit_u32_undef, - max_color_attachments: u32 = limit_u32_undef, - max_color_attachment_bytes_per_sample: u32 = limit_u32_undef, - max_compute_workgroup_storage_size: u32 = limit_u32_undef, - max_compute_invocations_per_workgroup: u32 = limit_u32_undef, - max_compute_workgroup_size_x: u32 = limit_u32_undef, - max_compute_workgroup_size_y: u32 = limit_u32_undef, - max_compute_workgroup_size_z: u32 = limit_u32_undef, - max_compute_workgroups_per_dimension: u32 = limit_u32_undef, + max_texture_dimension_1d: u32 = limit_u32_undefined, + max_texture_dimension_2d: u32 = limit_u32_undefined, + max_texture_dimension_3d: u32 = limit_u32_undefined, + max_texture_array_layers: u32 = limit_u32_undefined, + max_bind_groups: u32 = limit_u32_undefined, + max_bind_groups_plus_vertex_buffers: u32 = limit_u32_undefined, + max_bindings_per_bind_group: u32 = limit_u32_undefined, + max_dynamic_uniform_buffers_per_pipeline_layout: u32 = limit_u32_undefined, + max_dynamic_storage_buffers_per_pipeline_layout: u32 = limit_u32_undefined, + max_sampled_textures_per_shader_stage: u32 = limit_u32_undefined, + max_samplers_per_shader_stage: u32 = limit_u32_undefined, + max_storage_buffers_per_shader_stage: u32 = limit_u32_undefined, + max_storage_textures_per_shader_stage: u32 = limit_u32_undefined, + max_uniform_buffers_per_shader_stage: u32 = limit_u32_undefined, + max_uniform_buffer_binding_size: u64 = limit_u64_undefined, + max_storage_buffer_binding_size: u64 = limit_u64_undefined, + min_uniform_buffer_offset_alignment: u32 = limit_u32_undefined, + min_storage_buffer_offset_alignment: u32 = limit_u32_undefined, + max_vertex_buffers: u32 = limit_u32_undefined, + max_buffer_size: u64 = limit_u64_undefined, + max_vertex_attributes: u32 = limit_u32_undefined, + max_vertex_buffer_array_stride: u32 = limit_u32_undefined, + max_inter_stage_shader_components: u32 = limit_u32_undefined, + max_inter_stage_shader_variables: u32 = limit_u32_undefined, + max_color_attachments: u32 = limit_u32_undefined, + max_color_attachment_bytes_per_sample: u32 = limit_u32_undefined, + max_compute_workgroup_storage_size: u32 = limit_u32_undefined, + max_compute_invocations_per_workgroup: u32 = limit_u32_undefined, + max_compute_workgroup_size_x: u32 = limit_u32_undefined, + max_compute_workgroup_size_y: u32 = limit_u32_undefined, + max_compute_workgroup_size_z: u32 = limit_u32_undefined, + max_compute_workgroups_per_dimension: u32 = limit_u32_undefined, }; pub const Origin2D = extern struct { @@ -695,7 +695,7 @@ pub const StorageTextureBindingLayout = extern struct { next_in_chain: ?*const ChainedStruct = null, access: StorageTextureAccess = .undefined, format: Texture.Format = .undefined, - view_dimension: TextureView.Dimension = .dimension_undef, + view_dimension: TextureView.Dimension = .dimension_undefined, }; pub const VertexAttribute = extern struct { diff --git a/libs/gpu/src/texture.zig b/libs/gpu/src/texture.zig index 15c233dc..463a8682 100644 --- a/libs/gpu/src/texture.zig +++ b/libs/gpu/src/texture.zig @@ -156,15 +156,15 @@ pub const Texture = opaque { pub const BindingLayout = extern struct { next_in_chain: ?*const ChainedStruct = null, sample_type: SampleType = .undefined, - view_dimension: TextureView.Dimension = .dimension_undef, + view_dimension: TextureView.Dimension = .dimension_undefined, multisampled: bool = false, }; pub const DataLayout = extern struct { next_in_chain: ?*const ChainedStruct = null, offset: u64 = 0, - bytes_per_row: u32 = types.copy_stride_undef, - rows_per_image: u32 = types.copy_stride_undef, + bytes_per_row: u32 = types.copy_stride_undefined, + rows_per_image: u32 = types.copy_stride_undefined, }; pub const Descriptor = extern struct { diff --git a/libs/gpu/src/texture_view.zig b/libs/gpu/src/texture_view.zig index a4f443fc..15033275 100644 --- a/libs/gpu/src/texture_view.zig +++ b/libs/gpu/src/texture_view.zig @@ -5,7 +5,7 @@ const types = @import("main.zig"); pub const TextureView = opaque { pub const Dimension = enum(u32) { - dimension_undef = 0x00000000, + dimension_undefined = 0x00000000, dimension_1d = 0x00000001, dimension_2d = 0x00000002, dimension_2d_array = 0x00000003, @@ -18,11 +18,11 @@ pub const TextureView = opaque { next_in_chain: ?*const ChainedStruct = null, label: ?[*:0]const u8 = null, format: Texture.Format = .undefined, - dimension: Dimension = .dimension_undef, + dimension: Dimension = .dimension_undefined, 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, - array_layer_count: u32 = types.array_layer_count_undef, + array_layer_count: u32 = types.array_layer_count_undefined, aspect: Texture.Aspect = .all, };