return true;
}
-static ppir_reg *create_reg(ppir_compiler *comp, int num_components)
-{
- ppir_reg *r = rzalloc(comp, ppir_reg);
- if (!r)
- return NULL;
-
- r->num_components = num_components;
- r->live_in = INT_MAX;
- r->live_out = 0;
- r->is_head = false;
- list_addtail(&r->list, &comp->reg_list);
-
- return r;
-}
-
-/* lower vector alu node to multi scalar nodes */
-static bool ppir_lower_vec_to_scalar(ppir_block *block, ppir_node *node)
-{
- ppir_alu_node *alu = ppir_node_to_alu(node);
- ppir_dest *dest = &alu->dest;
-
- int n = 0;
- int index[4];
-
- unsigned mask = dest->write_mask;
- while (mask)
- index[n++] = u_bit_scan(&mask);
-
- if (n == 1)
- return true;
-
- ppir_reg *r;
- /* we need a reg for scalar nodes to store output */
- if (dest->type == ppir_target_register)
- r = dest->reg;
- else {
- r = create_reg(block->comp, n);
- if (!r)
- return false;
-
- /* change all successors to use reg r */
- ppir_node_foreach_succ(node, dep) {
- ppir_node *succ = dep->succ;
- if (succ->type == ppir_node_type_alu) {
- ppir_alu_node *sa = ppir_node_to_alu(succ);
- for (int i = 0; i < sa->num_src; i++) {
- ppir_src *src = sa->src + i;
- if (ppir_node_target_equal(src, dest)) {
- src->type = ppir_target_register;
- src->reg = r;
- }
- }
- }
- else {
- assert(succ->type == ppir_node_type_store);
- ppir_store_node *ss = ppir_node_to_store(succ);
- ppir_src *src = &ss->src;
- src->type = ppir_target_register;
- src->reg = r;
- }
- }
- }
-
- /* create each component's scalar node */
- for (int i = 0; i < n; i++) {
- ppir_node *s = ppir_node_create(block, node->op, -1, 0);
- if (!s)
- return false;
- list_addtail(&s->list, &node->list);
-
- ppir_alu_node *sa = ppir_node_to_alu(s);
- ppir_dest *sd = &sa->dest;
- sd->type = ppir_target_register;
- sd->reg = r;
- sd->modifier = dest->modifier;
- sd->write_mask = 1 << index[i];
-
- for (int j = 0; j < alu->num_src; j++)
- sa->src[j] = alu->src[j];
- sa->num_src = alu->num_src;
-
- /* TODO: need per reg component dependancy */
- ppir_node_foreach_succ(node, dep) {
- ppir_node_add_dep(dep->succ, s);
- }
-
- ppir_node_foreach_pred(node, dep) {
- ppir_node_add_dep(s, dep->pred);
- }
- }
-
- ppir_node_delete(node);
- return true;
-}
-
static bool ppir_lower_swap_args(ppir_block *block, ppir_node *node)
{
/* swapped op must be the next op */
return true;
}
-/* Prepare for sin and cos and then lower vector alu node to multi
- * scalar nodes */
-static bool ppir_lower_sin_cos_vec_to_scalar(ppir_block *block, ppir_node *node)
+static bool ppir_lower_sin_cos(ppir_block *block, ppir_node *node)
{
ppir_alu_node *alu = ppir_node_to_alu(node);
ppir_node_add_dep(node, mul_node);
ppir_node_add_dep(mul_node, inv_2pi_node);
- return ppir_lower_vec_to_scalar(block, node);
+ return true;
}
/* insert a move as the select condition to make sure it can
[ppir_op_abs] = ppir_lower_abs,
[ppir_op_neg] = ppir_lower_neg,
[ppir_op_const] = ppir_lower_const,
- [ppir_op_rcp] = ppir_lower_vec_to_scalar,
- [ppir_op_rsqrt] = ppir_lower_vec_to_scalar,
- [ppir_op_log2] = ppir_lower_vec_to_scalar,
- [ppir_op_exp2] = ppir_lower_vec_to_scalar,
- [ppir_op_sqrt] = ppir_lower_vec_to_scalar,
- [ppir_op_sin] = ppir_lower_sin_cos_vec_to_scalar,
- [ppir_op_cos] = ppir_lower_sin_cos_vec_to_scalar,
+ [ppir_op_sin] = ppir_lower_sin_cos,
+ [ppir_op_cos] = ppir_lower_sin_cos,
[ppir_op_lt] = ppir_lower_swap_args,
[ppir_op_le] = ppir_lower_swap_args,
[ppir_op_load_texture] = ppir_lower_texture,
void
lima_program_optimize_fs_nir(struct nir_shader *s)
{
+ BITSET_DECLARE(alu_lower, nir_num_opcodes) = {0};
bool progress;
+ 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_PASS_V(s, nir_lower_fragcoord_wtrans);
NIR_PASS_V(s, nir_lower_io, nir_var_all, type_size, 0);
NIR_PASS_V(s, nir_lower_regs_to_ssa);
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, alu_lower);
NIR_PASS(progress, s, nir_lower_phis_to_scalar);
NIR_PASS(progress, s, nir_copy_prop);
NIR_PASS(progress, s, nir_opt_remove_phis);