[Mesa-dev] [PATCH 3/3] glsl: don't eliminate unused inputs to SSO

Timothy Arceri t_arceri at yahoo.com.au
Thu Nov 19 02:48:20 PST 2015


From: Timothy Arceri <timothy.arceri at collabora.com>

We do however allow unused builtins to be removed.

Cc: Ian Romanick <ian.d.romanick at intel.com>
Cc: Gregory Hainaut <gregory.hainaut at gmail.com>
https://bugs.freedesktop.org/show_bug.cgi?id=79783
---
 src/glsl/glsl_parser_extras.cpp            |  8 +++++---
 src/glsl/ir_optimization.h                 |  5 +++--
 src/glsl/linker.cpp                        | 11 ++++++-----
 src/glsl/lower_named_interface_blocks.cpp  |  1 +
 src/glsl/opt_dead_code.cpp                 | 10 ++++++++--
 src/glsl/test_optpass.cpp                  |  5 +++--
 src/mesa/drivers/dri/i965/brw_link.cpp     |  3 ++-
 src/mesa/main/ff_fragment_shader.cpp       |  3 ++-
 src/mesa/program/ir_to_mesa.cpp            |  3 ++-
 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |  3 ++-
 10 files changed, 34 insertions(+), 18 deletions(-)

diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp
index 0dbef67..6348ac0 100644
--- a/src/glsl/glsl_parser_extras.cpp
+++ b/src/glsl/glsl_parser_extras.cpp
@@ -1798,7 +1798,7 @@ _mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *shader,
        * and reduce later work if the same shader is linked multiple times
        */
       while (do_common_optimization(shader->ir, false, false, options,
-                                    ctx->Const.NativeIntegers))
+                                    ctx->Const.NativeIntegers, false))
          ;
 
       validate_ir_tree(shader->ir);
@@ -1896,7 +1896,8 @@ bool
 do_common_optimization(exec_list *ir, bool linked,
 		       bool uniform_locations_assigned,
                        const struct gl_shader_compiler_options *options,
-                       bool native_integers)
+                       bool native_integers,
+                       bool separate_shader)
 {
    GLboolean progress = GL_FALSE;
 
@@ -1921,7 +1922,8 @@ do_common_optimization(exec_list *ir, bool linked,
    }
 
    if (linked)
-      progress = do_dead_code(ir, uniform_locations_assigned) || progress;
+      progress = do_dead_code(ir, uniform_locations_assigned, separate_shader)
+        || progress;
    else
       progress = do_dead_code_unlinked(ir) || progress;
    progress = do_dead_code_local(ir) || progress;
diff --git a/src/glsl/ir_optimization.h b/src/glsl/ir_optimization.h
index 2fee81c..c2628f1 100644
--- a/src/glsl/ir_optimization.h
+++ b/src/glsl/ir_optimization.h
@@ -75,7 +75,7 @@ enum lower_packing_builtins_op {
 bool do_common_optimization(exec_list *ir, bool linked,
 			    bool uniform_locations_assigned,
                             const struct gl_shader_compiler_options *options,
-                            bool native_integers);
+                            bool native_integers, bool separate_shader);
 
 bool do_rebalance_tree(exec_list *instructions);
 bool do_algebraic(exec_list *instructions, bool native_integers,
@@ -91,7 +91,8 @@ void do_dead_builtin_varyings(struct gl_context *ctx,
                               gl_shader *producer, gl_shader *consumer,
                               unsigned num_tfeedback_decls,
                               class tfeedback_decl *tfeedback_decls);
-bool do_dead_code(exec_list *instructions, bool uniform_locations_assigned);
+bool do_dead_code(exec_list *instructions, bool uniform_locations_assigned,
+                  bool separate_shader);
 bool do_dead_code_local(exec_list *instructions);
 bool do_dead_code_unlinked(exec_list *instructions);
 bool do_dead_functions(exec_list *instructions);
diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp
index 8e7d92e..49f181f 100644
--- a/src/glsl/linker.cpp
+++ b/src/glsl/linker.cpp
@@ -4224,7 +4224,8 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
 
       while (do_common_optimization(prog->_LinkedShaders[i]->ir, true, false,
                                     &ctx->Const.ShaderCompilerOptions[i],
-                                    ctx->Const.NativeIntegers))
+                                    ctx->Const.NativeIntegers,
+                                    prog->SeparateShader))
 	 ;
 
       lower_const_arrays_to_uniforms(prog->_LinkedShaders[i]->ir);
