Skip to content

wgpu examples don't work under Wayland when using OpenGL backend #1787

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

Closed
treeco123 opened this issue Aug 10, 2021 · 19 comments · Fixed by #2076
Closed

wgpu examples don't work under Wayland when using OpenGL backend #1787

treeco123 opened this issue Aug 10, 2021 · 19 comments · Fixed by #2076
Labels
external: driver-bug A driver is causing the bug, though we may still want to work around it help required We need community help to make this happen.

Comments

@treeco123
Copy link

Description
As title. They work under X11. This occurred both pre- and post- wgpu-hal.

Repro steps
WGPU_BACKEND=gl cargo run --example cube

Observed behavior
wgpu master, on Wayland:

[treeco@treeco-ms7b86 wgpu]$ WGPU_BACKEND=gl cargo run --example cube
    Finished dev [unoptimized + debuginfo] target(s) in 0.05s
     Running `target/debug/examples/cube`
[2021-08-10T18:50:34Z ERROR wgpu_hal::gles::egl] EGL 'eglCreatePlatformWindowSurface' code 0x3009: Unsupported surfacetype/colorspace configuration
Using AMD Radeon (TM) R5 340 (OLAND, DRM 3.41.0, 5.13.8-1-MANJARO, LLVM 12.0.1) (Gl)
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', wgpu-core/src/hub.rs:1037:29
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

wgpu master, on X11:

[treeco@treeco-ms7b86 wgpu]$ WGPU_BACKEND=gl cargo run --example cube
    Finished dev [unoptimized + debuginfo] target(s) in 0.06s
     Running `target/debug/examples/cube`
Using AMD Radeon (TM) R5 340 (OLAND, DRM 3.41.0, 5.13.8-1-MANJARO, LLVM 12.0.1) (Gl)
Avg frame time 16.510405ms
Avg frame time 16.676777ms

wgpu v0.9 branch, on Wayland:

[treeco@treeco-ms7b86 wgpu]$ WGPU_BACKEND=gl cargo run --example cube
    Finished dev [unoptimized + debuginfo] target(s) in 0.06s
     Running `target/debug/examples/cube`
Using AMD Radeon (TM) R5 340 (OLAND, DRM 3.41.0, 5.13.8-1-MANJARO, LLVM 12.0.1) (Gl)
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', wgpu-core/src/hub.rs:878:29
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Platform
Manjaro Linux, Plasma desktop environment, R5 340 GPU

@kvark
Copy link
Member

kvark commented Aug 10, 2021

According to EGL docs:

EGL_BAD_MATCH is generated if the pixel format of native_window does not correspond to the format, type, and size of the color buffers required by config. EGL_BAD_MATCH is generated if the pixel

EGL_BAD_MATCH is generated if config does not support rendering to windows (the EGL_SURFACE_TYPE attribute does not contain EGL_WINDOW_BIT).

EGL_BAD_MATCH is generated if config does not support the specified OpenVG alpha format attribute (the value of EGL_VG_ALPHA_FORMAT is EGL_VG_ALPHA_FORMAT_PRE and the EGL_VG_ALPHA_FORMAT_PRE_BIT is not set in the EGL_SURFACE_TYPE attribute of config) or colorspace attribute (the value of EGL_VG_COLORSPACE is EGL_VG_COLORSPACE_LINEAR and the EGL_VG_COLORSPACE_LINEAR_IT is not set in the EGL_SURFACE_TYPE attribute of config).

@kvark kvark added area: correctness We're behaving incorrectly help required We need community help to make this happen. type: bug Something isn't working labels Aug 10, 2021
@niklaskorz
Copy link
Contributor

niklaskorz commented Aug 13, 2021

For what it's worth, neither OpenGL or Vulkan work for Nvidia on Wayland (with the latest drivers that have improved Wayland support), but I think that's an issue on Nvidia's side... See also the issue on glutin.
I'm not sure if it's worth opening an issue for that on wgpu as it likely can't be fixed easily here. On the other hand, there are OpenGL applications using EGL that run fine on Wayland with Nvidia, so maybe it could be investigated after all. As for Vulkan, wgpu simply reports that the surface capabilities are empty.

Firefox runs completely fine on Wayland with Nvidia since 91 though, including Webrender and WebGL.

Edit: with nvidia package version 470.63.01-2, the wgpu Vulkan backend works on Wayland 🎊

@kvark kvark added external: driver-bug A driver is causing the bug, though we may still want to work around it and removed type: bug Something isn't working area: correctness We're behaving incorrectly labels Aug 17, 2021
@PolyMeilex
Copy link
Contributor

I'm running nouveau drivers, and it's the same here. Examples from Glutin repo work fine in my case.
So it seems that it's the same issue on 3 different drivers, radeon ones, nvidia ones, and nouveau

