[Mesa-dev] [PATCH 2/2] glsl/i965: call backend optimisations from glsl linker

Timothy Arceri timothy.arceri at collabora.com
Wed Jul 20 10:57:27 UTC 2016


Here we get the backend to do its extra GLSL IR passes before
assigning varying and uniform locations.

Broadwell shader-db results:

total instructions in shared programs: 8649621 -> 8642352 (-0.08%)
instructions in affected programs:     49023 -> 41754 (-14.83%)
helped:                                359
HURT:                                  5
---
 I attempted to reduce the amount of work required in the second
 brw_process_glsl_ir() call from brw_link_shader() but it was
 proving difficult to narrow down the requirements and didn't
 seem worth the effort as compile times of shader-db were comparable
 even now that we call this twice.

 Also if we are able to refactor link_shaders() to create nir earlier
 then this second call should go away.

 src/compiler/glsl/linker.cpp           | 14 ++++++++++++++
 src/mesa/drivers/dri/i965/brw_link.cpp |  7 ++++---
 src/mesa/drivers/dri/i965/brw_shader.h |  2 +-
 src/mesa/main/dd.h                     |  3 ++-
 4 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp
index 6d45a02..012c0ea 100644
--- a/src/compiler/glsl/linker.cpp
+++ b/src/compiler/glsl/linker.cpp
@@ -4799,6 +4799,20 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
    /* Check and validate stream emissions in geometry shaders */
    validate_geometry_shader_emissions(ctx, prog);
 
+   /* Call driver GLSL IR processing. Doing this before assigning varying
+    * locations allows us to do backend specific optimisations before we
+    * check for and remove usused varyings.
+    */
+   if (ctx->Driver.ProcessGLSLIR) {
+      for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
+         if (prog->_LinkedShaders[i] == NULL)
+	    continue;
+
+         ctx->Driver.ProcessGLSLIR(prog->_LinkedShaders[i]->Stage,
+                                   ctx, prog, prog->_LinkedShaders[i], false);
+      }
+   }
+
    /* Mark all generic shader inputs and outputs as unpaired. */
    for (unsigned i = MESA_SHADER_VERTEX; i <= MESA_SHADER_FRAGMENT; i++) {
       if (prog->_LinkedShaders[i] != NULL) {
diff --git a/src/mesa/drivers/dri/i965/brw_link.cpp b/src/mesa/drivers/dri/i965/brw_link.cpp
index 523b923..c34f9a0 100644
--- a/src/mesa/drivers/dri/i965/brw_link.cpp
+++ b/src/mesa/drivers/dri/i965/brw_link.cpp
@@ -89,7 +89,8 @@ extern "C" void
 brw_process_glsl_ir(gl_shader_stage stage,
                     struct gl_context *ctx,
                     struct gl_shader_program *shader_prog,
-                    struct gl_linked_shader *shader)
+                    struct gl_linked_shader *shader,
+                    bool uni_locs_assigned)
 {
    struct brw_context *brw = brw_context(ctx);
    const struct brw_compiler *compiler = brw->intelScreen->compiler;
@@ -163,7 +164,7 @@ brw_process_glsl_ir(gl_shader_stage stage,
                                 false /* loops */
                                 ) || progress;
 
-      progress = do_common_optimization(shader->ir, true, true,
+      progress = do_common_optimization(shader->ir, true, uni_locs_assigned,
                                         options, ctx->Const.NativeIntegers) || progress;
    } while (progress);
 
@@ -220,7 +221,7 @@ brw_link_shader(struct gl_context *ctx, struct gl_shader_program *shProg)
 
       _mesa_copy_linked_program_data((gl_shader_stage) stage, shProg, prog);
 
-      brw_process_glsl_ir((gl_shader_stage) stage, ctx, shProg, shader);
+      brw_process_glsl_ir((gl_shader_stage) stage, ctx, shProg, shader, true);
 
       /* Make a pass over the IR to add state references for any built-in
        * uniforms that are used.  This has to be done now (during linking).
diff --git a/src/mesa/drivers/dri/i965/brw_shader.h b/src/mesa/drivers/dri/i965/brw_shader.h
index 9151de8..b5e0463 100644
--- a/src/mesa/drivers/dri/i965/brw_shader.h
+++ b/src/mesa/drivers/dri/i965/brw_shader.h
@@ -293,7 +293,7 @@ struct gl_linked_shader *brw_new_shader(gl_shader_stage stage);
 void
 brw_process_glsl_ir(gl_shader_stage stage, struct gl_context *ctx,
                     struct gl_shader_program *shader_prog,
-                    struct gl_linked_shader *shader);
+                    struct gl_linked_shader *shader, bool uni_locs_assigned);
 
 int type_size_scalar(const struct glsl_type *type);
 int type_size_vec4(const struct glsl_type *type);
diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h
index fe65246..778fc55 100644
--- a/src/mesa/main/dd.h
+++ b/src/mesa/main/dd.h
@@ -788,7 +788,8 @@ struct dd_function_table {
    void (*UseProgram)(struct gl_context *ctx, struct gl_shader_program *shProg);
    void (*ProcessGLSLIR)(gl_shader_stage stage, struct gl_context *ctx,
                          struct gl_shader_program *shader_prog,
-                         struct gl_linked_shader *shader);
+                         struct gl_linked_shader *shader,
+                         bool uni_locs_assigned);
    /*@}*/
 
    /**
-- 
2.7.4



More information about the mesa-dev mailing list