gfx-rs / wgpu

A cross-platform, safe, pure-Rust graphics API.
https://wgpu.rs
Apache License 2.0
12.68k stars 928 forks source link

No EGL_DEFAULT_DISPLAY on GL Backend + Wayland (Vivante/OpenGL2) #3176

Open shoaibmerchant opened 2 years ago

shoaibmerchant commented 2 years ago

Description I am testing a bevy example application (with wayland enabled) compiled to a IMX8 (ARM64) target running Vivante GPU driver and OpenGL ES 2.0. Below is the command I am using to execute the application

WGPU_BACKEND=gl WAYLAND_DISPLAY=wayland-0 XDG_RUNTIME_DIR=/run/user/0 RUST_LOG=trace rust-hello-world

The primary error returned is

EGL: Warning: No default display support on wayland
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', /usr/src/debug/rust-hello-world/git-r0/cargo_home/registry/src/github.com-1ecc6299db9ec823/khronos-egl-4.1.0/src/lib.rs:1518:42

Below are the trace logs leading to the error

2022-11-03T17:37:19.395636Z DEBUG bevy_app::plugin_group: added plugin: bevy_core::CorePlugin
2022-11-03T17:37:19.396550Z TRACE bevy_core::task_pool_options: Assigning 4 cores to default task pools
2022-11-03T17:37:19.396591Z TRACE bevy_core::task_pool_options: IO Threads: 1
2022-11-03T17:37:19.396795Z TRACE bevy_core::task_pool_options: Async Compute Threads: 1
2022-11-03T17:37:19.396869Z TRACE bevy_core::task_pool_options: Compute Threads: 2
2022-11-03T17:37:19.397306Z DEBUG bevy_app::plugin_group: added plugin: bevy_time::TimePlugin
2022-11-03T17:37:19.397393Z DEBUG bevy_app::plugin_group: added plugin: bevy_transform::TransformPlugin
2022-11-03T17:37:19.397465Z DEBUG bevy_app::plugin_group: added plugin: bevy_hierarchy::HierarchyPlugin
2022-11-03T17:37:19.397533Z DEBUG bevy_app::plugin_group: added plugin: bevy_diagnostic::DiagnosticsPlugin
2022-11-03T17:37:19.397552Z DEBUG bevy_app::plugin_group: added plugin: bevy_input::InputPlugin
2022-11-03T17:37:19.397668Z DEBUG bevy_app::plugin_group: added plugin: bevy_window::WindowPlugin
2022-11-03T17:37:19.397793Z TRACE bevy_ecs::event: Events::send() -> id: event<CreateWindow>#0
2022-11-03T17:37:19.397829Z DEBUG bevy_app::plugin_group: added plugin: bevy_asset::AssetPlugin
2022-11-03T17:37:19.397982Z DEBUG bevy_app::plugin_group: added plugin: bevy_scene::ScenePlugin
2022-11-03T17:37:19.398110Z DEBUG bevy_app::plugin_group: added plugin: bevy_winit::WinitPlugin
2022-11-03T17:37:19.432845Z TRACE bevy_ecs::event: Events::send() -> id: event<WindowResized>#0
2022-11-03T17:37:19.432919Z TRACE bevy_ecs::event: Events::send() -> id: event<WindowCreated>#0
2022-11-03T17:37:19.432951Z DEBUG bevy_app::plugin_group: added plugin: bevy_render::RenderPlugin
2022-11-03T17:37:19.441332Z DEBUG wgpu_hal::gles::egl: Client extensions: [
    "EGL_EXT_client_extensions",
    "EGL_EXT_platform_base",
    "EGL_KHR_platform_wayland",
    "EGL_EXT_platform_wayland",
    "EGL_KHR_platform_gbm",
]
2022-11-03T17:37:19.441484Z  INFO wgpu_hal::gles::egl: Loading Wayland library to get the current display
2022-11-03T17:37:19.441836Z  INFO wgpu_hal::gles::egl: Using Wayland platform
EGL: Warning: No default display support on wayland
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', /usr/src/debug/rust-hello-world/git-r0/cargo_home/registry/src/github.com-1ecc6299db9ec823/khronos-egl-4.1.0/src/lib.rs:1518:42
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I tried to read through the code in gpu-hal/src/gles/egl.rs and could understand that EGL_DEFAULT_DISPLAY is returning None/null, even though test_wayland_display() is returning true. I am guessing that the default display is getting resolved via wl_display_connect but it is just not referenced by EGL_DEFAULT_DISPLAY by the GPU driver.

I will try to run wgpu locally on the device and see if I can conclude the above for sure.

PS - I am new to GPU development, and still learning rust, I will try to help as much as possible. Thank you for all the great work put into wgpu.

Repro steps This can be hard to reproduce as it is a hardware specific bug

Expected vs observed behavior The expected behaviour is that the EGL_DEFAULT_DISPLAY should get pointed to the default wayland display instead it returns None.

Extra materials

  1. Similar Firefox Bug - https://hg.mozilla.org/mozilla-central/rev/28dd89824e9b
  2. KHR_platform_wayland mentions that display could either be wl_display or EGL_DEFAULT_DISPLAY - https://registry.khronos.org/EGL/extensions/KHR/EGL_KHR_platform_wayland.txt
  3. Weston Simple EGL example also uses wl_display_connect to fetch the display - https://github.com/krh/weston/blob/master/clients/simple-egl.c#L643
  4. IMX8 Graphics Guide - https://www.nxp.com/docs/en/user-guide/i.MX_Graphics_User's_Guide_Linux.pdf

Platform OS=Yocto Linux Arch=ARM64 Kernel=5.4.47 GPU=Vivante Backend=OpenGL ES 2.0

MarijnS95 commented 1 month ago

Necromancing an old issue: could #5505 be related/duplicate? It looks like the panic code changed somewhat since the trace was posted in 2022, making it hard to relate.

cwfitzgerald commented 1 month ago

I will note though, that OpenGL ES 2.0 is below our minspec, which is ES 3.0, Desktop 3.3