@@ -4338,7 +4339,7 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
 
       /* Eliminate code that is now dead due to unused outputs being demoted.
        */
-      while (do_dead_code(sh->ir, false))
+      while (do_dead_code(sh->ir, false, prog->SeparateShader))
          ;
    }
    else if (first == MESA_SHADER_FRAGMENT) {
@@ -4359,7 +4360,7 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
       } else
          demote_shader_inputs_and_outputs(sh, ir_var_shader_in);
 
-      while (do_dead_code(sh->ir, false))
+      while (do_dead_code(sh->ir, false, prog->SeparateShader))
          ;
    }
 
@@ -4387,9 +4388,9 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
          /* Eliminate code that is now dead due to unused outputs being
           * demoted.
           */
-         while (do_dead_code(sh_i->ir, false))
+         while (do_dead_code(sh_i->ir, false, prog->SeparateShader))
             ;
-         while (do_dead_code(sh_next->ir, false))
+         while (do_dead_code(sh_next->ir, false, prog->SeparateShader))
             ;
       }
 
diff --git a/src/glsl/lower_named_interface_blocks.cpp b/src/glsl/lower_named_interface_blocks.cpp
index 114bb58..f29eba4 100644
--- a/src/glsl/lower_named_interface_blocks.cpp
+++ b/src/glsl/lower_named_interface_blocks.cpp
@@ -187,6 +187,7 @@ flatten_named_interface_blocks_declarations::run(exec_list *instructions)
             new_var->data.sample = iface_t->fields.structure[i].sample;
             new_var->data.patch = iface_t->fields.structure[i].patch;
             new_var->data.stream = var->data.stream;
+            new_var->data.how_declared = var->data.how_declared;
 
             new_var->init_interface_type(iface_t);
             hash_table_insert(interface_namespace, new_var,
diff --git a/src/glsl/opt_dead_code.cpp b/src/glsl/opt_dead_code.cpp
index c5be166..8685d0f 100644
--- a/src/glsl/opt_dead_code.cpp
+++ b/src/glsl/opt_dead_code.cpp
@@ -43,7 +43,8 @@ static bool debug = false;
  * for usage on an unlinked instruction stream.
  */
 bool
-do_dead_code(exec_list *instructions, bool uniform_locations_assigned)
+do_dead_code(exec_list *instructions, bool uniform_locations_assigned,
+             bool separate_shader)
 {
    ir_variable_refcount_visitor v;
    bool progress = false;
@@ -139,6 +140,11 @@ do_dead_code(exec_list *instructions, bool uniform_locations_assigned)
                continue;
          }
 
+        /* For SSO only remove builtin inputs */
+        if (separate_shader && entry->var->data.mode == ir_var_shader_in &&
+            entry->var->data.how_declared != ir_var_declared_implicitly) {
+           continue;
+}
 	 entry->var->remove();
 	 progress = true;
 
@@ -173,7 +179,7 @@ do_dead_code_unlinked(exec_list *instructions)
 	     * inside the body of the function, something has already gone
 	     * terribly, terribly wrong.
 	     */
-	    if (do_dead_code(&sig->body, false))
+	    if (do_dead_code(&sig->body, false, false))
 	       progress = true;
 	 }
       }
