[Mesa-dev] [PATCH 0.5/5] glsl: lower constant arrays to uniform arrays before optimisation loop

Timothy Arceri timothy.arceri at collabora.com
Wed Jan 18 03:27:06 UTC 2017


Previously the last stage would not get optimised until the backend did
its GLSL IR opt loop. I plan on removing that from i965 shortly which
caused huge regressions in Deus-ex and Tomb Raider which have large
constant arrays. Moving lowering before the opt loop in the GLSL linker
fixes this and unexpectedly improves some compute shaders also.

shader-db results BDW:

instructions helped:   shaders/closed/steam/deus-ex-mankind-divided/374.shader_test CS SIMD16: 204 -> 194 (-4.90%)
instructions helped:   shaders/closed/steam/deus-ex-mankind-divided/318.shader_test CS SIMD8: 1010 -> 741 (-26.63%)
instructions helped:   shaders/closed/steam/deus-ex-mankind-divided/144.shader_test CS SIMD8: 542 -> 385 (-28.97%)

cycles helped:   shaders/closed/steam/deus-ex-mankind-divided/318.shader_test CS SIMD8: 1831382 -> 1818492 (-0.70%)
cycles helped:   shaders/closed/steam/deus-ex-mankind-divided/144.shader_test CS SIMD8: 216238 -> 206180 (-4.65%)
cycles helped:   shaders/closed/steam/deus-ex-mankind-divided/374.shader_test CS SIMD16: 18484 -> 16644 (-9.95%)

total instructions in shared programs: 13060313 -> 13059877 (-0.00%)
instructions in affected programs: 1756 -> 1320 (-24.83%)
helped: 3
HURT: 0

total cycles in shared programs: 256586698 -> 256561910 (-0.01%)
cycles in affected programs: 2066104 -> 2041316 (-1.20%)
helped: 3
HURT: 0

V2: call opts before and after lowering (Suggested by Ken)
---
 src/compiler/glsl/linker.cpp | 38 ++++++++++++++++++++++++++------------
 1 file changed, 26 insertions(+), 12 deletions(-)

diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp
index d187b66..3d50963 100644
--- a/src/compiler/glsl/linker.cpp
+++ b/src/compiler/glsl/linker.cpp
@@ -4761,6 +4761,24 @@ link_varyings_and_uniforms(unsigned first, unsigned last,
    return true;
 }
 
+static void
+linker_optimisation_loop(struct gl_context *ctx, exec_list *ir,
+                         unsigned stage)
+{
+      if (ctx->Const.GLSLOptimizeConservatively) {
+         /* Run it just once. */
+         do_common_optimization(ir, true, false,
+                                &ctx->Const.ShaderCompilerOptions[stage],
+                                ctx->Const.NativeIntegers);
+      } else {
+         /* Repeat it until it stops making changes. */
+         while (do_common_optimization(ir, true, false,
+                                       &ctx->Const.ShaderCompilerOptions[stage],
+                                       ctx->Const.NativeIntegers))
+            ;
+      }
+}
+
 void
 link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
 {
@@ -5051,20 +5069,16 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
          lower_tess_level(prog->_LinkedShaders[i]);
       }
 
-      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))
-            ;
-      }
+      /* Call opts before lowering const arrays to uniforms so we can const
+       * propagate any elements accessed directly.
+       */
+      linker_optimisation_loop(ctx, prog->_LinkedShaders[i]->ir, i);
 
       lower_const_arrays_to_uniforms(prog->_LinkedShaders[i]->ir, i);
+
+      /* Call opts after lowering const arrays to copy propagate things. */
+      linker_optimisation_loop(ctx, prog->_LinkedShaders[i]->ir, i);
+
       propagate_invariance(prog->_LinkedShaders[i]->ir);
    }
 
-- 
2.9.3



More information about the mesa-dev mailing list