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

Changeset 285835 in webkit


Ignore:
Timestamp:
Nov 15, 2021, 2:16:38 PM (5 years ago)
Author:
Russell Epstein
Message:

Apply patch. rdar://problem/83971417

Location:
branches/safari-612.3.6.1-branch/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/safari-612.3.6.1-branch/Source/WebCore/ChangeLog

    r285834 r285835  
     12021-11-15  Alan Coon  <alancoon@apple.com>
     2
     3        Apply patch. rdar://problem/83971417
     4
     5    2021-11-09  Alan Coon  <alancoon@apple.com>
     6
     7            Apply patch. rdar://problem/83971417
     8
     9        2021-10-26  Russell Epstein  <repstein@apple.com>
     10
     11                Cherry-pick r284669. rdar://problem/83971417
     12
     13            WebGL low-power and high-performance contexts should use different ANGLE Metal EGLDisplays
     14            https://bugs.webkit.org/show_bug.cgi?id=231012
     15            <rdar://problem/83971417>
     16
     17            Patch by Kimmo Kinnunen <kkinnunen@apple.com> on 2021-10-22
     18            Reviewed by Dean Jackson.
     19
     20            Source/WebCore:
     21
     22            Use per-power preference EGLDisplay when creating Metal
     23            contexts.
     24
     25            Adds a new API test.
     26
     27            * platform/RuntimeApplicationChecks.cpp:
     28            (WebCore::setAuxiliaryProcessTypeForTesting):
     29            * platform/RuntimeApplicationChecks.h:
     30            Add a test function to reset the process type after test has set a specific type and then
     31            run to completion. process for the duration of the test. The volatile context flag in
     32            GraphicsContextGLOpenGL depends on condition isWebProcess || isGPUProcess.
     33            * platform/graphics/angle/GraphicsContextGLANGLE.cpp:
     34            (WebCore::GraphicsContextGLOpenGL::releaseThreadResources):
     35            * platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm:
     36            (WebCore::initializeEGLDisplay):
     37            (WebCore::GraphicsContextGLOpenGL::GraphicsContextGLOpenGL):
     38            (WebCore::GraphicsContextGLOpenGL::setContextVisibility):
     39            (WebCore::GraphicsContextGLOpenGL::displayWasReconfigured):
     40            * platform/graphics/opengl/GraphicsContextGLOpenGL.h:
     41
     42            Tools:
     43
     44            Add a API test to test GraphicsContextGLOpenGL
     45            Cocoa implementation regarding the bug where
     46            the GraphicsContextGLOpenGL instances would use
     47            the GPU that was selected by the first instance.
     48
     49            * TestWebKitAPI/Configurations/TestWebKitAPI.xcconfig:
     50            * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     51            * TestWebKitAPI/Tests/WebCore/cocoa/TestGraphicsContextGLOpenGLCocoa.mm: Added.
     52            (TestWebKitAPI::WebCore::TestedGraphicsContextGLOpenGL::create):
     53            (TestWebKitAPI::WebCore::TestedGraphicsContextGLOpenGL::TestedGraphicsContextGLOpenGL):
     54            (TestWebKitAPI::hasMultipleGPUs):
     55            (TestWebKitAPI::TEST):
     56            * TestWebKitAPI/WebCoreUtilities.h: Added.
     57            (TestWebKitAPI::ScopedSetAuxiliaryProcessTypeForTesting::ScopedSetAuxiliaryProcessTypeForTesting):
     58            (TestWebKitAPI::ScopedSetAuxiliaryProcessTypeForTesting::~ScopedSetAuxiliaryProcessTypeForTesting):
     59            Add a utility state setter to set the process type for the
     60            duration of a test.
     61
     62            git-svn-id: https://svn.webkit.org/repository/webkit/trunk@284669 268f45cc-cd09-0410-ab3c-d52691b4dbfc
     63
     64            2021-10-22  Kimmo Kinnunen  <kkinnunen@apple.com>
     65
     66                    WebGL low-power and high-performance contexts should use different ANGLE Metal EGLDisplays
     67                    https://bugs.webkit.org/show_bug.cgi?id=231012
     68                    <rdar://problem/83971417>
     69
     70                    Reviewed by Dean Jackson.
     71
     72                    Use per-power preference EGLDisplay when creating Metal
     73                    contexts.
     74
     75                    Adds a new API test.
     76
     77                    * platform/RuntimeApplicationChecks.cpp:
     78                    (WebCore::setAuxiliaryProcessTypeForTesting):
     79                    * platform/RuntimeApplicationChecks.h:
     80                    Add a test function to reset the process type after test has set a specific type and then
     81                    run to completion. process for the duration of the test. The volatile context flag in
     82                    GraphicsContextGLOpenGL depends on condition isWebProcess || isGPUProcess.
     83                    * platform/graphics/angle/GraphicsContextGLANGLE.cpp:
     84                    (WebCore::GraphicsContextGLOpenGL::releaseThreadResources):
     85                    * platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm:
     86                    (WebCore::initializeEGLDisplay):
     87                    (WebCore::GraphicsContextGLOpenGL::GraphicsContextGLOpenGL):
     88                    (WebCore::GraphicsContextGLOpenGL::setContextVisibility):
     89                    (WebCore::GraphicsContextGLOpenGL::displayWasReconfigured):
     90                    * platform/graphics/opengl/GraphicsContextGLOpenGL.h:
     91
    1922021-11-15  Alan Coon  <alancoon@apple.com>
    293
  • branches/safari-612.3.6.1-branch/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp

    r285598 r285835  
    8686    // context cannot be current on multiple threads.
    8787    if (releaseBehavior == ReleaseThreadResourceBehavior::ReleaseCurrentContext) {
    88         if (EGL_GetCurrentContext() == EGL_NO_CONTEXT)
     88        EGLDisplay display = EGL_GetCurrentDisplay();
     89        if (display == EGL_NO_DISPLAY)
    8990            return true;
    9091        // At the time of writing, ANGLE does not flush on MakeCurrent. Since we are
     
    9394        // we would need to flush each EGL context that has been used.
    9495        gl::Flush();
    95         EGLDisplay display = EGL_GetDisplay(EGL_DEFAULT_DISPLAY);
    96         if (display == EGL_NO_DISPLAY)
    97             return true;
    9896        return EGL_MakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
    9997    }
    10098    if (releaseBehavior == ReleaseThreadResourceBehavior::TerminateAndReleaseThreadResources) {
    101         EGLDisplay display = EGL_GetDisplay(EGL_DEFAULT_DISPLAY);
    102         if (display != EGL_NO_DISPLAY) {
    103             if (EGL_GetCurrentContext() != EGL_NO_CONTEXT) {
    104                 ASSERT_NOT_REACHED(); // All resources must have been destroyed.
    105                 EGL_MakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
    106             }
    107             EGL_Terminate(display);
     99        EGLDisplay currentDisplay = EGL_GetCurrentDisplay();
     100        if (currentDisplay != EGL_NO_DISPLAY) {
     101            ASSERT_NOT_REACHED(); // All resources must have been destroyed.
     102            EGL_MakeCurrent(currentDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
     103        }
     104        constexpr EGLNativeDisplayType nativeDisplays[] = {
     105            defaultDisplay,
     106#if PLATFORM(COCOA)
     107            lowPowerDisplay,
     108            highPerformanceDisplay
     109#endif
     110        };
     111        for (auto nativeDisplay : nativeDisplays) {
     112            EGLDisplay display = EGL_GetDisplay(nativeDisplay);
     113            if (display != EGL_NO_DISPLAY)
     114                EGL_Terminate(display);
    108115        }
    109116    }
  • branches/safari-612.3.6.1-branch/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm

    r285598 r285835  
    148148
    149149    LOG(WebGL, "Attempting to use ANGLE's %s backend.", attrs.useMetal ? "Metal" : "OpenGL");
     150    EGLNativeDisplayType nativeDisplay = GraphicsContextGLOpenGL::defaultDisplay;
    150151    if (attrs.useMetal) {
    151152        displayAttributes.append(EGL_PLATFORM_ANGLE_TYPE_ANGLE);
    152153        displayAttributes.append(EGL_PLATFORM_ANGLE_TYPE_METAL_ANGLE);
    153     }
    154 
    155     if (attrs.powerPreference != GraphicsContextGLAttributes::PowerPreference::Default || attrs.forceRequestForHighPerformanceGPU) {
    156         displayAttributes.append(EGL_POWER_PREFERENCE_ANGLE);
    157         if (attrs.powerPreference == GraphicsContextGLAttributes::PowerPreference::LowPower && !attrs.forceRequestForHighPerformanceGPU) {
    158             LOG(WebGL, "Requesting low power GPU.");
     154        // These properties are defined for EGL_ANGLE_power_preference as EGLContext attributes,
     155        // but Metal backend uses EGLDisplay attributes.
     156        auto powerPreference = attrs.forceRequestForHighPerformanceGPU ? GraphicsContextGLAttributes::PowerPreference::HighPerformance : attrs.powerPreference;
     157        if (powerPreference == GraphicsContextGLAttributes::PowerPreference::LowPower) {
     158            displayAttributes.append(EGL_POWER_PREFERENCE_ANGLE);
    159159            displayAttributes.append(EGL_LOW_POWER_ANGLE);
    160         } else {
    161             ASSERT(attrs.powerPreference == GraphicsContextGLAttributes::PowerPreference::HighPerformance || attrs.forceRequestForHighPerformanceGPU);
    162             LOG(WebGL, "Requesting high power GPU if available.");
     160            nativeDisplay = GraphicsContextGLOpenGL::lowPowerDisplay;
     161        } else if (powerPreference == GraphicsContextGLAttributes::PowerPreference::HighPerformance) {
     162            displayAttributes.append(EGL_POWER_PREFERENCE_ANGLE);
    163163            displayAttributes.append(EGL_HIGH_POWER_ANGLE);
     164            nativeDisplay = GraphicsContextGLOpenGL::highPerformanceDisplay;
    164165        }
    165166    }
    166167    displayAttributes.append(EGL_NONE);
    167     display = EGL_GetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, reinterpret_cast<void*>(EGL_DEFAULT_DISPLAY), displayAttributes.data());
     168    display = EGL_GetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, reinterpret_cast<void*>(nativeDisplay), displayAttributes.data());
    168169
    169170    if (EGL_Initialize(display, &majorVersion, &minorVersion) == EGL_FALSE) {
     
    174175    if (shouldInitializeWithVolatileContextSupport) {
    175176        // After initialization, EGL_DEFAULT_DISPLAY will return the platform-customized display.
    176         ASSERT(display == EGL_GetDisplay(EGL_DEFAULT_DISPLAY));
     177        ASSERT(display == EGL_GetDisplay(nativeDisplay));
    177178        ASSERT(checkVolatileContextSupportIfDeviceExists(display, "EGL_ANGLE_platform_device_context_volatile_eagl", "EGL_ANGLE_device_eagl", EGL_EAGL_CONTEXT_ANGLE));
    178179        ASSERT(checkVolatileContextSupportIfDeviceExists(display, "EGL_ANGLE_platform_device_context_volatile_cgl", "EGL_ANGLE_device_cgl", EGL_CGL_CONTEXT_ANGLE));
     
    242243        return;
    243244
    244     bool supportsPowerPreference = false;
    245245#if PLATFORM(MAC)
    246     const char *displayExtensions = EGL_QueryString(m_displayObj, EGL_EXTENSIONS);
    247     m_supportsPowerPreference = strstr(displayExtensions, "EGL_ANGLE_power_preference");
    248     supportsPowerPreference = m_supportsPowerPreference;
    249 #endif
    250     if (!supportsPowerPreference && attrs.powerPreference == GraphicsContextGLPowerPreference::HighPerformance) {
    251         attrs.powerPreference = GraphicsContextGLPowerPreference::Default;
    252         setContextAttributes(attrs);
    253     }
     246    if (!attrs.useMetal) {
     247        // For OpenGL, EGL_ANGLE_power_preference is used. The context is initialized with the
     248        // default, low-power device. For high-performance contexts, we request the high-performance
     249        // GPU in setContextVisibility. When the request is fullfilled by the system, we get the
     250        // display reconfiguration callback. Upon this, we update the CGL contexts inside ANGLE.
     251        const char *displayExtensions = EGL_QueryString(m_displayObj, EGL_EXTENSIONS);
     252        bool supportsPowerPreference = strstr(displayExtensions, "EGL_ANGLE_power_preference");
     253        if (supportsPowerPreference) {
     254            m_switchesGPUOnDisplayReconfiguration = attrs.powerPreference == GraphicsContextGLPowerPreference::HighPerformance
     255                || attrs.forceRequestForHighPerformanceGPU;
     256        } else {
     257            if (attrs.powerPreference == GraphicsContextGLPowerPreference::HighPerformance) {
     258                attrs.powerPreference = GraphicsContextGLPowerPreference::Default;
     259                setContextAttributes(attrs);
     260            }
     261        }
     262    }
     263#endif
    254264
    255265    EGLint configAttributes[] = {
     
    536546{
    537547#if PLATFORM(MAC)
    538     if (contextAttributes().powerPreference != GraphicsContextGLPowerPreference::HighPerformance)
     548    if (!m_switchesGPUOnDisplayReconfiguration)
    539549        return;
    540550    if (isVisible)
     
    550560{
    551561#if PLATFORM(MAC)
    552     if (m_supportsPowerPreference)
     562    if (m_switchesGPUOnDisplayReconfiguration)
    553563        EGL_HandleGPUSwitchANGLE(m_displayObj);
    554564#endif
  • branches/safari-612.3.6.1-branch/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h

    r285598 r285835  
    9898typedef WTF::HashMap<CString, uint64_t> ShaderNameHash;
    9999
    100 class WEBCORE_EXPORT GraphicsContextGLOpenGL final : public GraphicsContextGL
     100class WEBCORE_EXPORT GraphicsContextGLOpenGL : public GraphicsContextGL
    101101{
    102102public:
     
    543543#endif
    544544
     545#if USE(ANGLE)
     546    constexpr static EGLNativeDisplayType defaultDisplay = EGL_DEFAULT_DISPLAY;
     547#if PLATFORM(COCOA)
     548    constexpr static EGLNativeDisplayType lowPowerDisplay = EGL_CAST(EGLNativeDisplayType, -1);
     549    constexpr static EGLNativeDisplayType highPerformanceDisplay = EGL_CAST(EGLNativeDisplayType, -2);
     550#endif
     551#endif
     552
     553protected:
     554#if PLATFORM(COCOA)
     555    GraphicsContextGLOpenGL(GraphicsContextGLAttributes, HostWindow*, GraphicsContextGLIOSurfaceSwapChain* = nullptr);
     556#endif
    545557private:
    546 #if PLATFORM(COCOA)
    547     GraphicsContextGLOpenGL(GraphicsContextGLAttributes, HostWindow*, GraphicsContextGLIOSurfaceSwapChain* = nullptr);
    548 #else
     558#if !PLATFORM(COCOA)
    549559    GraphicsContextGLOpenGL(GraphicsContextGLAttributes, HostWindow*);
    550560#endif
     
    796806#endif
    797807#if PLATFORM(MAC)
    798     bool m_supportsPowerPreference { false };
     808    bool m_switchesGPUOnDisplayReconfiguration { false };
    799809    ScopedHighPerformanceGPURequest m_highPerformanceGPURequest;
    800810#endif
Note: See TracChangeset for help on using the changeset viewer.