Bug 1355430 - Part2: Implement Require Fastpath for texture copy; r=baku,jgilbert
authorChih-Yi Leu <cleu@mozilla.com>
Tue, 11 Apr 2017 17:15:25 +0800
changeset 388104 7dc7ebfb63055a03e60b0503f86133f656e33d9b
parent 388103 956140f2af5789bcae850657684456b87f308f5a
child 388105 eb0d4878a2e2815aba87e0c36f9f47f5efbf19a8
push id51
push userfmarier@mozilla.com
push dateFri, 05 May 2017 18:41:45 +0000
reviewersbaku, jgilbert
bugs1355430
milestone55.0a1
Bug 1355430 - Part2: Implement Require Fastpath for texture copy; r=baku,jgilbert MozReview-Commit-ID: EPNSJbbJHP4
dom/canvas/TexUnpackBlob.cpp
dom/canvas/WebGLContext.h
dom/canvas/WebGLContextGL.cpp
dom/canvas/WebGLContextValidate.cpp
dom/webidl/WebGLRenderingContext.webidl
--- a/dom/canvas/TexUnpackBlob.cpp
+++ b/dom/canvas/TexUnpackBlob.cpp
@@ -705,19 +705,26 @@ TexUnpackImage::TexOrSubImage(bool isSub
             break;
         }
 
         // Blitting was successful, so we're done!
         *out_error = 0;
         return true;
     } while (false);
 
-    webgl->GeneratePerfWarning("%s: Failed to hit GPU-copy fast-path. (src type %u)"
-                               " Falling back to CPU upload. (%s)",
-                               funcName, uint32_t(mImage->GetFormat()), fallbackReason);
+    const nsPrintfCString perfMsg("%s: Failed to hit GPU-copy fast-path: %s (src type %u)",
+                                  funcName, fallbackReason, uint32_t(mImage->GetFormat()));
+
+    if (webgl->mPixelStore_RequireFastPath) {
+        webgl->ErrorInvalidOperation("%s", perfMsg.BeginReading());
+        return false;
+    }
+
+    webgl->GeneratePerfWarning("%s Falling back to CPU upload.",
+                               perfMsg.BeginReading());
 
     const RefPtr<gfx::SourceSurface> surf = mImage->GetAsSourceSurface();
 
     RefPtr<gfx::DataSourceSurface> dataSurf;
     if (surf) {
         // WARNING: OSX can lose our MakeCurrent here.
         dataSurf = surf->GetDataSurface();
     }
--- a/dom/canvas/WebGLContext.h
+++ b/dom/canvas/WebGLContext.h
@@ -316,16 +316,19 @@ class WebGLContext
     friend class WebGLExtensionLoseContext;
     friend class WebGLExtensionVertexArray;
     friend class WebGLMemoryTracker;
     friend struct webgl::UniformBlockInfo;
 
     enum {
         UNPACK_FLIP_Y_WEBGL = 0x9240,
         UNPACK_PREMULTIPLY_ALPHA_WEBGL = 0x9241,
+        // We throw InvalidOperation in TexImage if we fail to use GPU fast-path
+        // for texture copy when it is set to true, only for debug purpose.
+        UNPACK_REQUIRE_FASTPATH = 0x10001,
         CONTEXT_LOST_WEBGL = 0x9242,
         UNPACK_COLORSPACE_CONVERSION_WEBGL = 0x9243,
         BROWSER_DEFAULT_WEBGL = 0x9244,
         UNMASKED_VENDOR_WEBGL = 0x9245,
         UNMASKED_RENDERER_WEBGL = 0x9246
     };
 
     static const uint32_t kMinMaxColorAttachments;
@@ -1866,16 +1869,17 @@ protected:
 
     bool ValidatePackSize(const char* funcName, uint32_t width, uint32_t height,
                           uint8_t bytesPerPixel, uint32_t* const out_rowStride,
                           uint32_t* const out_endOffset);
 
     GLenum mPixelStore_ColorspaceConversion;
     bool mPixelStore_FlipY;
     bool mPixelStore_PremultiplyAlpha;
+    bool mPixelStore_RequireFastPath;
 
     ////////////////////////////////////
     class FakeBlackTexture {
     public:
         static UniquePtr<FakeBlackTexture> Create(gl::GLContext* gl,
                                                   TexTarget target,
                                                   FakeBlackType type);
         gl::GLContext* const mGL;
--- a/dom/canvas/WebGLContextGL.cpp
+++ b/dom/canvas/WebGLContextGL.cpp
@@ -1123,16 +1123,23 @@ WebGLContext::PixelStorei(GLenum pname, 
             return;
 
         default:
             ErrorInvalidEnumInfo("pixelStorei: colorspace conversion parameter",
                                  param);
             return;
         }
 
+    case UNPACK_REQUIRE_FASTPATH:
+        if (IsExtensionEnabled(WebGLExtensionID::MOZ_debug)) {
+            mPixelStore_RequireFastPath = bool(param);
+            return;
+        }
+        break;
+
     case LOCAL_GL_PACK_ALIGNMENT:
     case LOCAL_GL_UNPACK_ALIGNMENT:
         switch (param) {
         case 1:
         case 2:
         case 4:
         case 8:
             if (pname == LOCAL_GL_PACK_ALIGNMENT)
--- a/dom/canvas/WebGLContextValidate.cpp
+++ b/dom/canvas/WebGLContextValidate.cpp
@@ -696,16 +696,17 @@ WebGLContext::InitAndValidateGL(FailureR
     if (gl->IsCoreProfile()) {
         mDefaultVertexArray->GenVertexArray();
         mDefaultVertexArray->BindVertexArray();
     }
 
     mPixelStore_FlipY = false;
     mPixelStore_PremultiplyAlpha = false;
     mPixelStore_ColorspaceConversion = BROWSER_DEFAULT_WEBGL;
+    mPixelStore_RequireFastPath = false;
 
     // GLES 3.0.4, p259:
     mPixelStore_UnpackImageHeight = 0;
     mPixelStore_UnpackSkipImages = 0;
     mPixelStore_UnpackRowLength = 0;
     mPixelStore_UnpackSkipRows = 0;
     mPixelStore_UnpackSkipPixels = 0;
     mPixelStore_UnpackAlignment = 4;
--- a/dom/webidl/WebGLRenderingContext.webidl
+++ b/dom/webidl/WebGLRenderingContext.webidl
@@ -1083,12 +1083,13 @@ interface EXT_disjoint_timer_query {
     any getQueryEXT(GLenum target, GLenum pname);
     any getQueryObjectEXT(WebGLQuery query, GLenum pname);
 };
 
 [NoInterfaceObject]
 interface MOZ_debug {
     const GLenum EXTENSIONS = 0x1F03;
     const GLenum WSI_INFO   = 0x10000;
+    const GLenum UNPACK_REQUIRE_FASTPATH = 0x10001;
 
     [Throws]
     any getParameter(GLenum pname);
 };