Closed Bug 2055894 Opened 1 month ago Closed 1 month ago

Create an EGL GLContext for webrender render thread when ANGLE is enabled on macOS

Categories

(Core :: Graphics, task)

task

Tracking

()

RESOLVED FIXED
155 Branch
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. CreateGLContextCGL for comparison calls GLContextProviderCGL::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.

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.

For devices with a single GPU. This remains off by default behind the
pref "gfx.webrender.enable-angle".

Pushed by jnicol@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/b355d7223a3c https://hg.mozilla.org/integration/autoland/rev/baa59c16ec80 Create render thread's GLContext using EGL (Metal ANGLE) if enabled. r=gfx-reviewers,bradwerth https://github.com/mozilla-firefox/firefox/commit/ff96938d6427 https://hg.mozilla.org/integration/autoland/rev/a44e7fe7bc16 Unblock webrender on Metal ANGLE for macOS 12 onwards. r=gfx-reviewers,bradwerth
Status: NEW → RESOLVED
Closed: 1 month ago
Resolution: --- → FIXED
Target Milestone: --- → 155 Branch
See Also: → 2060857
QA Whiteboard: [qa-triage-done-c156/b155]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: