macro_rules! pipeline {
{ @texturefmt $inputfmt:ident , ANY } => { ... };
{ @texturefmt $format:ident , $fragmentfmt:ident } => { ... };
{ $struct:ident {
bind_groups : [
$( $bindgroupnum:tt => $bindgroup:ty ),* $(,)?
],
vertex_types: [
$( $vertexnum:tt => $vertexty:ty ),* $(,)?
],
fragment_targets: [
$( $fragmentnum:tt => $blend:ident $mask:ident as $fragmentfmt:ident ),* $(,)?
],
immediate_size: $immediate:expr,
depth: $depthfmt:expr,
cull: $cull:expr,
} } => { ... };
}Expand description
Define a render pipeline, with internal bind group and vertex types.
bind_group needs to be a numbered list of crate::bindgroup types,
mirrored in the shader.
vertex_types must be another numbered list of crate::vertexstructs.
These are the allowed types of vertex formats for the shader (I’m not sure
why you would have multiple entries but wgpu allows it so whatever).
fragment_targets is in the format
wgpu::BlendState wgpu::ColorWrites as .
The ANY/wgpu::TextureFormatwgpu::ColorTargetState will be Some if the pipeline is built with
the same format specified here, or if it’s ANY then always Some with
the format it’s built with - otherwise it’s a None entry in the slice.
(tbh idk what the purpose of having multiple fragment targets is but I assume
it’s supposed be used something like this)
immediate_size is the length of the
immediate buffer
in the wgpu::PipelineLayoutDescriptor.
depth is an
Option<wgpu::TextureFormat>
to use in the wgpu::DepthStencilState.
Said DepthStencilState comes default with depth_write_enabled = true,
depth_compare = wgpu::CompareFunction::Less,
and default stencil and bias.
cull is the cull face, an Option<wgpu::Face>.
The pipeline comes with some other defaults set (like 0 mipmaps), but there
are quite a few things to define, so to simplify the macro I’ve picked out
the most important things. If you really need to change them, copy the
source of this macro into your own struct and implement MewPipeline
yourself you lazy bastard.
pipeline! { Pipeline {
bind_groups: [
0 => BindGroup,
1 => AnotherBindGroup,
],
vertex_types: [
0 => Vertex,
],
fragment_targets: [
0 => ALPHA_BLENDING ALL as ANY,
],
immediate_size: 0,
depth: None,
cull: Some(Front),
} }
let pipeline: Pipeline = render_context.new_pipeline(wgpu::Rgba8Unorm, shader, None, None);
render_pass.set_pipeline(&pipeline);