From c82f64029694a59a58af17dd17162c22b7df2897 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Tue, 16 Aug 2022 17:56:47 -0700 Subject: [PATCH] gpu: add QuerySet.Descriptor.init slice helper Signed-off-by: Stephen Gutekanst --- gpu/README.md | 1 + gpu/src/query_set.zig | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/gpu/README.md b/gpu/README.md index 355f2ef7..58cadf11 100644 --- a/gpu/README.md +++ b/gpu/README.md @@ -171,6 +171,7 @@ And, to initialize data structures with slices in them, the following helpers ar * `TogglesDeviceDescriptor.init` * `Device.Descriptor.init` * `PipelineLayout.Descriptor.init` +* `QuerySet.Descriptor.init` ### Typed callbacks diff --git a/gpu/src/query_set.zig b/gpu/src/query_set.zig index 62100cdd..59b38501 100644 --- a/gpu/src/query_set.zig +++ b/gpu/src/query_set.zig @@ -9,9 +9,26 @@ pub const QuerySet = opaque { label: ?[*:0]const u8 = null, type: QueryType, count: u32, - // TODO: slice helper pipeline_statistics: ?[*]const PipelineStatisticName = null, pipeline_statistics_count: u32 = 0, + + /// 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, + type: QueryType, + count: u32, + pipeline_statistics: ?[]const PipelineStatisticName = null, + }) Descriptor { + return .{ + .next_in_chain = v.next_in_chain, + .label = v.label, + .type = v.type, + .count = v.count, + .pipeline_statistics_count = if (v.pipeline_statistics) |e| @intCast(u32, e.len) else 0, + .pipeline_statistics = if (v.pipeline_statistics) |e| e.ptr else null, + }; + } }; pub inline fn destroy(query_set: *QuerySet) void {