gpu: make RenderPipeline.fragment optional (#212)

pipeline with vertex stage only is perfectly valid

Helps hexops/mach#182
This commit is contained in:
Michal Ziulek 2022-04-10 19:30:34 +02:00 committed by GitHub
parent d0782d24d1
commit a943fbed3e
Failed to generate hash of commit
2 changed files with 13 additions and 11 deletions

View file

@ -807,15 +807,17 @@ inline fn convertRenderPipelineDescriptor(
};
}
tmp_fragment_state.* = c.WGPUFragmentState{
.nextInChain = null,
.module = @ptrCast(c.WGPUShaderModule, d.fragment.module.ptr),
.entryPoint = d.vertex.entry_point,
.constantCount = if (d.fragment.constants) |v| @intCast(u32, v.len) else 0,
.constants = if (d.fragment.constants) |v| @ptrCast([*]const c.WGPUConstantEntry, v.ptr) else null,
.targetCount = if (d.fragment.targets) |v| @intCast(u32, v.len) else 0,
.targets = if (d.fragment.targets) |v| @ptrCast([*]const c.WGPUColorTargetState, v.ptr) else null,
};
if (d.fragment) |frag| {
tmp_fragment_state.* = c.WGPUFragmentState{
.nextInChain = null,
.module = @ptrCast(c.WGPUShaderModule, frag.module.ptr),
.entryPoint = frag.entry_point,
.constantCount = if (frag.constants) |v| @intCast(u32, v.len) else 0,
.constants = if (frag.constants) |v| @ptrCast([*]const c.WGPUConstantEntry, v.ptr) else null,
.targetCount = if (frag.targets) |v| @intCast(u32, v.len) else 0,
.targets = if (frag.targets) |v| @ptrCast([*]const c.WGPUColorTargetState, v.ptr) else null,
};
}
return c.WGPURenderPipelineDescriptor{
.nextInChain = null,
@ -844,7 +846,7 @@ inline fn convertRenderPipelineDescriptor(
.mask = d.multisample.mask,
.alphaToCoverageEnabled = d.multisample.alpha_to_coverage_enabled,
},
.fragment = tmp_fragment_state,
.fragment = if (d.fragment != null) tmp_fragment_state else null,
};
}

View file

@ -43,7 +43,7 @@ pub const Descriptor = struct {
primitive: PrimitiveState,
depth_stencil: ?*const DepthStencilState,
multisample: MultisampleState,
fragment: *const FragmentState,
fragment: ?*const FragmentState,
};
pub const CreateStatus = enum(u32) {