egl-wayland: Incompatibility with rust wayland-client crate

When trying to run wezterm under Wayland, EGL initialization fails with BAD_NATIVE_WINDOW.

Getting this under a debugger, it looks like this runtime check is the critical piece:

#1  wlEglIsWaylandWindowValid (window=window@entry=0x55555a44f740) at ../src/wayland-eglsurface.c:74
74          return WL_CHECK_INTERFACE_TYPE(surface, wl_surface_interface);

Poking around at the surface that was passed in:

>>> p surface
$5 = (struct wl_surface *) 0x555559938800
>>> p *(void**)surface
$8 = (void *) 0x555559904ea8 <wayland_client::protocol::wl_surface::wl_surface_interface>
>>> p *(struct wl_interface*)0x555559904ea8
$12 = {
  name = 0x555558d3994c "wl_surface",
  version = 4,
  method_count = 10,
  methods = 0x555559904d78 <wayland_client::protocol::wl_surface::wl_surface_requests>,
  event_count = 2,
  events = 0x555559904e78 <wayland_client::protocol::wl_surface::wl_surface_events>
}

And comparing with the wl_surface type that is checked against by this part of the macro:

https://github.com/NVIDIA/egl-wayland/blob/9c9c4c684983f7b0821f516f8821118170a785ea/include/wayland-eglutils.h#L60

>>> p &wl_surface_interface
$13 = (const struct wl_interface *) 0x7ffff7d4aa00 <wl_surface_interface>
>>> p wl_surface_interface
$14 = {
  name = 0x7ffff7d46a88 "wl_surface",
  version = 4,
  method_count = 10,
  methods = 0x7ffff7d4a540 <wl_surface_requests>,
  event_count = 2,
  events = 0x7ffff7d4a500 <wl_surface_events>
}

The interface appears to be compatible if the check were to perform a comparison of what’s inside the wl_interface, even though the addresses are not identical.

Why aren’t the addresses identical?

The rust client implementation employs code generation to produce most of its code; here’s an example of the definition of that particular interface:

https://docs.rs/wayland-client/0.28.1/src/wayland_client/opt/rustwide/target/debug/build/wayland-client-fdd09ed62affdce6/out/wayland_api.rs.html#5885-5892

The rust client does, however, call out to the system libraries so that it should be comptible with EGL libraries. This same code runs fine when run against the nouveau driver.

So! Should NVIDIA/egl-wayland project be performing a deeper wl_interface comparison here to unblock this usage?

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17

Most upvoted comments

Thanks! I add the symlink then the wgpu examples start running! But if the mouse hovers on them, the window runs very slowly and not responding sometimes. It seems not the driver’s fault. Maybe rust’s GUI library needs some improvements. Alacritty and some other rust GUI apps also experience input latency AFAIK. Anyway it worked! Thanks for your help!

Should be fixed by https://github.com/NVIDIA/egl-wayland/commit/2eb4628d64a8297fb4c08aa796fdf33ff54a670f Again, sorry sorry sorry this took so damned long. Note that there are a few more changes to this library coming in the next few days, so I’m going to wait to those to land, but will bump the release as soon as they do.

I believe the first release to include this will be the 495 series beta release, due some time next week if all goes to plan.

@cubanismo Hi! I have the 495.29.05 beta driver installed. When running wgpu’s examples with Wayland, there are still errors:

RUST_LOG=info WINIT_UNIX_BACKEND=wayland WGPU_BACKEND=gl cargo run --example shadow
    Finished dev [unoptimized + debuginfo] target(s) in 0.12s
     Running `target/debug/examples/shadow`
[2021-10-18T21:44:39Z ERROR smithay_client_toolkit::window::concept_frame] No font could be found
[2021-10-18T21:44:39Z INFO  shadow::framework] Initializing the surface...
[2021-10-18T21:44:39Z INFO  wgpu_hal::gles::egl] Loading Wayland library to get the current display
[2021-10-18T21:44:39Z INFO  wgpu_hal::gles::egl] Loading X11 library to get the current display
[2021-10-18T21:44:39Z INFO  wgpu_hal::gles::egl] Using Wayland platform
[2021-10-18T21:44:39Z INFO  wgpu_hal::gles::egl] Enabling EGL debug output
[2021-10-18T21:44:39Z INFO  wgpu_hal::gles::egl] Display vendor "NVIDIA", version (1, 5)
[2021-10-18T21:44:39Z INFO  wgpu_hal::gles::egl] 	EGL surface: +srgb
[2021-10-18T21:44:39Z INFO  wgpu_hal::gles::egl] 	Trying native-render
[2021-10-18T21:44:39Z WARN  wgpu_hal::gles::egl] No config found!
[2021-10-18T21:44:39Z INFO  wgpu_hal::gles::egl] 	Trying presentation
[2021-10-18T21:44:39Z WARN  wgpu_hal::gles::egl] EGL says it can present to the window but not natively. This has been confirmed to malfunction on Intel+NV laptops. Therefore, we disable presentation entirely for this platform
[2021-10-18T21:44:39Z INFO  wgpu_hal::gles::egl] 	EGL context: +debug
[2021-10-18T21:44:39Z INFO  wgpu_hal::gles::egl] 	EGL context: +robust access
[2021-10-18T21:44:39Z INFO  wgpu_hal::gles::egl] 	EGL context: +surfaceless
[2021-10-18T21:44:39Z WARN  wgpu_hal::gles::egl] Re-initializing Gles context due to Wayland window
[2021-10-18T21:44:40Z INFO  wgpu_hal::gles::egl] Display vendor "NVIDIA", version (1, 5)
[2021-10-18T21:44:40Z INFO  wgpu_hal::gles::egl] 	EGL surface: +srgb
[2021-10-18T21:44:40Z INFO  wgpu_hal::gles::egl] 	Trying native-render
[2021-10-18T21:44:40Z WARN  wgpu_hal::gles::egl] No config found!
[2021-10-18T21:44:40Z INFO  wgpu_hal::gles::egl] 	Trying presentation
[2021-10-18T21:44:40Z WARN  wgpu_hal::gles::egl] EGL says it can present to the window but not natively. This has been confirmed to malfunction on Intel+NV laptops. Therefore, we disable presentation entirely for this platform
[2021-10-18T21:44:40Z INFO  wgpu_hal::gles::egl] 	EGL context: +debug
[2021-10-18T21:44:40Z INFO  wgpu_hal::gles::egl] 	EGL context: +robust access
[2021-10-18T21:44:40Z INFO  wgpu_hal::gles::egl] 	EGL context: +surfaceless
[2021-10-18T21:44:40Z INFO  wgpu_hal::gles::egl] Max label length: 256
[2021-10-18T21:44:40Z INFO  wgpu_hal::gles::egl] Enabling GLES debug output
[2021-10-18T21:44:40Z INFO  wgpu_hal::gles::adapter] Vendor: NVIDIA Corporation
[2021-10-18T21:44:40Z INFO  wgpu_hal::gles::adapter] Renderer: NVIDIA GeForce GTX 1060/PCIe/SSE2
[2021-10-18T21:44:40Z INFO  wgpu_hal::gles::adapter] Version: OpenGL ES 3.2 NVIDIA 495.29.05
[2021-10-18T21:44:40Z INFO  wgpu_hal::gles::adapter] SL version: OpenGL ES GLSL ES 3.20
[2021-10-18T21:44:40Z INFO  wgpu_core::instance] Adapter GL AdapterInfo { name: "NVIDIA GeForce GTX 1060/PCIe/SSE2", vendor: 4318, device: 0, device_type: DiscreteGpu, backend: Gl }
Using NVIDIA GeForce GTX 1060/PCIe/SSE2 (Gl)
[2021-10-18T21:44:40Z INFO  wgpu_core::device] configuring surface with SurfaceConfiguration { usage: RENDER_ATTACHMENT, format: Bgra8UnormSrgb, width: 800, height: 600, present_mode: Mailbox }
[2021-10-18T21:44:40Z WARN  wgpu_core::device] Surface does not support present mode: Mailbox, falling back to FIFO
[2021-10-18T21:44:40Z ERROR wgpu_hal::gles::egl] EGL 'eglGetConfigAttrib' code 0x3004: EGL_BAD_ATTRIBUTE error: In internal function: Additional INFO may be available
    
[2021-10-18T21:44:40Z WARN  wgpu_hal::gles::egl] Error in create_platform_window_surface: BadAttribute
thread 'main' panicked at 'Error in Surface::configure: invalid surface', wgpu/src/backend/direct.rs:204:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[2021-10-18T21:44:40Z INFO  wgpu_core::hub] Dropping Global
[2021-10-18T21:44:40Z INFO  wgpu_core::device] Destroying 0 command encoders
[2021-10-18T21:44:40Z WARN  calloop::sources::ping] [calloop] Failed to write a ping: Sys(EPIPE)

wgpu’s code disables presentation for the platform because it detects something wrong with EGL support. If I edit the check, there are BAD_NATIVE_WINDOW errors appearing. Some discussions here.

And when running winit examples, the code didn’t report errors but there are no windows visible on the screen, only icons on the desktop dock.

It seems that there is still incompatibility among the driver and rust wayland-client crate. Could Nvidia do more to improve this? Thanks!