[Mesa-dev] [PATCH 05/15] glsl: Do some "post link" optimizations on just built-in functions
Ian Romanick
idr at freedesktop.org
Thu Sep 15 22:12:38 UTC 2016
From: Ian Romanick <ian.d.romanick at intel.com>
This enables the support added by the previous two patches in
do_common_optimization. This will be used by the stand-alone compiler.
Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
src/compiler/glsl/glsl_parser_extras.cpp | 12 ++++++++----
src/compiler/glsl/ir_optimization.h | 3 ++-
src/compiler/glsl/linker.cpp | 3 ++-
src/compiler/glsl/test_optpass.cpp | 2 +-
src/mesa/drivers/dri/i965/brw_link.cpp | 3 ++-
src/mesa/main/ff_fragment_shader.cpp | 2 +-
src/mesa/program/ir_to_mesa.cpp | 3 ++-
src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 2 +-
8 files changed, 19 insertions(+), 11 deletions(-)
diff --git a/src/compiler/glsl/glsl_parser_extras.cpp b/src/compiler/glsl/glsl_parser_extras.cpp
index 807bf3f..e2e5cb7 100644
--- a/src/compiler/glsl/glsl_parser_extras.cpp
+++ b/src/compiler/glsl/glsl_parser_extras.cpp
@@ -1921,7 +1921,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);
@@ -2020,7 +2020,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 process_builtin_functions)
{
const bool debug = false;
GLboolean progress = GL_FALSE;
@@ -2041,9 +2042,12 @@ do_common_optimization(exec_list *ir, bool linked,
OPT(lower_instructions, ir, SUB_TO_ADD_NEG);
+ if (linked || process_builtin_functions) {
+ /* If the shader is not linked, only inline built-in functions. */
+ OPT(do_function_inlining, ir, !linked);
+ OPT(do_dead_functions, ir, !linked);
+ }
if (linked) {
- OPT(do_function_inlining, ir, false);
- OPT(do_dead_functions, ir, false);
OPT(do_structure_splitting, ir);
}
propagate_invariance(ir);
diff --git a/src/compiler/glsl/ir_optimization.h b/src/compiler/glsl/ir_optimization.h
index 20c17e3..bb97c6e 100644
--- a/src/compiler/glsl/ir_optimization.h
+++ b/src/compiler/glsl/ir_optimization.h
@@ -78,7 +78,8 @@ 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 process_builtin_functions);
bool ir_constant_fold(ir_rvalue **rvalue);
diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp
index f3eece2..2699c1e 100644
--- a/src/compiler/glsl/linker.cpp
+++ b/src/compiler/glsl/linker.cpp
@@ -5031,7 +5031,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,
+ false))
;
lower_const_arrays_to_uniforms(prog->_LinkedShaders[i]->ir);
diff --git a/src/compiler/glsl/test_optpass.cpp b/src/compiler/glsl/test_optpass.cpp
index 3659c8b..baa1ee5 100644
--- a/src/compiler/glsl/test_optpass.cpp
+++ b/src/compiler/glsl/test_optpass.cpp
@@ -63,7 +63,7 @@ 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) {
diff --git a/src/mesa/drivers/dri/i965/brw_link.cpp b/src/mesa/drivers/dri/i965/brw_link.cpp
index 2b1fa61..d8f14ef 100644
--- a/src/mesa/drivers/dri/i965/brw_link.cpp
+++ b/src/mesa/drivers/dri/i965/brw_link.cpp
@@ -171,7 +171,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,
+ false) || 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 db3736e..91e4462 100644
--- a/src/mesa/main/ff_fragment_shader.cpp
+++ b/src/mesa/main/ff_fragment_shader.cpp
@@ -1252,7 +1252,7 @@ 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, false))
;
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 530c00f..1149c41 100644
--- a/src/mesa/program/ir_to_mesa.cpp
+++ b/src/mesa/program/ir_to_mesa.cpp
@@ -2986,7 +2986,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,
+ false)
|| 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 507a782..2a85720 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -6939,7 +6939,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,
- ctx->Const.NativeIntegers)
+ ctx->Const.NativeIntegers, false)
|| progress;
progress = lower_if_to_cond_assign(ir, options->MaxIfDepth) || progress;
--
2.5.5
More information about the mesa-dev
mailing list