From 05cb8b90c9a4ca3f9737f731ff5c7a688f795ddf Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Tue, 16 Aug 2022 18:44:50 -0700 Subject: [PATCH] gpu: add RenderBundleEncoder.Descriptor.init slice helper Signed-off-by: Stephen Gutekanst --- gpu/README.md | 1 + gpu/src/render_bundle_encoder.zig | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/gpu/README.md b/gpu/README.md index 58cadf11..ca63ce69 100644 --- a/gpu/README.md +++ b/gpu/README.md @@ -172,6 +172,7 @@ And, to initialize data structures with slices in them, the following helpers ar * `Device.Descriptor.init` * `PipelineLayout.Descriptor.init` * `QuerySet.Descriptor.init` +* `RenderBundleEncoder.Descriptor.init` ### Typed callbacks diff --git a/gpu/src/render_bundle_encoder.zig b/gpu/src/render_bundle_encoder.zig index ae879be8..8d4e550a 100644 --- a/gpu/src/render_bundle_encoder.zig +++ b/gpu/src/render_bundle_encoder.zig @@ -11,13 +11,34 @@ pub const RenderBundleEncoder = opaque { pub const Descriptor = extern struct { next_in_chain: ?*const ChainedStruct = null, label: ?[*:0]const u8 = null, - // TODO: slice helper color_formats_count: u32 = 0, color_formats: ?[*]const Texture.Format = null, depth_stencil_format: Texture.Format = .undef, sample_count: u32 = 1, depth_read_only: bool = false, stencil_read_only: bool = false, + + /// 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, + color_formats: ?[]const Texture.Format = null, + depth_stencil_format: Texture.Format = .undef, + sample_count: u32 = 1, + depth_read_only: bool = false, + stencil_read_only: bool = false, + }) Descriptor { + return .{ + .next_in_chain = v.next_in_chain, + .label = v.label, + .color_formats_count = if (v.color_formats) |e| @intCast(u32, e.len) else 0, + .color_formats = if (v.color_formats) |e| e.ptr else null, + .depth_stencil_format = v.depth_stencil_format, + .sample_count = v.sample_count, + .depth_read_only = v.depth_read_only, + .stencil_read_only = v.stencil_read_only, + }; + } }; /// Default `instance_count`: 1