[Mesa-dev] [PATCH 3/5] glsl: disable dead code removal of lowered ubos
Timothy Arceri
timothy.arceri at collabora.com
Sun Sep 25 12:50:26 UTC 2016
This lets us assign uniform storage for packed UBOs after
they have been lowered otherwise the var is removed too early.
---
src/compiler/glsl/glsl_parser_extras.cpp | 5 +++--
src/compiler/glsl/ir_optimization.h | 4 +++-
src/compiler/glsl/link_varyings.cpp | 2 +-
src/compiler/glsl/linker.cpp | 1 +
src/compiler/glsl/opt_dead_code.cpp | 8 +++++---
src/compiler/glsl/test_optpass.cpp | 5 +++--
src/mesa/drivers/dri/i965/brw_link.cpp | 2 +-
src/mesa/main/ff_fragment_shader.cpp | 2 +-
src/mesa/program/ir_to_mesa.cpp | 2 +-
src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 2 +-
10 files changed, 20 insertions(+), 13 deletions(-)
diff --git a/src/compiler/glsl/glsl_parser_extras.cpp b/src/compiler/glsl/glsl_parser_extras.cpp
index b108afd..82ac6db 100644
--- a/src/compiler/glsl/glsl_parser_extras.cpp
+++ b/src/compiler/glsl/glsl_parser_extras.cpp
@@ -1922,7 +1922,7 @@ _mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *shader,
/* 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, options,
+ while (do_common_optimization(shader->ir, false, false, false, options,
ctx->Const.NativeIntegers))
;
@@ -2020,6 +2020,7 @@ _mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *shader,
bool
do_common_optimization(exec_list *ir, bool linked,
bool uniform_locations_assigned,
+ bool ubos_lowered,
const struct gl_shader_compiler_options *options,
bool native_integers)
{
@@ -2062,7 +2063,7 @@ do_common_optimization(exec_list *ir, bool linked,
}
if (linked)
- OPT(do_dead_code, ir, uniform_locations_assigned);
+ OPT(do_dead_code, ir, uniform_locations_assigned, ubos_lowered);
else
OPT(do_dead_code_unlinked, ir);
OPT(do_dead_code_local, ir);
diff --git a/src/compiler/glsl/ir_optimization.h b/src/compiler/glsl/ir_optimization.h
index 3bd6928..3bda2fd 100644
--- a/src/compiler/glsl/ir_optimization.h
+++ b/src/compiler/glsl/ir_optimization.h
@@ -77,6 +77,7 @@ enum lower_packing_builtins_op {
bool do_common_optimization(exec_list *ir, bool linked,
bool uniform_locations_assigned,
+ bool ubos_lowered,
const struct gl_shader_compiler_options *options,
bool native_integers);
@@ -97,7 +98,8 @@ void do_dead_builtin_varyings(struct gl_context *ctx,
gl_linked_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 ubos_lowered);
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/compiler/glsl/link_varyings.cpp b/src/compiler/glsl/link_varyings.cpp
index e622b3e..d533e76 100644
--- a/src/compiler/glsl/link_varyings.cpp
+++ b/src/compiler/glsl/link_varyings.cpp
@@ -605,7 +605,7 @@ remove_unused_shader_inputs_and_outputs(bool is_separate_shader_object,
/* Eliminate code that is now dead due to unused inputs/outputs being
* demoted.
*/
- while (do_dead_code(sh->ir, false))
+ while (do_dead_code(sh->ir, false, true))
;
}
diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp
index c124c06..02a9b40 100644
--- a/src/compiler/glsl/linker.cpp
+++ b/src/compiler/glsl/linker.cpp
@@ -4893,6 +4893,7 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
}
while (do_common_optimization(prog->_LinkedShaders[i]->ir, true, false,
+ false,
&ctx->Const.ShaderCompilerOptions[i],
ctx->Const.NativeIntegers))
;
diff --git a/src/compiler/glsl/opt_dead_code.cpp b/src/compiler/glsl/opt_dead_code.cpp
index 75e668a..980660e 100644
--- a/src/compiler/glsl/opt_dead_code.cpp
+++ b/src/compiler/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 ubos_lowered)
{
ir_variable_refcount_visitor v;
bool progress = false;
@@ -144,7 +145,8 @@ do_dead_code(exec_list *instructions, bool uniform_locations_assigned)
* layouts, do not eliminate it.
*/
if (entry->var->is_in_buffer_block()) {
- if (entry->var->get_interface_type_packing() !=
+ if (ubos_lowered ||
+ entry->var->get_interface_type_packing() !=
GLSL_INTERFACE_PACKING_PACKED)
continue;
}
@@ -187,7 +189,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/compiler/glsl/test_optpass.cpp b/src/compiler/glsl/test_optpass.cpp
index 852af19..2df7371 100644
--- a/src/compiler/glsl/test_optpass.cpp
+++ b/src/compiler/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, false, options,
+ true);
} 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 f5dbfcf..fc2e539 100644
--- a/src/mesa/drivers/dri/i965/brw_link.cpp
+++ b/src/mesa/drivers/dri/i965/brw_link.cpp
@@ -170,7 +170,7 @@ process_glsl_ir(gl_shader_stage stage,
false /* loops */
) || progress;
- progress = do_common_optimization(shader->ir, true, true,
+ progress = do_common_optimization(shader->ir, true, true, true,
options, ctx->Const.NativeIntegers) || progress;
} while (progress);
diff --git a/src/mesa/main/ff_fragment_shader.cpp b/src/mesa/main/ff_fragment_shader.cpp
index db3736e..b8e35a7 100644
--- a/src/mesa/main/ff_fragment_shader.cpp
+++ b/src/mesa/main/ff_fragment_shader.cpp
@@ -1251,7 +1251,7 @@ create_new_program(struct gl_context *ctx, struct state_key *key)
const struct gl_shader_compiler_options *options =
&ctx->Const.ShaderCompilerOptions[MESA_SHADER_FRAGMENT];
- while (do_common_optimization(p.shader->ir, false, false, options,
+ while (do_common_optimization(p.shader->ir, false, false, false, options,
ctx->Const.NativeIntegers))
;
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..04db22d 100644
--- a/src/mesa/program/ir_to_mesa.cpp
+++ b/src/mesa/program/ir_to_mesa.cpp
@@ -2985,7 +2985,7 @@ _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,
+ progress = do_common_optimization(ir, true, true, true,
options, ctx->Const.NativeIntegers)
|| 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..73c9972 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -6938,7 +6938,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,
+ progress = do_common_optimization(ir, true, true, true, options,
ctx->Const.NativeIntegers)
|| progress;
--
2.7.4
More information about the mesa-dev
mailing list