glsl: Add flag to disable part of do_vec_index_to_cond_assign

As of ca63a5ed3e ("glsl: fix interpolateAtXxx(some_vec[idx], ...)  with
dynamic idx"), this lowering pass does two things.  It converts
ir_binop_vector_extract to an if-ladder to select the dynamically
indexed component, and it extracts a ir_binop_vector_extract from the
source of an interpolateAt function and applies to the result instead.

This change adds a flag to disable the former behavior.  The latter is
still useful, but NIR has better (and soon even better) ways of doing
the former.

Reviewed-by: Matt Turner <mattst88@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16440>
This commit is contained in:
Ian Romanick
2022-01-14 13:39:06 -08:00
committed by Marge Bot
parent 4eff1e6481
commit e944a98826
4 changed files with 20 additions and 12 deletions

View File

@@ -116,7 +116,7 @@ bool do_minmax_prune(exec_list *instructions);
bool do_structure_splitting(exec_list *instructions); bool do_structure_splitting(exec_list *instructions);
bool optimize_swizzles(exec_list *instructions); bool optimize_swizzles(exec_list *instructions);
bool do_tree_grafting(exec_list *instructions); bool do_tree_grafting(exec_list *instructions);
bool do_vec_index_to_cond_assign(exec_list *instructions); bool do_vec_index_to_cond_assign(exec_list *instructions, bool lower_extracts);
bool do_vec_index_to_swizzle(exec_list *instructions); bool do_vec_index_to_swizzle(exec_list *instructions);
bool lower_discard(exec_list *instructions); bool lower_discard(exec_list *instructions);
void lower_discard_flow(exec_list *instructions); void lower_discard_flow(exec_list *instructions);

View File

@@ -53,8 +53,8 @@ namespace {
class ir_vec_index_to_cond_assign_visitor : public ir_hierarchical_visitor { class ir_vec_index_to_cond_assign_visitor : public ir_hierarchical_visitor {
public: public:
ir_vec_index_to_cond_assign_visitor() ir_vec_index_to_cond_assign_visitor(bool _lower_extracts)
: progress(false) : lower_extracts(_lower_extracts), progress(false)
{ {
/* empty */ /* empty */
} }
@@ -73,6 +73,7 @@ public:
virtual ir_visitor_status visit_enter(ir_call *); virtual ir_visitor_status visit_enter(ir_call *);
virtual ir_visitor_status visit_enter(ir_if *); virtual ir_visitor_status visit_enter(ir_if *);
bool lower_extracts;
bool progress; bool progress;
}; };
@@ -191,13 +192,20 @@ ir_vec_index_to_cond_assign_visitor::convert_vector_extract_to_cond_assign(ir_rv
new(base_ir) ir_expression(expr->operation, vec_input->type, new(base_ir) ir_expression(expr->operation, vec_input->type,
vec_input, expr->operands[1]); vec_input, expr->operands[1]);
return convert_vec_index_to_cond_assign(ralloc_parent(ir), if (lower_extracts) {
vec_interpolate, return convert_vec_index_to_cond_assign(ralloc_parent(ir),
interpolant->operands[1], vec_interpolate,
ir->type); interpolant->operands[1],
ir->type);
} else {
this->progress = true;
return new(base_ir) ir_expression(ir_binop_vector_extract, ir->type,
vec_interpolate,
interpolant->operands[1]);
}
} }
if (expr->operation != ir_binop_vector_extract) if (!lower_extracts || expr->operation != ir_binop_vector_extract)
return ir; return ir;
return convert_vec_index_to_cond_assign(ralloc_parent(ir), return convert_vec_index_to_cond_assign(ralloc_parent(ir),
@@ -267,9 +275,9 @@ ir_vec_index_to_cond_assign_visitor::visit_enter(ir_if *ir)
} }
bool bool
do_vec_index_to_cond_assign(exec_list *instructions) do_vec_index_to_cond_assign(exec_list *instructions, bool lower_extracts)
{ {
ir_vec_index_to_cond_assign_visitor v; ir_vec_index_to_cond_assign_visitor v(lower_extracts);
visit_list_elements(&v, instructions); visit_list_elements(&v, instructions);

View File

@@ -102,7 +102,7 @@ do_optimization(struct exec_list *ir, const char *optimization,
} else if (strcmp(optimization, "do_tree_grafting") == 0) { } else if (strcmp(optimization, "do_tree_grafting") == 0) {
return do_tree_grafting(ir); return do_tree_grafting(ir);
} else if (strcmp(optimization, "do_vec_index_to_cond_assign") == 0) { } else if (strcmp(optimization, "do_vec_index_to_cond_assign") == 0) {
return do_vec_index_to_cond_assign(ir); return do_vec_index_to_cond_assign(ir, true);
} else if (strcmp(optimization, "do_vec_index_to_swizzle") == 0) { } else if (strcmp(optimization, "do_vec_index_to_swizzle") == 0) {
return do_vec_index_to_swizzle(ir); return do_vec_index_to_swizzle(ir);
} else if (strcmp(optimization, "lower_discard") == 0) { } else if (strcmp(optimization, "lower_discard") == 0) {

View File

@@ -130,7 +130,7 @@ link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
IMUL_HIGH_TO_MUL IMUL_HIGH_TO_MUL
: 0)); : 0));
do_vec_index_to_cond_assign(ir); do_vec_index_to_cond_assign(ir, true);
lower_vector_insert(ir, true); lower_vector_insert(ir, true);
if (options->MaxIfDepth == 0) { if (options->MaxIfDepth == 0) {
lower_discard(ir); lower_discard(ir);