bevyengine / bevy

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

REGRESSION: wgpu panic `BadDisplay` after winit 0.30 on Wayland OpenGL #13923

Open inodentry opened 5 months ago

inodentry commented 5 months ago

Bevy version

I first found the bug when trying the 0.14 release candidates. I ran a git bisect and tracked down the problem to the commit which updated bevy to use winit 0.30. So all Bevy versions that are based on winit 0.30 are affected.

Bevy 0.13.x (and commits before the winit 0.30 update) are not affected.

Relevant system information

SystemInfo { os: "Linux 39 Fedora Linux Asahi Remix", kernel: "6.8.10-400.asahi.fc39.aarch64+16k", cpu: "Icestorm-M1-Pro", core_count: "10", memory: "30.9 GiB" }
AdapterInfo { name: "Apple M1 Pro (G13S C0)", vendor: 65541, device: 0, device_type: IntegratedGpu, driver: "", driver_info: "", backend: Gl }

Asahi does not have a GPU Vulkan driver yet (though probably will soon…) and this bug makes Bevy unusable.

What you did

Run any bevy app or example.

You need --features wayland and WGPU_BACKEND=gl to run Bevy on Asahi. Bevy chooses CPU Vulkan over OpenGL by default for some reason, and X11 with Gl backend does not work.

WGPU_BACKEND=gl cargo run --features wayland --example 3d_scene

What went wrong

Bevy immediately crashes with various systems in the Render schedule panicking. The panic comes from wgpu unwrapping a BadDisplay error related to calling eglMakeCurrent. Something must be going wrong with how winit and wgpu interact in Bevy.

