[Mesa-dev] [PATCH 3/6] glsl: Pass struct shader_compiler_options into do_common_optimization.
Kenneth Graunke
kenneth at whitecape.org
Wed Apr 17 17:30:22 PDT 2013
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 at whitecape.org>
---
src/glsl/glsl_parser_extras.cpp | 4 +++-
src/glsl/ir_optimization.h | 3 ++-
src/glsl/linker.cpp | 2 +-
src/glsl/main.cpp | 4 +++-
src/mesa/drivers/dri/i965/brw_shader.cpp | 3 ++-
src/mesa/main/ff_fragment_shader.cpp | 5 ++++-
src/mesa/program/ir_to_mesa.cpp | 7 +++++--
src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 2 +-
8 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp
index 0992294..37e9196 100644
--- a/src/glsl/glsl_parser_extras.cpp
+++ b/src/glsl/glsl_parser_extras.cpp
@@ -1202,11 +1202,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;
diff --git a/src/glsl/ir_optimization.h b/src/glsl/ir_optimization.h
index a8885d7..a8948bc 100644
--- a/src/glsl/ir_optimization.h
+++ b/src/glsl/ir_optimization.h
@@ -65,7 +65,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);
diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp
index 2b30d2b..10d9fea 100644
--- a/src/glsl/linker.cpp
+++ b/src/glsl/linker.cpp
@@ -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]))
;
}
diff --git a/src/glsl/main.cpp b/src/glsl/main.cpp
index ce084b4..d7e35bc 100644
--- a/src/glsl/main.cpp
+++ b/src/glsl/main.cpp
@@ -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);
diff --git a/src/mesa/drivers/dri/i965/brw_shader.cpp b/src/mesa/drivers/dri/i965/brw_shader.cpp
index b3bd1b9..ff7ecf9 100644
--- a/src/mesa/drivers/dri/i965/brw_shader.cpp
+++ b/src/mesa/drivers/dri/i965/brw_shader.cpp
@@ -207,7 +207,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);
diff --git a/src/mesa/main/ff_fragment_shader.cpp b/src/mesa/main/ff_fragment_shader.cpp
index 01a4542..91c425b 100644
--- a/src/mesa/main/ff_fragment_shader.cpp
+++ b/src/mesa/main/ff_fragment_shader.cpp
@@ -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);
diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
index 14cf5ba..d54ae25 100644
--- a/src/mesa/program/ir_to_mesa.cpp
+++ b/src/mesa/program/ir_to_mesa.cpp
@@ -3012,7 +3012,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;
@@ -3118,11 +3119,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);
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index f2eb3e7..48eee3b 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -5245,7 +5245,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;
--
1.8.2.1
More information about the mesa-dev
mailing list