Title: [180609] trunk/Source/WebCore
Revision
180609
Author
[email protected]
Date
2015-02-24 20:19:30 -0800 (Tue, 24 Feb 2015)

Log Message

WebGL: Destroy the GLContext if a GPU restart has been detected.
https://bugs.webkit.org/show_bug.cgi?id=141567.
<rdar://problem/18507496>
Reviewed by Dean Jackson.
* html/canvas/WebGLRenderingContextBase.cpp:
(WebCore::WebGLRenderingContextBase::WebGLRenderingContextBase):
* platform/graphics/GraphicsContext3D.h:
(WebCore::GraphicsContext3D::setWebGLContext): 
Keep track of which WebGLRenderingContext is associated with the current GraphicsContext3D.
* platform/graphics/mac/GraphicsContext3DMac.mm:
(WebCore::GraphicsContext3D::checkGPUStatusIfNecessary): Helper method to check GPU status.
(WebCore::GraphicsContext3D::GraphicsContext3D): 
Don’t immediately abort the GPU process when the restart status is kCGLCPGPURestartStatusBlacklisted.
* platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp:
(WebCore::GraphicsContext3D::forceContextLost): 
Force the WebGLRenderingContext to be lost.
(WebCore::GraphicsContext3D::drawArrays): Check GPU status after calling drawArrays.
(WebCore::GraphicsContext3D::drawElements): Check GPU status after calling drawElements.
* WebCore.xcodeproj/project.pbxproj: Add SPI header for iOS.
* platform/spi/ios/OpenGLESSPI.h: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (180608 => 180609)


--- trunk/Source/WebCore/ChangeLog	2015-02-25 04:10:54 UTC (rev 180608)
+++ trunk/Source/WebCore/ChangeLog	2015-02-25 04:19:30 UTC (rev 180609)
@@ -1,3 +1,28 @@
+2015-02-19  Roger Fong  <[email protected]>
+
+        WebGL: Destroy the GLContext if a GPU restart has been detected.
+        https://bugs.webkit.org/show_bug.cgi?id=141567.
+        <rdar://problem/18507496>
+
+        Reviewed by Dean Jackson.
+
+        * html/canvas/WebGLRenderingContextBase.cpp:
+        (WebCore::WebGLRenderingContextBase::WebGLRenderingContextBase):
+        * platform/graphics/GraphicsContext3D.h:
+        (WebCore::GraphicsContext3D::setWebGLContext): 
+        Keep track of which WebGLRenderingContext is associated with the current GraphicsContext3D.
+        * platform/graphics/mac/GraphicsContext3DMac.mm:
+        (WebCore::GraphicsContext3D::checkGPUStatusIfNecessary): Helper method to check GPU status.
+        (WebCore::GraphicsContext3D::GraphicsContext3D): 
+        Don’t immediately abort the GPU process when the restart status is kCGLCPGPURestartStatusBlacklisted.
+        * platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp:
+        (WebCore::GraphicsContext3D::forceContextLost): 
+        Force the WebGLRenderingContext to be lost.
+        (WebCore::GraphicsContext3D::drawArrays): Check GPU status after calling drawArrays.
+        (WebCore::GraphicsContext3D::drawElements): Check GPU status after calling drawElements.
+        * WebCore.xcodeproj/project.pbxproj: Add SPI header for iOS.
+        * platform/spi/ios/OpenGLESSPI.h: Added.
+
 2015-02-24  Stephanie Lewis  <[email protected]>
 
         Unreviewed ios build fix after http://trac.webkit.org/changeset/180602.

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (180608 => 180609)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2015-02-25 04:10:54 UTC (rev 180608)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2015-02-25 04:19:30 UTC (rev 180609)
@@ -9498,6 +9498,7 @@
 		6F995A2E1A70833700A735F4 /* JSWebGLTransformFeedback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSWebGLTransformFeedback.h; sourceTree = "<group>"; };
 		6F995A2F1A70833700A735F4 /* JSWebGLVertexArrayObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSWebGLVertexArrayObject.cpp; sourceTree = "<group>"; };
 		6F995A301A70833700A735F4 /* JSWebGLVertexArrayObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSWebGLVertexArrayObject.h; sourceTree = "<group>"; };
+		6FAD4A561A9D0FAE009F7D3C /* OpenGLESSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = OpenGLESSPI.h; path = ios/OpenGLESSPI.h; sourceTree = "<group>"; };
 		7117445614BC34E200EE5FC8 /* SVGTextMetricsBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SVGTextMetricsBuilder.cpp; sourceTree = "<group>"; };
 		7117445714BC34E200EE5FC8 /* SVGTextMetricsBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGTextMetricsBuilder.h; sourceTree = "<group>"; };
 		7118FED215685CC60030B79A /* JSSVGViewSpec.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSSVGViewSpec.cpp; sourceTree = "<group>"; };
@@ -18570,6 +18571,7 @@
 				CE1252481A16C3BC00864480 /* MobileGestaltSPI.h */,
 				CE1252401A16B1B600864480 /* MediaPlayerSPI.h */,
 				CE1252381A166FA000864480 /* QuickLookSPI.h */,
