Bug 1326378 - Infer indexed frag output location from base location on OSX. - r=ethlin a=ritu
authorJeff Gilbert <jgilbert@mozilla.com>
Thu, 29 Dec 2016 23:08:37 -0800
changeset 353338 d2e232a08cc9c897a0c6d425bed3581e7ef01995
parent 353337 1294f3456b539e042b8d05c103e54afa92106580
child 353339 279134247633b312459dddf748634374f148aade
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersethlin, ritu
bugs1326378
milestone52.0a2
Bug 1326378 - Infer indexed frag output location from base location on OSX. - r=ethlin a=ritu MozReview-Commit-ID: Ar07ZnNhu5d
dom/canvas/WebGLProgram.cpp
--- a/dom/canvas/WebGLProgram.cpp
+++ b/dom/canvas/WebGLProgram.cpp
@@ -649,35 +649,62 @@ WebGLProgram::GetAttribLocation(const ns
 
     const webgl::AttribInfo* info;
     if (!LinkInfo()->FindAttrib(userName, &info))
         return -1;
 
     return GLint(info->mLoc);
 }
 
+static GLint
+GetFragDataByUserName(const WebGLProgram* prog,
+                      const nsCString& userName)
+{
+    nsCString mappedName;
+    if (!prog->LinkInfo()->MapFragDataName(userName, &mappedName))
+        return -1;
+
+    return prog->mContext->gl->fGetFragDataLocation(prog->mGLName, mappedName.BeginReading());
+}
+
 GLint
 WebGLProgram::GetFragDataLocation(const nsAString& userName_wide) const
 {
     if (!ValidateGLSLVariableName(userName_wide, mContext, "getFragDataLocation"))
         return -1;
 
     if (!IsLinked()) {
         mContext->ErrorInvalidOperation("getFragDataLocation: `program` must be linked.");
         return -1;
     }
 
+
+    const auto& gl = mContext->gl;
+    gl->MakeCurrent();
+
     const NS_LossyConvertUTF16toASCII userName(userName_wide);
-    nsCString mappedName;
-    if (!LinkInfo()->MapFragDataName(userName, &mappedName))
-        return -1;
+#ifdef XP_MACOSX
+    if (gl->WorkAroundDriverBugs()) {
+        // OSX doesn't return locs for indexed names, just the base names.
+        // Indicated by failure in: conformance2/programs/gl-get-frag-data-location.html
+        bool isArray;
+        size_t arrayIndex;
+        nsCString baseUserName;
+        if (!ParseName(userName, &baseUserName, &isArray, &arrayIndex))
+            return -1;
 
-    gl::GLContext* gl = mContext->GL();
-    gl->MakeCurrent();
-    return gl->fGetFragDataLocation(mGLName, mappedName.BeginReading());
+        if (arrayIndex >= mContext->mImplMaxDrawBuffers)
+            return -1;
+
+        const auto baseLoc = GetFragDataByUserName(this, baseUserName);
+        const auto loc = baseLoc + GLint(arrayIndex);
+        return loc;
+    }
+#endif
+    return GetFragDataByUserName(this, userName);
 }
 
 void
 WebGLProgram::GetProgramInfoLog(nsAString* const out) const
 {
     CopyASCIItoUTF16(mLinkLog, *out);
 }