Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shader_prepass example crashes with opaque CustomMaterial #8273

Closed
TesseractCat opened this issue Mar 31, 2023 · 3 comments · Fixed by #8330
Closed

shader_prepass example crashes with opaque CustomMaterial #8273

TesseractCat opened this issue Mar 31, 2023 · 3 comments · Fixed by #8330
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior C-Examples An addition or correction to our examples P-Crash A sudden unexpected crash

Comments

@TesseractCat
Copy link

TesseractCat commented Mar 31, 2023

Bevy version

release-0.10.0 (also get the same crash on main).

Relevant system information

`AdapterInfo { name: "NVIDIA GeForce RTX 2060 with Max-Q Design", vendor: 4318, device: 7954, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "526.86", backend: Vulkan }`

What you did

I modified the shader_prepass example so that the CustomMaterial was AlphaMode::Opaque rather than AlphaMode::Blend.

diff --git a/examples/shader/shader_prepass.rs b/examples/shader/shader_prepass.rs
index 688152c5..ae85d681 100644
--- a/examples/shader/shader_prepass.rs
+++ b/examples/shader/shader_prepass.rs
@@ -109,7 +109,7 @@ fn setup(
         material: materials.add(CustomMaterial {
             color: Color::WHITE,
             color_texture: Some(asset_server.load("branding/icon.png")),
-            alpha_mode: AlphaMode::Blend,
+            alpha_mode: AlphaMode::Opaque,
         }),
         transform: Transform::from_xyz(1.0, 0.5, 0.0),
         ..default()

What went wrong

Bevy crashes. With other testing it appears the issue only happens when the camera is looking at the object with the custom material.

Additional information

2023-03-31T07:35:36.907647Z  INFO bevy_winit::system: Creating new window "Bevy App" (0v0)
2023-03-31T07:35:39.202777Z  INFO bevy_render::renderer: AdapterInfo { name: "NVIDIA GeForce RTX 2060 with Max-Q Design", vendor: 4318, device: 7954, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "526.86", backend: Vulkan }
2023-03-31T07:35:40.722993Z  INFO bevy_diagnostic::system_information_diagnostics_plugin::internal: SystemInfo { os: "Windows 10 Home", kernel: "18363", cpu: "AMD Ryzen 9 4900HS with Radeon Graphics", core_count: "8", memory: "15.4 GiB" }
2023-03-31T07:35:41.512883Z  INFO naga::back::spv::writer: Skip function Some("calculate_view")
2023-03-31T07:35:41.553574Z ERROR wgpu::backend::direct: Handling wgpu errors as fatal by default
thread 'Compute Task Pool (7)' panicked at 'wgpu error: Validation Error

Caused by:
    In Device::create_render_pipeline
      note: label = `prepass_pipeline`
    error matching FRAGMENT shader requirements against the pipeline
    location[0] is provided by the previous stage output but is not consumed as input by this stage.

', C:\Users\Tesse\scoop\persist\rustup\.cargo\registry\src\github.com-1ecc6299db9ec823\wgpu-0.15.1\src\backend\direct.rs:3024:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'Compute Task Pool (7)' panicked at 'A system has panicked so the executor cannot continue.: RecvError', crates\bevy_ecs\src\schedule\executor\multi_threaded.rs:194:60
thread '<unnamed>' panicked at 'called `Option::unwrap()` on a `None` value', C:\Users\Tesse\Desktop\Bevy Games\bevy\crates\bevy_tasks\src\task_pool.rs:376:49
thread 'Compute Task Pool (7)' panicked at 'called `Result::unwrap()` on an `Err` value: RecvError', crates\bevy_render\src\pipelined_rendering.rs:136:45
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', C:\Users\Tesse\Desktop\Bevy Games\bevy\crates\bevy_tasks\src\task_pool.rs:376:49
@TesseractCat TesseractCat added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Mar 31, 2023
@james7132 james7132 added A-Rendering Drawing game state to the screen C-Examples An addition or correction to our examples P-Crash A sudden unexpected crash and removed S-Needs-Triage This issue needs to be labelled labels Mar 31, 2023
@TesseractCat
Copy link
Author

I found this interaction on the discord: https://discord.com/channels/691052431525675048/866787577687310356/1077982198331867166. Not sure why this is necessary though.

@TesseractCat
Copy link
Author

Okay, I'm pretty sure the issue is that the default vertex prepass shader isn't consuming location[0]

struct FragmentInput {
#ifdef NORMAL_PREPASS
@location(1) world_normal: vec3<f32>,
#endif // NORMAL_PREPASS
#ifdef MOTION_VECTOR_PREPASS
@location(3) world_position: vec4<f32>,
@location(4) previous_world_position: vec4<f32>,
#endif // MOTION_VECTOR_PREPASS
}
, which is why this happens with custom materials. The pbr_prepass shader does consume it though,
struct FragmentInput {
@builtin(front_facing) is_front: bool,
@builtin(position) frag_coord: vec4<f32>,
#ifdef VERTEX_UVS
@location(0) uv: vec2<f32>,
#endif // VERTEX_UVS
. I assume the UV location isn't defined when AlphaMode is blend, which causes this problem only with opaque materials. Not sure if this is intentional.

@josfeenstra
Copy link
Contributor

josfeenstra commented Apr 28, 2023

Thanks for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior C-Examples An addition or correction to our examples P-Crash A sudden unexpected crash
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants