glsl: Pass struct shader_compiler_options into do_common_optimization.
authorKenneth Graunke <kenneth@whitecape.org>
Thu, 18 Apr 2013 00:30:22 +0000 (17:30 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Sun, 12 May 2013 16:36:41 +0000 (09:36 -0700)
do_common_optimization may need to make choices about whether to emit
certain kinds of instructions.  gl_context::ShaderCompilerOptions
contains exactly that information, so it makes sense to pass it in.

Rather than passing the whole array, pass the structure for the stage
that's currently being worked on.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
src/glsl/glsl_parser_extras.cpp
src/glsl/ir_optimization.h
src/glsl/linker.cpp
src/glsl/main.cpp
src/mesa/drivers/dri/i965/brw_shader.cpp
src/mesa/main/ff_fragment_shader.cpp
src/mesa/program/ir_to_mesa.cpp
src/mesa/state_tracker/st_glsl_to_tgsi.cpp

index cf6c8c621516399cb8df0db14f82dd52e0eccd10..4e496a1749d0a760f30055326fe7efe217bddf7a 100644 (file)
@@ -1203,11 +1203,13 @@ ast_struct_specifier::ast_struct_specifier(const char *identifier,
  * \param max_unroll_iterations       Maximum number of loop iterations to be
  *                                    unrolled.  Setting to 0 disables loop
  *                                    unrolling.
+ * \param options                     The driver's preferred shader options.
  */
 bool
 do_common_optimization(exec_list *ir, bool linked,
                       bool uniform_locations_assigned,
-                      unsigned max_unroll_iterations)
+                      unsigned max_unroll_iterations,
+                       const struct gl_shader_compiler_options *options)
 {
    GLboolean progress = GL_FALSE;
 
index 49b1475b5424403eda6c97b9f0185ab7298b7904..9d28e9166e9b803a9d8ad73e12f35f6edb0af79b 100644 (file)
@@ -66,7 +66,8 @@ enum lower_packing_builtins_op {
 
 bool do_common_optimization(exec_list *ir, bool linked,
                            bool uniform_locations_assigned,
-                           unsigned max_unroll_iterations);
+                           unsigned max_unroll_iterations,
+                            const struct gl_shader_compiler_options *options);
 
 bool do_algebraic(exec_list *instructions);
 bool do_constant_folding(exec_list *instructions);
index 3ef5940f892f2baf47b7ac387037f79212a40d59..dea583871602d3d8e2a100b38dd146bd1b41dc12 100644 (file)
@@ -1767,7 +1767,7 @@ 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))
+      while (do_common_optimization(prog->_LinkedShaders[i]->ir, true, false, max_unroll, &ctx->ShaderCompilerOptions[i]))
         ;
    }
 
index ce084b4d7ac39c9672eebcbc51e94f501d0a8dc9..d7e35bcb3a2916071a964d3ce8ddca246544879f 100644 (file)
@@ -174,9 +174,11 @@ compile_shader(struct gl_context *ctx, struct gl_shader *shader)
 
    /* Optimization passes */
    if (!state->error && !shader->ir->is_empty()) {
+      const struct gl_shader_compiler_options *opts =
+         &ctx->ShaderCompilerOptions[_mesa_shader_type_to_index(shader->Type)];
       bool progress;
       do {
-        progress = do_common_optimization(shader->ir, false, false, 32);
+        progress = do_common_optimization(shader->ir, false, false, 32, opts);
       } while (progress);
 
       validate_ir_tree(shader->ir);
index 3bbcccdd3b35cdcc63ab0cbbe3936bf8cd61b346..8dcab75a4336480c8b58443b9852f39faaa27c54 100644 (file)
@@ -209,7 +209,8 @@ brw_link_shader(struct gl_context *ctx, struct gl_shader_program *shProg)
                                   false /* loops */
                                   ) || progress;
 
-        progress = do_common_optimization(shader->ir, true, true, 32)
+        progress = do_common_optimization(shader->ir, true, true, 32,
+                                           &ctx->ShaderCompilerOptions[stage])
           || progress;
       } while (progress);
 
index 01a4542d747c8478de9bdb91f1bb751c70ab5d22..91c425be678a21b6c7b0154c2102f763ecef295b 100644 (file)
@@ -1336,7 +1336,10 @@ create_new_program(struct gl_context *ctx, struct state_key *key)
 
    validate_ir_tree(p.shader->ir);
 
-   while (do_common_optimization(p.shader->ir, false, false, 32))
+   const struct gl_shader_compiler_options *options =
+      &ctx->ShaderCompilerOptions[MESA_SHADER_FRAGMENT];
+
+   while (do_common_optimization(p.shader->ir, false, false, 32, options))
       ;
    reparent_ir(p.shader->ir, p.shader->ir);
 
index 363efe7da65b1def1e6edfef0ced6fa1dec3e4f6..258b864f559c885d983f41b0e0686c4e4169f252 100644 (file)
@@ -3025,7 +3025,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->MaxUnrollIterations)
+                                          options->MaxUnrollIterations,
+                                           options)
           || progress;
 
         progress = lower_quadop_vector(ir, true) || progress;
@@ -3131,11 +3132,13 @@ _mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *shader)
 
    if (!state->error && !shader->ir->is_empty()) {
       validate_ir_tree(shader->ir);
+      struct gl_shader_compiler_options *options =
+         &ctx->ShaderCompilerOptions[_mesa_shader_type_to_index(shader->Type)];
 
       /* 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, 32))
+      while (do_common_optimization(shader->ir, false, false, 32, options))
         ;
 
       validate_ir_tree(shader->ir);
index dd8810d454c885ac350a0201a183fe107b931535..d175be602f4e5117c4bf42aac73ed3eeb5746519 100644 (file)
@@ -5255,7 +5255,7 @@ 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->MaxUnrollIterations, options)
           || progress;
 
          progress = lower_if_to_cond_assign(ir, options->MaxIfDepth) || progress;