@niklaskorz
Copy link
Contributor

So the issue on proprietary Nvidia is actually unrelated as it turns out: NVIDIA/egl-wayland#34

As for the error reported here on AMD and Nouveau ("Unsupported surfacetype/colorspace") I'm able to reproduce it for Zink as well (OpenGL on Vulkan driver of Mesa), where glutin runs just fine.

@PolyMeilex
Copy link
Contributor

Any ideas how to tackle this? Not being able to run my own software is super annoying, so I would love to help with that, not sure where to start tho.
Would comparing glutin code with wgpu-hal help in any way? Or are the projects too different to even attempt that?

@kvark
Copy link
Member

kvark commented Oct 14, 2021

Our presentation is different, but that could be a good starting point. As I'm setting up a new system, I may be able to investigate in the upcoming month. But if you can start looking into this yourself, it would be most welcome.

@VitalyAnkh
Copy link

@kvark Hi! This PR doesn't fix #1787 in my system with Nvidia 495.29.05 beta driver and Gnome on Wayland. I pull the latest code and run

RUST_LOG=info WINIT_UNIX_BACKEND=wayland WGPU_BACKEND=gl cargo run --example shadow

Then I got this:

RUST_LOG=info WINIT_UNIX_BACKEND=wayland WGPU_BACKEND=gl cargo run --example shadow
   Compiling wgpu v0.11.0 (/home/vitalyr/projects/contribute/rust-projects/wgpu/wgpu)
    Finished dev [unoptimized + debuginfo] target(s) in 18.61s
     Running `target/debug/examples/shadow`
[2021-10-16T00:26:48Z ERROR smithay_client_toolkit::window::concept_frame] No font could be found
[2021-10-16T00:26:48Z INFO  shadow::framework] Initializing the surface...
[2021-10-16T00:26:48Z INFO  wgpu_hal::gles::egl] Loading Wayland library to get the current display
[2021-10-16T00:26:48Z INFO  wgpu_hal::gles::egl] Loading X11 library to get the current display
[2021-10-16T00:26:48Z INFO  wgpu_hal::gles::egl] Using Wayland platform
[2021-10-16T00:26:48Z INFO  wgpu_hal::gles::egl] Enabling EGL debug output
[2021-10-16T00:26:48Z INFO  wgpu_hal::gles::egl] Display vendor "NVIDIA", version (1, 5)
[2021-10-16T00:26:48Z INFO  wgpu_hal::gles::egl] 	EGL surface: +srgb
[2021-10-16T00:26:48Z INFO  wgpu_hal::gles::egl] 	Trying native-render
[2021-10-16T00:26:48Z WARN  wgpu_hal::gles::egl] No config found!
[2021-10-16T00:26:48Z INFO  wgpu_hal::gles::egl] 	Trying presentation
[2021-10-16T00:26:48Z 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-16T00:26:48Z INFO  wgpu_hal::gles::egl] 	EGL context: +debug
[2021-10-16T00:26:48Z INFO  wgpu_hal::gles::egl] 	EGL context: +robust access
[2021-10-16T00:26:48Z INFO  wgpu_hal::gles::egl] 	EGL context: +surfaceless
[2021-10-16T00:26:48Z WARN  wgpu_hal::gles::egl] Re-initializing Gles context due to Wayland window
[2021-10-16T00:26:49Z INFO  wgpu_hal::gles::egl] Display vendor "NVIDIA", version (1, 5)
[2021-10-16T00:26:49Z INFO  wgpu_hal::gles::egl] 	EGL surface: +srgb
[2021-10-16T00:26:49Z INFO  wgpu_hal::gles::egl] 	Trying native-render
[2021-10-16T00:26:49Z WARN  wgpu_hal::gles::egl] No config found!
[2021-10-16T00:26:49Z INFO  wgpu_hal::gles::egl] 	Trying presentation
[2021-10-16T00:26:49Z 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-16T00:26:49Z INFO  wgpu_hal::gles::egl] 	EGL context: +debug
[2021-10-16T00:26:49Z INFO  wgpu_hal::gles::egl] 	EGL context: +robust access
[2021-10-16T00:26:49Z INFO  wgpu_hal::gles::egl] 	EGL context: +surfaceless
[2021-10-16T00:26:49Z INFO  wgpu_hal::gles::egl] Max label length: 256
[2021-10-16T00:26:49Z INFO  wgpu_hal::gles::egl] Enabling GLES debug output
[2021-10-16T00:26:49Z INFO  wgpu_hal::gles::adapter] Vendor: NVIDIA Corporation
[2021-10-16T00:26:49Z INFO  wgpu_hal::gles::adapter] Renderer: NVIDIA GeForce GTX 1060/PCIe/SSE2
[2021-10-16T00:26:49Z INFO  wgpu_hal::gles::adapter] Version: OpenGL ES 3.2 NVIDIA 495.29.05
[2021-10-16T00:26:49Z INFO  wgpu_hal::gles::adapter] SL version: OpenGL ES GLSL ES 3.20
thread 'main' panicked at 'No suitable GPU adapters found on the system!', wgpu/examples/shadow/../framework.rs:136:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[2021-10-16T00:26:49Z INFO  wgpu_core::hub] Dropping Global

