Render pipeline error wgpu

let render_pipeline_layout = device.create_pipeline_layout(&PipelineLayoutDescriptor {
            label: None,
            bind_group_layouts: &[Some(&default_bgl), Some(&camera_bgl)],
            immediate_size: 0,
        });

        let shader = device.create_shader_module(include_wgsl!("shaders/shader.wgsl"));

        let render_pipeline = device.create_render_pipeline(&RenderPipelineDescriptor {
            label: None,
            layout: Some(&render_pipeline_layout),
            vertex: VertexState {
                module: &shader,
                entry_point: Some("vs_main"),
                buffers: &[],
                compilation_options: PipelineCompilationOptions::default(),
            },
            fragment: Some(FragmentState {
                // 3.
                module: &shader,
                entry_point: Some("fs_main"),
                targets: &[Some(ColorTargetState {
                    // 4.
                    format: config.format,
                    blend: Some(BlendState::REPLACE),
                    write_mask: ColorWrites::ALL,
                })],
                compilation_options: PipelineCompilationOptions::default(),
            }),
            primitive: PrimitiveState {
                topology: PrimitiveTopology::TriangleList, // 1.
                strip_index_format: None,
                front_face: FrontFace::Ccw, // 2.
                cull_mode: Some(Face::Back),
                // Setting this to anything other than Fill requires Features::NON_FILL_POLYGON_MODE
                polygon_mode: PolygonMode::Fill,
                // Requires Features::DEPTH_CLIP_CONTROL
                unclipped_depth: false,
                // Requires Features::CONSERVATIVE_RASTERIZATION
                conservative: false,
            },
            depth_stencil: Some(wgpu::DepthStencilState {
                format: TextureFormat::Depth32Float,
                depth_write_enabled: Some(true), // write new depth values
                depth_compare: Some(CompareFunction::Less), // closer to camera wins
                stencil: StencilState::default(),
                bias: DepthBiasState::default(),
            }),
            multisample: MultisampleState {
                count: 8,
                mask: !0,
                alpha_to_coverage_enabled: false,
            },
            multiview_mask: None,
            cache: None,
        });

thread 'main' (50701) panicked at /home/alpha/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/wgpu-30.0.1/src/backend/wgpu_core.rs:1414:26:
wgpu error: Validation Error

Caused by:
In Device::create_render_pipeline
Error matching ShaderStages(VERTEX) shader requirements against the pipeline
Shader global ResourceBinding { group: 1, binding: 1 } is not available in the pipeline layout
Binding is missing from the pipeline layout

pretty sure it's available in the pipeline layout

code please? what's the value default_bgl and &camera_bgl, and the corresponding vertex shader code?

let default_bgl = device.create_bind_group_layout(&BindGroupLayoutDescriptor {
            label: None,
            entries: &[
                BindGroupLayoutEntry {
                    binding: 0,
                    visibility: ShaderStages::VERTEX,
                    ty: BindingType::Buffer {
                        ty: BufferBindingType::Uniform,
                        has_dynamic_offset: false,
                        min_binding_size: None,
                    },
                    count: None,
                },
                BindGroupLayoutEntry {
                    binding: 1,
                    visibility: ShaderStages::VERTEX,
                    ty: BindingType::Buffer {
                        ty: BufferBindingType::Storage { read_only: true },
                        has_dynamic_offset: false,
                        min_binding_size: None,
                    },
                    count: None,
                },
            ],
        });

let camera_bgl = device.create_bind_group_layout(&BindGroupLayoutDescriptor {
            label: None,
            entries: &[BindGroupLayoutEntry {
                binding: 0,
                visibility: ShaderStages::VERTEX,
                ty: BindingType::Buffer {
                    ty: BufferBindingType::Uniform,
                    has_dynamic_offset: false,
                    min_binding_size: None,
                },
                count: None,
            }],
        });

you didn't show the shader code, but this error message is self explanatory:

your layout was created with two groups:

  • default_bgl is group 0, which has two bindings

    • binding 0 is a uniform buffer
    • binding 1 is a storage buffer (read only)
  • camera_bgl is group 1, which has only one binding:

    • binding 0 is a uniform buffer

the validation message indicates your shader references the binding of group 1 index 1, which is not available in your pipeline layout apparently.

either you forgot to include the other binding in the layout, or you have a mistake in the shader code.

Switched their positions and this is the error:

Caused by:
In Device::create_bind_group
Number of bindings in bind group descriptor (1) does not match the number of bindings defined in the bind group layout (2)

there is no bind group descriptor in wgpu so i'm confused.

a descriptor describes the actual resource you use when you create the bind group. they must match the layout of the group.

for instance, if the layout of a group has two bindings, 0 for a uniform buffer, 1 for a storage buffer, then the descriptor must have two entries, entry 0 must be a uniform buffer resource, and entry 1 must be a storage buffer resource.

yes, there is.

it is the argument to the Device::create_bind_group() method.