Using more than one `VertexBufferLayout` generates wrong attribute locations in the `RenderPipelineDescriptor`
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## Bevy version
v0.7.0
b9102b8836bd2aa07df2732f5364b9ac90accb66 (haven't tested yet but looking at the code the bug should still exist)
## Operating system & version
Linux arch 5.17.5-arch1-1
## What you did
```rust
let vertex_layout = VertexBufferLayout::from_vertex_formats(
VertexStepMode::Vertex,
[VertexFormat::Float32x3, VertexFormat::Float32x2], // position, uv
);
let instance_layout = VertexBufferLayout::from_vertex_formats(
VertexStepMode::Instance,
// transform
[VertexFormat::Float32x4, VertexFormat::Float32x4, VertexFormat::Float32x4, VertexFormat::Float32x4],
);
RenderPipelineDescriptor {
vertex: VertexState {
shader: self.chunk_shader.as_weak(),
entry_point: "vertex".into(),
shader_defs: Vec::default(),
buffers: vec![vertex_layout, instance_layout],
},
...
}
```
```wgsl
struct VertexInput {
[[location(0)]] position: vec3;
[[location(1)]] uv: vec2;
};
struct Transform {
[[location(2)]] row_0: vec4;
[[location(3)]] row_1: vec4;
[[location(4)]] row_2: vec4;
[[location(5)]] row_3: vec4;
};
```
## What you expected to happen
The pipeline to be created successfully.
## What actually happened
The pipeline fails validation with the following error:
```
Finished dev [optimized + debuginfo] target(s) in 9.34s
Running `target/debug/examples/minimal`
2022-04-30T04:41:41.033552Z INFO winit::platform_impl::platform::x11::window: Guessed window scale factor: 1
2022-04-30T04:41:41.159530Z INFO bevy_render::renderer: AdapterInfo { name: "NVIDIA GeForce GTX 1060", vendor: 4318, device: 7200, device_type: DiscreteGpu, backend: Vulkan }
2022-04-30T04:41:41.436149Z ERROR wgpu::backend::direct: Handling wgpu errors as fatal by default
thread 'main' panicked at 'wgpu error: Validation Error
Caused by:
In Device::create_render_pipeline
note: label = `custom_pipeline`
error matching VERTEX shader requirements against the pipeline
location[4] Float32x4 interpolated as Some(Perspective) with sampling Some(Center) is not provided by the previous stage outputs
input is not provided by the earlier stage in the pipeline
```
## Additional information
```rust
let mut instance_layout = ... ;
instance_layout
.attributes
.iter_mut()
.for_each(|attr| attr.shader_location += 2); // +2 because vertex_layout has two attributes
```
The above change in my code allows the pipeline to be created successfully.
Also relevant bevy code: https://github.com/bevyengine/bevy/blob/b9102b8836bd2aa07df2732f5364b9ac90accb66/crates/bevy_render/src/render_resource/pipeline_cache.rs#L397-L406
Contributor guide
Assessment
This issue has not been assessed yet.