Bug 1241042 - Get correct frag varying from angle validator. r=jmuizelaar
authorEthan Lin <ethlin@mozilla.com>
Mon, 14 Mar 2016 02:48:00 -0400
changeset 340114 74282731c3d1dfcdbe182b7ba0919f408df2bf33
parent 340113 06033c2f79c430dd6649f894d153d76894fefd83
child 340115 bbaa07377c478859182fdc9aef2f29f515084adb
push id12912
push userbmo:mh+mozilla@glandium.org
push dateTue, 15 Mar 2016 01:01:59 +0000
reviewersjmuizelaar
bugs1241042
milestone48.0a1
Bug 1241042 - Get correct frag varying from angle validator. r=jmuizelaar
dom/canvas/WebGLProgram.cpp
dom/canvas/WebGLProgram.h
dom/canvas/WebGLShader.cpp
dom/canvas/WebGLShader.h
dom/canvas/WebGLShaderValidator.cpp
dom/canvas/WebGLShaderValidator.h
--- a/dom/canvas/WebGLProgram.cpp
+++ b/dom/canvas/WebGLProgram.cpp
@@ -337,17 +337,16 @@ QueryProgramInfo(WebGLProgram* prog, gl:
 
     return info.forget();
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 
 webgl::LinkedProgramInfo::LinkedProgramInfo(WebGLProgram* prog)
     : prog(prog)
-    , fragDataMap(nullptr)
 { }
 
 ////////////////////////////////////////////////////////////////////////////////
 // WebGLProgram
 
 static GLuint
 CreateProgram(gl::GLContext* gl)
 {
@@ -564,18 +563,19 @@ WebGLProgram::GetFragDataLocation(const 
     if (!IsLinked()) {
         mContext->ErrorInvalidOperation("getFragDataLocation: `program` must be linked.");
         return -1;
     }
 
     const NS_LossyConvertUTF16toASCII userName(userName_wide);
 
     nsCString mappedName;
-    if (!LinkInfo()->FindFragData(userName, &mappedName))
-        return -1;
+    if (!FindActiveOutputMappedNameByUserName(userName, &mappedName)) {
+        mappedName = userName;
+    }
 
     gl::GLContext* gl = mContext->GL();
     gl->MakeCurrent();
 
     return gl->fGetFragDataLocation(mGLName, mappedName.BeginReading());
 }
 
 void
@@ -1046,16 +1046,27 @@ WebGLProgram::LinkAndUpdate()
     MOZ_ASSERT(mMostRecentLinkInfo);
     if (!mMostRecentLinkInfo)
         mLinkLog.AssignLiteral("Failed to gather program info.");
 
     return mMostRecentLinkInfo;
 }
 
 bool
+WebGLProgram::FindActiveOutputMappedNameByUserName(const nsACString& userName,
+                                                   nsCString* const out_mappedName) const
+{
+    if (mFragShader->FindActiveOutputMappedNameByUserName(userName, out_mappedName)) {
+        return true;
+    }
+
+    return false;
+}
+
+bool
 WebGLProgram::FindAttribUserNameByMappedName(const nsACString& mappedName,
                                              nsDependentCString* const out_userName) const
 {
     if (mVertShader->FindAttribUserNameByMappedName(mappedName, out_userName))
         return true;
 
     return false;
 }
--- a/dom/canvas/WebGLProgram.h
+++ b/dom/canvas/WebGLProgram.h
@@ -62,17 +62,16 @@ struct LinkedProgramInfo final
     std::vector<RefPtr<WebGLActiveInfo>> activeUniforms;
     std::vector<RefPtr<WebGLActiveInfo>> transformFeedbackVaryings;
 
     // Needed for Get{Attrib,Uniform}Location. The keys for these are non-mapped
     // user-facing `GLActiveInfo::name`s, without any final "[0]".
     std::map<nsCString, const WebGLActiveInfo*> attribMap;
     std::map<nsCString, const WebGLActiveInfo*> uniformMap;
     std::map<nsCString, const WebGLActiveInfo*> transformFeedbackVaryingsMap;
-    std::map<nsCString, const nsCString>* fragDataMap;
 
     std::vector<RefPtr<UniformBlockInfo>> uniformBlocks;
 
     // Needed for draw call validation.
     std::set<GLuint> activeAttribLocs;
 
     explicit LinkedProgramInfo(WebGLProgram* prog);
 
@@ -107,27 +106,16 @@ struct LinkedProgramInfo final
                 *out_info = uniformBlocks[i].get();
                 return true;
             }
         }
 
         return false;
     }
 
-    bool FindFragData(const nsCString& baseUserName,
-                      nsCString* const out_baseMappedName) const
-    {
-        if (!fragDataMap) {
-            *out_baseMappedName = baseUserName;
-            return true;
-        }
-
-        MOZ_CRASH("Not implemented.");
-    }
-
     bool HasActiveAttrib(GLuint loc) const {
         auto itr = activeAttribLocs.find(loc);
         return itr != activeAttribLocs.end();
     }
 };
 
 } // namespace webgl
 
@@ -169,16 +157,18 @@ public:
     void UniformBlockBinding(GLuint uniformBlockIndex, GLuint uniformBlockBinding) const;
 
     bool LinkProgram();
     bool UseProgram() const;
     void ValidateProgram() const;
 
     ////////////////
 
