bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
36.67k stars 3.61k forks source link

Crash on macOS, related to ExtendedMaterial and custom vertex buffer layout #16588

Open splashdust opened 1 day ago

splashdust commented 1 day ago

Bevy version

0.15

[Optional] Relevant system information

Rust version: 1.83

SystemInfo { os: "MacOS 15.1.1 ", kernel: "24.1.0", cpu: "Apple M1 Max", core_count: "10", memory: "64.0 GiB" }
AdapterInfo { name: "Apple M1 Max", vendor: 0, device: 0, device_type: IntegratedGpu, driver: "", driver_info: "", backend: Metal }

Problem

Since updating to Bevy 0.15, my plugin no longer runs on macOS. The plugin is using ExtendedMaterial with a custom shader and one extra vertex attribute.

The application crashes immediately on startup with the following error:

thread 'Compute Task Pool (0)' panicked at /Users/joacim/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-23.0.1/src/backend/wgpu_core.rs:1102:18:
wgpu error: Validation Error

Caused by:
  In Device::create_render_pipeline, label = 'pbr_prepass_pipeline'
    Internal error in ShaderStages(VERTEX) shader: Metal: program_source:252:14: error:  from vector 'metal::float3' (aka 'float3') to vector 'metal::float2' (aka 'float2') of different size
        uv = metal::float2(unpackFloat32x3_(vb_15_elem.data[12], vb_15_elem.data[13], vb_15_elem.data[14], vb_15_elem.data[15], vb_15_elem.data[16], vb_15_elem.data[17], vb_15_elem.data[18], vb_15_elem.data[19], vb_15_elem.data[20], vb_15_elem.data[21], vb_15_elem.data[22], vb_15_elem.data[23]));
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Encountered a panic in system `bevy_render::render_resource::pipeline_cache::PipelineCache::process_pipeline_queue_system`!
thread '<unnamed>' panicked at /Users/joacim/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_render-0.15.0/src/render_resource/pipeline_cache.rs:546:28:
index out of bounds: the len is 0 but the index is 6
Encountered a panic in system `bevy_render::renderer::render_system`!

It looks like some UVs are being supplied to the shader as vec3 instead of vec2, and I can't figure out why. When the mesh is created, I'm only inserting [f32; 2] UV entries.

Other than that, I haven't been able to isolate the problem, but it goes away if I just remove the UV data from the mesh and buffer layout. Also, it seems to be related to ExtendedMaterial, because using a different material with the same meshes and layout works, so I think the issue is happening in the pbr pipeline.

It's possible that the error is somewhere in my code, but the fact that it only happens on macOS (with metal backend) causes me to suspect that it's an upstream issue. I was not able to reproduce the issue in Bevys extended_material example though, so it's likely being caused by some combination of things.

Additional information

The issue can be reproduced by running the noise_terrain example (or any example except custom_material) in https://github.com/splashdust/bevy_voxel_world

The custom_material example does not use ExtendedMaterial and does not cause the error to happen.

Touma-Kazusa2 commented 6 hours ago

when I use bevy_voxel_world plugin with Bevy's SSAO,it crash too.(Windows platform)

2024-12-02T16:31:44.652852Z ERROR wgpu_core::device::global: Device::create_render_pipeline error: Error matching ShaderStages(VERTEX) shader requirements against the pipeline
2024-12-02T16:31:44.653235Z ERROR wgpu::backend::wgpu_core: Handling wgpu errors as fatal by default
thread 'Async Compute Task Pool (0)' panicked at /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-23.0.1/src/backend/wgpu_core.rs:1102:18:
wgpu error: Validation Error

Caused by:
  In Device::create_render_pipeline, label = 'pbr_prepass_pipeline'
    Error matching ShaderStages(VERTEX) shader requirements against the pipeline
      Location[3] Float32x3 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

note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Encountered a panic in system `bevy_render::render_resource::pipeline_cache::PipelineCache::process_pipeline_queue_system`!
thread '<unnamed>' panicked at /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_render-0.15.0/src/render_resource/pipeline_cache.rs:580:28:
index out of bounds: the len is 0 but the index is 11
Encountered a panic in system `bevy_render::renderer::render_system`!

I want read the vertex shader in the pbr_prepass_pipeline,but I don't know how to find it,Does anybody can teach me?