Create an EGL GLContext for webrender render thread when ANGLE is enabled on macOS
Categories
(Core :: Graphics, task)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox155 | --- | fixed |
People
(Reporter: jnicol, Assigned: jnicol)
References
(Blocks 1 open bug)
Details
(Whiteboard: [fxpe])
Attachments
(2 files)
If gfxVars::UseWebRenderANGLE() is enabled, RenderThread.cpp's CreateGLContext() helper should create an EGL GLContext.
We probably don't want to just call CreateGLContextEGL() for two reasons:
- It calls
GLContextProviderEGL::CreateForCompositorWidget()which deliberately creates a window surface, which we don't need.CreateGLContextCGLfor comparison callsGLContextProviderCGL::CreateHeadless(). - It uses the default display, and I've seen glitches when using Metal ANGLE for both webgl and webrender sharing the same display. Presumably some threading issues. Using a separate display appears to solve it.
Instead we'll want to do something similar to (or extend) CreateGLContextANGLE(). Add a new entry point so we can create a unique EGL display that won't be shared with WebGL. Then call GLContextEGL::CreateWithoutSurface() for said display.
In the currently vendored version of ANGLE, we can use the EGL_ANGLE_platform_angle_device_id extension to ensure we create a unique EGLDisplay. We need to obtain the ID of the Metal device we wish to use and provide that along with a "display key" to create the EGL display. A non-zero display key will ensure that ANGLE will provide us with a different EGL display than that created via other means (e.g. via WebGL asking for the default display), even if it otherwise would have given the same one due to being for the same Metal device.
Note that upstream ANGLE has since split the display key functionality out into a separate extension EGL_ANGLE_platform_angle_display_key. Since we currently only support Metal ANGLE on devices with single GPUs we obviously don't care which specific Metal device we use (there's only 1!), and therefore could provide only the display key, avoiding having to obtain a metal device ID somehow. But on the other hand it's not particularly complicated to obtain one (MTLCreateSystemDefaultDevice() will suffice if there's only 1 device anyway), and we will eventually need to select a specific Metal device when we do want to ship to users with multiple GPUs.
Updated•1 month ago
|
| Assignee | ||
Comment 1•1 month ago
|
||
On macOS, if gfxVars::UseWebRenderANGLE() is enabled create the
webrender render thread's GL context using EGL (i.e. Metal ANGLE). Note
that this is currently blocklisted, but will be unblocked for common
configurations in the subsequent patch. It will still remain off by
default behind the pref "gfx.webrender.enable-angle".
Expose a new function GLLibraryEGL::CreateDisplayForMetalDevice() that
creates an EGLDisplay for a given Metal device ID. Since Metal ANGLE
will, for the time being, remain blocked on systems with multiple GPUs,
the device ID we provide does not really matter. The key detail here is
that by providing an explicit device ID, ANGLE's display cache will
return to us a different display than would have been obtained through
calling CreateDisplay(), even if the underlying device would have been
the same.
This ensures that when ANGLE is enabled for both WebGL and webrender
they each use different EGLDisplays, which avoids rendering glitches
presumably due to lack of thread safety.
A simple helper class is added in order to obtain the Metal device
ID. Currently this simply calls MTLCreateSystemDefaultDevice(). Note
that on systems with multiple GPUs this will return the device for the
discrete GPU. This is moot since we only currently support systems with
a single GPU, but when we do eventually support systems with multiple
GPUs we will probably want to do something cleverer.
| Assignee | ||
Comment 2•1 month ago
|
||
For devices with a single GPU. This remains off by default behind the
pref "gfx.webrender.enable-angle".
Comment 4•1 month ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/baa59c16ec80
https://hg.mozilla.org/mozilla-central/rev/a44e7fe7bc16
Updated•17 days ago
|
Description
•