Wgpu validation error with light and custom material
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 171
Description
## Bevy version
0.11.3
## Relevant system information
```ignore
AdapterInfo { name: "NVIDIA GeForce GTX 1050 Ti", vendor: 4318, device: 7298, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "537.34", backend: Vulkan }
```
## What you did
Create a project with a custom material (vertex and fragment shaders) and a light
## What went wrong
The application crashed with a wgpu validation error
## Additional information
The `shader_material_screenspace_texture` works fine and have point Light and custom material (only fragment shader)
Other dependencies:
- bevy_editor_pls
- color-backtrace
- bevy_screen_diagnositcs
- bevy_rapier_2d
- bevy_shader_utils
Shader:
```wgsl
#import bevy_pbr::mesh_bindings mesh
#import bevy_pbr::mesh_functions mesh_position_local_to_clip
#import bevy_pbr::mesh_view_bindings globals
#import bevy_shader_utils::simplex_noise_2d simplex_noise_2d
struct VertexIn {
@location(0) position: vec3,
}
struct VertexOut {
@builtin(position) position: vec4,
@location(0) height: f32,
}
@vertex
fn vertex(in: VertexIn) -> VertexOut {
var out: VertexOut;
out.height = height(in.position.xz);
out.position = mesh_position_local_to_clip(
mesh.model,
vec4(
in.position.x,
in.position.y + out.height,
in.position.z,
1.0
)
);
return out;
}
struct FragmentIn {
@location(0) height: f32,
}
@fragment
fn fragment(in: FragmentIn) -> @location(0) vec4 {
return mix(
vec4(129.0 / 255.0, 192.0 / 255.0, 240.0 / 255.0, 1.0),
vec4(26.0 / 255.0, 146.0 / 255.0, 237.0 / 255.0, 1.0),
in.height
);
}
fn height(position: vec2) -> f32 {
return simplex_noise_2d(
position + vec2(globals.time, globals.time) * 0.3
);
}
```
Material:
```rust
#[derive(AsBindGroup, TypePath, TypeUuid, Clone)]
#[uuid = "dd271efa-de36-45ae-a742-915b00b01e55"]
struct WaterMaterial {}
impl Material for WaterMaterial {
fn vertex_shader() -> ShaderRef {
"shaders/water.wgsl".into()
}
fn fragment_shader() -> ShaderRef {
"shaders/water.wgsl".into()
}
fn alpha_mode(&self) -> AlphaMode {
AlphaMode::Blend
}
fn specialize(
_pipeline: &MaterialPipeline,
descriptor: &mut RenderPipelineDescriptor,
layout: &MeshVertexBufferLayout,
_key: MaterialPipelineKey,
) -> Result<(), SpecializedMeshPipelineError> {
let vertex_layout = layout.get_layout(&[Mesh::ATTRIBUTE_POSITION.at_shader_location(0)])?;
descriptor.vertex.buffers = vec![vertex_layout];
Ok(())
}
}
```
MeshMaterial:
```rust
commands.spawn(MaterialMeshBundle {
mesh: meshes.add(
shape::Plane {
size: 100.0,
subdivisions: 10,
}
.into(),
),
material: materials.add(WaterMaterial {}),
transform: Transform::from_xyz(0.0, 0.0, 0.0),
..Default::default()
});
```
PointLight:
```rust
commands.spawn(PointLightBundle {
point_light: PointLight {
color: Color::WHITE,
intensity: 1000.0,
range: 30.0,
radius: 0.5,
shadows_enabled: true,
..Default::default()
},
transform: Transform::from_xyz(0.0, 10.0, 0.0),
..Default::default()
});
```
Logs:
```
2023-09-30T16:59:37.230068Z INFO bevy_winit::system: Creating new window "App" (0v0)
2023-09-30T16:59:37.648091Z INFO bevy_render::renderer: AdapterInfo { name: "NVIDIA GeForce GTX 1050 Ti", vendor: 4318, device: 7298, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "537.34", backend: Vulkan }
2023-09-30T16:59:37.726248Z INFO bevy_editor_pls_default_windows::cameras: Spawning editor cameras
2023-09-30T16:59:37.729229Z INFO bevy_input::gamepad: Gamepad { id: 0 } Connected
2023-09-30T16:59:38.962692Z ERROR wgpu::backend::direct: Handling wgpu errors as fatal by default
The application panicked (crashed).
Message: wgpu error: Validation Error
Caused by:
In Device::create_render_pipeline
note: label = `prepass_pipeline`
Error matching ShaderStages(VERTEX) shader requirements against the pipeline
Location[1] Float32x2 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
Location: D:\Dev\Tools\Rust\cargo\registry\src\index.crates.io-6f17d22bba15001f\wgpu-0.16.3\src\backend\direct.rs:3019
Backtrace omitted.
Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.
Encountered a panic in system `bevy_render::render_resource::pipeline_cache::PipelineCache::process_pipeline_queue_system`!
The application panicked (crashed).
Message: called `Result::unwrap()` on an `Err` value: RecvError
Location: D:\Dev\Tools\Rust\cargo\registry\src\index.crates.io-6f17d22bba15001f\bevy_render-0.11.3\src\pipelined_rendering.rs:143
Backtrace omitted.
Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.
error: process didn't exit successfully: `target\debug\bevy_template.exe` (exit code: 101)`
```
Contributor guide
Research direction
Start by reproducing the issue with the shown Bevy 0.11.3 WaterMaterial, shader, plane, and PointLight setup, then inspect the `prepass_pipeline` validation failure and `bevy_render::pipelined_rendering.rs:143`. Trace how `Material::specialize` and the shader stage interfaces are used when a light is present. Done means the example no longer panics on pipeline creation and the material renders with the light.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- computer-graphics, game-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100