Bug 1326367 - Fix FakeVertex0 and enable emulation for OSX+NV+Core profiles. - r=ethlin draft
authorJeff Gilbert <jgilbert@mozilla.com>
Thu, 29 Dec 2016 21:44:51 -0800
changeset 454768 89e2f45810c8a686dbf70c4c540be6acd1c2a756
parent 454641 79ef936724454728beeeba41fb76a61d02c7c226
child 454776 a25031f93e145867c74bc712eb54b8dd504a8af5
push id40032
push userbmo:jgilbert@mozilla.com
push dateFri, 30 Dec 2016 05:46:13 +0000
reviewersethlin
bugs1326367
milestone53.0a1
Bug 1326367 - Fix FakeVertex0 and enable emulation for OSX+NV+Core profiles. - r=ethlin MozReview-Commit-ID: IafpirHZroB
dom/canvas/WebGLContextDraw.cpp
dom/canvas/WebGLContextValidate.cpp
--- a/dom/canvas/WebGLContextDraw.cpp
+++ b/dom/canvas/WebGLContextDraw.cpp
@@ -992,35 +992,36 @@ WebGLContext::ValidateBufferFetching(con
 WebGLVertexAttrib0Status
 WebGLContext::WhatDoesVertexAttrib0Need() const
 {
     MOZ_ASSERT(mCurrentProgram);
     MOZ_ASSERT(mActiveProgramLinkInfo);
 
     const auto& isAttribArray0Enabled = mBoundVertexArray->mAttribs[0].mEnabled;
 
-    // work around Mac OSX crash, see bug 631420
+    bool legacyAttrib0 = gl->IsCompatibilityProfile();
 #ifdef XP_MACOSX
-    if (gl->WorkAroundDriverBugs() &&
-        isAttribArray0Enabled &&
-        !mBufferFetch_IsAttrib0Active)
-    {
-        return WebGLVertexAttrib0Status::EmulatedUninitializedArray;
+    if (gl->WorkAroundDriverBugs()) {
+        // Failures in conformance/attribs/gl-disabled-vertex-attrib.
+        // Even in Core profiles on NV. Sigh.
+        legacyAttrib0 |= (gl->Vendor() == gl::GLVendor::NVIDIA);
     }
 #endif
 
-    if (MOZ_LIKELY(!gl->IsCompatibilityProfile() ||
-                   isAttribArray0Enabled))
-    {
+    if (!legacyAttrib0)
+        return WebGLVertexAttrib0Status::Default;
+
+    if (isAttribArray0Enabled && mBufferFetch_IsAttrib0Active)
         return WebGLVertexAttrib0Status::Default;
-    }
 
-    return mBufferFetch_IsAttrib0Active
-           ? WebGLVertexAttrib0Status::EmulatedInitializedArray
-           : WebGLVertexAttrib0Status::EmulatedUninitializedArray;
+    if (mBufferFetch_IsAttrib0Active)
+        return WebGLVertexAttrib0Status::EmulatedInitializedArray;
+
+    // Ensure that the legacy code has enough buffer.
+    return WebGLVertexAttrib0Status::EmulatedUninitializedArray;
 }
 
 bool
 WebGLContext::DoFakeVertexAttrib0(const char* funcName, GLuint vertexCount)
 {
     if (!vertexCount) {
         vertexCount = 1;
     }
@@ -1033,16 +1034,18 @@ WebGLContext::DoFakeVertexAttrib0(const 
         GenerateWarning("Drawing without vertex attrib 0 array enabled forces the browser "
                         "to do expensive emulation work when running on desktop OpenGL "
                         "platforms, for example on Mac. It is preferable to always draw "
                         "with vertex attrib 0 array enabled, by using bindAttribLocation "
                         "to bind some always-used attribute to location 0.");
         mAlreadyWarnedAboutFakeVertexAttrib0 = true;
     }
 
+    gl->fEnableVertexAttribArray(0);
+
     if (!mFakeVertexAttrib0BufferObject) {
         gl->fGenBuffers(1, &mFakeVertexAttrib0BufferObject);
         mFakeVertexAttrib0BufferObjectSize = 0;
     }
     gl->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, mFakeVertexAttrib0BufferObject);
 
     ////
 
--- a/dom/canvas/WebGLContextValidate.cpp
+++ b/dom/canvas/WebGLContextValidate.cpp
@@ -531,20 +531,16 @@ WebGLContext::InitAndValidateGL(FailureR
     mCurrentProgram = nullptr;
 
     mBoundDrawFramebuffer = nullptr;
     mBoundReadFramebuffer = nullptr;
     mBoundRenderbuffer = nullptr;
 
     MakeContextCurrent();
 
-    // For OpenGL compat. profiles, we always keep vertex attrib 0 array enabled.
-    if (gl->IsCompatibilityProfile())
-        gl->fEnableVertexAttribArray(0);
-
     if (MinCapabilityMode())
         mGLMaxVertexAttribs = MINVALUE_GL_MAX_VERTEX_ATTRIBS;
     else
         gl->GetUIntegerv(LOCAL_GL_MAX_VERTEX_ATTRIBS, &mGLMaxVertexAttribs);
 
     if (mGLMaxVertexAttribs < 8) {
         const nsPrintfCString reason("GL_MAX_VERTEX_ATTRIBS: %d is < 8!",
                                      mGLMaxVertexAttribs);