2024-06-19T11:15:27.791229Z ERROR wgpu_hal::gles::egl: EGL 'eglMakeCurrent' code 0x3008: eglMakeCurrent
thread 'Compute Task Pool (1)' panicked at /home/iyes/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-hal-0.19.4/src/gles/egl.rs:295:14:
called `Result::unwrap()` on an `Err` value: BadDisplay
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Encountered a panic in system `bevy_render::view::window::create_surfaces`!
2024-06-19T11:15:27.794062Z ERROR wgpu_hal::gles::egl: EGL 'eglMakeCurrent' code 0x3008: eglMakeCurrent
thread 'main' panicked at /home/iyes/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-hal-0.19.4/src/gles/egl.rs:295:14:
called `Result::unwrap()` on an `Err` value: BadDisplay
Encountered a panic in system `bevy_render::render_asset::prepare_assets<bevy_render::texture::image::GpuImage>`!
2024-06-19T11:15:27.794372Z ERROR wgpu_hal::gles::egl: EGL 'eglMakeCurrent' code 0x3008: eglMakeCurrent
thread 'Compute Task Pool (0)' panicked at /home/iyes/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-hal-0.19.4/src/gles/egl.rs:295:14:
called `Result::unwrap()` on an `Err` value: BadDisplay
Encountered a panic in system `bevy_pbr::render::light::prepare_lights`!
2024-06-19T11:15:27.794516Z ERROR wgpu_hal::gles::egl: EGL 'eglMakeCurrent' code 0x3008: eglMakeCurrent
thread 'Compute Task Pool (1)' panicked at /home/iyes/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-hal-0.19.4/src/gles/egl.rs:295:14:
called `Result::unwrap()` on an `Err` value: BadDisplay
Encountered a panic in system `bevy_render::render_asset::prepare_assets<bevy_sprite::mesh2d::material::PreparedMaterial2d<bevy_sprite::mesh2d::color_material::ColorMaterial>>`!
2024-06-19T11:15:27.794976Z ERROR wgpu_hal::gles::egl: EGL 'eglMakeCurrent' code 0x3008: eglMakeCurrent
thread 'Compute Task Pool (2)' panicked at /home/iyes/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-hal-0.19.4/src/gles/egl.rs:295:14:
called `Result::unwrap()` on an `Err` value: BadDisplay
Encountered a panic in system `bevy_render::render_asset::prepare_assets<bevy_pbr::material::PreparedMaterial<bevy_pbr::pbr_material::StandardMaterial>>`!
2024-06-19T11:15:27.795235Z ERROR wgpu_hal::gles::egl: EGL 'eglMakeCurrent' code 0x3008: eglMakeCurrent
thread 'Compute Task Pool (1)' panicked at /home/iyes/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-hal-0.19.4/src/gles/egl.rs:295:14:
called `Result::unwrap()` on an `Err` value: BadDisplay
Encountered a panic in system `bevy_render::render_asset::prepare_assets<bevy_render::mesh::mesh::GpuMesh>`!
2024-06-19T11:15:27.795881Z ERROR wgpu_hal::gles::egl: EGL 'eglMakeCurrent' code 0x3008: eglMakeCurrent
thread 'main' panicked at /home/iyes/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-hal-0.19.4/src/gles/egl.rs:295:14:
called `Result::unwrap()` on an `Err` value: BadDisplay
Encountered a panic in system `bevy_render::view::prepare_view_uniforms`!
2024-06-19T11:15:27.795956Z ERROR wgpu_hal::gles::egl: EGL 'eglMakeCurrent' code 0x3008: eglMakeCurrent
thread 'Compute Task Pool (0)' panicked at /home/iyes/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-hal-0.19.4/src/gles/egl.rs:295:14:
called `Result::unwrap()` on an `Err` value: BadDisplay
Encountered a panic in system `bevy_render::globals::prepare_globals_buffer`!
2024-06-19T11:15:27.796070Z ERROR wgpu_hal::gles::egl: EGL 'eglMakeCurrent' code 0x3008: eglMakeCurrent
thread 'main' panicked at /home/iyes/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-hal-0.19.4/src/gles/egl.rs:295:14:
called `Result::unwrap()` on an `Err` value: BadDisplay
Encountered a panic in system `bevy_pbr::render::skin::prepare_skins`!
2024-06-19T11:15:27.796160Z ERROR wgpu_hal::gles::egl: EGL 'eglMakeCurrent' code 0x3008: eglMakeCurrent
thread 'Compute Task Pool (1)' panicked at /home/iyes/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-hal-0.19.4/src/gles/egl.rs:295:14:
called `Result::unwrap()` on an `Err` value: BadDisplay
2024-06-19T11:15:27.796272Z ERROR wgpu_hal::gles::egl: EGL 'eglMakeCurrent' code 0x3008: eglMakeCurrent
thread 'main' panicked at /home/iyes/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-hal-0.19.4/src/gles/egl.rs:295:14:
called `Result::unwrap()` on an `Err` value: BadDisplay
Encountered a panic in system `bevy_pbr::render::fog::prepare_fog`!
Encountered a panic in system `bevy_pbr::ssr::prepare_ssr_settings`!
2024-06-19T11:15:27.796741Z ERROR wgpu_hal::gles::egl: EGL 'eglMakeCurrent' code 0x3008: eglMakeCurrent
thread 'main' panicked at /home/iyes/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-hal-0.19.4/src/gles/egl.rs:295:14:
called `Result::unwrap()` on an `Err` value: BadDisplay
Encountered a panic in system `bevy_pbr::cluster::prepare_clusters`!
2024-06-19T11:15:27.796812Z ERROR wgpu_hal::gles::egl: EGL 'eglMakeCurrent' code 0x3008: eglMakeCurrent
thread 'Compute Task Pool (0)' panicked at /home/iyes/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-hal-0.19.4/src/gles/egl.rs:295:14:
called `Result::unwrap()` on an `Err` value: BadDisplay
2024-06-19T11:15:27.798305Z ERROR wgpu_hal::gles::egl: EGL 'eglMakeCurrent' code 0x3008: eglMakeCurrent
thread 'Compute Task Pool (1)' panicked at /home/iyes/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-hal-0.19.4/src/gles/egl.rs:295:14:
called `Result::unwrap()` on an `Err` value: BadDisplay
Encountered a panic in system `bevy_core_pipeline::core_3d::prepare_core_3d_depth_textures`!
2024-06-19T11:15:27.799596Z ERROR wgpu_hal::gles::egl: EGL 'eglMakeCurrent' code 0x3008: eglMakeCurrent
thread 'Compute Task Pool (3)' panicked at /home/iyes/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-hal-0.19.4/src/gles/egl.rs:295:14:
Encountered a panic in system `bevy_pbr::light_probe::upload_light_probes`!
called `Result::unwrap()` on an `Err` value: BadDisplay
2024-06-19T11:15:27.800186Z ERROR wgpu_hal::gles::egl: EGL 'eglMakeCurrent' code 0x3008: eglMakeCurrent
thread 'Compute Task Pool (2)' panicked at /home/iyes/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-hal-0.19.4/src/gles/egl.rs:295:14:
called `Result::unwrap()` on an `Err` value: BadDisplay
Encountered a panic in system `bevy_render::view::visibility::range::write_render_visibility_ranges`!
Encountered a panic in system `bevy_render::batching::gpu_preprocessing::write_batched_instance_buffers<bevy_pbr::render::mesh::MeshPipeline>`!
2024-06-19T11:15:27.800911Z ERROR wgpu_hal::gles::egl: EGL 'eglMakeCurrent' code 0x3008: eglMakeCurrent
thread 'Compute Task Pool (3)' panicked at /home/iyes/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-hal-0.19.4/src/gles/egl.rs:295:14:
called `Result::unwrap()` on an `Err` value: BadDisplay
Encountered a panic in system `bevy_sprite::render::prepare_sprite_image_bind_groups`!
2024-06-19T11:15:27.802199Z ERROR wgpu_hal::gles::egl: EGL 'eglMakeCurrent' code 0x3008: eglMakeCurrent
thread '<unnamed>' panicked at /home/iyes/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-hal-0.19.4/src/gles/egl.rs:295:14:
called `Result::unwrap()` on an `Err` value: BadDisplay
Encountered a panic in system `bevy_render::renderer::render_system`!