+				6FAD4A561A9D0FAE009F7D3C /* OpenGLESSPI.h */,
 			);
 			name = ios;
 			sourceTree = "<group>";

Modified: trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp (180608 => 180609)


--- trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp	2015-02-25 04:10:54 UTC (rev 180608)
+++ trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp	2015-02-25 04:19:30 UTC (rev 180609)
@@ -463,6 +463,8 @@
     ASSERT(m_context);
     m_contextGroup = WebGLContextGroup::create();
     m_contextGroup->addContext(this);
+    
+    m_context->setWebGLContext(this);
 
     m_maxViewportDims[0] = m_maxViewportDims[1] = 0;
     m_context->getIntegerv(GraphicsContext3D::MAX_VIEWPORT_DIMS, m_maxViewportDims);

Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h (180608 => 180609)


--- trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h	2015-02-25 04:10:54 UTC (rev 180608)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h	2015-02-25 04:19:30 UTC (rev 180609)
@@ -98,6 +98,7 @@
 class ImageData;
 class IntRect;
 class IntSize;
+class WebGLRenderingContextBase;
 #if USE(CAIRO)
 class PlatformContextCairo;
 #endif
@@ -780,6 +781,7 @@
 #endif
 
     bool makeContextCurrent();
+    void setWebGLContext(WebGLRenderingContextBase* base) { m_webglContext = base; }
 
     // With multisampling on, blit from multisampleFBO to regular FBO.
     void prepareTexture();
@@ -1128,6 +1130,7 @@
     void markContextChanged();
     void markLayerComposited();
     bool layerComposited() const;
+    void forceContextLost();
 
     void paintRenderingResultsToCanvas(ImageBuffer*, DrawingBuffer*);
     PassRefPtr<ImageData> paintRenderingResultsToImageData(DrawingBuffer*);
@@ -1256,6 +1259,7 @@
 private:
     GraphicsContext3D(Attributes, HostWindow*, RenderStyle = RenderOffscreen);
     static int numActiveContexts;
+    static int GPUCheckCounter;
 
     // Helper for packImageData/extractImageData/extractTextureData which implement packing of pixel
     // data into the specified OpenGL destination format and type.
@@ -1270,6 +1274,9 @@
     // implementation.
     void validateDepthStencil(const char* packedDepthStencilExtension);
     void validateAttributes();
+    
+    // Call to make during draw calls to check on the GPU's status.
+    void checkGPUStatusIfNecessary();
 
     // Read rendering results into a pixel array with the same format as the
     // backbuffer.
@@ -1438,6 +1445,8 @@
 
     friend class GraphicsContext3DPrivate;
     std::unique_ptr<GraphicsContext3DPrivate> m_private;
+    
+    WebGLRenderingContextBase* m_webglContext;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/cairo/GraphicsContext3DCairo.cpp (180608 => 180609)


--- trunk/Source/WebCore/platform/graphics/cairo/GraphicsContext3DCairo.cpp	2015-02-25 04:10:54 UTC (rev 180608)
+++ trunk/Source/WebCore/platform/graphics/cairo/GraphicsContext3DCairo.cpp	2015-02-25 04:19:30 UTC (rev 180609)
@@ -282,6 +282,10 @@
     return m_private->makeContextCurrent();
 }
 
+void GraphicsContext3D::checkGPUStatusIfNecessary()
+{
+}
+
 PlatformGraphicsContext3D GraphicsContext3D::platformGraphicsContext3D()
 {
     return m_private->platformContext();

Modified: trunk/Source/WebCore/platform/graphics/efl/GraphicsContext3DEfl.cpp (180608 => 180609)


--- trunk/Source/WebCore/platform/graphics/efl/GraphicsContext3DEfl.cpp	2015-02-25 04:10:54 UTC (rev 180608)
+++ trunk/Source/WebCore/platform/graphics/efl/GraphicsContext3DEfl.cpp	2015-02-25 04:19:30 UTC (rev 180609)
@@ -183,6 +183,10 @@
     return m_private->makeContextCurrent();
 }
 
