mesa: add gl_constants::GLSLOptimizeConservatively
authorMarek Olšák <marek.olsak@amd.com>
Sat, 31 Dec 2016 12:42:09 +0000 (13:42 +0100)
committerMarek Olšák <marek.olsak@amd.com>
Thu, 5 Jan 2017 12:07:12 +0000 (13:07 +0100)
to reduce the amount of GLSL optimizations for drivers that can do better.

Reviewed-by: Eric Anholt <eric@anholt.net>
src/compiler/glsl/glsl_parser_extras.cpp
src/compiler/glsl/linker.cpp
src/mesa/main/ff_fragment_shader.cpp
src/mesa/main/mtypes.h

index b12cf3d90c0073a84a2e87c7ca8a5028223ce537..e97cbf4b8260d943a3396dff98d2d7698e1568f9 100644 (file)
@@ -1949,12 +1949,20 @@ _mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *shader,
 
       assign_subroutine_indexes(shader, state);
       lower_subroutine(shader->ir, state);
+
       /* Do some optimization at compile time to reduce shader IR size
        * and reduce later work if the same shader is linked multiple times
        */
-      while (do_common_optimization(shader->ir, false, false, options,
-                                    ctx->Const.NativeIntegers))
-         ;
+      if (ctx->Const.GLSLOptimizeConservatively) {
+         /* Run it just once. */
+         do_common_optimization(shader->ir, false, false, options,
+                                ctx->Const.NativeIntegers);
+      } else {
+         /* Repeat it until it stops making changes. */
+         while (do_common_optimization(shader->ir, false, false, options,
+                                       ctx->Const.NativeIntegers))
+            ;
+      }
 
       validate_ir_tree(shader->ir);
 
index f4f918a34e7e467a421b2ca6704634ecaf006b76..13fbb30b27bc71ee8dccd592754f4046d12203d0 100644 (file)
@@ -5048,10 +5048,18 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
          lower_tess_level(prog->_LinkedShaders[i]);
       }
 
-      while (do_common_optimization(prog->_LinkedShaders[i]->ir, true, false,
-                                    &ctx->Const.ShaderCompilerOptions[i],
-                                    ctx->Const.NativeIntegers))
-         ;
+      if (ctx->Const.GLSLOptimizeConservatively) {
+         /* Run it just once. */
+         do_common_optimization(prog->_LinkedShaders[i]->ir, true, false,
+                                &ctx->Const.ShaderCompilerOptions[i],
+                                ctx->Const.NativeIntegers);
+      } else {
+         /* Repeat it until it stops making changes. */
+         while (do_common_optimization(prog->_LinkedShaders[i]->ir, true, false,
+                                       &ctx->Const.ShaderCompilerOptions[i],
+                                       ctx->Const.NativeIntegers))
+            ;
+      }
 
       lower_const_arrays_to_uniforms(prog->_LinkedShaders[i]->ir, i);
       propagate_invariance(prog->_LinkedShaders[i]->ir);
index fd2c71f93ee94c656c098878d4ffef72d521c59c..48b84e8fd7324211b178428d418b75521c2f2030 100644 (file)
@@ -1254,9 +1254,13 @@ create_new_program(struct gl_context *ctx, struct state_key *key)
    const struct gl_shader_compiler_options *options =
       &ctx->Const.ShaderCompilerOptions[MESA_SHADER_FRAGMENT];
 
-   while (do_common_optimization(p.shader->ir, false, false, options,
-                                 ctx->Const.NativeIntegers))
-      ;
+   /* Conservative approach: Don't optimize here, the linker does it too. */
+   if (!ctx->Const.GLSLOptimizeConservatively) {
+      while (do_common_optimization(p.shader->ir, false, false, options,
+                                    ctx->Const.NativeIntegers))
+         ;
+   }
+
    reparent_ir(p.shader->ir, p.shader->ir);
 
    p.shader->CompileStatus = true;
index c7535a3776187aaae654f026d01535b015c39d11..2693a8068c0a63f410a235de70390c8eeec5ab21 100644 (file)
@@ -3642,6 +3642,13 @@ struct gl_constants
    bool GLSLFragCoordIsSysVal;
    bool GLSLFrontFacingIsSysVal;
 
+   /**
+    * Run the minimum amount of GLSL optimizations to be able to link
+    * shaders optimally (eliminate dead varyings and uniforms) and just do
+    * all the necessary lowering.
+    */
+   bool GLSLOptimizeConservatively;
+
    /**
     * Always use the GetTransformFeedbackVertexCount() driver hook, rather
     * than passing the transform feedback object to the drawing function.