Bug 1286768 - Fix num used attrib locations for matrix types. - r=mtseng draft
authorJeff Gilbert <jgilbert@mozilla.com>
Thu, 14 Jul 2016 00:35:56 -0700
changeset 387553 84784d712504e0e4d120972ae277399baff24e57
parent 387552 d6803eb88f2bc4ec4cb80e1b9f379e805a147c36
child 525376 083f4ac49f700b327d35ab8da42554af2a34fcc5
push id22989
push userbmo:jgilbert@mozilla.com
push dateThu, 14 Jul 2016 08:09:21 +0000
reviewersmtseng
bugs1286768
milestone50.0a1
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;