I still can't run wgpu with Nvidia driver and Wayland...

@VitalyAnkh
Copy link

Sorry, now I know I should let this example use wgpu's latest code, not 0.11.0.

@kvark
Copy link
Member

kvark commented Oct 16, 2021

What you are seeing is not Wayland-related, it's this line in the log:

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

Thus, it would be great if you could try an experiment. Change this check to tier_max >= 1 and see if it works.

@VitalyAnkh
Copy link

@kvark I changed the check then tested. It seems wgpu could find a suitable GPU adapter but there are other errors happening:

RUST_LOG=info WINIT_UNIX_BACKEND=wayland WGPU_BACKEND=gl cargo run --example shadow
    Finished dev [unoptimized + debuginfo] target(s) in 0.08s
     Running `target/debug/examples/shadow`
[2021-10-16T15:17:17Z ERROR smithay_client_toolkit::window::concept_frame] No font could be found
[2021-10-16T15:17:17Z INFO  shadow::framework] Initializing the surface...
[2021-10-16T15:17:17Z INFO  wgpu_hal::gles::egl] Loading Wayland library to get the current display
[2021-10-16T15:17:17Z INFO  wgpu_hal::gles::egl] Loading X11 library to get the current display
[2021-10-16T15:17:17Z INFO  wgpu_hal::gles::egl] Using Wayland platform
[2021-10-16T15:17:18Z INFO  wgpu_hal::gles::egl] Enabling EGL debug output
[2021-10-16T15:17:18Z INFO  wgpu_hal::gles::egl] Display vendor "NVIDIA", version (1, 5)
[2021-10-16T15:17:18Z INFO  wgpu_hal::gles::egl] 	EGL surface: +srgb
[2021-10-16T15:17:18Z INFO  wgpu_hal::gles::egl] 	Trying native-render
[2021-10-16T15:17:18Z WARN  wgpu_hal::gles::egl] No config found!
[2021-10-16T15:17:18Z INFO  wgpu_hal::gles::egl] 	Trying presentation
[2021-10-16T15:17:18Z 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-16T15:17:18Z INFO  wgpu_hal::gles::egl] 	EGL context: +debug
[2021-10-16T15:17:18Z INFO  wgpu_hal::gles::egl] 	EGL context: +robust access
[2021-10-16T15:17:18Z INFO  wgpu_hal::gles::egl] 	EGL context: +surfaceless
[2021-10-16T15:17:18Z WARN  wgpu_hal::gles::egl] Re-initializing Gles context due to Wayland window
[2021-10-16T15:17:18Z INFO  wgpu_hal::gles::egl] Display vendor "NVIDIA", version (1, 5)
[2021-10-16T15:17:18Z INFO  wgpu_hal::gles::egl] 	EGL surface: +srgb
[2021-10-16T15:17:18Z INFO  wgpu_hal::gles::egl] 	Trying native-render
[2021-10-16T15:17:18Z WARN  wgpu_hal::gles::egl] No config found!
[2021-10-16T15:17:18Z INFO  wgpu_hal::gles::egl] 	Trying presentation
[2021-10-16T15:17:18Z 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-16T15:17:18Z INFO  wgpu_hal::gles::egl] 	EGL context: +debug
[2021-10-16T15:17:18Z INFO  wgpu_hal::gles::egl] 	EGL context: +robust access
[2021-10-16T15:17:18Z INFO  wgpu_hal::gles::egl] 	EGL context: +surfaceless
[2021-10-16T15:17:18Z INFO  wgpu_hal::gles::egl] Max label length: 256
[2021-10-16T15:17:18Z INFO  wgpu_hal::gles::egl] Enabling GLES debug output
[2021-10-16T15:17:18Z INFO  wgpu_hal::gles::adapter] Vendor: NVIDIA Corporation
[2021-10-16T15:17:18Z INFO  wgpu_hal::gles::adapter] Renderer: NVIDIA GeForce GTX 1060/PCIe/SSE2
[2021-10-16T15:17:18Z INFO  wgpu_hal::gles::adapter] Version: OpenGL ES 3.2 NVIDIA 495.29.05
[2021-10-16T15:17:18Z INFO  wgpu_hal::gles::adapter] SL version: OpenGL ES GLSL ES 3.20
[2021-10-16T15:17:18Z 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-16T15:17:18Z INFO  wgpu_core::device] configuring surface with SurfaceConfiguration { usage: RENDER_ATTACHMENT, format: Bgra8UnormSrgb, width: 800, height: 600, present_mode: Mailbox }
[2021-10-16T15:17:18Z WARN  wgpu_core::device] Surface does not support present mode: Mailbox, falling back to FIFO
[2021-10-16T15:17:18Z ERROR wgpu_hal::gles::egl] EGL 'eglCreatePlatformWindowSurface' code 0x300b: EGL_BAD_NATIVE_WINDOW error: In internal function: Additional INFO may be available
    
