We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4833 - Use EGL for X11?
Summary: Use EGL for X11?
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: HG 2.0
Hardware: All Linux
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-10-18 16:48 UTC by Ryan C. Gordon
Modified: 2020-02-03 16:07 UTC (History)
2 users (show)

See Also:


Attachments
patch (3.31 KB, text/x-csrc)
2019-10-26 12:56 UTC, Sylvain
Details
patch (3.31 KB, patch)
2019-10-26 12:58 UTC, Sylvain
Details | Diff
patch v2 (5.04 KB, patch)
2019-10-26 14:22 UTC, Sylvain
Details | Diff
patch_v3 (5.83 KB, patch)
2020-02-03 14:06 UTC, Martin Fiedler
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ryan C. Gordon 2019-10-18 16:48:42 UTC
As discussed here:

https://twitter.com/keyj_trbl/status/1185100810541305856

...apparently modern X11 considers glX deprecated? Or this is the only way to get a GLES context on X11? Look into this and maybe add support.

--ryan.
Comment 1 Sylvain 2019-10-22 05:32:20 UTC
Not sure, but we have SDL_x11opengles.c that uses EGL.

/* If we need a GL ES context and there's no  
 * GLX_EXT_create_context_es2_profile extension, switch over to X11_GLES functions */

This can be forced with:

SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
SDL_SetHint(SDL_HINT_OPENGL_ES_DRIVER, "1");
Comment 2 Martin Fiedler 2019-10-25 14:26:51 UTC
To be precise, this is about *desktop OpenGL* on X11. For OpenGL ES, EGL is already used (as it's the only way to get an OpenGL ES context), as Sylvain noted above.

To shine some light on why this is needed:
In 99% of all cases, using GLX on X11 is fine, even though it's effectively deprecated in favor of EGL [1]. However, there's at least one use case that *requires* the OpenGL context being created with EGL instead of GLX, and that's DRM_PRIME interoperability: The function glEGLImageTargetTexture2DOES simply doesn't work with GLX. (Currently, Mesa actually crashes when trying that.)
Some example code:
https://gist.github.com/kajott/d1b29c613be30893c855621edd1f212e
Runs on Intel and open-source AMD drivers just fine (others unconfirmed), but with #define USE_EGL 0 (i.e. forcing it to GLX), it crashes. The same happens when using SDL for window and context creation.

The good news is that most of the pieces for EGL support on X11 are already in place: SDL_egl.c is pretty complete (and used for desktop OpenGL on Wayland, for example), and SDL_x11opengl.c has the aforementioned OpenGL-ES-on-EGL support. However, when it comes to desktop OpenGL, it's hardcoded to fall back to GLX.

I'm not advocating to make EGL the default for desktop OpenGL on X11; don't fix what ain't broken. But something like an SDL_HINT_VIDEO_X11_FORCE_EGL would be very appreciated to make use cases like the above work with SDL.


[1] source: Eric Anholt, major Linux graphics stack developer, 7 years ago already - see last paragraph of https://www.phoronix.com/scan.php?page=news_item&px=MTE3MTI
Comment 3 Sylvain 2019-10-26 12:56:35 UTC
Created attachment 4019 [details]
patch

Here's a patch for the Hint.
It can either work like this or maybe just miss a lot of things !
Comment 4 Sylvain 2019-10-26 12:58:30 UTC
Created attachment 4020 [details]
patch

I just rename extension of the file.
Comment 5 Sylvain 2019-10-26 13:10:35 UTC
Ok, please ignore, it's missing probably more things :)
Comment 6 Sylvain 2019-10-26 14:22:18 UTC
Created attachment 4021 [details]
patch v2

Maybe this new version would be better
Comment 7 Martin Fiedler 2020-02-03 14:06:48 UTC
Created attachment 4186 [details]
patch_v3

Here's another patch. Verified to work with core, compatibility and ES2 profiles, both with GLX and EGL.

It's basically the same at Sylvain's v2 patch, but now really all GLS-vs-EGL decision points are addressed, and the logic to select the GL method implementations in SDL_x11video.c is a little more DRY now.
Comment 8 Sam Lantinga 2020-02-03 16:07:21 UTC
Looks good, thanks!
https://hg.libsdl.org/SDL/rev/c0c6f54d2dce