diff --git a/src/glsl/test_optpass.cpp b/src/glsl/test_optpass.cpp
index fed1fab..4413a60 100644
--- a/src/glsl/test_optpass.cpp
+++ b/src/glsl/test_optpass.cpp
@@ -63,7 +63,8 @@ do_optimization(struct exec_list *ir, const char *optimization,
    int int_4;
 
    if (sscanf(optimization, "do_common_optimization ( %d ) ", &int_0) == 1) {
-      return do_common_optimization(ir, int_0 != 0, false, options, true);
+      return do_common_optimization(ir, int_0 != 0, false, options, true,
+                                    false);
    } else if (strcmp(optimization, "do_algebraic") == 0) {
       return do_algebraic(ir, true, options);
    } else if (strcmp(optimization, "do_constant_folding") == 0) {
@@ -79,7 +80,7 @@ do_optimization(struct exec_list *ir, const char *optimization,
    } else if (strcmp(optimization, "do_constant_propagation") == 0) {
       return do_constant_propagation(ir);
    } else if (strcmp(optimization, "do_dead_code") == 0) {
-      return do_dead_code(ir, false);
+      return do_dead_code(ir, false, false);
    } else if (strcmp(optimization, "do_dead_code_local") == 0) {
       return do_dead_code_local(ir);
    } else if (strcmp(optimization, "do_dead_code_unlinked") == 0) {
diff --git a/src/mesa/drivers/dri/i965/brw_link.cpp b/src/mesa/drivers/dri/i965/brw_link.cpp
index 2991173..def550f 100644
--- a/src/mesa/drivers/dri/i965/brw_link.cpp
+++ b/src/mesa/drivers/dri/i965/brw_link.cpp
@@ -173,7 +173,8 @@ process_glsl_ir(gl_shader_stage stage,
                                 ) || progress;
 
       progress = do_common_optimization(shader->ir, true, true,
-                                        options, ctx->Const.NativeIntegers) || progress;
+                                        options, ctx->Const.NativeIntegers,
+                                        shader_prog->SeparateShader) || progress;
    } while (progress);
 
    validate_ir_tree(shader->ir);
diff --git a/src/mesa/main/ff_fragment_shader.cpp b/src/mesa/main/ff_fragment_shader.cpp
index e63d0f1..f6093a6 100644
--- a/src/mesa/main/ff_fragment_shader.cpp
+++ b/src/mesa/main/ff_fragment_shader.cpp
@@ -1250,7 +1250,8 @@ create_new_program(struct gl_context *ctx, struct state_key *key)
       &ctx->Const.ShaderCompilerOptions[MESA_SHADER_FRAGMENT];
 
    while (do_common_optimization(p.shader->ir, false, false, options,
-                                 ctx->Const.NativeIntegers))
+                                 ctx->Const.NativeIntegers,
+                                 p.shader_program->SeparateShader))
       ;
    reparent_ir(p.shader->ir, p.shader->ir);
 
diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
index 61a5064..7c97fe2 100644
--- a/src/mesa/program/ir_to_mesa.cpp
+++ b/src/mesa/program/ir_to_mesa.cpp
@@ -2897,7 +2897,8 @@ _mesa_ir_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
 	 progress = do_lower_jumps(ir, true, true, options->EmitNoMainReturn, options->EmitNoCont, options->EmitNoLoops) || progress;
 
 	 progress = do_common_optimization(ir, true, true,
-                                           options, ctx->Const.NativeIntegers)
+                                           options, ctx->Const.NativeIntegers,
+                                           prog->SeparateShader)
 	   || progress;
 
 	 progress = lower_quadop_vector(ir, true) || progress;
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 3ad1afd..98cd564 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -5839,7 +5839,8 @@ st_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
          progress = do_lower_jumps(ir, true, true, options->EmitNoMainReturn, options->EmitNoCont, options->EmitNoLoops) || progress;
 
          progress = do_common_optimization(ir, true, true, options,
-                                           ctx->Const.NativeIntegers)
+                                           ctx->Const.NativeIntegers,
+                                           prog->SeparateShader)
            || progress;
 
          progress = lower_if_to_cond_assign(ir, options->MaxIfDepth) || progress;
-- 
2.4.3



More information about the mesa-dev mailing list