Skip to content

bevy_render: Pass RawDisplayHandle to wgpu for compositor-aware Instance creation - #25647

Open
AlexanderStein wants to merge 1 commit into
bevyengine:mainfrom
AlexanderStein:egl-wayland
Open

bevy_render: Pass RawDisplayHandle to wgpu for compositor-aware Instance creation#25647
AlexanderStein wants to merge 1 commit into
bevyengine:mainfrom
AlexanderStein:egl-wayland

Conversation

@AlexanderStein

Copy link
Copy Markdown
Contributor

This is an AI-assisted (GPT-5.5) update to #20358

With gfx-rs/wgpu#8782 integrated in wgpu-30 this PR doesn't depend on external changes, but just bevy.

EGL backend requires for the wgpu instance creation that a display handle is already passed through. This is necessary to detect which compositor (X11 or wayland) is used.
This is achieved by creating a RawDisplayHandle upfront and store it as a resource inside RawDisplayHandleWrapper.

Objective

Render creation using EGL on Wayland already requires a display handle upon context creation.

Solution

Create that RawDisplayHandle early, store it as a resource and pass it during render creation.

Testing

Command for test:

RUST_LOG=wgpu_hal=debug WGPU_BACKEND=gl cargo r --example 2d_shapes -Fwayland -Fbevy_render/gles -Fdynamic_linking -Fbevy_feathers --no-default-features -F2d -Fdebug -Fui

Note: --no-default-features is necessary because the 3d feature raises a different GLSL problem in wgpu unrelated to this issue.

Before

2026-09-02T05:51:18.782935Z DEBUG wgpu_hal::gles::egl: Client extensions: [
    "EGL_EXT_device_base",
   [...]
]
2026-09-02T05:51:18.782988Z DEBUG wgpu_hal::gles::egl: No (or unknown) windowing system ((None, Some(Instance(Dynamic(Library@0x55d1850b7440))))) present. Using surfaceless platform
2026-09-02T05:51:18.783007Z DEBUG wgpu_hal::gles::egl: Enabling EGL debug output
2026-09-02T05:51:18.791771Z DEBUG wgpu_hal::gles::egl: Display vendor "Mesa Project", version (1, 5)
2026-09-02T05:51:18.791819Z DEBUG wgpu_hal::gles::egl: Display extensions: [
    "EGL_ANDROID_blob_cache",
   [...]
]
2026-09-02T05:51:18.791858Z DEBUG wgpu_hal::gles::egl:  EGL surface: +srgb
2026-09-02T05:51:18.792026Z DEBUG wgpu_hal::gles::egl:  Trying native-render
2026-09-02T05:51:18.792041Z DEBUG wgpu_hal::gles::egl: No config found!
2026-09-02T05:51:18.792045Z DEBUG wgpu_hal::gles::egl:  Trying presentation
2026-09-02T05:51:18.792053Z DEBUG wgpu_hal::gles::egl: No config found!
2026-09-02T05:51:18.792057Z DEBUG wgpu_hal::gles::egl:  Trying off-screen
2026-09-02T05:51:18.792080Z DEBUG wgpu_hal::gles::egl:  EGL context: +debug
2026-09-02T05:51:18.793185Z DEBUG wgpu_hal::gles::egl:  EGL context: +robust access
2026-09-02T05:51:18.793201Z DEBUG wgpu_hal::gles::egl:  EGL context: +surfaceless
2026-09-02T05:51:18.794066Z DEBUG wgpu_hal::gles::egl: Max label length: 256
2026-09-02T05:51:18.794074Z DEBUG wgpu_hal::gles::egl: Enabling GLES debug output
2026-09-02T05:51:18.794109Z DEBUG wgpu_hal::gles::adapter: Vendor: AMD
2026-09-02T05:51:18.794114Z DEBUG wgpu_hal::gles::adapter: Renderer: AMD Ryzen 9 9900X 12-Core Processor (radeonsi, raphael_mendocino, ACO, DRM 3.64, 7.2.2-arch1-1)
2026-09-02T05:51:18.794119Z DEBUG wgpu_hal::gles::adapter: Version: 4.6 (Core Profile) Mesa 26.2.1-arch1.1
2026-09-02T05:51:18.794139Z DEBUG wgpu_hal::gles::adapter: SL version: 4.60
2026-09-02T05:51:18.794146Z DEBUG wgpu_hal::gles::adapter: Supported GL Extensions: {
    "GL_EXT_EGL_image_storage",
   [...]
}
2026-09-02T05:51:18.794505Z  INFO bevy_render::renderer: AdapterInfo { name: "AMD Ryzen 9 9900X 12-Core Processor (radeonsi, raphael_mendocino, ACO, DRM 3.64, 7.2.2-arch1-1)", vendor: 4098, device: 0, device_type: Other, device_pci_bus_id: "", driver: "", driver_info: "4.6 (Core Profile) Mesa 26.2.1-arch1.1", backend: Gl, subgroup_min_size: 4, subgroup_max_size: 128, transient_saves_memory: None, limit_bucket: None }
2026-09-02T05:51:18.796113Z DEBUG wgpu_hal::gles::device: Naga generated shader:
[...]
2026-09-02T05:51:18.796190Z DEBUG wgpu_hal::gles::device:       Compiled shader NativeShader(2)
2026-09-02T05:51:18.797894Z DEBUG wgpu_hal::gles::device:       Linked program NativeProgram(1)
2026-09-02T05:51:18.801208Z DEBUG wgpu_hal::gles::device: Naga generated shader:
[...]
2026-09-02T05:51:18.801373Z DEBUG wgpu_hal::gles::device:       Compiled shader NativeShader(4)
2026-09-02T05:51:18.801392Z DEBUG wgpu_hal::gles::device:       Linked program NativeProgram(3)
2026-09-02T05:51:19.094913Z  INFO bevy_winit::system: Creating new window 2d_shapes (67v0)
2026-09-02T05:51:19.157765Z  INFO bevy_render::batching::gpu_preprocessing: GPU preprocessing is not supported on this device. Falling back to CPU preprocessing.

