gpu: add BindGroupLayout.Descriptor slice helper

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2022-08-16 17:10:02 -07:00
parent 68d5f6fcb1
commit 67d07b0c55

View file

@ -92,9 +92,22 @@ pub const BindGroupLayout = opaque {
pub const Descriptor = extern struct { pub const Descriptor = extern struct {
next_in_chain: ?*const ChainedStruct = null, next_in_chain: ?*const ChainedStruct = null,
label: ?[*:0]const u8 = null, label: ?[*:0]const u8 = null,
// TODO: slice helper
entry_count: u32 = 0, entry_count: u32 = 0,
entries: ?[*]const Entry = null, 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 { pub inline fn setLabel(bind_group_layout: *BindGroupLayout, label: [*:0]const u8) void {