[Mesa-dev] [RFC PATCH 33/56] glsl: Don't lower indexing with gl_InvocationID in the TCS to cond assign
Chris Forbes
chrisf at ijw.co.nz
Sat Sep 20 18:41:13 PDT 2014
From: Fabian Bieler <fabianbieler at fastmail.fm>
---
src/glsl/ir_optimization.h | 5 +--
src/glsl/lower_variable_index_to_cond_assign.cpp | 39 ++++++++++++++++--------
src/glsl/test_optpass.cpp | 3 +-
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 | 2 +-
6 files changed, 35 insertions(+), 19 deletions(-)
diff --git a/src/glsl/ir_optimization.h b/src/glsl/ir_optimization.h
index b0a06cd..2ddbc1e 100644
--- a/src/glsl/ir_optimization.h
+++ b/src/glsl/ir_optimization.h
@@ -110,8 +110,9 @@ bool lower_discard(exec_list *instructions);
void lower_discard_flow(exec_list *instructions);
bool lower_instructions(exec_list *instructions, unsigned what_to_lower);
bool lower_noise(exec_list *instructions);
-bool lower_variable_index_to_cond_assign(exec_list *instructions,
- bool lower_input, bool lower_output, bool lower_temp, bool lower_uniform);
+bool lower_variable_index_to_cond_assign(gl_shader_stage stage,
+ exec_list *instructions, bool lower_input, bool lower_output,
+ bool lower_temp, bool lower_uniform);
bool lower_quadop_vector(exec_list *instructions, bool dont_lower_swz);
bool lower_clip_distance(gl_shader *shader);
void lower_output_reads(exec_list *instructions);
diff --git a/src/glsl/lower_variable_index_to_cond_assign.cpp b/src/glsl/lower_variable_index_to_cond_assign.cpp
index d878cb0..f3dcd48 100644
--- a/src/glsl/lower_variable_index_to_cond_assign.cpp
+++ b/src/glsl/lower_variable_index_to_cond_assign.cpp
@@ -335,12 +335,14 @@ struct switch_generator
class variable_index_to_cond_assign_visitor : public ir_rvalue_visitor {
public:
- variable_index_to_cond_assign_visitor(bool lower_input,
- bool lower_output,
- bool lower_temp,
- bool lower_uniform)
+ variable_index_to_cond_assign_visitor(gl_shader_stage stage,
+ bool lower_input,
+ bool lower_output,
+ bool lower_temp,
+ bool lower_uniform)
{
this->progress = false;
+ this->stage = stage;
this->lower_inputs = lower_input;
this->lower_outputs = lower_output;
this->lower_temps = lower_temp;
@@ -348,6 +350,8 @@ public:
}
bool progress;
+
+ gl_shader_stage stage;
bool lower_inputs;
bool lower_outputs;
bool lower_temps;
@@ -394,6 +398,13 @@ public:
|| !is_array_or_matrix(deref->array))
return false;
+ if (stage == MESA_SHADER_TESS_CTRL &&
+ deref->array_index->as_dereference_variable() &&
+ strcmp(deref->array_index->as_dereference_variable()->var->name,
+ "gl_InvocationID") == 0) {
+ return false;
+ }
+
return this->storage_type_needs_lowering(deref);
}
@@ -522,16 +533,18 @@ public:
} /* anonymous namespace */
bool
-lower_variable_index_to_cond_assign(exec_list *instructions,
- bool lower_input,
- bool lower_output,
- bool lower_temp,
- bool lower_uniform)
+lower_variable_index_to_cond_assign(gl_shader_stage stage,
+ exec_list *instructions,
+ bool lower_input,
+ bool lower_output,
+ bool lower_temp,
+ bool lower_uniform)
{
- variable_index_to_cond_assign_visitor v(lower_input,
- lower_output,
- lower_temp,
- lower_uniform);
+ variable_index_to_cond_assign_visitor v(stage,
+ lower_input,
+ lower_output,
+ lower_temp,
+ lower_uniform);
/* Continue lowering until no progress is made. If there are multiple
* levels of indirection (e.g., non-constant indexing of array elements and
diff --git a/src/glsl/test_optpass.cpp b/src/glsl/test_optpass.cpp
index 24c06f1..109b7f6 100644
--- a/src/glsl/test_optpass.cpp
+++ b/src/glsl/test_optpass.cpp
@@ -124,7 +124,8 @@ do_optimization(struct exec_list *ir, const char *optimization,
} else if (sscanf(optimization, "lower_variable_index_to_cond_assign "
"( %d , %d , %d , %d ) ", &int_0, &int_1, &int_2,
&int_3) == 4) {
- return lower_variable_index_to_cond_assign(ir, int_0 != 0, int_1 != 0,
+ return lower_variable_index_to_cond_assign(MESA_SHADER_VERTEX, ir,
+ int_0 != 0, int_1 != 0,
int_2 != 0, int_3 != 0);
} else if (sscanf(optimization, "lower_quadop_vector ( %d ) ",
&int_0) == 1) {
diff --git a/src/mesa/drivers/dri/i965/brw_shader.cpp b/src/mesa/drivers/dri/i965/brw_shader.cpp
index 0a33063..8c80994 100644
--- a/src/mesa/drivers/dri/i965/brw_shader.cpp
+++ b/src/mesa/drivers/dri/i965/brw_shader.cpp
@@ -174,7 +174,8 @@ brw_link_shader(struct gl_context *ctx, struct gl_shader_program *shProg)
lower_quadop_vector(shader->base.ir, false);
bool lowered_variable_indexing =
- lower_variable_index_to_cond_assign(shader->base.ir,
+ lower_variable_index_to_cond_assign((gl_shader_stage) stage,
+ shader->base.ir,
options->EmitNoIndirectInput,
options->EmitNoIndirectOutput,
options->EmitNoIndirectTemp,
diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
index 293fe34..95eecac 100644
--- a/src/mesa/program/ir_to_mesa.cpp
+++ b/src/mesa/program/ir_to_mesa.cpp
@@ -2972,7 +2972,7 @@ _mesa_ir_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
if (options->EmitNoIndirectInput || options->EmitNoIndirectOutput
|| options->EmitNoIndirectTemp || options->EmitNoIndirectUniform)
progress =
- lower_variable_index_to_cond_assign(ir,
+ lower_variable_index_to_cond_assign(prog->_LinkedShaders[i]->Stage, ir,
options->EmitNoIndirectInput,
options->EmitNoIndirectOutput,
options->EmitNoIndirectTemp,
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index b338a98..65e0221 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -5387,7 +5387,7 @@ st_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
*/
if (options->EmitNoIndirectInput || options->EmitNoIndirectOutput ||
options->EmitNoIndirectTemp || options->EmitNoIndirectUniform) {
- lower_variable_index_to_cond_assign(ir,
+ lower_variable_index_to_cond_assign(prog->_LinkedShaders[i]->Stage, ir,
options->EmitNoIndirectInput,
options->EmitNoIndirectOutput,
options->EmitNoIndirectTemp,
--
2.1.0
More information about the mesa-dev
mailing list