thread 'main' (69840) panicked at crates/bevy_render/src/view/window/mod.rs:488:13:
internal error: entered unreachable code: Fallback system failed to choose present mode. This is a bug. Mode: Fifo, Options: []
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

The line

2026-09-02T05:51:18.782988Z DEBUG wgpu_hal::gles::egl: No (or unknown) windowing system ((None, Some(Instance(Dynamic(Library@0x55d1850b7440))))) present. Using surfaceless platform

indicates there is already a problem which causes to create a native-render EGL surface:

2026-09-02T05:51:18.791858Z DEBUG wgpu_hal::gles::egl:  EGL surface: +srgb
2026-09-02T05:51:18.792026Z DEBUG wgpu_hal::gles::egl:  Trying native-render
2026-09-02T05:51:18.792041Z DEBUG wgpu_hal::gles::egl: No config found!

After

2026-09-02T05:45:46.188361Z DEBUG wgpu_hal::gles::egl: Client extensions: [
    "EGL_EXT_device_base",
    [...]
]
2026-09-02T05:45:46.188405Z DEBUG wgpu_hal::gles::egl: Using Wayland platform
2026-09-02T05:45:46.188415Z DEBUG wgpu_hal::gles::egl: Enabling EGL debug output
2026-09-02T05:45:46.195187Z DEBUG wgpu_hal::gles::egl: Display vendor "Mesa Project", version (1, 5)
2026-09-02T05:45:46.195225Z DEBUG wgpu_hal::gles::egl: Display extensions: [
    "EGL_ANDROID_blob_cache",
    [...]
]
2026-09-02T05:45:46.195260Z DEBUG wgpu_hal::gles::egl:  EGL surface: +srgb
2026-09-02T05:45:46.195439Z DEBUG wgpu_hal::gles::egl:  Trying native-render
2026-09-02T05:45:46.195465Z DEBUG wgpu_hal::gles::egl:  EGL context: +debug
2026-09-02T05:45:46.196293Z DEBUG wgpu_hal::gles::egl:  EGL context: +robust access
2026-09-02T05:45:46.196304Z DEBUG wgpu_hal::gles::egl:  EGL context: +surfaceless
2026-09-02T05:45:46.197036Z DEBUG wgpu_hal::gles::egl: Max label length: 256
2026-09-02T05:45:46.197043Z DEBUG wgpu_hal::gles::egl: Enabling GLES debug output
2026-09-02T05:45:46.197073Z DEBUG wgpu_hal::gles::adapter: Vendor: AMD
2026-09-02T05:45:46.197078Z DEBUG wgpu_hal::gles::adapter: Renderer: AMD Radeon RX 9070 XT (radeonsi, gfx1201, ACO, DRM 3.64, 7.2.2-arch1-1)
2026-09-02T05:45:46.197082Z DEBUG wgpu_hal::gles::adapter: Version: 4.6 (Core Profile) Mesa 26.2.1-arch1.1
2026-09-02T05:45:46.197095Z DEBUG wgpu_hal::gles::adapter: SL version: 4.60
2026-09-02T05:45:46.197101Z DEBUG wgpu_hal::gles::adapter: Supported GL Extensions: {
    "GL_KHR_robustness",
    [...]
}
2026-09-02T05:45:46.197379Z  INFO bevy_render::renderer: AdapterInfo { name: "AMD Radeon RX 9070 XT (radeonsi, gfx1201, ACO, DRM 3.64, 7.2.2-arch1-1)", vendor: 4098, device: 0, device_type: Other, device_pci_bus_id: "", driver: "", driver_info: "4.6 (Core Profile) Mesa 26.2.1-arch1.1", backend: Gl, subgroup_min_size: 4, subgroup_max_size: 128, transient_saves_memory: None, limit_bucket: None }