+    bool FindActiveOutputMappedNameByUserName(const nsACString& userName,
+                                              nsCString* const out_mappedName) const;
     bool FindAttribUserNameByMappedName(const nsACString& mappedName,
                                         nsDependentCString* const out_userName) const;
     bool FindVaryingByMappedName(const nsACString& mappedName,
                                  nsCString* const out_userName,
                                  bool* const out_isArray) const;
     bool FindUniformByMappedName(const nsACString& mappedName,
                                  nsCString* const out_userName,
                                  bool* const out_isArray) const;
--- a/dom/canvas/WebGLShader.cpp
+++ b/dom/canvas/WebGLShader.cpp
@@ -325,16 +325,32 @@ WebGLShader::BindAttribLocation(GLuint p
     const std::string* mappedNameStr = &userNameStr;
     if (mValidator)
         mValidator->FindAttribMappedNameByUserName(userNameStr, &mappedNameStr);
 
     mContext->gl->fBindAttribLocation(prog, index, mappedNameStr->c_str());
 }
 
 bool
+WebGLShader::FindActiveOutputMappedNameByUserName(const nsACString& userName,
+                                                  nsCString* const out_mappedName) const
+{
+    if (!mValidator)
+        return false;
+
+    const std::string userNameStr(userName.BeginReading());
+    const std::string* mappedNameStr;
+    if (!mValidator->FindActiveOutputMappedNameByUserName(userNameStr, &mappedNameStr))
+        return false;
+
+    *out_mappedName = mappedNameStr->c_str();
+    return true;
+}
+
+bool
 WebGLShader::FindAttribUserNameByMappedName(const nsACString& mappedName,
                                             nsDependentCString* const out_userName) const
 {
     if (!mValidator)
         return false;
 
     const std::string mappedNameStr(mappedName.BeginReading());
     const std::string* userNameStr;
--- a/dom/canvas/WebGLShader.h
+++ b/dom/canvas/WebGLShader.h
@@ -47,16 +47,18 @@ public:
     void GetShaderTranslatedSource(nsAString* out) const;
     void ShaderSource(const nsAString& source);
 
     // Util funcs
     bool CanLinkTo(const WebGLShader* prev, nsCString* const out_log) const;
     size_t CalcNumSamplerUniforms() const;
     size_t NumAttributes() const;
     void BindAttribLocation(GLuint prog, const nsCString& userName, GLuint index) const;
+    bool FindActiveOutputMappedNameByUserName(const nsACString& userName,
+                                              nsCString* const out_mappedName) const;
     bool FindAttribUserNameByMappedName(const nsACString& mappedName,
                                         nsDependentCString* const out_userName) const;
     bool FindVaryingByMappedName(const nsACString& mappedName,
                                  nsCString* const out_userName,
                                  bool* const out_isArray) const;
     bool FindUniformByMappedName(const nsACString& mappedName,
                                  nsCString* const out_userName,
                                  bool* const out_isArray) const;
--- a/dom/canvas/WebGLShaderValidator.cpp
+++ b/dom/canvas/WebGLShaderValidator.cpp
@@ -392,16 +392,31 @@ ShaderValidator::FindAttribUserNameByMap
             return true;
         }
     }
 
     return false;
 }
 
 bool
+ShaderValidator::FindActiveOutputMappedNameByUserName(const std::string& userName,
+                                                      const std::string** const out_mappedName) const
+{
+    const std::vector<sh::OutputVariable>& varibles = *ShGetOutputVariables(mHandle);
+    for (auto itr = varibles.begin(); itr != varibles.end(); ++itr) {
+        if (itr->name == userName) {
+            *out_mappedName = &(itr->mappedName);
+            return true;
+        }
+    }
+
+    return false;
+}
+
+bool
 ShaderValidator::FindAttribMappedNameByUserName(const std::string& userName,
                                                 const std::string** const out_mappedName) const
 {
     const std::vector<sh::Attribute>& attribs = *ShGetAttributes(mHandle);
     for (auto itr = attribs.begin(); itr != attribs.end(); ++itr) {
         if (itr->name == userName) {
             *out_mappedName = &(itr->mappedName);
             return true;
--- a/dom/canvas/WebGLShaderValidator.h
+++ b/dom/canvas/WebGLShaderValidator.h
@@ -43,16 +43,19 @@ public:
     void GetOutput(nsACString* out) const;
     bool CanLinkTo(const ShaderValidator* prev, nsCString* const out_log) const;
     size_t CalcNumSamplerUniforms() const;
     size_t NumAttributes() const;
 
     bool FindAttribUserNameByMappedName(const std::string& mappedName,
                                         const std::string** const out_userName) const;
 
+    bool FindActiveOutputMappedNameByUserName(const std::string& userName,
+                                              const std::string** const out_mappedName) const;
+
     bool FindAttribMappedNameByUserName(const std::string& userName,
                                         const std::string** const out_mappedName) const;
 
     bool FindVaryingMappedNameByUserName(const std::string& userName,
                                          const std::string** const out_mappedName) const;
 
     bool FindVaryingByMappedName(const std::string& mappedName,
                                  std::string* const out_userName,