-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
bevy_render: Pass DisplayHandle
to wgpu
for compositor-aware Instance
creation
#20358
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
base: main
Are you sure you want to change the base?
Conversation
DisplayHandle
to wgpu
for compositor-aware Instance
creation
@alice-i-cecile just curious why this PR, which is effectively a one-line change of code on top of dependent PR #20357 is marked
D-Complex
Edit: this likely needs
O-OpenGL
|
Very reasonable; I've amended the labels :) |
Long ago `raw-window-handle` and `winit` split out a `RawDisplayHandle` type and respective traits for dealing with the connection - or at the very least type - of a compositor, and typically implement this for a `Window` directly. `wgpu` and `bevy` seem to have caught on to the latter and folded the two traits/types together because `Window` provides it, but miss a critical goal here: that `(Raw)DisplayHandle` is important for initialization of certain graphics APIs. In the case of Wayland all resources are unique per connection, and in general for others it's important to distinguish between Wayland and X11 if `winit` chose one over the other, even if both are available; currently that's just guesswork inside `wgpu`. Newer APIs like Vulkan don't suffer from this, but older graphics APIs like OpenGL and specifically the EGL backend (or GLX for X11) set up their entire state based on the compositor connection (alternatives are available) even if it's ultimately "only" important for the surface that is going to be rendered into. Note that I haven't yet checked all the safety constraints carefully in this PR; some existing messages seem flawed but I need to perform a clean audit from scratch to denote what limitations should apply to the newly proposed `RawDisplayHandleWrapper` as well.
…tance` creation Multiple community members have asked me to look into persistent `BadDisplay` crashes on `wgpu` when using its EGL backend in conjunction with Wayland. Besides realizing that this backend is quite literally the definition of Undefined Behaviour itself, various hacks to patch the EGL context - which is compositor-specific - inside the `Instance`/`Adapter` with the actual `wl_display` handle as soon as a `surface` is created will not only void any previously created GL resources, only the `Instance` handles are patched leaving any previously queried `Adapter`s to reference destroyed EGL objects causing those `BadDisplay` errors. Solving that handle lifetime/ownership problem has yet to be done (and is why crates like `glutin` exist...), but at the very least we might as well create an `EGLDisplay` and `EGLContext` which is compatible with the current compositor from the get-go, which is what gfx-rs/wgpu#8012 allows callers to do. This is one of the reasons why `raw-display-handle` split out a `RawDisplayHandle` type and related enums: to know up-front what compositor is used (telling X11 and Wayland apart, if both could be used concurrently instead of letting `wgpu` "guess") and to use the same `wl_display` compositor connection as `winit`. There are alternatives available, which is why this and the related `wgpu` PR is a draft to shake out some feedback. Anything that's involving more complexity inside `wgpu`'s EGL backend should be attempted incredibly cautiously if it weren't for a full rewrite on top of a higher-level EGL abstraction.
Depends on: #20357
Depends on: gfx-rs/wgpu#8012
Objective
BadDisplay
after winit 0.30 on Wayland OpenGL #13923Solution
Multiple community members have asked me to look into persistent
BadDisplay
crashes onwgpu
when using its EGL backend in conjunction with Wayland. Besides realizing that this backend is quite literally the definition of Undefined Behaviour itself, various hacks to patch the EGL context - which is compositor-specific - inside theInstance
/Adapter
with the actualwl_display
handle as soon as asurface
is created will not only void any previously created GL resources, only theInstance
handles are patched leaving any previously queriedAdapter
s to reference destroyed EGL objects causing thoseBadDisplay
errors.Solving that handle lifetime/ownership problem has yet to be done (and is why crates like
glutin
exist...), but at the very least we might as well create anEGLDisplay
andEGLContext
which is compatible with the current compositor from the get-go, which is what gfx-rs/wgpu#8012 allows callers to do. This is one of the reasons whyraw-display-handle
split out aRawDisplayHandle
type and related enums: to know up-front what compositor is used (telling X11 and Wayland apart, if both could be used concurrently instead of lettingwgpu
"guess") and to use the samewl_display
compositor connection aswinit
.There are alternatives available, which is why this and the related
wgpu
PR is a draft to shake out some feedback. Anything that's involving more complexity insidewgpu
's EGL backend should be attempted incredibly cautiously if it weren't for a full rewrite on top of a higher-level EGL abstraction.Testing
WGPU_BACKEND=gl cargo r --example 3d_bloom -Fwayland -Fbevy_render/decoupled_naga
on a Wayland compositor.