The important line is

2026-09-02T05:45:46.188405Z DEBUG wgpu_hal::gles::egl: Using Wayland platform

showing that initialization detected a Wayland platform for which a EGL surface can be created:

2026-09-02T05:45:46.195260Z DEBUG wgpu_hal::gles::egl:  EGL surface: +srgb
2026-09-02T05:45:46.195439Z DEBUG wgpu_hal::gles::egl:  Trying native-render
2026-09-02T05:45:46.195465Z DEBUG wgpu_hal::gles::egl:  EGL context: +debug
2026-09-02T05:45:46.196293Z DEBUG wgpu_hal::gles::egl:  EGL context: +robust access
2026-09-02T05:45:46.196304Z DEBUG wgpu_hal::gles::egl:  EGL context: +surfaceless

…Instance` creation

EGL backend requires for the wgpu instance creation that a display handle
is already passed through. This is necessary to detect which compositor
(X11 or wayland) is used.
This is achieved by creating a RawDisplayHandle upfront and store it as
a resource inside RawDisplayHandleWrapper.
@beicause beicause added A-Rendering Drawing game state to the screen O-OpenGL Specific to the OpenGL render API S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Sep 5, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in Rendering Sep 5, 2026
@beicause

beicause commented Sep 5, 2026

Copy link
Copy Markdown
Member

I believe the OpenGL support is very fragile. None of the places that use cfg(feature = "webgl") is gated specifically for OpenGL as well. And it seems there are very few contributors interested in fixing it (#22220).

Comment on lines +151 to 155
app.insert_resource(
RawDisplayHandleWrapper::new(&event_loop)
.expect("Failed to get the display handle from the event loop"),
);
app.init_resource::<WinitMonitors>()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
app.insert_resource(
RawDisplayHandleWrapper::new(&event_loop)
.expect("Failed to get the display handle from the event loop"),
);
app.init_resource::<WinitMonitors>()
app.insert_resource(
RawDisplayHandleWrapper::new(&event_loop)
.expect("Failed to get the display handle from the event loop"),
)
.init_resource::<WinitMonitors>()

@IceSentry

IceSentry commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

The opengl backend is officially not supported with bevy's full renderer. With that said, we can still accept non-invasive changes that make it possible to use bevy_winit/bevy_render with the opengl backend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Rendering Drawing game state to the screen O-OpenGL Specific to the OpenGL render API S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

Status: Needs SME Triage

Development

Successfully merging this pull request may close these issues.

3 participants