From 6497f0d27b9e3c000e7f27eba3ed01be9ade41a4 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Tue, 16 Aug 2022 19:04:01 -0700 Subject: [PATCH] gpu: add FragmentState.init slice helper Signed-off-by: Stephen Gutekanst --- gpu/README.md | 1 + gpu/src/types.zig | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/gpu/README.md b/gpu/README.md index 395fe878..dcbcbc09 100644 --- a/gpu/README.md +++ b/gpu/README.md @@ -179,6 +179,7 @@ And, to initialize data structures with slices in them, the following helpers ar * `ProgrammableStageDescriptor.init` * `VertexBufferLayout.init` * `VertexState.init` +* `FragmentState.init` ### Typed callbacks diff --git a/gpu/src/types.zig b/gpu/src/types.zig index 267afca9..029a6bfe 100644 --- a/gpu/src/types.zig +++ b/gpu/src/types.zig @@ -761,12 +761,29 @@ pub const FragmentState = 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, - // TODO: slice helper target_count: u32, targets: ?[*]const ColorTargetState = 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, + targets: ?[]const ColorTargetState = null, + }) FragmentState { + return .{ + .next_in_chain = v.next_in_chain, + .module = v.module, + .entry_point = v.entry_point, + .constant_count = if (v.constants) |e| @intCast(u32, e.len) else 0, + .constants = if (v.constants) |e| e.ptr else null, + .target_count = if (v.targets) |e| @intCast(u32, e.len) else 0, + .targets = if (v.targets) |e| e.ptr else null, + }; + } }; test "BackendType name" {