From 67d07b0c558a7f2e42699010d78d6d8300de2884 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Tue, 16 Aug 2022 17:10:02 -0700 Subject: [PATCH] gpu: add BindGroupLayout.Descriptor slice helper Signed-off-by: Stephen Gutekanst --- gpu/src/bind_group_layout.zig | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/gpu/src/bind_group_layout.zig b/gpu/src/bind_group_layout.zig index c6cc2022..8a0ffdda 100644 --- a/gpu/src/bind_group_layout.zig +++ b/gpu/src/bind_group_layout.zig @@ -92,9 +92,22 @@ pub const BindGroupLayout = opaque { pub const Descriptor = extern struct { next_in_chain: ?*const ChainedStruct = null, label: ?[*:0]const u8 = null, - // TODO: slice helper entry_count: u32 = 0, entries: ?[*]const Entry = null, + + /// Provides a slightly friendlier Zig API to initialize this structure. + pub fn init(v: struct { + next_in_chain: ?*const ChainedStruct = null, + label: ?[*:0]const u8 = null, + entries: ?[]const Entry = null, + }) Descriptor { + return .{ + .next_in_chain = v.next_in_chain, + .label = v.label, + .entry_count = if (v.entries) |e| @intCast(u32, e.len) else 0, + .entries = if (v.entries) |e| e.ptr else null, + }; + } }; pub inline fn setLabel(bind_group_layout: *BindGroupLayout, label: [*:0]const u8) void {