⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 275097 in webkit


Ignore:
Timestamp:
Mar 26, 2021, 8:34:49 AM (5 years ago)
Author:
commit-queue@webkit.org
Message:

GraphicsContextGLOpenGL should avoid calling into ANGLE MakeCurrent
https://bugs.webkit.org/show_bug.cgi?id=223511

Patch by Kimmo Kinnunen <kkinnunen@apple.com> on 2021-03-26
Reviewed by Kenneth Russell.

Avoid calling ANGLE MakeCurrent for contexts that are already current. Cache the current context pointer into a
global variable. Currently the code adds no locking. For the forseeable future, ANGLE does not support
simultaneous access from multiple threads.

The optimization can be done when run in WebContent process or in GPU process, but not when in WK1. This is because in WK1,
the 3rd party client may run arbitrary code in WebKit thread. This includes code that changes EAGL or AGL state.
This code might change the current context underneath WebKit. In WK1 mode, we already use "volatile context" feature of
ANGLE to reset the platform context on every EGL command. The command we use for this for normal GL commands is EGL_MakeCurrent.
Makes in-process WebGL faster in MotionMark triangles by 6300 -> 9800 pts
Makes GPU process WebGL faster in MotionMark triangles by 5300 -> 7000 pts

  • platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm:

(WebCore::isCurrentContextPredictable):
(WebCore::InitializeEGLDisplay):
(WebCore::GraphicsContextGLOpenGL::~GraphicsContextGLOpenGL):
(WebCore::GraphicsContextGLOpenGL::makeContextCurrent):
(WebCore::GraphicsContextGLOpenGL::clearCurrentContext):
(WebCore::GraphicsContextGLOpenGL::releaseCurrentContext):
(WebCore::GraphicsContextGLOpenGL::checkGPUStatus):

  • platform/graphics/opengl/GraphicsContextGLOpenGL.h:
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r275092 r275097  
     12021-03-26  Kimmo Kinnunen  <kkinnunen@apple.com>
     2
     3        GraphicsContextGLOpenGL should avoid calling into ANGLE MakeCurrent
     4        https://bugs.webkit.org/show_bug.cgi?id=223511
     5
     6        Reviewed by Kenneth Russell.
     7
     8        Avoid calling ANGLE MakeCurrent for contexts that are already current. Cache the current context pointer into a
     9        global variable. Currently the code adds no locking. For the forseeable future, ANGLE does not support
     10        simultaneous access from multiple threads.
     11
     12        The optimization can be done when run in WebContent process or in GPU process, but not when in WK1. This is because in WK1,
     13        the 3rd party client may run arbitrary code in WebKit thread. This includes code that changes EAGL or AGL state.
     14        This code might change the current context underneath WebKit. In WK1 mode, we already use "volatile context" feature of
     15        ANGLE to reset the platform context on every EGL command. The command we use for this for normal GL commands is EGL_MakeCurrent.
     16        Makes in-process WebGL faster in MotionMark triangles by 6300 -> 9800 pts
     17        Makes GPU process WebGL faster in MotionMark triangles by 5300 -> 7000 pts
     18
     19        * platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm:
     20        (WebCore::isCurrentContextPredictable):
     21        (WebCore::InitializeEGLDisplay):
     22        (WebCore::GraphicsContextGLOpenGL::~GraphicsContextGLOpenGL):
     23        (WebCore::GraphicsContextGLOpenGL::makeContextCurrent):
     24        (WebCore::GraphicsContextGLOpenGL::clearCurrentContext):
     25        (WebCore::GraphicsContextGLOpenGL::releaseCurrentContext):
     26        (WebCore::GraphicsContextGLOpenGL::checkGPUStatus):
     27        * platform/graphics/opengl/GraphicsContextGLOpenGL.h:
     28
    1292021-03-25  Antoine Quint  <graouts@webkit.org>
    230
  • trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm

    r274750 r275097  
    5050namespace WebCore {
    5151
     52// In isCurrentContextPredictable() == true case this variable is accessed in single-threaded manner.
     53// In isCurrentContextPredictable() == false case this variable is accessed from multiple threads but always sequentially
     54// and it always contains nullptr and nullptr is always written to it.
     55static GraphicsContextGLOpenGL* currentContext;
     56
     57static bool isCurrentContextPredictable()
     58{
     59    static bool value = isInWebProcess() || isInGPUProcess();
     60    return value;
     61}
     62
    5263#if ASSERT_ENABLED
    5364// Returns true if we have volatile context extension for the particular API or
     
    8394
    8495    // FIXME: This should come in from the GraphicsContextGLAttributes.
    85     bool shouldInitializeWithVolatileContextSupport = !(isInWebProcess() || isInGPUProcess());
     96    bool shouldInitializeWithVolatileContextSupport = !isCurrentContextPredictable();
    8697    if (shouldInitializeWithVolatileContextSupport) {
    8798        // For WK1 type APIs we need to set "volatile platform context" for specific
     
    374385    }
    375386    if (m_contextObj) {
    376         EGL_MakeCurrent(m_displayObj, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
     387        clearCurrentContext();
    377388        EGL_DestroyContext(m_displayObj, m_contextObj);
    378     }
    379 
     389    } else
     390        ASSERT(currentContext != this);
    380391    LOG(WebGL, "Destroyed a GraphicsContextGLOpenGL (%p).", this);
    381392}
     
    428439    if (!m_displayBufferBacking && !getInternalFramebufferSize().isEmpty())
    429440        return false;
    430     // ANGLE has an early out for case where nothing changes. Calling MakeCurrent
    431     // is important to set volatile platform context. See InitializeEGLDisplay().
     441    if (currentContext == this)
     442        return true;
     443    // Calling MakeCurrent is important to set volatile platform context. See InitializeEGLDisplay().
    432444    if (!EGL_MakeCurrent(m_displayObj, EGL_NO_SURFACE, EGL_NO_SURFACE, m_contextObj))
    433445        return false;
     446    if (isCurrentContextPredictable())
     447        currentContext = this;
    434448    return true;
     449}
     450
     451void GraphicsContextGLOpenGL::clearCurrentContext()
     452{
     453    EGLBoolean result = EGL_MakeCurrent(m_displayObj, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
     454    ASSERT_UNUSED(result, result);
     455    currentContext = nullptr;
    435456}
    436457
     
    439460{
    440461    // At the moment this function is relevant only when web thread lock owns the GraphicsContextGLOpenGL current context.
    441     ASSERT(!WebCore::isInWebProcess());
     462    ASSERT(!isCurrentContextPredictable());
    442463
    443464    if (!EGL_BindAPI(EGL_OPENGL_ES_API))
     
    477498        m_failNextStatusCheck = false;
    478499        forceContextLost();
    479 
    480         EGL_BindAPI(EGL_OPENGL_ES_API);
    481         EGL_MakeCurrent(m_displayObj, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
     500        clearCurrentContext();
    482501        return;
    483502    }
  • trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h

    r274557 r275097  
    537537    // Called once by all the public entry points of ExtensionsGL that eventually call OpenGL.
    538538    bool makeContextCurrent() WARN_UNUSED_RETURN;
     539    void clearCurrentContext();
    539540
    540541    // Take into account the user's requested context creation attributes,
Note: See TracChangeset for help on using the changeset viewer.