[2021-10-16T15:17:18Z WARN  wgpu_hal::gles::egl] Error in create_platform_window_surface: BadNativeWindow
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-16T15:17:18Z INFO  wgpu_core::hub] Dropping Global
[2021-10-16T15:17:18Z INFO  wgpu_core::device] Destroying 0 command encoders
[2021-10-16T15:17:18Z WARN  calloop::sources::ping] [calloop] Failed to write a ping: Sys(EPIPE)

It seems that it can't create a window. When I change WINIT_UNIX_BACKEND=wayland to WINIT_UNIX_BACKEND=x11 it runs flawlessly. Maybe it's a problem of winit?

@kvark
Copy link
Member

kvark commented Oct 16, 2021

maybe... it seems that our code that prevents you from requesting that adapter is doing the right thing, after all.
Can you run other EGL stuff on wayland (not related to wgpu)?

@kvark
Copy link
Member

kvark commented Oct 16, 2021

The wayland fix is included in wgpu-hal-0.11.3

@VitalyAnkh
Copy link

@kvark I could run alacritty on my OS, which relies on winit but no wgpu. But its performance is very poor... Maybe it's nvidia 495.29.05's fault.

And I pulled the latest code of winit, run the examples. They can run without printing errors, but I couldn't find their windows on the screen. Meanwhile, the example application's icons are on the desktop dock. Maybe winit thinks it has created the window but in fact it didn't? This also explains why I got "EGL_BAD_NATIVE_WINDOW" errors before.

About the code tier_max >= 2, if I don't change it,

command result
RUST_LOG=info WINIT_UNIX_BACKEND=wayland WGPU_BACKEND=gl cargo run --example shadow No suitable GPU adapters found on the system!
RUST_LOG=info WINIT_UNIX_BACKEND=x11 WGPU_BACKEND=gl cargo run --example shadow No suitable GPU adapters found on the system!
RUST_LOG=info WINIT_UNIX_BACKEND=wayland WGPU_BACKEND=vulkan cargo run --example shadow No suitable GPU adapters found on the system!
RUST_LOG=info WINIT_UNIX_BACKEND=x11 WGPU_BACKEND=vulkan cargo run --example shadow runs flawlessly

After changing it to tier_max >= 1, all the errors No suitable GPU adapters found on the system! above become BadNativeWindow errors. So it does do the right thing.

But I still can't run wgpu with Nvidia and Wayland... I'm not able to understand wgpu's codebase now but I'm eager to help you solve this problem:cry:

@kvark
Copy link
Member

kvark commented Oct 18, 2021

That's quite sad. Thank you for investigating so far!
I tested the examples on Intel with and without Wayland, and made sure this worked. So what you are seeing may be some weirdness with NVidia that we need to figure out.

@kvark kvark reopened this Oct 18, 2021
@PolyMeilex
Copy link
Contributor

I can confirm that for nouveau it's fixed, there is something wrong with resize events but that's probably unrelated I will check winit for that. The rendering itself runs really well

@kvark
Copy link
Member

kvark commented Oct 18, 2021

Thanks!
For proprietary driver, it seems to be a different issue then.
@VitalyAnkh other EGL applications may work because wgpu does something special here. It creates a context, and then it creates a surface to present to. Most of the operations on the context are done without the surface attached. Then we only attach the surface on present() to copy into it. NVidia driver gets confused by this.

@kvark kvark closed this as completed Oct 18, 2021
@VitalyAnkh
Copy link

@kvark Then changes should be made by wgpu or NVidia driver in order to make them work together?

@kvark
Copy link
Member

kvark commented Oct 18, 2021

@VitalyAnkh I have this machine (Linux with Intel + NV GPUs), and I tried to fix this on our side with no success. What we do here is legal, and it works outside of NV proprietary driver... Therefore, best we can do is file a bug to NVidia, assuming they still care about GLES running on Linux.

@VitalyAnkh
Copy link

@kvark Thanks! Since NVidia seems to be more friendly about Wayland, I will try reporting this and see if something good will happen...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external: driver-bug A driver is causing the bug, though we may still want to work around it help required We need community help to make this happen.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants