Bug 1286768 - Fix num used attrib locations for matrix types. - r=mtseng
authorJeff Gilbert <jgilbert@mozilla.com>
Thu, 14 Jul 2016 00:35:56 -0700
changeset 305296 fba169c6ead923420d03932778ef5d88cbf2f0d7
parent 305295 37a5b78f9a9de71c3272185a770e1c2c4b0d9981
child 305297 63eeb207ec658de26ec797a9f85a9b1daa7ad158
push id79542
push userjgilbert@mozilla.com
push dateMon, 18 Jul 2016 07:21:03 +0000
treeherdermozilla-inbound@fba169c6ead9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmtseng
bugs1286768
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1286768 - Fix num used attrib locations for matrix types. - r=mtseng MozReview-Commit-ID: 71v2R1cj0aC
dom/canvas/WebGLActiveInfo.cpp
dom/canvas/WebGLActiveInfo.h
dom/canvas/WebGLProgram.cpp
--- a/dom/canvas/WebGLActiveInfo.cpp
+++ b/dom/canvas/WebGLActiveInfo.cpp
@@ -4,17 +4,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WebGLActiveInfo.h"
 
 #include "mozilla/dom/WebGLRenderingContextBinding.h"
 
 namespace mozilla {
 
-uint8_t
+static uint8_t
 ElemSizeFromType(GLenum elemType)
 {
     switch (elemType) {
     case LOCAL_GL_BOOL:
     case LOCAL_GL_FLOAT:
     case LOCAL_GL_INT:
     case LOCAL_GL_UNSIGNED_INT:
     case LOCAL_GL_SAMPLER_2D:
--- a/dom/canvas/WebGLActiveInfo.h
+++ b/dom/canvas/WebGLActiveInfo.h
@@ -86,14 +86,13 @@ private:
     { }
 
     // Private destructor, to discourage deletion outside of Release():
     ~WebGLActiveInfo() { }
 };
 
 //////////
 
-uint8_t ElemSizeFromType(GLenum elemType);
 bool IsElemTypeSampler(GLenum elemType);
 
 } // namespace mozilla
 
 #endif // WEBGL_ACTIVE_INFO_H_
--- a/dom/canvas/WebGLProgram.cpp
+++ b/dom/canvas/WebGLProgram.cpp
@@ -1041,16 +1041,42 @@ WebGLProgram::LinkProgram()
         if (!mLinkLog.IsEmpty()) {
             mContext->GenerateWarning("linkProgram: Failed to link, leaving the following"
                                       " log:\n%s\n",
                                       mLinkLog.BeginReading());
         }
     }
 }
 
+static uint8_t
+NumUsedLocationsByElemType(GLenum elemType)
+{
+    // GLES 3.0.4 p55
+
+    switch (elemType) {
+    case LOCAL_GL_FLOAT_MAT2:
+    case LOCAL_GL_FLOAT_MAT2x3:
+    case LOCAL_GL_FLOAT_MAT2x4:
+        return 2;
+
+    case LOCAL_GL_FLOAT_MAT3x2:
+    case LOCAL_GL_FLOAT_MAT3:
+    case LOCAL_GL_FLOAT_MAT3x4:
+        return 3;
+
+    case LOCAL_GL_FLOAT_MAT4x2:
+    case LOCAL_GL_FLOAT_MAT4x3:
+    case LOCAL_GL_FLOAT_MAT4:
+        return 4;
+
+    default:
+        return 1;
+    }
+}
+
 bool
 WebGLProgram::ValidateAfterTentativeLink(nsCString* const out_linkLog) const
 {
     const auto& linkInfo = mMostRecentLinkInfo;
 
     // Check if the attrib name conflicting to uniform name
     for (const auto& attrib : linkInfo->attribs) {
         const auto& attribName = attrib.mActiveInfo->mBaseUserName;
@@ -1063,19 +1089,19 @@ WebGLProgram::ValidateAfterTentativeLink
                                                attribName.BeginReading());
                 return false;
             }
         }
     }
 
     std::map<uint32_t, const webgl::AttribInfo*> attribsByLoc;
     for (const auto& attrib : linkInfo->attribs) {
-        const uint32_t elemSize = ElemSizeFromType(attrib.mActiveInfo->mElemType);
-        const uint32_t numUsedLocation = (elemSize + 3) / 4;
-        for (uint32_t i = 0; i < numUsedLocation; i++) {
+        const auto& elemType = attrib.mActiveInfo->mElemType;
+        const auto numUsedLocs = NumUsedLocationsByElemType(elemType);
+        for (uint32_t i = 0; i < numUsedLocs; i++) {
             const uint32_t usedLoc = attrib.mLoc + i;
 
             const auto res = attribsByLoc.insert({usedLoc, &attrib});
             const bool& didInsert = res.second;
             if (!didInsert) {
                 const auto& aliasingName = attrib.mActiveInfo->mBaseUserName;
                 const auto& itrExisting = res.first;
                 const auto& existingInfo = itrExisting->second;