Bug 1136494 - Update post-link validation. - r=mtseng
authorJeff Gilbert <jgilbert@mozilla.com>
Thu, 14 Jul 2016 12:08:06 -0700
changeset 305368 5a13fc6c82c4b8bdf83e9727c7548af55789b123
parent 305367 b78045c38ca2d18182e3cebe563e48e03a6c25e1
child 305369 be7d2dd9f84fd2b05d862d5715621189f9ccf6d3
push id30460
push usercbook@mozilla.com
push dateMon, 18 Jul 2016 15:08:19 +0000
treeherdermozilla-central@cde56ead650f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmtseng
bugs1136494
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 1136494 - Update post-link validation. - r=mtseng MozReview-Commit-ID: 75soRjg1h0o
dom/canvas/WebGLActiveInfo.h
dom/canvas/WebGLProgram.cpp
--- a/dom/canvas/WebGLActiveInfo.h
+++ b/dom/canvas/WebGLActiveInfo.h
@@ -25,21 +25,20 @@ public:
     NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLActiveInfo)
 
     virtual JSObject* WrapObject(JSContext* js, JS::Handle<JSObject*> givenProto) override;
 
     WebGLContext* GetParentObject() const {
         return mWebGL;
     }
 
-
     WebGLContext* const mWebGL;
 
     // ActiveInfo state:
-    const GLint mElemCount; // `size`
+    const uint32_t mElemCount; // `size`
     const GLenum mElemType; // `type`
     const nsCString mBaseUserName; // `name`, but ASCII, and without any final "[0]".
 
     // Not actually part of ActiveInfo:
     const bool mIsArray;
     const uint8_t mElemSize;
     const nsCString mBaseMappedName; // Without any final "[0]".
 
--- a/dom/canvas/WebGLProgram.cpp
+++ b/dom/canvas/WebGLProgram.cpp
@@ -1047,53 +1047,48 @@ WebGLProgram::LinkProgram()
 }
 
 bool
 WebGLProgram::ValidateAfterTentativeLink(nsCString* const out_linkLog) const
 {
     const auto& linkInfo = mMostRecentLinkInfo;
 
     // Check if the attrib name conflicting to uniform name
-    for (const auto& uniform : linkInfo->uniformMap) {
-        if (linkInfo->attribMap.find(uniform.first) != linkInfo->attribMap.end()) {
-            *out_linkLog = nsPrintfCString("The uniform name (%s) conflicts with"
-                                           " attribute name.",
-                                           uniform.first.get());
-            return false;
+    for (const auto& attrib : linkInfo->attribs) {
+        const auto& attribName = attrib.mActiveInfo->mBaseUserName;
+
+        for (const auto& uniform : linkInfo->uniforms) {
+            const auto& uniformName = uniform->mActiveInfo->mBaseUserName;
+            if (attribName == uniformName) {
+                *out_linkLog = nsPrintfCString("Attrib name conflicts with uniform name:"
+                                               " %s",
+                                               attribName.BeginReading());
+                return false;
+            }
         }
     }
 
-    std::map<GLuint, const WebGLActiveInfo*> attribsByLoc;
-    for (const auto& pair : linkInfo->activeAttribLocs) {
-        const auto dupe = attribsByLoc.find(pair.second);
-        if (dupe != attribsByLoc.end()) {
-            *out_linkLog = nsPrintfCString("Aliased location between active attribs"
-                                           " \"%s\" and \"%s\".",
-                                           dupe->second->mBaseUserName.BeginReading(),
-                                           pair.first->mBaseUserName.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 uint32_t usedLoc = attrib.mLoc + i;
 
-    for (const auto& pair : attribsByLoc) {
-        const GLuint attribLoc = pair.first;
-        const auto attrib = pair.second;
-
-        const auto elemSize = ElemSizeFromType(attrib->mElemType);
-        const GLuint locationsUsed = (elemSize + 3) / 4;
-        for (GLuint i = 1; i < locationsUsed; i++) {
-            const GLuint usedLoc = attribLoc + i;
-
-            const auto dupe = attribsByLoc.find(usedLoc);
-            if (dupe != attribsByLoc.end()) {
-                *out_linkLog = nsPrintfCString("Attrib \"%s\" of type \"0x%04x\" aliases"
-                                               " \"%s\" by overhanging its location.",
-                                               attrib->mBaseUserName.BeginReading(),
-                                               attrib->mElemType,
-                                               dupe->second->mBaseUserName.BeginReading());
+            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;
+                const auto& existingName = existingInfo->mActiveInfo->mBaseUserName;
+                *out_linkLog = nsPrintfCString("Attrib \"%s\" aliases locations used by"
+                                               " attrib \"%s\".",
+                                               aliasingName.BeginReading(),
+                                               existingName.BeginReading());
                 return false;
             }
         }
     }
 
     return true;
 }