Commit 69a78e6d by Jonah Ryan-Davis Committed by Commit Bot

CGL: Add basic multithreading support

Adds first step to allowing multithreaded contexts: letting multiple threads use ANGLE as long as only one thread has a current context at a time. Bug: angleproject:4724 Bug: angleproject:4725 Bug: chromium:1087084 Change-Id: Ia6ca48c5fa838b93e49fc9ea259d626029439ca3 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2257273 Commit-Queue: Jonah Ryan-Davis <jonahr@google.com> Reviewed-by: 's avatarShahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 4eb2f6dc
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#ifndef LIBANGLE_RENDERER_GL_CGL_DISPLAYCGL_H_ #ifndef LIBANGLE_RENDERER_GL_CGL_DISPLAYCGL_H_
#define LIBANGLE_RENDERER_GL_CGL_DISPLAYCGL_H_ #define LIBANGLE_RENDERER_GL_CGL_DISPLAYCGL_H_
#include <thread>
#include "libANGLE/renderer/gl/DisplayGL.h" #include "libANGLE/renderer/gl/DisplayGL.h"
struct _CGLContextObject; struct _CGLContextObject;
...@@ -101,6 +103,7 @@ class DisplayCGL : public DisplayGL ...@@ -101,6 +103,7 @@ class DisplayCGL : public DisplayGL
egl::Display *mEGLDisplay; egl::Display *mEGLDisplay;
CGLContextObj mContext; CGLContextObj mContext;
std::unordered_map<std::thread::id, CGLContextObj> mCurrentContexts;
CGLPixelFormatObj mPixelFormat; CGLPixelFormatObj mPixelFormat;
bool mSupportsGPUSwitching; bool mSupportsGPUSwitching;
uint64_t mCurrentGPUID; uint64_t mCurrentGPUID;
......
...@@ -184,6 +184,8 @@ egl::Error DisplayCGL::initialize(egl::Display *display) ...@@ -184,6 +184,8 @@ egl::Error DisplayCGL::initialize(egl::Display *display)
CGLSetCurrentContext(mContext); CGLSetCurrentContext(mContext);
mCurrentContexts[std::this_thread::get_id()] = mContext;
// There is no equivalent getProcAddress in CGL so we open the dylib directly // There is no equivalent getProcAddress in CGL so we open the dylib directly
void *handle = dlopen(kDefaultOpenGLDylibName, RTLD_NOW); void *handle = dlopen(kDefaultOpenGLDylibName, RTLD_NOW);
if (!handle) if (!handle)
...@@ -219,6 +221,7 @@ void DisplayCGL::terminate() ...@@ -219,6 +221,7 @@ void DisplayCGL::terminate()
CGLDestroyPixelFormat(mPixelFormat); CGLDestroyPixelFormat(mPixelFormat);
mPixelFormat = nullptr; mPixelFormat = nullptr;
} }
mCurrentContexts.clear();
if (mContext != nullptr) if (mContext != nullptr)
{ {
CGLSetCurrentContext(nullptr); CGLSetCurrentContext(nullptr);
...@@ -238,6 +241,18 @@ egl::Error DisplayCGL::makeCurrent(egl::Surface *drawSurface, ...@@ -238,6 +241,18 @@ egl::Error DisplayCGL::makeCurrent(egl::Surface *drawSurface,
gl::Context *context) gl::Context *context)
{ {
checkDiscreteGPUStatus(); checkDiscreteGPUStatus();
// If the thread that's calling makeCurrent does not have the correct
// context current (either mContext or 0), we need to set it current.
CGLContextObj newContext = 0;
if (context)
{
newContext = mContext;
}
if (newContext != mCurrentContexts[std::this_thread::get_id()])
{
CGLSetCurrentContext(newContext);
mCurrentContexts[std::this_thread::get_id()] = newContext;
}
return DisplayGL::makeCurrent(drawSurface, readSurface, context); return DisplayGL::makeCurrent(drawSurface, readSurface, context);
} }
......
...@@ -204,8 +204,8 @@ TEST_P(MultithreadingTest, MultiContextDraw) ...@@ -204,8 +204,8 @@ TEST_P(MultithreadingTest, MultiContextDraw)
TEST_P(MultithreadingTest, MultiCreateContext) TEST_P(MultithreadingTest, MultiCreateContext)
{ {
// Supported by WGL and GLX (https://anglebug.com/4725) // Supported by CGL, GLX, and WGL (https://anglebug.com/4725)
ANGLE_SKIP_TEST_IF(!IsWindows() && !IsLinux()); ANGLE_SKIP_TEST_IF(!IsWindows() && !IsLinux() && !IsOSX());
EGLWindow *window = getEGLWindow(); EGLWindow *window = getEGLWindow();
EGLDisplay dpy = window->getDisplay(); EGLDisplay dpy = window->getDisplay();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment