Mesa (master): mesa: add gl_constants::GLSLOptimizeConservatively

Marek Olšák mareko at kemper.freedesktop.org
Thu Jan 5 12:08:32 UTC 2017


Module: Mesa
Branch: master
Commit: 0a5018c1a483abe6c4dddc6c65a7f4e939efc726
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=0a5018c1a483abe6c4dddc6c65a7f4e939efc726

Author: Marek Olšák <marek.olsak at amd.com>
Date:   Sat Dec 31 13:42:09 2016 +0100

mesa: add gl_constants::GLSLOptimizeConservatively

to reduce the amount of GLSL optimizations for drivers that can do better.

Reviewed-by: Eric Anholt <eric at anholt.net>

---

 src/compiler/glsl/glsl_parser_extras.cpp | 14 +++++++++++---
 src/compiler/glsl/linker.cpp             | 16 ++++++++++++----
 src/mesa/main/ff_fragment_shader.cpp     | 10 +++++++---
 src/mesa/main/mtypes.h                   |  7 +++++++
 4 files changed, 37 insertions(+), 10 deletions(-)

diff --git a/src/compiler/glsl/glsl_parser_extras.cpp b/src/compiler/glsl/glsl_parser_extras.cpp
index b12cf3d..e97cbf4 100644
--- a/src/compiler/glsl/glsl_parser_extras.cpp
+++ b/src/compiler/glsl/glsl_parser_extras.cpp
@@ -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);
 
diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp
index f4f918a..13fbb30 100644
--- a/src/compiler/glsl/linker.cpp
+++ b/src/compiler/glsl/linker.cpp
@@ -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);
diff --git a/src/mesa/main/ff_fragment_shader.cpp b/src/mesa/main/ff_fragment_shader.cpp
index fd2c71f..48b84e8 100644
--- a/src/mesa/main/ff_fragment_shader.cpp
+++ b/src/mesa/main/ff_fragment_shader.cpp
@@ -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;
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index c7535a3..2693a80 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -3643,6 +3643,13 @@ struct gl_constants
    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.
     */




More information about the mesa-commit mailing list