Understanding EGL, GLX and friends in the Linux and X graphics stack
Earlier this month I wrote a blog entry about Firefox having jank
with WebRender turned on, in
which I mentioned that the problem had appeared when I stopped using
an environment variable
$MOZ_X11_EGL that forced Firefox to use
"EGL". The blog post led to someone filing a quite productive
where I learned in passing that Firefox is switching to EGL by
in the future. This made me realize that I didn't actually know
what EGL was, where it fit into the Linux and X graphics stack, and
if it was old or new. So here is a somewhat simplified explanation
of what I learned.
In the beginning of our story is OpenGL, which in the 1990s became the dominant API (and pretty much the only one) for 3D graphics on Unix systems, as well as spreading to other platforms. However, OpenGL is more or less just about drawing things on a "framebuffer". Generally people on Unix and X don't want to just draw 3D things over top of the entire screen; they want to draw 3D things in an X window (or several) and then have those mix seamlessly with other 3D things being done by other programs in other windows. So you need to somehow connect the OpenGL world and the X world so that you can have OpenGL draw in a way that will be properly displayed in a specific X window and so on.
(This involves the action of many parties, especially once hardware acceleration gets involved and you have partially obscured windows with OpenGL rendering happening in them.)
The first version of an interconnection layer was GLX. As you can see from its
features, GLX is a
very X way of approaching the problem, since its default is to send
all your OpenGL operations to the X server so that the X server can
do the actual OpenGL things. The result inherits the X protocol's
advantages of (theoretical) network transparency, at the cost of
various issues. The 'glx' in programs like '
glxinfo' (used to find out whether
your X environment has decent OpenGL capabilities) and '
(everyone's favorite basic OpenGL on X test program) comes from,
well, GLX. As suggested by the 'X' in its name, GLX is specific
to the X Window System.
Eventually, various issues led to a second version of an interconnection layer. This time around the design was intended to be cross platform (instead of being tied to X) and it was done through the Khronos Group, the OpenGL standards organization. The result is EGL, and you can read (some of?) its manpages here. EGL will let you use more than just OpenGL, such as the simpler subset OpenGL ES, and I believe its API is platform and window system independent (although any particular implementation is likely to be specific to some window system). EGL apparently fixes various inefficiencies and design mistakes in GLX and so offers better performance, at least in theory. Also, pretty much everyone working on the Unix graphics stack likes EGL much more than GLX.
On Unix, EGL is implemented in Mesa, works with X, and
has been present for a long time (back to 2012); current documentation
is here. Wayland requires and
uses EGL, which is unsurprising since GLX is specific to X (eg). I
suspect that EGL on X is not in any way network transparent, but I
don't know and haven't tested much (I did try some EGL programs
from the Mesa demos and
they mostly failed, although
eglinfo printed stuff).
On X, programs can use either the older GLX or the newer EGL in order to use OpenGL; if they want to use OpenGL ES, I believe they have to use EGL. Which one of GLX and EGL works better, has fewer bugs, and performs better has varied over time and may depend on your hardware. Generally the view of people working on Unix graphics is that everyone should move to EGL (cf), but in practice, well, Firefox has had a bug about it for nine years now and in my searches I've seen people say that EGL used to perform much worse than GLX in some environments (eg, from 2018).
While I'm here, Vulkan is the next generation replacement for OpenGL and OpenGL ES, at least for things that want high performance, developed by the Khronos Group. As you'd expect for something developed by the same people who created EGL, it was designed with an interconnection layer, Windows System Integration (WSI) (also [pdf]). I believe that a Vulkan WSI is already available for X, as well as for Wayland. Vulkan (and its WSI) is potentially relevant for the future partly because of Zink, a Mesa project to implement OpenGL on top of Vulkan. If people like Intel, AMD, and maybe someday NVIDIA increasingly provide Vulkan support (open source or otherwise) that's better than their OpenGL support, Zink and Vulkan may become an important thing in the overall stack. I don't know how an application using EGL and OpenGL on top of a Zink backed would interact with a Vulkan WSI, but I assume that Zink plumbs it all through somehow.
On Ubuntu, programs like
eglinfo are available in the mesa-utils-extra
package. On Fedora, the egl-utils package gives you
es2_info, but for everything else you'll need the mesa-demos
PS: For one high level view of the difference between OpenGL and OpenGL ES, see here.
Comments on this page:Written on 24 September 2021.