gfx-rs / gfx

[maintenance mode] A low-overhead Vulkan-like GPU API for Rust.
http://gfx-rs.github.io/
Apache License 2.0
5.35k stars 549 forks source link

Selecting either Wayland or X11 for the GL backend, when both are available #3558

Closed torokati44 closed 3 years ago

torokati44 commented 3 years ago

Short info header:

I'd like to give the newly merged GL backend a try, with Ruffle (with a 2-line patch on top of its master, to allow selecting the GL backend). On startup, I get:

[... INFO gfx_backend_gl::window::egl] Using X11 platform

But then:

[... INFO wgpu_core::instance] Instance::create_surface
thread 'main' panicked at 'Unsupported window: Wayland(WaylandHandle { surface:

I tried forcing gfx to either use only X11 (through XWayland), or only Wayland (natively); but could only do the former, by setting WAYLAND_DISPLAY='' The same method doesn't work for disabling X11 though (DISPLAY=''), gfx will still try to use X11, but will fail to open the display. I also tried EGL_PLATFORM=wayland, but that didn't seem to do anything.

kvark commented 3 years ago

I imagine that we could prefer Wayland if we discover it to be available, over X11, and expect all windows to be Wayland handles.

torokati44 commented 3 years ago

That seems reasonable to me. Will the WAYLAND_DISPLAY='' forced fallback to X11/XWayland still work then, with the added expectation?

kvark commented 3 years ago

No idea. We need to find out!

nemosupremo commented 3 years ago

Commenting because I worked in this recently. For the GL backend I recently added support for wayland (#3545), before that it only supported X (which is the version you are using).

I think the issue you are hitting is actually because of winit - winit by default will prefer to use wayland directly and gives us a wayland window if possible - which obviously causes problems as gfx had only supported X. I’m sure you can force winit to use XWayland which should make things work in your case.

I don’t know if gfx should attempt a fallback here - the issue (which I hit) is that gfx attempts to create a context before we know for use what window manager we will be drawing into. If they don’t match, then the context has to be recreates

torokati44 commented 3 years ago

I’m sure you can force winit to use XWayland which should make things work in your case.

Yes, I could, and I mentioned this in the original report as well. It's just... How does this work at all for anyone on Wayland (directly) who also has X11 available (via XWayland)? This will be the case for a vast majority of users for many years still, I believe.

nemosupremo commented 3 years ago

Right, the way it currently works on master is it first checks for a wayland session, and if that fails it falls back to X. This previously didn’t work as the GL backend didn’t support Wayland.

torokati44 commented 3 years ago

Ah, I see. Wasn't aware that this was already changed in master, sorry.