Changeset 285835 in webkit
- Timestamp:
- Nov 15, 2021, 2:16:38 PM (5 years ago)
- Location:
- branches/safari-612.3.6.1-branch/Source/WebCore
- Files:
-
- 4 edited
-
ChangeLog (modified) (1 diff)
-
platform/graphics/angle/GraphicsContextGLANGLE.cpp (modified) (2 diffs)
-
platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm (modified) (5 diffs)
-
platform/graphics/opengl/GraphicsContextGLOpenGL.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/safari-612.3.6.1-branch/Source/WebCore/ChangeLog
r285834 r285835 1 2021-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 1 92 2021-11-15 Alan Coon <alancoon@apple.com> 2 93 -
branches/safari-612.3.6.1-branch/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp
r285598 r285835 86 86 // context cannot be current on multiple threads. 87 87 if (releaseBehavior == ReleaseThreadResourceBehavior::ReleaseCurrentContext) { 88 if (EGL_GetCurrentContext() == EGL_NO_CONTEXT) 88 EGLDisplay display = EGL_GetCurrentDisplay(); 89 if (display == EGL_NO_DISPLAY) 89 90 return true; 90 91 // At the time of writing, ANGLE does not flush on MakeCurrent. Since we are … … 93 94 // we would need to flush each EGL context that has been used. 94 95 gl::Flush(); 95 EGLDisplay display = EGL_GetDisplay(EGL_DEFAULT_DISPLAY);96 if (display == EGL_NO_DISPLAY)97 return true;98 96 return EGL_MakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); 99 97 } 100 98 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); 108 115 } 109 116 } -
branches/safari-612.3.6.1-branch/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm
r285598 r285835 148 148 149 149 LOG(WebGL, "Attempting to use ANGLE's %s backend.", attrs.useMetal ? "Metal" : "OpenGL"); 150 EGLNativeDisplayType nativeDisplay = GraphicsContextGLOpenGL::defaultDisplay; 150 151 if (attrs.useMetal) { 151 152 displayAttributes.append(EGL_PLATFORM_ANGLE_TYPE_ANGLE); 152 153 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); 159 159 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); 163 163 displayAttributes.append(EGL_HIGH_POWER_ANGLE); 164 nativeDisplay = GraphicsContextGLOpenGL::highPerformanceDisplay; 164 165 } 165 166 } 166 167 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()); 168 169 169 170 if (EGL_Initialize(display, &majorVersion, &minorVersion) == EGL_FALSE) { … … 174 175 if (shouldInitializeWithVolatileContextSupport) { 175 176 // 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)); 177 178 ASSERT(checkVolatileContextSupportIfDeviceExists(display, "EGL_ANGLE_platform_device_context_volatile_eagl", "EGL_ANGLE_device_eagl", EGL_EAGL_CONTEXT_ANGLE)); 178 179 ASSERT(checkVolatileContextSupportIfDeviceExists(display, "EGL_ANGLE_platform_device_context_volatile_cgl", "EGL_ANGLE_device_cgl", EGL_CGL_CONTEXT_ANGLE)); … … 242 243 return; 243 244 244 bool supportsPowerPreference = false;245 245 #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 254 264 255 265 EGLint configAttributes[] = { … … 536 546 { 537 547 #if PLATFORM(MAC) 538 if ( contextAttributes().powerPreference != GraphicsContextGLPowerPreference::HighPerformance)548 if (!m_switchesGPUOnDisplayReconfiguration) 539 549 return; 540 550 if (isVisible) … … 550 560 { 551 561 #if PLATFORM(MAC) 552 if (m_s upportsPowerPreference)562 if (m_switchesGPUOnDisplayReconfiguration) 553 563 EGL_HandleGPUSwitchANGLE(m_displayObj); 554 564 #endif -
branches/safari-612.3.6.1-branch/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h
r285598 r285835 98 98 typedef WTF::HashMap<CString, uint64_t> ShaderNameHash; 99 99 100 class WEBCORE_EXPORT GraphicsContextGLOpenGL final: public GraphicsContextGL100 class WEBCORE_EXPORT GraphicsContextGLOpenGL : public GraphicsContextGL 101 101 { 102 102 public: … … 543 543 #endif 544 544 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 553 protected: 554 #if PLATFORM(COCOA) 555 GraphicsContextGLOpenGL(GraphicsContextGLAttributes, HostWindow*, GraphicsContextGLIOSurfaceSwapChain* = nullptr); 556 #endif 545 557 private: 546 #if PLATFORM(COCOA) 547 GraphicsContextGLOpenGL(GraphicsContextGLAttributes, HostWindow*, GraphicsContextGLIOSurfaceSwapChain* = nullptr); 548 #else 558 #if !PLATFORM(COCOA) 549 559 GraphicsContextGLOpenGL(GraphicsContextGLAttributes, HostWindow*); 550 560 #endif … … 796 806 #endif 797 807 #if PLATFORM(MAC) 798 bool m_s upportsPowerPreference{ false };808 bool m_switchesGPUOnDisplayReconfiguration { false }; 799 809 ScopedHighPerformanceGPURequest m_highPerformanceGPURequest; 800 810 #endif
Note:
See TracChangeset
for help on using the changeset viewer.