gpu: add BindGroup.Descriptor slice helper

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2022-08-16 17:16:52 -07:00
parent 67d07b0c55
commit c3bb1683a6
2 changed files with 21 additions and 0 deletions

View file

@ -163,6 +163,11 @@ The slice helpers are:
* `RenderBundleEncoder.setBindGroup`
* `RenderPassEncoder.setBindGroup`
And, to initialize data structures with slices in them, the following helpers are provided:
* `BindGroupLayout.Descriptor.init`
* `BindGroup.Descriptor.init`
### Typed callbacks
Most WebGPU callbacks provide a way to provide a `userdata: *anyopaque` pointer to the callback for context. We alter these APIs to expose a typed context pointer instead (again, the original API is always available via the `gpu.Impl` type should you want it):

View file

@ -51,6 +51,22 @@ pub const BindGroup = opaque {
// 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,
layout: *BindGroupLayout,
entries: ?[]const Entry = null,
}) Descriptor {
return .{
.next_in_chain = v.next_in_chain,
.label = v.label,
.layout = v.layout,
.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: *BindGroup, label: [*:0]const u8) void {