lima/ppir: combine varying loads in node_to_instr
authorErico Nunes <nunes.erico@gmail.com>
Mon, 13 Apr 2020 13:26:16 +0000 (15:26 +0200)
committerMarge Bot <eric+marge@anholt.net>
Sat, 9 May 2020 11:30:07 +0000 (11:30 +0000)
Varying loads with a single successor have a high potential to be
combined with its successor node, like ppir does for uniforms, rather
than being in a separate instruction.
Even if ppir becomes capable of combining instructions in a separate
step, combining varying loads during node_to_instr is trivial enough
that it seems to be worth doing it in this stage, and this benefits
pretty much every program that uses varyings.

Signed-off-by: Erico Nunes <nunes.erico@gmail.com>
Reviewed-by: Vasily Khoruzhick <anarsoul@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4535>

src/gallium/drivers/lima/ir/pp/node_to_instr.c

index 9882951db46864b49f9149dd291705afbf922046..35cf5f10f63d7c4205c3c4d19101bede63c62860 100644 (file)
@@ -42,23 +42,37 @@ static bool create_new_instr(ppir_block *block, ppir_node *node)
  * successor.
  * Since it has a pipeline dest, it must have only one successor and since we
  * schedule nodes backwards, its successor must have already been scheduled.
+ * Load varyings can't output to a pipeline register but are also potentially
+ * trivial to insert and save an instruction if they have a single successor.
  */
-static bool ppir_do_node_to_instr_pipeline(ppir_block *block, ppir_node *node)
+static bool ppir_do_node_to_instr_try_insert(ppir_block *block, ppir_node *node)
 {
    ppir_dest *dest = ppir_node_get_dest(node);
 
-   if (!dest || dest->type != ppir_target_pipeline)
+   if (dest && dest->type == ppir_target_pipeline) {
+      assert(ppir_node_has_single_src_succ(node));
+      ppir_node *succ = ppir_node_first_succ(node);
+      assert(succ);
+      assert(succ->instr);
+
+      return ppir_instr_insert_node(succ->instr, node);
+   }
+
+   switch (node->type) {
+      case ppir_node_type_load:
+         break;
+      default:
+         return false;
+   }
+
+   if (!ppir_node_has_single_src_succ(node))
       return false;
 
-   assert(ppir_node_has_single_src_succ(node));
    ppir_node *succ = ppir_node_first_succ(node);
    assert(succ);
    assert(succ->instr);
 
-   if (!ppir_instr_insert_node(succ->instr, node))
-      return false;
-
-   return true;
+   return ppir_instr_insert_node(succ->instr, node);
 }
 
 static bool ppir_do_one_node_to_instr(ppir_block *block, ppir_node *node, ppir_node **next)
@@ -184,7 +198,7 @@ static bool ppir_do_node_to_instr(ppir_block *block, ppir_node *node)
    ppir_node *next = node;
 
    /* first try pipeline sched, if that didn't succeed try normal scheduling */
-   if (!ppir_do_node_to_instr_pipeline(block, node))
+   if (!ppir_do_node_to_instr_try_insert(block, node))
       if (!ppir_do_one_node_to_instr(block, node, &next))
          return false;