[Mesa-dev] [WIP 05/13] glsl: change do_common_optimization signature

Tapani Pälli tapani.palli at intel.com
Thu Mar 27 23:45:28 PDT 2014


Patch adds gl_shader_program struct as a mandatory parameter
for calls that supply linked IR. This is to assure that optimization
passes can construct common data to be used in a gl_shader_program
across shader stages. This will be utilized by explicit uniform
locations to save data on unactive uniforms that get removed by the
optimization passes.

Signed-off-by: Tapani Pälli <tapani.palli at intel.com>
---
 src/glsl/glsl_parser_extras.cpp            | 8 +++++++-
 src/glsl/ir_optimization.h                 | 3 ++-
 src/glsl/linker.cpp                        | 7 ++++++-
 src/mesa/drivers/dri/i965/brw_shader.cpp   | 3 ++-
 src/mesa/program/ir_to_mesa.cpp            | 2 +-
 src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 3 ++-
 6 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp
index 61ae621..e5fcd91 100644
--- a/src/glsl/glsl_parser_extras.cpp
+++ b/src/glsl/glsl_parser_extras.cpp
@@ -1502,10 +1502,16 @@ bool
 do_common_optimization(exec_list *ir, bool linked,
 		       bool uniform_locations_assigned,
 		       unsigned max_unroll_iterations,
-                       const struct gl_shader_compiler_options *options)
+                       const struct gl_shader_compiler_options *options,
+                       struct gl_shader_program *prog)
 {
    GLboolean progress = GL_FALSE;
 
+   if (linked) {
+      /* linked shader must have gl_shader_program supplied here */
+      assert(prog);
+   }
+
    progress = lower_instructions(ir, SUB_TO_ADD_NEG) || progress;
 
    if (linked) {
diff --git a/src/glsl/ir_optimization.h b/src/glsl/ir_optimization.h
index 5f4a2f4..8db6e2e 100644
--- a/src/glsl/ir_optimization.h
+++ b/src/glsl/ir_optimization.h
@@ -67,7 +67,8 @@ enum lower_packing_builtins_op {
 bool do_common_optimization(exec_list *ir, bool linked,
 			    bool uniform_locations_assigned,
 			    unsigned max_unroll_iterations,
-                            const struct gl_shader_compiler_options *options);
+                            const struct gl_shader_compiler_options *options,
+                            struct gl_shader_program *prog = NULL);
 
 bool do_algebraic(exec_list *instructions);
 bool do_constant_folding(exec_list *instructions);
diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp
index 3bf2789..43db824 100644
--- a/src/glsl/linker.cpp
+++ b/src/glsl/linker.cpp
@@ -2298,7 +2298,12 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
 
       unsigned max_unroll = ctx->ShaderCompilerOptions[i].MaxUnrollIterations;
 
-      while (do_common_optimization(prog->_LinkedShaders[i]->ir, true, false, max_unroll, &ctx->ShaderCompilerOptions[i]))
+      while (do_common_optimization(prog->_LinkedShaders[i]->ir,
+                                    true,
+                                    false,
+                                    max_unroll,
+                                    &ctx->ShaderCompilerOptions[i],
+                                    prog))
 	 ;
    }
 
diff --git a/src/mesa/drivers/dri/i965/brw_shader.cpp b/src/mesa/drivers/dri/i965/brw_shader.cpp
index bbc5f3d..c938e4b 100644
--- a/src/mesa/drivers/dri/i965/brw_shader.cpp
+++ b/src/mesa/drivers/dri/i965/brw_shader.cpp
@@ -202,7 +202,8 @@ brw_link_shader(struct gl_context *ctx, struct gl_shader_program *shProg)
 				   ) || progress;
 
 	 progress = do_common_optimization(shader->base.ir, true, true, 32,
-                                           &ctx->ShaderCompilerOptions[stage])
+                                           &ctx->ShaderCompilerOptions[stage],
+                                           shProg)
 	   || progress;
       } while (progress);
 
diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
index 9598710..e65daa4 100644
--- a/src/mesa/program/ir_to_mesa.cpp
+++ b/src/mesa/program/ir_to_mesa.cpp
@@ -3009,7 +3009,7 @@ _mesa_ir_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
 
 	 progress = do_common_optimization(ir, true, true,
 					   options->MaxUnrollIterations,
-                                           options)
+                                           options, prog)
 	   || 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 f019a55..875a826 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -5357,7 +5357,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->MaxUnrollIterations, options)
+					   options->MaxUnrollIterations,
+					   options, prog)
 	   || progress;
 
          progress = lower_if_to_cond_assign(ir, options->MaxIfDepth) || progress;
-- 
1.8.3.1



More information about the mesa-dev mailing list