Bug 1325238 - Use ShCompileOptions type instead of int. - r=daoshengmu draft
authorJeff Gilbert <jgilbert@mozilla.com>
Wed, 21 Dec 2016 16:37:25 -0800
changeset 452706 7cc690a7ab9841fd09b97d5bb7f0360b7e3556f6
parent 452190 eeaa51f4a55d08e69438fa7ccb43543987a5641b
child 452714 423f9ecb33fdf076426e93d5fa5861c352ec7ba0
push id39454
push userbmo:jgilbert@mozilla.com
push dateThu, 22 Dec 2016 00:41:12 +0000
reviewersdaoshengmu
bugs1325238
milestone53.0a1
Bug 1325238 - Use ShCompileOptions type instead of int. - r=daoshengmu Also only use SH_LIMIT_CALL_STACK_DEPTH if we have resources.MaxCallStackDepth. MozReview-Commit-ID: DXhw7A7gCjF
dom/canvas/WebGLShaderValidator.cpp
dom/canvas/WebGLShaderValidator.h
--- a/dom/canvas/WebGLShaderValidator.cpp
+++ b/dom/canvas/WebGLShaderValidator.cpp
@@ -23,48 +23,31 @@ IdentifierHashFunc(const char* name, siz
 {
     // NB: we use the x86 function everywhere, even though it's suboptimal perf
     // on x64.  They return different results; not sure if that's a requirement.
     uint64_t hash[2];
     MurmurHash3_x86_128(name, len, 0, hash);
     return hash[0];
 }
 
-static int
+static ShCompileOptions
 ChooseValidatorCompileOptions(const ShBuiltInResources& resources,
                               const mozilla::gl::GLContext* gl)
 {
-    int options = SH_VARIABLES |
-                  SH_ENFORCE_PACKING_RESTRICTIONS |
-                  SH_OBJECT_CODE |
-                  SH_LIMIT_CALL_STACK_DEPTH |
-                  SH_INIT_GL_POSITION;
-
-    if (resources.MaxExpressionComplexity > 0) {
-        options |= SH_LIMIT_EXPRESSION_COMPLEXITY;
-    }
+    ShCompileOptions options = SH_VARIABLES |
+                               SH_ENFORCE_PACKING_RESTRICTIONS |
+                               SH_OBJECT_CODE |
+                               SH_INIT_GL_POSITION;
 
     // Sampler arrays indexed with non-constant expressions are forbidden in
     // GLSL 1.30 and later.
     // ESSL 3 requires constant-integral-expressions for this as well.
     // Just do it universally.
     options |= SH_UNROLL_FOR_LOOP_WITH_SAMPLER_ARRAY_INDEX;
 
-    if (gfxPrefs::WebGLAllANGLEOptions()) {
-        return options |
-               SH_VALIDATE_LOOP_INDEXING |
-               SH_UNROLL_FOR_LOOP_WITH_INTEGER_INDEX |
-               SH_UNROLL_FOR_LOOP_WITH_SAMPLER_ARRAY_INDEX |
-               SH_CLAMP_INDIRECT_ARRAY_BOUNDS |
-               SH_UNFOLD_SHORT_CIRCUIT |
-               SH_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS |
-               SH_INIT_OUTPUT_VARIABLES |
-               SH_REGENERATE_STRUCT_NAMES;
-    }
-
 #ifndef XP_MACOSX
     // We want to do this everywhere, but to do this on Mac, we need
     // to do it only on Mac OSX > 10.6 as this causes the shader
     // compiler in 10.6 to crash
     options |= SH_CLAMP_INDIRECT_ARRAY_BOUNDS;
 #endif
 
 #ifdef XP_MACOSX
@@ -74,16 +57,40 @@ ChooseValidatorCompileOptions(const ShBu
         options |= SH_UNFOLD_SHORT_CIRCUIT;
 
         // Work around that Mac drivers handle struct scopes incorrectly.
         options |= SH_REGENERATE_STRUCT_NAMES;
         options |= SH_INIT_OUTPUT_VARIABLES;
     }
 #endif
 
+    if (gfxPrefs::WebGLAllANGLEOptions()) {
+        options = -1;
+
+        options ^= SH_INTERMEDIATE_TREE;
+        options ^= SH_LINE_DIRECTIVES;
+        options ^= SH_SOURCE_PATH;
+
+        options ^= SH_LIMIT_EXPRESSION_COMPLEXITY;
+        options ^= SH_LIMIT_CALL_STACK_DEPTH;
+
+        options ^= SH_EXPAND_SELECT_HLSL_INTEGER_POW_EXPRESSIONS;
+        options ^= SH_HLSL_GET_DIMENSIONS_IGNORES_BASE_LEVEL;
+
+        options ^= SH_DONT_REMOVE_INVARIANT_FOR_FRAGMENT_INPUT;
+        options ^= SH_REMOVE_INVARIANT_AND_CENTROID_FOR_ESSL3;
+    }
+
+    if (resources.MaxExpressionComplexity > 0) {
+        options |= SH_LIMIT_EXPRESSION_COMPLEXITY;
+    }
+    if (resources.MaxCallStackDepth > 0) {
+        options |= SH_LIMIT_CALL_STACK_DEPTH;
+    }
+
     return options;
 }
 
 } // namespace webgl
 
 ////////////////////////////////////////
 
 static ShShaderOutput
