pub fn create_default_render_pipeline(
    label: &str,
    device: &Device,
    fragment_shader: &str,
    bindings: Vec<BindingDesc>,
    push_constants_size: usize,
) -> (RenderPipeline, BindGroup) {
    let quad_shader = quad_shader(device);

    let fragment_shader = device.create_shader_module(&ShaderModuleDescriptor {
        label: Some(label),
        source: ShaderSource::Wgsl(fragment_shader.into()),
    });

    let layout_entries = bindings
        .iter()
        .map(|binding| BindGroupLayoutEntry {
            binding: binding.index,
            visibility: ShaderStages::FRAGMENT,
            ty: binding.binding_type,
            count: binding
                .array_size
                .map(|size| NonZeroU32::new(size as _).unwrap()),
        })
        .collect::<Vec<_>>();

    let bind_group_layout = device.create_bind_group_layout(&BindGroupLayoutDescriptor {
        label: Some(label),
        entries: &layout_entries,
    });

    let pipeline_layout = device.create_pipeline_layout(&PipelineLayoutDescriptor {
        label: Some(label),
        bind_group_layouts: &[&bind_group_layout],
        push_constant_ranges: &[PushConstantRange {
            stages: ShaderStages::FRAGMENT,
            range: 0..push_constants_size as _,
        }],
    });

    let pipeline = device.create_render_pipeline(&RenderPipelineDescriptor {
        label: Some(label),
        layout: Some(&pipeline_layout),
        vertex: VertexState {
            module: &quad_shader,
            entry_point: "main",
            buffers: &[],
        },
        primitive: Default::default(),
        depth_stencil: None,
        multisample: MultisampleState::default(),
        fragment: Some(FragmentState {
            module: &fragment_shader,
            entry_point: "main",
            targets: &[ColorTargetState {
                format: TARGET_FORMAT,
                blend: None,
                write_mask: ColorWrites::ALL,
            }],
        }),
        multiview: None,
    });

    let bind_group_entries = bindings
        .into_iter()
        .map(|binding| BindGroupEntry {
            binding: binding.index,
            resource: binding.resource,
        })
        .collect::<Vec<_>>();

    let bind_group = device.create_bind_group(&BindGroupDescriptor {
        label: Some(label),
        layout: &pipeline.get_bind_group_layout(0),
        entries: &bind_group_entries,
    });

    (pipeline, bind_group)
}
// All bindings map to the bind group 0
All bindings map to the bind group 0
All bindings map to the bind group 0
pub fn create_default_render_pipeline(
    label: &str,
    device: &Device,
    fragment_shader: &str,
    bindings: Vec<BindingDesc>,
    push_constants_size: usize,
) -> (RenderPipeline, BindGroup) {
    let quad_shader = quad_shader(device);
    let fragment_shader = device.create_shader_module(&ShaderModuleDescriptor {
        label: Some(label),
        source: ShaderSource::Wgsl(fragment_shader.into()),
    });
    let layout_entries = bindings
        .iter()
        .map(|binding| BindGroupLayoutEntry {
            binding: binding.index,
            visibility: ShaderStages::FRAGMENT,
            ty: binding.binding_type,
            count: binding
                .array_size
                .map(|size| NonZeroU32::new(size as _).unwrap()),
        })
        .collect::<Vec<_>>();
    let bind_group_layout = device.create_bind_group_layout(&BindGroupLayoutDescriptor {
        label: Some(label),
        entries: &layout_entries,
    });
    let pipeline_layout = device.create_pipeline_layout(&PipelineLayoutDescriptor {
        label: Some(label),
        bind_group_layouts: &[&bind_group_layout],
        push_constant_ranges: &[PushConstantRange {
            stages: ShaderStages::FRAGMENT,
            range: 0..push_constants_size as _,
        }],
    });
    let pipeline = device.create_render_pipeline(&RenderPipelineDescriptor {
        label: Some(label),
        layout: Some(&pipeline_layout),
        vertex: VertexState {
            module: &quad_shader,
            entry_point: "main",
            buffers: &[],
        },
        primitive: Default::default(),
        depth_stencil: None,
        multisample: MultisampleState::default(),
        fragment: Some(FragmentState {
            module: &fragment_shader,
            entry_point: "main",
            targets: &[ColorTargetState {
                format: TARGET_FORMAT,
                blend: None,
                write_mask: ColorWrites::ALL,
            }],
        }),
        multiview: None,
    });
    let bind_group_entries = bindings
        .into_iter()
        .map(|binding| BindGroupEntry {
            binding: binding.index,
            resource: binding.resource,
        })
        .collect::<Vec<_>>();
    let bind_group = device.create_bind_group(&BindGroupDescriptor {
        label: Some(label),
        layout: &pipeline.get_bind_group_layout(0),
        entries: &bind_group_entries,
    });
    (pipeline, bind_group)
}
pub fn create_default_render_pipeline ( label : & str , device : & Device , fragment_shader : & str , bindings : Vec < BindingDesc > , push_constants_size : usize , ) -> ( RenderPipeline , BindGroup ) { let quad_shader = quad_shader ( device ) ; let fragment_shader = device . create_shader_module ( & ShaderModuleDescriptor { label : Some ( label ) , source : ShaderSource :: Wgsl ( fragment_shader . into ( ) ) , } ) ; let layout_entries = bindings . iter ( ) . map ( | binding | BindGroupLayoutEntry { binding : binding . index , visibility : ShaderStages :: FRAGMENT , ty : binding . binding_type , count : binding . array_size . map ( | size | NonZeroU32 :: new ( size as _ ) . unwrap ( ) ) , } ) . collect :: < Vec < _ > > ( ) ; let bind_group_layout = device . create_bind_group_layout ( & BindGroupLayoutDescriptor { label : Some ( label ) , entries : & layout_entries , } ) ; let pipeline_layout = device . create_pipeline_layout ( & PipelineLayoutDescriptor { label : Some ( label ) , bind_group_layouts : & [ & bind_group_layout ] , push_constant_ranges : & [ PushConstantRange { stages : ShaderStages :: FRAGMENT , range : 0 .. push_constants_size as _ , } ] , } ) ; let pipeline = device . create_render_pipeline ( & RenderPipelineDescriptor { label : Some ( label ) , layout : Some ( & pipeline_layout ) , vertex : VertexState { module : & quad_shader , entry_point : " " , buffers : & [ ] , } , primitive : Default :: default ( ) , depth_stencil : None , multisample : MultisampleState :: default ( ) , fragment : Some ( FragmentState { module : & fragment_shader , entry_point : " " , targets : & [ ColorTargetState { format : TARGET_FORMAT , blend : None , write_mask : ColorWrites :: ALL , } ] , } ) , multiview : None , } ) ; let bind_group_entries = bindings . into_iter ( ) . map ( | binding | BindGroupEntry { binding : binding . index , resource : binding . resource , } ) . collect :: < Vec < _ > > ( ) ; let bind_group = device . create_bind_group ( & BindGroupDescriptor { label : Some ( label ) , layout : & pipeline . get_bind_group_layout ( 0 ) , entries : & bind_group_entries , } ) ; ( pipeline , bind_group ) }
All bindings map to the bind group 0
All bindings map to the bind group 0
label
&str
device
&Device
fragment_shader
&str
bindings
Vec<BindingDesc>
push_constants_size
usize