diff --git a/gpu/README.md b/gpu/README.md index 27012675..355f2ef7 100644 --- a/gpu/README.md +++ b/gpu/README.md @@ -170,6 +170,7 @@ And, to initialize data structures with slices in them, the following helpers ar * `InstanceDescriptor.init` * `TogglesDeviceDescriptor.init` * `Device.Descriptor.init` +* `PipelineLayout.Descriptor.init` ### Typed callbacks diff --git a/gpu/src/pipeline_layout.zig b/gpu/src/pipeline_layout.zig index 5f88217e..d66f8253 100644 --- a/gpu/src/pipeline_layout.zig +++ b/gpu/src/pipeline_layout.zig @@ -6,9 +6,22 @@ pub const PipelineLayout = opaque { pub const Descriptor = extern struct { next_in_chain: ?*const ChainedStruct = null, label: ?[*:0]const u8 = null, - // TODO: slice helper bind_group_layout_count: u32 = 0, bind_group_layouts: ?[*]const *BindGroupLayout = 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, + bind_group_layouts: ?[]const *BindGroupLayout = null, + }) Descriptor { + return .{ + .next_in_chain = v.next_in_chain, + .label = v.label, + .bind_group_layout_count = if (v.bind_group_layouts) |e| @intCast(u32, e.len) else 0, + .bind_group_layouts = if (v.bind_group_layouts) |e| e.ptr else null, + }; + } }; pub inline fn setLabel(pipeline_layout: *PipelineLayout, label: [*:0]const u8) void {