@@ -161,30 +168,30 @@ WebGLContext::CreateShaderValidator(GLen
 #ifdef XP_MACOSX
         if (gl->Vendor() == gl::GLVendor::NVIDIA) {
             // Work around bug 890432
             resources.MaxExpressionComplexity = 1000;
         }
 #endif
     }
 
-    int compileOptions = webgl::ChooseValidatorCompileOptions(resources, gl);
-
+    const auto compileOptions = webgl::ChooseValidatorCompileOptions(resources, gl);
     return webgl::ShaderValidator::Create(shaderType, spec, outputLanguage, resources,
                                           compileOptions);
 }
 
 ////////////////////////////////////////
 
 namespace webgl {
 
 /*static*/ ShaderValidator*
 ShaderValidator::Create(GLenum shaderType, ShShaderSpec spec,
                         ShShaderOutput outputLanguage,
-                        const ShBuiltInResources& resources, int compileOptions)
+                        const ShBuiltInResources& resources,
+                        ShCompileOptions compileOptions)
 {
     ShHandle handle = ShConstructCompiler(shaderType, spec, outputLanguage, &resources);
     if (!handle)
         return nullptr;
 
     return new ShaderValidator(handle, compileOptions, resources.MaxVaryingVectors);
 }
 
--- a/dom/canvas/WebGLShaderValidator.h
+++ b/dom/canvas/WebGLShaderValidator.h
@@ -12,28 +12,29 @@
 #include <string>
 
 namespace mozilla {
 namespace webgl {
 
 class ShaderValidator final
 {
     const ShHandle mHandle;
-    const int mCompileOptions;
+    const ShCompileOptions mCompileOptions;
     const int mMaxVaryingVectors;
     bool mHasRun;
 
 public:
     static ShaderValidator* Create(GLenum shaderType, ShShaderSpec spec,
                                    ShShaderOutput outputLanguage,
                                    const ShBuiltInResources& resources,
-                                   int compileOptions);
+                                   ShCompileOptions compileOptions);
 
 private:
-    ShaderValidator(ShHandle handle, int compileOptions, int maxVaryingVectors)
+    ShaderValidator(ShHandle handle, ShCompileOptions compileOptions,
+                    int maxVaryingVectors)
         : mHandle(handle)
         , mCompileOptions(compileOptions)
         , mMaxVaryingVectors(maxVaryingVectors)
         , mHasRun(false)
     { }
 
 public:
     ~ShaderValidator();