gpu: add TogglesDeviceDescriptor.init slice helper

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2022-08-16 17:32:03 -07:00
parent cb80cfc3c2
commit 5e4aa7e6df
4 changed files with 19 additions and 5 deletions

View file

@ -168,6 +168,7 @@ And, to initialize data structures with slices in them, the following helpers ar
* `BindGroupLayout.Descriptor.init` * `BindGroupLayout.Descriptor.init`
* `BindGroup.Descriptor.init` * `BindGroup.Descriptor.init`
* `InstanceDescriptor.init` * `InstanceDescriptor.init`
* `TogglesDeviceDescriptor.init`
### Typed callbacks ### Typed callbacks

View file

@ -52,7 +52,7 @@ pub const BindGroup = opaque {
entries: ?[*]const Entry = null, entries: ?[*]const Entry = null,
/// Provides a slightly friendlier Zig API to initialize this structure. /// Provides a slightly friendlier Zig API to initialize this structure.
pub fn init(v: struct { pub inline fn init(v: struct {
next_in_chain: ?*const ChainedStruct = null, next_in_chain: ?*const ChainedStruct = null,
label: ?[*:0]const u8 = null, label: ?[*:0]const u8 = null,
layout: *BindGroupLayout, layout: *BindGroupLayout,

View file

@ -96,7 +96,7 @@ pub const BindGroupLayout = opaque {
entries: ?[*]const Entry = null, entries: ?[*]const Entry = null,
/// Provides a slightly friendlier Zig API to initialize this structure. /// Provides a slightly friendlier Zig API to initialize this structure.
pub fn init(v: struct { pub inline fn init(v: struct {
next_in_chain: ?*const ChainedStruct = null, next_in_chain: ?*const ChainedStruct = null,
label: ?[*:0]const u8 = null, label: ?[*:0]const u8 = null,
entries: ?[]const Entry = null, entries: ?[]const Entry = null,

View file

@ -21,7 +21,7 @@ pub const InstanceDescriptor = extern struct {
additional_runtime_search_paths: ?[*]const u8 = null, additional_runtime_search_paths: ?[*]const u8 = null,
/// Provides a slightly friendlier Zig API to initialize this structure. /// Provides a slightly friendlier Zig API to initialize this structure.
pub fn init(v: struct { pub inline fn init(v: struct {
chain: ChainedStruct, chain: ChainedStruct,
additional_runtime_search_paths: ?[]const u8 = null, additional_runtime_search_paths: ?[]const u8 = null,
}) InstanceDescriptor { }) InstanceDescriptor {
@ -42,10 +42,23 @@ pub const TextureInternalUsageDescriptor = extern struct {
/// TODO: Can be chained in gpu.Device.Descriptor /// TODO: Can be chained in gpu.Device.Descriptor
pub const TogglesDeviceDescriptor = extern struct { pub const TogglesDeviceDescriptor = extern struct {
chain: ChainedStruct, chain: ChainedStruct,
// TODO: slice helper
force_enabled_toggles_count: u32 = 0, force_enabled_toggles_count: u32 = 0,
force_enabled_toggles: ?[*]const u8 = null, force_enabled_toggles: ?[*]const u8 = null,
// TODO: slice helper
force_disabled_toggles_count: u32 = 0, force_disabled_toggles_count: u32 = 0,
force_disabled_toggles: ?[*]const u8 = null, force_disabled_toggles: ?[*]const u8 = null,
/// Provides a slightly friendlier Zig API to initialize this structure.
pub inline fn init(v: struct {
chain: ChainedStruct,
force_enabled_toggles: ?[]const u8 = null,
force_disabled_toggles: ?[]const u8 = null,
}) TogglesDeviceDescriptor {
return .{
.chain = v.chain,
.force_enabled_toggles_count = if (v.force_enabled_toggles) |e| @intCast(u32, e.len) else 0,
.force_enabled_toggles = if (v.force_enabled_toggles) |e| e.ptr else null,
.force_disabled_toggles_count = if (v.force_disabled_toggles) |e| @intCast(u32, e.len) else 0,
.force_disabled_toggles = if (v.force_disabled_toggles) |e| e.ptr else null,
};
}
}; };