From e95481db2196069dce42da1e0e54a96d8e076953 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Tue, 16 Aug 2022 18:57:05 -0700 Subject: [PATCH] gpu: add ProgrammableStageDescriptor slice helper Signed-off-by: Stephen Gutekanst --- gpu/README.md | 1 + gpu/src/types.zig | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/gpu/README.md b/gpu/README.md index c90c285a..e63ca339 100644 --- a/gpu/README.md +++ b/gpu/README.md @@ -176,6 +176,7 @@ And, to initialize data structures with slices in them, the following helpers ar * `Texture.Descriptor.init` * `ComputePassDescriptor.init` * `RenderPassDescriptor.init` +* `ProgrammableStageDescriptor.init` ### Typed callbacks diff --git a/gpu/src/types.zig b/gpu/src/types.zig index 56ac536c..ba9b5ba5 100644 --- a/gpu/src/types.zig +++ b/gpu/src/types.zig @@ -655,9 +655,24 @@ pub const ProgrammableStageDescriptor = extern struct { next_in_chain: ?*const ChainedStruct = null, module: *ShaderModule, entry_point: [*:0]const u8, - // TODO: slice helper constant_count: u32 = 0, constants: ?[*]const ConstantEntry = null, + + /// Provides a slightly friendlier Zig API to initialize this structure. + pub inline fn init(v: struct { + next_in_chain: ?*const ChainedStruct = null, + module: *ShaderModule, + entry_point: [*:0]const u8, + constants: ?[]const ConstantEntry = null, + }) ComputePassDescriptor { + return .{ + .next_in_chain = v.next_in_chain, + .module = v.module, + .entry_point = v.entry_point, + .constant_count = if (v.timestamp_writes) |e| @intCast(u32, e.len) else 0, + .constants = if (v.constants) |e| e.ptr else null, + }; + } }; pub const RenderPassColorAttachment = extern struct {