gpu: correctly handle null RenderPipeline.Descriptor transitive values
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
f5e6976937
commit
4e31e015a4
3 changed files with 32 additions and 30 deletions
|
|
@ -393,42 +393,44 @@ inline fn convertRenderPipelineDescriptor(
|
||||||
tmp_depth_stencil: *c.WGPUDepthStencilState,
|
tmp_depth_stencil: *c.WGPUDepthStencilState,
|
||||||
tmp_fragment_state: *c.WGPUFragmentState,
|
tmp_fragment_state: *c.WGPUFragmentState,
|
||||||
) c.WGPURenderPipelineDescriptor {
|
) c.WGPURenderPipelineDescriptor {
|
||||||
tmp_depth_stencil.* = c.WGPUDepthStencilState{
|
if (d.depth_stencil) |ds| {
|
||||||
.nextInChain = null,
|
tmp_depth_stencil.* = c.WGPUDepthStencilState{
|
||||||
.format = @enumToInt(d.depth_stencil.format),
|
.nextInChain = null,
|
||||||
.depthWriteEnabled = d.depth_stencil.depth_write_enabled,
|
.format = @enumToInt(ds.format),
|
||||||
.depthCompare = @enumToInt(d.depth_stencil.depth_compare),
|
.depthWriteEnabled = ds.depth_write_enabled,
|
||||||
.stencilFront = @bitCast(c.WGPUStencilFaceState, d.depth_stencil.stencil_front),
|
.depthCompare = @enumToInt(ds.depth_compare),
|
||||||
.stencilBack = @bitCast(c.WGPUStencilFaceState, d.depth_stencil.stencil_back),
|
.stencilFront = @bitCast(c.WGPUStencilFaceState, ds.stencil_front),
|
||||||
.stencilReadMask = d.depth_stencil.stencil_read_mask,
|
.stencilBack = @bitCast(c.WGPUStencilFaceState, ds.stencil_back),
|
||||||
.stencilWriteMask = d.depth_stencil.stencil_write_mask,
|
.stencilReadMask = ds.stencil_read_mask,
|
||||||
.depthBias = d.depth_stencil.depth_bias,
|
.stencilWriteMask = ds.stencil_write_mask,
|
||||||
.depthBiasSlopeScale = d.depth_stencil.depth_bias_slope_scale,
|
.depthBias = ds.depth_bias,
|
||||||
.depthBiasClamp = d.depth_stencil.depth_bias_clamp,
|
.depthBiasSlopeScale = ds.depth_bias_slope_scale,
|
||||||
};
|
.depthBiasClamp = ds.depth_bias_clamp,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
tmp_fragment_state.* = c.WGPUFragmentState{
|
tmp_fragment_state.* = c.WGPUFragmentState{
|
||||||
.nextInChain = null,
|
.nextInChain = null,
|
||||||
.module = @ptrCast(c.WGPUShaderModule, d.fragment.module.ptr),
|
.module = @ptrCast(c.WGPUShaderModule, d.fragment.module.ptr),
|
||||||
.entryPoint = d.vertex.entry_point,
|
.entryPoint = d.vertex.entry_point,
|
||||||
.constantCount = @intCast(u32, d.fragment.constants.len),
|
.constantCount = if (d.fragment.constants) |v| @intCast(u32, v.len) else 0,
|
||||||
.constants = @ptrCast(*const c.WGPUConstantEntry, &d.fragment.constants[0]),
|
.constants = if (d.fragment.constants) |v| @ptrCast(*const c.WGPUConstantEntry, &v[0]) else null,
|
||||||
.targetCount = @intCast(u32, d.fragment.targets.len),
|
.targetCount = if (d.fragment.targets) |v| @intCast(u32, v.len) else 0,
|
||||||
.targets = @ptrCast(*const c.WGPUColorTargetState, &d.fragment.targets[0]),
|
.targets = if (d.fragment.targets) |v| @ptrCast(*const c.WGPUColorTargetState, &v[0]) else null,
|
||||||
};
|
};
|
||||||
|
|
||||||
return c.WGPURenderPipelineDescriptor{
|
return c.WGPURenderPipelineDescriptor{
|
||||||
.nextInChain = null,
|
.nextInChain = null,
|
||||||
.label = d.label,
|
.label = d.label,
|
||||||
.layout = @ptrCast(c.WGPUPipelineLayout, d.layout.ptr),
|
.layout = if (d.layout) |v| @ptrCast(c.WGPUPipelineLayout, v.ptr) else null,
|
||||||
.vertex = c.WGPUVertexState{
|
.vertex = c.WGPUVertexState{
|
||||||
.nextInChain = null,
|
.nextInChain = null,
|
||||||
.module = @ptrCast(c.WGPUShaderModule, d.vertex.module.ptr),
|
.module = @ptrCast(c.WGPUShaderModule, d.vertex.module.ptr),
|
||||||
.entryPoint = d.vertex.entry_point,
|
.entryPoint = d.vertex.entry_point,
|
||||||
.constantCount = @intCast(u32, d.vertex.constants.len),
|
.constantCount = if (d.vertex.constants) |v| @intCast(u32, v.len) else 0,
|
||||||
.constants = @ptrCast(*const c.WGPUConstantEntry, &d.vertex.constants[0]),
|
.constants = if (d.vertex.constants) |v| @ptrCast(*const c.WGPUConstantEntry, &v[0]) else null,
|
||||||
.bufferCount = @intCast(u32, d.vertex.buffers.len),
|
.bufferCount = if (d.vertex.buffers) |v| @intCast(u32, v.len) else 0,
|
||||||
.buffers = @ptrCast(*const c.WGPUVertexBufferLayout, &d.vertex.buffers[0]),
|
.buffers = if (d.vertex.buffers) |v| @ptrCast(*const c.WGPUVertexBufferLayout, &v[0]) else null,
|
||||||
},
|
},
|
||||||
.primitive = c.WGPUPrimitiveState{
|
.primitive = c.WGPUPrimitiveState{
|
||||||
.nextInChain = null,
|
.nextInChain = null,
|
||||||
|
|
@ -437,7 +439,7 @@ inline fn convertRenderPipelineDescriptor(
|
||||||
.frontFace = @enumToInt(d.primitive.front_face),
|
.frontFace = @enumToInt(d.primitive.front_face),
|
||||||
.cullMode = @enumToInt(d.primitive.cull_mode),
|
.cullMode = @enumToInt(d.primitive.cull_mode),
|
||||||
},
|
},
|
||||||
.depthStencil = tmp_depth_stencil,
|
.depthStencil = if (d.depth_stencil != null) tmp_depth_stencil else null,
|
||||||
.multisample = c.WGPUMultisampleState{
|
.multisample = c.WGPUMultisampleState{
|
||||||
.nextInChain = null,
|
.nextInChain = null,
|
||||||
.count = d.multisample.count,
|
.count = d.multisample.count,
|
||||||
|
|
|
||||||
|
|
@ -34,10 +34,10 @@ pub inline fn setLabel(pipeline: RenderPipeline, label: [:0]const u8) void {
|
||||||
|
|
||||||
pub const Descriptor = struct {
|
pub const Descriptor = struct {
|
||||||
label: ?[*:0]const u8 = null,
|
label: ?[*:0]const u8 = null,
|
||||||
layout: PipelineLayout,
|
layout: ?PipelineLayout,
|
||||||
vertex: VertexState,
|
vertex: VertexState,
|
||||||
primitive: PrimitiveState,
|
primitive: PrimitiveState,
|
||||||
depth_stencil: *const DepthStencilState,
|
depth_stencil: ?*const DepthStencilState,
|
||||||
multisample: MultisampleState,
|
multisample: MultisampleState,
|
||||||
fragment: *const FragmentState,
|
fragment: *const FragmentState,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ pub const ProgrammableStageDescriptor = struct {
|
||||||
label: ?[*:0]const u8 = null,
|
label: ?[*:0]const u8 = null,
|
||||||
module: ShaderModule,
|
module: ShaderModule,
|
||||||
entry_point: [*:0]const u8,
|
entry_point: [*:0]const u8,
|
||||||
constants: []const ConstantEntry,
|
constants: ?[]const ConstantEntry,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const ComputePassTimestampWrite = struct {
|
pub const ComputePassTimestampWrite = struct {
|
||||||
|
|
@ -119,15 +119,15 @@ pub const RenderPassColorAttachment = struct {
|
||||||
pub const VertexState = struct {
|
pub const VertexState = struct {
|
||||||
module: ShaderModule,
|
module: ShaderModule,
|
||||||
entry_point: [*:0]const u8,
|
entry_point: [*:0]const u8,
|
||||||
constants: []const ConstantEntry,
|
constants: ?[]const ConstantEntry = null,
|
||||||
buffers: []const VertexBufferLayout,
|
buffers: ?[]const VertexBufferLayout = null,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const FragmentState = struct {
|
pub const FragmentState = struct {
|
||||||
module: ShaderModule,
|
module: ShaderModule,
|
||||||
entry_point: [*:0]const u8,
|
entry_point: [*:0]const u8,
|
||||||
constants: []const ConstantEntry,
|
constants: ?[]const ConstantEntry = null,
|
||||||
targets: []const ColorTargetState,
|
targets: ?[]const ColorTargetState = null,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const ColorTargetState = extern struct {
|
pub const ColorTargetState = extern struct {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue