From 6c9c4c71bb80f8f351f294a484f5a5921344c3ad Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Tue, 16 Aug 2022 18:51:59 -0700 Subject: [PATCH] gpu: add ComputePassDescriptor.init slice helper Signed-off-by: Stephen Gutekanst --- gpu/README.md | 1 + gpu/src/types.zig | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/gpu/README.md b/gpu/README.md index 20ccdf9f..20d4f4df 100644 --- a/gpu/README.md +++ b/gpu/README.md @@ -174,6 +174,7 @@ And, to initialize data structures with slices in them, the following helpers ar * `QuerySet.Descriptor.init` * `RenderBundleEncoder.Descriptor.init` * `Texture.Descriptor.init` +* `ComputePassDescriptor.init` ### Typed callbacks diff --git a/gpu/src/types.zig b/gpu/src/types.zig index e7c48651..fa0a8a34 100644 --- a/gpu/src/types.zig +++ b/gpu/src/types.zig @@ -57,9 +57,22 @@ pub const RequestAdapterOptions = extern struct { pub const ComputePassDescriptor = extern struct { next_in_chain: ?*const ChainedStruct = null, label: ?[*:0]const u8 = null, - // TODO: slice helper timestamp_write_count: u32 = 0, timestamp_writes: ?[*]const ComputePassTimestampWrite = null, + + /// Provides a slightly friendlier Zig API to initialize this structure. + pub inline fn init(v: struct { + next_in_chain: ?*const ChainedStruct = null, + label: ?[*:0]const u8 = null, + timestamp_writes: ?[]const ComputePassTimestampWrite = null, + }) ComputePassDescriptor { + return .{ + .next_in_chain = v.next_in_chain, + .label = v.label, + .timestamp_write_count = if (v.timestamp_writes) |e| @intCast(u32, e.len) else 0, + .timestamp_writes = if (v.timestamp_writes) |e| e.ptr else null, + }; + } }; pub const RenderPassDescriptor = extern struct {