From 8cd2fb3f19242bf8df8be234de951b030d9f692a Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Tue, 16 Aug 2022 18:59:52 -0700 Subject: [PATCH] gpu: add VertexBufferLayout.init slice helper Signed-off-by: Stephen Gutekanst --- gpu/README.md | 1 + gpu/src/types.zig | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/gpu/README.md b/gpu/README.md index e63ca339..f2206896 100644 --- a/gpu/README.md +++ b/gpu/README.md @@ -177,6 +177,7 @@ And, to initialize data structures with slices in them, the following helpers ar * `ComputePassDescriptor.init` * `RenderPassDescriptor.init` * `ProgrammableStageDescriptor.init` +* `VertexBufferLayout.init` ### Typed callbacks diff --git a/gpu/src/types.zig b/gpu/src/types.zig index ba9b5ba5..7b653a7a 100644 --- a/gpu/src/types.zig +++ b/gpu/src/types.zig @@ -93,7 +93,7 @@ pub const RenderPassDescriptor = extern struct { depth_stencil_attachment: ?*const RenderPassDepthStencilAttachment = null, occlusion_query_set: ?*QuerySet = null, timestamp_writes: ?[]const RenderPassTimestampWrite = null, - }) ComputePassDescriptor { + }) RenderPassDescriptor { return .{ .next_in_chain = v.next_in_chain, .label = v.label, @@ -664,7 +664,7 @@ pub const ProgrammableStageDescriptor = extern struct { module: *ShaderModule, entry_point: [*:0]const u8, constants: ?[]const ConstantEntry = null, - }) ComputePassDescriptor { + }) ProgrammableStageDescriptor { return .{ .next_in_chain = v.next_in_chain, .module = v.module, @@ -703,9 +703,22 @@ pub const SupportedLimits = extern struct { pub const VertexBufferLayout = extern struct { array_stride: u64, step_mode: VertexStepMode = .vertex, - // TODO: slice helper attribute_count: u32, attributes: ?[*]const VertexAttribute = null, + + /// Provides a slightly friendlier Zig API to initialize this structure. + pub inline fn init(v: struct { + array_stride: u64, + step_mode: VertexStepMode = .vertex, + attributes: ?[]const VertexAttribute = null, + }) ProgrammableStageDescriptor { + return .{ + .array_stride = v.array_stride, + .step_mode = v.step_mode, + .attribute_count = if (v.attributes) |e| @intCast(u32, e.len) else 0, + .attributes = if (v.attributes) |e| e.ptr else null, + }; + } }; pub const ColorTargetState = extern struct {