From 26755e0837497a0a59196138be860c03aace3bdf Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Tue, 16 Aug 2022 19:44:57 -0700 Subject: [PATCH] gpu: update TODOs, give all chain fields default values Signed-off-by: Stephen Gutekanst --- gpu/src/dawn.zig | 14 +++++++------- gpu/src/dawn_impl.zig | 4 ++-- gpu/src/external_texture.zig | 4 ++-- gpu/src/interface.zig | 8 ++------ gpu/src/queue.zig | 2 +- gpu/src/types.zig | 8 ++++---- 6 files changed, 18 insertions(+), 22 deletions(-) diff --git a/gpu/src/dawn.zig b/gpu/src/dawn.zig index c1e8979e..4cbc6d19 100644 --- a/gpu/src/dawn.zig +++ b/gpu/src/dawn.zig @@ -4,25 +4,25 @@ pub const Interface = @import("dawn_impl.zig").Interface; /// TODO: Can be chained in gpu.Device.Descriptor pub const CacheDeviceDescriptor = extern struct { - chain: ChainedStruct, + chain: ChainedStruct = .{ .next = null, .s_type = .dawn_cache_device_descriptor }, isolation_key: [*:0]const u8 = "", }; /// TODO: Can be chained in gpu.CommandEncoder.Descriptor pub const EncoderInternalUsageDescriptor = extern struct { - chain: ChainedStruct, + chain: ChainedStruct = .{ .next = null, .s_type = .dawn_encoder_internal_usage_descriptor }, use_internal_usages: bool = false, }; /// TODO: Can be chained in gpu.Instance.Descriptor pub const InstanceDescriptor = extern struct { - chain: ChainedStruct, + chain: ChainedStruct = .{ .next = null, .s_type = .dawn_instance_descriptor }, additional_runtime_search_paths_count: u32 = 0, additional_runtime_search_paths: ?[*]const u8 = null, /// Provides a slightly friendlier Zig API to initialize this structure. pub inline fn init(v: struct { - chain: ChainedStruct, + chain: ChainedStruct = .{ .next = null, .s_type = .dawn_instance_descriptor }, additional_runtime_search_paths: ?[]const u8 = null, }) InstanceDescriptor { return .{ @@ -35,13 +35,13 @@ pub const InstanceDescriptor = extern struct { /// TODO: Can be chained in gpu.Texture.Descriptor pub const TextureInternalUsageDescriptor = extern struct { - chain: ChainedStruct, + chain: ChainedStruct = .{ .next = null, .s_type = .dawn_texture_internal_usage_descriptor }, internal_usage: Texture.UsageFlags = Texture.UsageFlags.none, }; /// TODO: Can be chained in gpu.Device.Descriptor pub const TogglesDeviceDescriptor = extern struct { - chain: ChainedStruct, + chain: ChainedStruct = .{ .next = null, .s_type = .dawn_toggles_device_descriptor }, force_enabled_toggles_count: u32 = 0, force_enabled_toggles: ?[*]const u8 = null, force_disabled_toggles_count: u32 = 0, @@ -49,7 +49,7 @@ pub const TogglesDeviceDescriptor = extern struct { /// Provides a slightly friendlier Zig API to initialize this structure. pub inline fn init(v: struct { - chain: ChainedStruct, + chain: ChainedStruct = .{ .next = null, .s_type = .dawn_toggles_device_descriptor }, force_enabled_toggles: ?[]const u8 = null, force_disabled_toggles: ?[]const u8 = null, }) TogglesDeviceDescriptor { diff --git a/gpu/src/dawn_impl.zig b/gpu/src/dawn_impl.zig index fa38601c..ed82b88b 100644 --- a/gpu/src/dawn_impl.zig +++ b/gpu/src/dawn_impl.zig @@ -108,7 +108,7 @@ pub const Interface = struct { procs.bufferDestroy.?(@ptrCast(c.WGPUBuffer, buffer)); } - // TODO: file a bug on Dawn docstrings, this returns null but is not documented as such. + // TODO: dawn: return value not marked as nullable in dawn.json but in fact is. pub inline fn bufferGetConstMappedRange(buffer: *gpu.Buffer, offset: usize, size: usize) ?*const anyopaque { return procs.bufferGetConstMappedRange.?( @ptrCast(c.WGPUBuffer, buffer), @@ -117,7 +117,7 @@ pub const Interface = struct { ); } - // TODO: file a bug on Dawn docstrings, this returns null but is not documented as such. + // TODO: dawn: return value not marked as nullable in dawn.json but in fact is. pub inline fn bufferGetMappedRange(buffer: *gpu.Buffer, offset: usize, size: usize) ?*anyopaque { return procs.bufferGetMappedRange.?( @ptrCast(c.WGPUBuffer, buffer), diff --git a/gpu/src/external_texture.zig b/gpu/src/external_texture.zig index 6f4e2a3a..21916185 100644 --- a/gpu/src/external_texture.zig +++ b/gpu/src/external_texture.zig @@ -5,13 +5,13 @@ const Impl = @import("interface.zig").Impl; pub const ExternalTexture = opaque { /// TODO: Can be chained in gpu.BindGroup.Entry pub const BindingEntry = extern struct { - chain: ChainedStruct, + chain: ChainedStruct = .{ .next = null, .s_type = .external_texture_binding_entry }, external_texture: *ExternalTexture, }; /// TODO: Can be chained in gpu.BindGroupLayout.Entry pub const BindingLayout = extern struct { - chain: ChainedStruct, + chain: ChainedStruct = .{ .next = null, .s_type = .external_texture_binding_layout }, }; pub const Descriptor = extern struct { diff --git a/gpu/src/interface.zig b/gpu/src/interface.zig index a4024227..158aff84 100644 --- a/gpu/src/interface.zig +++ b/gpu/src/interface.zig @@ -333,8 +333,6 @@ pub fn Export(comptime T: type) type { return T.bufferGetUsage(buffer); } - // TODO: Zig cannot currently export a packed struct gpu.MapModeFlags, so we use a u32 for - // now. // WGPU_EXPORT void wgpuBufferMapAsync(WGPUBuffer buffer, WGPUMapModeFlags mode, size_t offset, size_t size, WGPUBufferMapCallback callback, void * userdata); export fn wgpuBufferMapAsync(buffer: *gpu.Buffer, mode: u32, offset: usize, size: usize, callback: gpu.Buffer.MapCallback, userdata: ?*anyopaque) void { T.bufferMapAsync(buffer, @bitCast(gpu.MapModeFlags, mode), offset, size, callback, userdata); @@ -1115,8 +1113,6 @@ pub fn Export(comptime T: type) type { T.surfaceRelease(surface); } - // TODO: Zig cannot currently export a packed struct gpu.Texture.UsageFlags, so we use a u32 - // for now. // WGPU_EXPORT void wgpuSwapChainConfigure(WGPUSwapChain swapChain, WGPUTextureFormat format, WGPUTextureUsageFlags allowedUsage, uint32_t width, uint32_t height); export fn wgpuSwapChainConfigure(swap_chain: *gpu.SwapChain, format: gpu.Texture.Format, allowed_usage: u32, width: u32, height: u32) void { T.swapChainConfigure(swap_chain, format, @bitCast(gpu.Texture.UsageFlags, allowed_usage), width, height); @@ -1322,7 +1318,7 @@ pub const StubInterface = Interface(struct { unreachable; } - // TODO: file a bug on Dawn docstrings, this returns null but is not documented as such. + // TODO: dawn: return value not marked as nullable in dawn.json but in fact is. pub inline fn bufferGetConstMappedRange(buffer: *gpu.Buffer, offset: usize, size: usize) ?*const anyopaque { _ = buffer; _ = offset; @@ -1330,7 +1326,7 @@ pub const StubInterface = Interface(struct { unreachable; } - // TODO: file a bug on Dawn docstrings, this returns null but is not documented as such. + // TODO: dawn: return value not marked as nullable in dawn.json but in fact is. pub inline fn bufferGetMappedRange(buffer: *gpu.Buffer, offset: usize, size: usize) ?*anyopaque { _ = buffer; _ = offset; diff --git a/gpu/src/queue.zig b/gpu/src/queue.zig index 9fd26ec1..7017fbe8 100644 --- a/gpu/src/queue.zig +++ b/gpu/src/queue.zig @@ -30,7 +30,7 @@ pub const Queue = opaque { Impl.queueCopyTextureForBrowser(queue, source, destination, copy_size, options); } - // TODO: is it not possible to *unset* this callback? Presumably it should be nullable? + // TODO: presumably callback should be nullable for unsetting pub inline fn onSubmittedWorkDone( queue: *Queue, signal_value: u64, diff --git a/gpu/src/types.zig b/gpu/src/types.zig index a9fd22ba..90e0e020 100644 --- a/gpu/src/types.zig +++ b/gpu/src/types.zig @@ -466,13 +466,13 @@ pub const ShaderStageFlags = packed struct { }; pub const ChainedStruct = extern struct { - // TODO: file a bug on Dawn, this is not marked as nullable but in fact is. + // TODO: dawn: not marked as nullable in dawn.json but in fact is. next: ?*const ChainedStruct = null, s_type: SType, }; pub const ChainedStructOut = extern struct { - // TODO: file a bug on Dawn, this is not marked as nullable but in fact is. + // TODO: dawn: not marked as nullable in dawn.json but in fact is. next: ?*ChainedStructOut = null, s_type: SType, }; @@ -573,7 +573,7 @@ pub const MultisampleState = extern struct { /// TODO: Can be chained in gpu.PrimitiveState pub const PrimitiveDepthClipControl = extern struct { - chain: ChainedStruct, + chain: ChainedStruct = .{ .next = null, .s_type = .primitive_depth_clip_control }, unclipped_depth: bool = false, }; @@ -587,7 +587,7 @@ pub const PrimitiveState = extern struct { /// TODO: Can be chained in gpu.RenderPassDescriptor pub const RenderPassDescriptorMaxDrawCount = extern struct { - chain: ChainedStruct, + chain: ChainedStruct = .{ .next = null, .s_type = .render_pass_descriptor_max_draw_count }, max_draw_count: u64 = 50000000, };