Skip to content

Fix GLES/EGL surface creation on older Mesa (Linux)#331

Open
guillaug wants to merge 1 commit into
kvark:mainfrom
guillaug:fix/gles-egl-linux-compat
Open

Fix GLES/EGL surface creation on older Mesa (Linux)#331
guillaug wants to merge 1 commit into
kvark:mainfrom
guillaug:fix/gles-egl-linux-compat

Conversation

@guillaug
Copy link
Copy Markdown

Summary

  • Prefer native windowed EGL platforms over surfaceless: try Wayland
    first (when WAYLAND_DISPLAY is set), then X11, then surfaceless
    as last resort
  • Pass XCB window ID as value instead of pointer to eglCreateWindowSurface
  • Use EGL_BACK_BUFFER unconditionally — some Mesa drivers reject
    EGL_SINGLE_BUFFER with BadAlloc

Tested on Debian Bullseye, Mesa 21.2.6, Intel UHD.

Fixes #330


Co-authored with Claude Code (Opus 4.6).

Three issues prevented the GLES backend from working on Linux with
older Mesa (tested: 21.2.6, Intel UHD, Vulkan 1.2 only):

1. EGL platform selection preferred surfaceless over native X11/Wayland,
   making window surface creation impossible (BadNativeWindow). Now
   tries Wayland (when WAYLAND_DISPLAY is set), then X11, then
   surfaceless as last resort.
2. XCB window ID was passed as a pointer instead of the raw XID value,
   causing BadAlloc in eglCreateWindowSurface.
3. EGL_SINGLE_BUFFER is rejected by some Mesa drivers with BadAlloc.
   Switch to BACK_BUFFER unconditionally.
Copy link
Copy Markdown
Owner

@kvark kvark left a comment

Choose a reason for hiding this comment

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

Nice work! A few suggestions to improve

} else if let Some(egl1_5) = egl.upcast::<egl::EGL1_5>() {
if let Some(state) = try_create_gbm_display(egl1_5, &client_extensions) {
(state.0, Some(state.1))
} else if std::env::var("WAYLAND_DISPLAY").is_ok()
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Let's check X11 before wayland, otherwise this would potentially fail on XWayland.
Perhaps don't check wayland at all? If you are running wayland, chances are your platform already supports EGL-1.5

temp_xcb_handle = handle.window;
&mut temp_xcb_handle as *mut _ as *mut ffi::c_void
}
Rwh::Xcb(handle) => handle.window.get() as usize as *mut ffi::c_void,
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

nice catch!

} else {
egl::SINGLE_BUFFER
},
// Use BACK_BUFFER unconditionally: some Mesa drivers reject
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I don't want to use BACK_BUFFER pessimistically on the main path where DMA-BUF is in effect.

@kvark kvark mentioned this pull request Apr 13, 2026
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GLES backend: EGL surface creation fails on older Mesa (Linux)

2 participants