nir: allow specifying filter callback in lower_alu_to_scalar

Set of opcodes doesn't have enough flexibility in certain cases. E.g.
Utgard PP has vector conditional select operation, but condition is always
scalar. Lowering all the vector selects to scalar increases instruction
number, so we need a way to filter only those ops that can't be handled
in hardware.

Reviewed-by: Qiang Yu <yuq825@gmail.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
This commit is contained in:
Vasily Khoruzhick
2019-08-29 21:14:54 -07:00
parent f9f7cbc1aa
commit 9367d2ca37
16 changed files with 109 additions and 63 deletions

View File

@@ -110,7 +110,7 @@ lima_program_optimize_vs_nir(struct nir_shader *s)
progress = false;
NIR_PASS_V(s, nir_lower_vars_to_ssa);
NIR_PASS(progress, s, nir_lower_alu_to_scalar, NULL);
NIR_PASS(progress, s, nir_lower_alu_to_scalar, NULL, NULL);
NIR_PASS(progress, s, nir_lower_phis_to_scalar);
NIR_PASS(progress, s, nir_copy_prop);
NIR_PASS(progress, s, nir_opt_remove_phis);
@@ -145,24 +145,38 @@ lima_program_optimize_vs_nir(struct nir_shader *s)
nir_sweep(s);
}
void
lima_program_optimize_fs_nir(struct nir_shader *s)
static bool
lima_alu_to_scalar_filter_cb(const nir_instr *instr, const void *data)
{
BITSET_DECLARE(alu_lower, nir_num_opcodes) = {0};
bool progress;
if (instr->type != nir_instr_type_alu)
return false;
BITSET_SET(alu_lower, nir_op_frcp);
BITSET_SET(alu_lower, nir_op_frsq);
BITSET_SET(alu_lower, nir_op_flog2);
BITSET_SET(alu_lower, nir_op_fexp2);
BITSET_SET(alu_lower, nir_op_fsqrt);
BITSET_SET(alu_lower, nir_op_fsin);
BITSET_SET(alu_lower, nir_op_fcos);
nir_alu_instr *alu = nir_instr_as_alu(instr);
switch (alu->op) {
case nir_op_frcp:
case nir_op_frsq:
case nir_op_flog2:
case nir_op_fexp2:
case nir_op_fsqrt:
case nir_op_fsin:
case nir_op_fcos:
/* nir vec4 fcsel assumes that each component of the condition will be
* used to select the same component from the two options, but lima
* can't implement that since we only have 1 component condition */
BITSET_SET(alu_lower, nir_op_fcsel);
BITSET_SET(alu_lower, nir_op_bcsel);
case nir_op_fcsel:
case nir_op_bcsel:
return true;
default:
break;
}
return false;
}
void
lima_program_optimize_fs_nir(struct nir_shader *s)
{
bool progress;
NIR_PASS_V(s, nir_lower_fragcoord_wtrans);
NIR_PASS_V(s, nir_lower_io, nir_var_all, type_size, 0);
@@ -178,7 +192,7 @@ lima_program_optimize_fs_nir(struct nir_shader *s)
progress = false;
NIR_PASS_V(s, nir_lower_vars_to_ssa);
NIR_PASS(progress, s, nir_lower_alu_to_scalar, alu_lower);
NIR_PASS(progress, s, nir_lower_alu_to_scalar, lima_alu_to_scalar_filter_cb, NULL);
NIR_PASS(progress, s, nir_lower_phis_to_scalar);
NIR_PASS(progress, s, nir_copy_prop);
NIR_PASS(progress, s, nir_opt_remove_phis);