lima/ppir: turn store_color into ALU node
authorVasily Khoruzhick <anarsoul@gmail.com>
Thu, 22 Aug 2019 14:42:56 +0000 (07:42 -0700)
committerVasily Khoruzhick <anarsoul@gmail.com>
Sat, 24 Aug 2019 01:19:47 +0000 (18:19 -0700)
We don't have a special OP to store color in PP, all we need to do is to
store gl_FragColor into reg0, thus it's just a mov and therefore ALU node.

Yet we still need to indicate that it's store_color op so regalloc ignores
its destination.

Tested-by: Andreas Baierl <ichgeh@imkreisrum.de>
Reviewed-by: Qiang Yu <yuq825@gmail.com>
Reviewed-by: Erico Nunes <nunes.erico@gmail.com>
Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
src/gallium/drivers/lima/ir/pp/codegen.c
src/gallium/drivers/lima/ir/pp/nir.c
src/gallium/drivers/lima/ir/pp/node.c
src/gallium/drivers/lima/ir/pp/node_to_instr.c

index 43dd896695c5d1a100e35dc567390d103834fa21..4b1c48dffa3b0d605242fabd4f870d6e477e92bf 100644 (file)
@@ -168,6 +168,7 @@ static void ppir_codegen_encode_vec_mul(ppir_node *node, void *code)
       f->op = shift_to_op(alu->shift);
       break;
    case ppir_op_mov:
+   case ppir_op_store_color:
       f->op = ppir_codegen_vec4_mul_op_mov;
       break;
    case ppir_op_max:
@@ -310,6 +311,7 @@ static void ppir_codegen_encode_vec_add(ppir_node *node, void *code)
       f->op = ppir_codegen_vec4_acc_op_add;
       break;
    case ppir_op_mov:
+   case ppir_op_store_color:
       f->op = ppir_codegen_vec4_acc_op_mov;
       break;
    case ppir_op_sum3:
index 3793f2a154304320dcd7e23abf3b75647a191295..75a09f0d441549bd79b8c92d3eaf9fb4cb79e734 100644 (file)
@@ -286,7 +286,7 @@ static ppir_node *ppir_emit_intrinsic(ppir_block *block, nir_instr *ni)
    nir_intrinsic_instr *instr = nir_instr_as_intrinsic(ni);
    unsigned mask = 0;
    ppir_load_node *lnode;
-   ppir_store_node *snode;
+   ppir_alu_node *alu_node;
 
    switch (instr->intrinsic) {
    case nir_intrinsic_load_input:
@@ -344,20 +344,29 @@ static ppir_node *ppir_emit_intrinsic(ppir_block *block, nir_instr *ni)
 
       return &lnode->node;
 
-   case nir_intrinsic_store_output:
-      snode = ppir_node_create_dest(block, ppir_op_store_color, NULL, 0);
-      if (!snode)
+   case nir_intrinsic_store_output: {
+      alu_node = ppir_node_create_dest(block, ppir_op_store_color, NULL, 0);
+      if (!alu_node)
          return NULL;
 
-      snode->index = nir_intrinsic_base(instr);
+      ppir_dest *dest = ppir_node_get_dest(&alu_node->node);
+      dest->type = ppir_target_ssa;
+      dest->ssa.num_components = instr->num_components;
+      dest->ssa.live_in = INT_MAX;
+      dest->ssa.live_out = 0;
+      dest->ssa.index = 0;
+      dest->write_mask = u_bit_consecutive(0, instr->num_components);
+
+      alu_node->num_src = 1;
 
       for (int i = 0; i < instr->num_components; i++)
-         snode->src.swizzle[i] = i;
+         alu_node->src[0].swizzle[i] = i;
 
-      ppir_node_add_src(block->comp, &snode->node, &snode->src, instr->src,
+      ppir_node_add_src(block->comp, &alu_node->node, alu_node->src, instr->src,
                         u_bit_consecutive(0, instr->num_components));
 
-      return &snode->node;
+      return &alu_node->node;
+   }
 
    case nir_intrinsic_discard:
       return ppir_emit_discard(block, ni);
index 37dd65823fad194b8b25175fca9fb4c8695230fc..59635df3cdf4c2a4289f7a4c72b74f49d560147b 100644 (file)
@@ -308,7 +308,11 @@ const ppir_op_info ppir_op_infos[] = {
    },
    [ppir_op_store_color] = {
       .name = "st_col",
-      .type = ppir_node_type_store,
+      .type = ppir_node_type_alu,
+      .slots = (int []) {
+         PPIR_INSTR_SLOT_ALU_VEC_ADD, PPIR_INSTR_SLOT_ALU_VEC_MUL,
+         PPIR_INSTR_SLOT_END
+      },
    },
    [ppir_op_store_temp] = {
       .name = "st_temp",
index d1ceb2c67b6b828340cd8e9975de12462df1e4d9..50a3c65ebc780d687d2c0ec01c48251460f78a32 100644 (file)
@@ -87,6 +87,9 @@ static bool ppir_do_one_node_to_instr(ppir_block *block, ppir_node *node, ppir_n
       if (!node->instr && !create_new_instr(block, node))
          return false;
 
+      if (node->op == ppir_op_store_color)
+         node->instr->is_end = true;
+
       break;
    }
    case ppir_node_type_load:
@@ -118,58 +121,6 @@ static bool ppir_do_one_node_to_instr(ppir_block *block, ppir_node *node, ppir_n
             return false;
          break;
       }
-
-      /* Only the store color node should appear here.
-       * Currently we always insert a move node as the end instr.
-       * But it should only be done when:
-       *   1. store a const node
-       *   2. store a load node
-       *   3. store a reg assigned in another block like loop/if
-       */
-
-      assert(node->op == ppir_op_store_color);
-
-      ppir_node *move = ppir_node_create(block, ppir_op_mov, -1, 0);
-      if (unlikely(!move))
-         return false;
-
-      ppir_debug("node_to_instr create move %d from store %d\n",
-                 move->index, node->index);
-
-      ppir_node_foreach_pred_safe(node, dep) {
-         ppir_node *pred = dep->pred;
-         /* we can't do this in this function except here as this
-          * store is the root of this recursion */
-         ppir_node_remove_dep(dep);
-         ppir_node_add_dep(move, pred);
-      }
-
-      ppir_node_add_dep(node, move);
-      list_addtail(&move->list, &node->list);
-
-      ppir_alu_node *alu = ppir_node_to_alu(move);
-      ppir_store_node *store = ppir_node_to_store(node);
-      alu->src[0] = store->src;
-      alu->num_src = 1;
-
-      alu->dest.type = ppir_target_ssa;
-      alu->dest.ssa.num_components = 4;
-      alu->dest.ssa.live_in = INT_MAX;
-      alu->dest.ssa.live_out = 0;
-      alu->dest.write_mask = 0xf;
-
-      store->src.type = ppir_target_ssa;
-      store->src.ssa = &alu->dest.ssa;
-
-      if (!create_new_instr(block, move))
-         return false;
-
-      move->instr->is_end = true;
-      node->instr = move->instr;
-
-      /* use move for the following recursion */
-      *next = move;
-      break;
    }
    case ppir_node_type_discard:
       if (!create_new_instr(block, node))