Additional Information

winit 0.30.2 is broken on aarch64 and does not compile. winit 0.30.0, 0.30.1, and git main, compile successfully. You have to force cargo to use one of those versions, in order to compile bevy successfully and to reproduce this bug.

Friz64 commented 5 months ago

FWIW I can reproduce this exact same behavior on x86. This is https://github.com/gfx-rs/wgpu/issues/5505.

Stazis555 commented 4 months ago

Reproduced on nixos x86 with AMD graphiscs. I am using a dev-shell so adding vulkan-loader to the derivation allowed bevy to use vulkan and fixed the issue.

MarouaneMebarki commented 3 months ago

SystemInfo { os: "Linux 23.10 Ubuntu", kernel: "6.5.0-44-generic", cpu: "Intel(R) Core(TM) i5-2400 CPU @ 3.10GHz", core_count: "4", memory: "11.5 GiB" } AdapterInfo { name: "Mesa Intel(R) HD Graphics 2000 (SNB GT1)", vendor: 32902, device: 0, device_type: IntegratedGpu, driver: "OpenGL", driver_info: "3.3 (Compatibility Profile) Mesa 23.2.1-1ubuntu3.1", backend: Gl }

by default : cargo run --example 3d_gizmo

bevy choose : --features x11 WGPU_BACKEND=gl

what works for me : WGPU_BACKEND=vulkan cargo run --features wayland --example 3d_gizmos

with a terrible performance and this warning : WARN bevy_render::renderer: The selected adapter is using a driver that only supports software rendering. This is likely to be very slow. See https://bevyengine.org/learn/errors/b0006/

MeoMix commented 3 months ago

SystemInfo { os: "Linux 23.10 Ubuntu", kernel: "6.5.0-44-generic", cpu: "Intel(R) Core(TM) i5-2400 CPU @ 3.10GHz", core_count: "4", memory: "11.5 GiB" } AdapterInfo { name: "Mesa Intel(R) HD Graphics 2000 (SNB GT1)", vendor: 32902, device: 0, device_type: IntegratedGpu, driver: "OpenGL", driver_info: "3.3 (Compatibility Profile) Mesa 23.2.1-1ubuntu3.1", backend: Gl }

by default : cargo run --example 3d_gizmo

bevy choose : --features x11 WGPU_BACKEND=gl

what works for me : WGPU_BACKEND=vulkan cargo run --features wayland --example 3d_gizmos

with a terrible performance and this warning : WARN bevy_render::renderer: The selected adapter is using a driver that only supports software rendering. This is likely to be very slow. See https://bevyengine.org/learn/errors/b0006/

I would try this and see if it resolves the issue for you:

sudo add-apt-repository ppa:kisak/kisak-mesa
sudo apt-get update
sudo apt-get upgrade

I was having a similar issue when using an NVIDIA GPU + Vulkan (although I was falling back to llvmpipe) and the solution was to install newer mesa drivers.

MarouaneMebarki commented 3 months ago

sudo add-apt-repository ppa:kisak/kisak-mesa sudo apt-get update sudo apt-get upgrade

I think my device primarily supports Opengl vulkan works terribly.

I did update the mesa drivers although my Ubuntu version is 23.10 kisak-mesa supported versions: `--- Support status ---

Bionic (18.04) - Discontinued - Long term users can use kisak-mesa stable Focal (20.04) - Supported Jammy (22.04) - Supported Mantic (23.10) - End of Life (Removal after 2024-08-14) Noble (24.04) - Preliminary support (Not tested locally) ` and still getting the issue :

ERROR wgpu_hal::gles::egl: EGL 'eglMakeCurrent' code 0x3008: eglMakeCurrent thread 'Compute Task Pool (1)' panicked at /home/marwan/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-hal-0.21.1/src/gles/egl.rs:296:14: calledResult::unwrap()on anErrvalue: BadDisplay note: run withRUST_BACKTRACE=1environment variable to display a backtrace Encountered a panic in systembevy_render::view::window::create_surfaces!