Bug 1288638 - Update shader validator usage. - r=mtseng
authorJeff Gilbert <jgilbert@mozilla.com>
Thu, 21 Jul 2016 01:15:02 -0700
changeset 348737 2f9e3bde4fd004e32126c7c3c0e68f77589f6b88
parent 348736 8ae1c435a0939dc96ce47b977d8c78524829444f
child 348738 f8ada839cad0cad17040174331ff92afd96ec0e1
push id1230
push userjlund@mozilla.com
push dateMon, 31 Oct 2016 18:13:35 +0000
treeherdermozilla-release@5e06e3766db2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmtseng
bugs1288638
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 1288638 - Update shader validator usage. - r=mtseng MozReview-Commit-ID: 5bSUacggvR8
dom/canvas/WebGLShaderValidator.cpp
--- a/dom/canvas/WebGLShaderValidator.cpp
+++ b/dom/canvas/WebGLShaderValidator.cpp
@@ -124,23 +124,18 @@ ShaderOutput(gl::GLContext* gl)
 }
 
 webgl::ShaderValidator*
 WebGLContext::CreateShaderValidator(GLenum shaderType) const
 {
     if (mBypassShaderValidation)
         return nullptr;
 
-    ShShaderSpec spec = IsWebGL2() ? SH_WEBGL2_SPEC : SH_WEBGL_SPEC;
-    ShShaderOutput outputLanguage = gl->IsGLES() ? SH_ESSL_OUTPUT
-                                                 : SH_GLSL_COMPATIBILITY_OUTPUT;
-
-    // If we're using WebGL2 we want a more specific version of GLSL
-    if (IsWebGL2())
-        outputLanguage = ShaderOutput(gl);
+    const auto spec = (IsWebGL2() ? SH_WEBGL2_SPEC : SH_WEBGL_SPEC);
+    const auto outputLanguage = ShaderOutput(gl);
 
     ShBuiltInResources resources;
     memset(&resources, 0, sizeof(resources));
     ShInitBuiltInResources(&resources);
 
     resources.HashFunction = webgl::IdentifierHashFunc;
 
     resources.MaxVertexAttribs = mGLMaxVertexAttribs;
@@ -248,17 +243,18 @@ bool
 ShaderValidator::CanLinkTo(const ShaderValidator* prev, nsCString* const out_log) const
 {
     if (!prev) {
         nsPrintfCString error("Passed in NULL prev ShaderValidator.");
         *out_log = error;
         return false;
     }
 
-    if (ShGetShaderVersion(prev->mHandle) != ShGetShaderVersion(mHandle)) {
+    const auto shaderVersion = ShGetShaderVersion(mHandle);
+    if (ShGetShaderVersion(prev->mHandle) != shaderVersion) {
         nsPrintfCString error("Vertex shader version %d does not match"
                               " fragment shader version %d.",
                               ShGetShaderVersion(prev->mHandle),
                               ShGetShaderVersion(mHandle));
         *out_log = error;
         return false;
     }
 
@@ -314,17 +310,17 @@ ShaderValidator::CanLinkTo(const ShaderV
 
             bool definedInVertShader = false;
             bool staticVertUse = false;
 
             for (const auto& vertVarying : *vertVaryings) {
                 if (vertVarying.name != fragVarying.name)
                     continue;
 
-                if (!vertVarying.isSameVaryingAtLinkTime(fragVarying)) {
+                if (!vertVarying.isSameVaryingAtLinkTime(fragVarying, shaderVersion)) {
                     nsPrintfCString error("Varying `%s`is not linkable between"
                                           " attached shaders.",
                                           fragVarying.name.c_str());
                     *out_log = error;
                     return false;
                 }
 
                 definedInVertShader = true;
@@ -350,17 +346,18 @@ ShaderValidator::CanLinkTo(const ShaderV
                                                  staticUseVaryingList.size()))
         {
             *out_log = "Statically used varyings do not fit within packing limits. (see"
                        " GLSL ES Specification 1.0.17, p111)";
             return false;
         }
     }
 
-    {
+    if (shaderVersion == 100) {
+        // Enforce ESSL1 invariant linking rules.
         bool isInvariant_Position = false;
         bool isInvariant_PointSize = false;
         bool isInvariant_FragCoord = false;
         bool isInvariant_PointCoord = false;
 
         for (const auto& varying : *vertVaryings) {
             if (varying.name == "gl_Position") {
                 isInvariant_Position = varying.isInvariant;