gpu: add FragmentState.init slice helper

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2022-08-16 19:04:01 -07:00
parent 772eb9b89d
commit 6497f0d27b
2 changed files with 20 additions and 2 deletions

View file

@ -179,6 +179,7 @@ And, to initialize data structures with slices in them, the following helpers ar
* `ProgrammableStageDescriptor.init` * `ProgrammableStageDescriptor.init`
* `VertexBufferLayout.init` * `VertexBufferLayout.init`
* `VertexState.init` * `VertexState.init`
* `FragmentState.init`
### Typed callbacks ### Typed callbacks

View file

@ -761,12 +761,29 @@ pub const FragmentState = extern struct {
next_in_chain: ?*const ChainedStruct = null, next_in_chain: ?*const ChainedStruct = null,
module: *ShaderModule, module: *ShaderModule,
entry_point: [*:0]const u8, entry_point: [*:0]const u8,
// TODO: slice helper
constant_count: u32 = 0, constant_count: u32 = 0,
constants: ?[*]const ConstantEntry = null, constants: ?[*]const ConstantEntry = null,
// TODO: slice helper
target_count: u32, target_count: u32,
targets: ?[*]const ColorTargetState = null, 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" { test "BackendType name" {