+void GraphicsContext3D::checkGPUStatusIfNecessary()
+{
+}
+
 bool GraphicsContext3D::isGLES2Compliant() const
 {
 #if USE(OPENGL_ES_2)

Modified: trunk/Source/WebCore/platform/graphics/mac/GraphicsContext3DMac.mm (180608 => 180609)


--- trunk/Source/WebCore/platform/graphics/mac/GraphicsContext3DMac.mm	2015-02-25 04:10:54 UTC (rev 180608)
+++ trunk/Source/WebCore/platform/graphics/mac/GraphicsContext3DMac.mm	2015-02-25 04:19:30 UTC (rev 180609)
@@ -42,6 +42,7 @@
 #include "HTMLCanvasElement.h"
 #include "ImageBuffer.h"
 #if PLATFORM(IOS)
+#import "OpenGLESSPI.h"
 #import <OpenGLES/ES2/glext.h>
 #import <OpenGLES/EAGL.h>
 #import <OpenGLES/EAGLDrawable.h>
@@ -52,6 +53,7 @@
 #endif
 #include "WebGLLayer.h"
 #include "WebGLObject.h"
+#include "WebGLRenderingContextBase.h"
 #include <runtime/ArrayBuffer.h>
 #include <runtime/ArrayBufferView.h>
 #include <runtime/Int32Array.h>
@@ -63,7 +65,9 @@
 
 const int maxActiveContexts = 64;
 int GraphicsContext3D::numActiveContexts = 0;
-
+const int GPUStatusCheckThreshold = 5;
+int GraphicsContext3D::GPUCheckCounter = 0;
+    
 // FIXME: This class is currently empty on Mac, but will get populated as 
 // the restructuring in https://bugs.webkit.org/show_bug.cgi?id=66903 is done
 class GraphicsContext3DPrivate {
@@ -145,6 +149,7 @@
     , m_multisampleDepthStencilBuffer(0)
     , m_multisampleColorBuffer(0)
     , m_private(std::make_unique<GraphicsContext3DPrivate>(this))
+    , m_webglContext(0)
 {
     UNUSED_PARAM(hostWindow);
     UNUSED_PARAM(renderStyle);
@@ -196,6 +201,15 @@
         return;
 
     CGLError err = CGLCreateContext(pixelFormatObj, 0, &m_contextObj);
+#if ((PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000) || PLATFORM(IOS))
+    GLint abortOnBlacklist = 0;
+#if PLATFORM(MAC)
+    CGLSetParameter(m_contextObj, kCGLCPAbortOnGPURestartStatusBlacklisted, &abortOnBlacklist);
+#elif PLATFORM(IOS)
+    CGLSetParameter(m_contextObj, kEAGLCPAbortOnGPURestartStatusBlacklisted, &abortOnBlacklist);
+#endif
+#endif
+
     CGLDestroyPixelFormat(pixelFormatObj);
     
     if (err != kCGLNoError || !m_contextObj) {
@@ -353,6 +367,33 @@
     return true;
 }
 
+void GraphicsContext3D::checkGPUStatusIfNecessary()
+{
+#if ((PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000) || PLATFORM(IOS))
+    GPUCheckCounter = (GPUCheckCounter + 1) % GPUStatusCheckThreshold;
+    if (GPUCheckCounter)
+        return;
+#if PLATFORM(MAC)
+    GLint restartStatus = 0;
+    CGLGetParameter(platformGraphicsContext3D(), kCGLCPGPURestartStatus, &restartStatus);
+    if (restartStatus == kCGLCPGPURestartStatusCaused || restartStatus == kCGLCPGPURestartStatusBlacklisted) {
+        CGLSetCurrentContext(0);
+        CGLDestroyContext(platformGraphicsContext3D());
+        forceContextLost();
+    }
+#elif PLATFORM(IOS)
+    GLint restartStatus = 0;
+    EAGLContext* currentContext = static_cast<EAGLContext*>(PlatformGraphicsContext3D());
+    [currentContext getParameter:kEAGLCPGPURestartStatus to:&restartStatus];
+    if (restartStatus == kEAGLCPGPURestartStatusCaused || restartStatus == kEAGLCPGPURestartStatusBlacklisted) {
+        [EAGLContext setCurrentContext:0];
+        [static_cast<EAGLContext*>(currentContext) release];
+        forceContextLost();
+    }
+#endif
+#endif
+}
+
 #if PLATFORM(IOS)
 void GraphicsContext3D::endPaint()
 {

Modified: trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp (180608 => 180609)


--- trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp	2015-02-25 04:10:54 UTC (rev 180608)
+++ trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp	2015-02-25 04:19:30 UTC (rev 180609)
@@ -48,6 +48,7 @@
 #include "IntSize.h"
 #include "Logging.h"
 #include "TemporaryOpenGLSetting.h"
+#include "WebGLRenderingContextBase.h"
 #include <cstring>
 #include <runtime/ArrayBuffer.h>
 #include <runtime/ArrayBufferView.h>
@@ -75,6 +76,7 @@
 #endif
 #endif
 
+
 namespace WebCore {
 
 static ShaderNameHash* currentNameHashMapForShader = nullptr;
@@ -683,12 +685,14 @@
 {
     makeContextCurrent();
     ::glDrawArrays(mode, first, count);
+    checkGPUStatusIfNecessary();
 }
 
 void GraphicsContext3D::drawElements(GC3Denum mode, GC3Dsizei count, GC3Denum type, GC3Dintptr offset)
 {
     makeContextCurrent();
     ::glDrawElements(mode, count, type, reinterpret_cast<GLvoid*>(static_cast<intptr_t>(offset)));
+    checkGPUStatusIfNecessary();
 }
 
 void GraphicsContext3D::enable(GC3Denum cap)
@@ -1763,6 +1767,12 @@
     return m_layerComposited;
 }
 
+void GraphicsContext3D::forceContextLost()
+{
+    if (m_webglContext)
+        m_webglContext->forceLostContext(WebGLRenderingContextBase::RealLostContext);
+}
+
 void GraphicsContext3D::texImage2DDirect(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum format, GC3Denum type, const void* pixels)
 {
     makeContextCurrent();

Modified: trunk/Source/WebCore/platform/graphics/win/GraphicsContext3DWin.cpp (180608 => 180609)


--- trunk/Source/WebCore/platform/graphics/win/GraphicsContext3DWin.cpp	2015-02-25 04:10:54 UTC (rev 180608)
+++ trunk/Source/WebCore/platform/graphics/win/GraphicsContext3DWin.cpp	2015-02-25 04:19:30 UTC (rev 180609)
@@ -178,6 +178,10 @@
     return m_private->makeContextCurrent();
 }
 
+void GraphicsContext3D::checkGPUStatusIfNecessary()
+{
+}
+
 PlatformGraphicsContext3D GraphicsContext3D::platformGraphicsContext3D()
 {
     return m_private->platformContext();

Added: trunk/Source/WebCore/platform/spi/ios/OpenGLESSPI.h (0 => 180609)


--- trunk/Source/WebCore/platform/spi/ios/OpenGLESSPI.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/spi/ios/OpenGLESSPI.h	2015-02-25 04:19:30 UTC (rev 180609)
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <Foundation/Foundation.h>
+#import <UIKit/UIKit.h>
+
+#if USE(APPLE_INTERNAL_SDK)
+
+#import <OpenGLES/EAGLPrivate.h>
+
+#else
+
+typedef uint32_t EAGLContextParameter;
+
+enum {
+    kEAGLCPGPURestartStatusNone        = 0, /* context has not caused recent GPU restart */
+    kEAGLCPGPURestartStatusCaused      = 1, /* context caused recent GPU restart (clear on query) */
+    kEAGLCPGPURestartStatusBlacklisted = 2, /* context is being ignored for excessive GPU restarts */
+};
+
+/* (read-only) context caused GPU hang/crash, requiring a restart (see EAGLGPGPURestartStatus) */
+#define kEAGLCPGPURestartStatus                   ((EAGLContextParameter)317)
+/* (read-write) how to react to being blacklisted for causing excessive restarts (default to 1) */
+#define kEAGLCPAbortOnGPURestartStatusBlacklisted ((EAGLContextParameter)318)
+/* (read-only) does driver support auto-restart of GPU on hang/crash? */
+#define kEAGLCPSupportGPURestart                  ((EAGLContextParameter)319)
+/* (read-only) does driver/GPU support separate address space per context? */
+#define kEAGLCPSupportSeparateAddressSpace        ((EAGLContextParameter)320)
+
+@interface EAGLContext (EAGLPrivate)
+- (NSUInteger)setParameter:(EAGLContextParameter)pname to:(int32_t *)params;
+- (NSUInteger)getParameter:(EAGLContextParameter)pname to:(int32_t *)params;
+@end
+#endif
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to