lima/gpir: support vector ssa load
authorQiang Yu <yuq825@gmail.com>
Wed, 15 May 2019 02:39:57 +0000 (10:39 +0800)
committerQiang Yu <yuq825@gmail.com>
Mon, 20 May 2019 02:57:11 +0000 (10:57 +0800)
Some vector sysval can't be lowered to scaler, so need to break
it to scaler in nir to gpir convertion.

Reviewed-by: Vasily Khoruzhick <anarsoul@gmail.com>
Reviewed-by: Erico Nunes <nunes.erico@gmail.com>
Signed-off-by: Qiang Yu <yuq825@gmail.com>
src/gallium/drivers/lima/ir/gp/gpir.h
src/gallium/drivers/lima/ir/gp/nir.c

index 43d2adf..cbdf74d 100644 (file)
@@ -319,6 +319,8 @@ typedef struct {
 
 struct lima_vs_shader_state;
 
+#define GPIR_VECTOR_SSA_NUM 0
+
 typedef struct gpir_compiler {
    struct list_head block_list;
    int cur_index;
@@ -330,6 +332,12 @@ typedef struct gpir_compiler {
    struct list_head reg_list;
    int cur_reg;
 
+   /* lookup for vector ssa */
+   struct {
+      int ssa;
+      gpir_node *nodes[4];
+   } vector_ssa[GPIR_VECTOR_SSA_NUM];
+
    struct lima_vs_shader_state *prog;
    int constant_base;
 } gpir_compiler;
index f38e230..655ea1a 100644 (file)
@@ -72,12 +72,22 @@ static void *gpir_node_create_dest(gpir_block *block, gpir_op op, nir_dest *dest
       return gpir_node_create_reg(block, op, &dest->reg);
 }
 
-static gpir_node *gpir_node_find(gpir_block *block, gpir_node *succ, nir_src *src)
+static gpir_node *gpir_node_find(gpir_block *block, gpir_node *succ, nir_src *src,
+                                 int channel)
 {
-   gpir_node *pred;
+   gpir_node *pred = NULL;
 
    if (src->is_ssa) {
-      pred = block->comp->var_nodes[src->ssa->index];
+      if (src->ssa->num_components > 1) {
+         for (int i = 0; i < GPIR_VECTOR_SSA_NUM; i++) {
+            if (block->comp->vector_ssa[i].ssa == src->ssa->index) {
+               pred = block->comp->vector_ssa[i].nodes[channel];
+               break;
+            }
+         }
+      } else
+         pred = block->comp->var_nodes[src->ssa->index];
+
       assert(pred);
    }
    else {
@@ -144,7 +154,7 @@ static bool gpir_emit_alu(gpir_block *block, nir_instr *ni)
       nir_alu_src *src = instr->src + i;
       node->children_negate[i] = src->negate;
 
-      gpir_node *child = gpir_node_find(block, &node->node, &src->src);
+      gpir_node *child = gpir_node_find(block, &node->node, &src->src, src->swizzle[0]);
       node->children[i] = child;
 
       gpir_node_add_dep(&node->node, child, GPIR_DEP_INPUT);
@@ -165,6 +175,26 @@ static gpir_node *gpir_create_load(gpir_block *block, nir_dest *dest,
    return &load->node;
 }
 
+static bool gpir_create_vector_load(gpir_block *block, nir_dest *dest, int index)
+{
+   assert(dest->is_ssa);
+   assert(index < GPIR_VECTOR_SSA_NUM);
+
+   block->comp->vector_ssa[index].ssa = dest->ssa.index;
+
+   for (int i = 0; i < dest->ssa.num_components; i++) {
+      gpir_node *node = gpir_create_load(block, dest, gpir_op_load_uniform,
+                                         block->comp->constant_base + index, i);
+      if (!node)
+         return false;
+
+      block->comp->vector_ssa[index].nodes[i] = node;
+      snprintf(node->name, sizeof(node->name), "ssa%d.%c", dest->ssa.index, "xyzw"[i]);
+   }
+
+   return true;
+}
+
 static bool gpir_emit_intrinsic(gpir_block *block, nir_instr *ni)
 {
    nir_intrinsic_instr *instr = nir_instr_as_intrinsic(ni);
@@ -194,7 +224,7 @@ static bool gpir_emit_intrinsic(gpir_block *block, nir_instr *ni)
       store->index = nir_intrinsic_base(instr);
       store->component = nir_intrinsic_component(instr);
 
-      gpir_node *child = gpir_node_find(block, &store->node, instr->src);
+      gpir_node *child = gpir_node_find(block, &store->node, instr->src, 0);
       store->child = child;
       gpir_node_add_dep(&store->node, child, GPIR_DEP_INPUT);
 
@@ -348,6 +378,9 @@ static gpir_compiler *gpir_compiler_create(void *prog, unsigned num_reg, unsigne
    for (int i = 0; i < num_reg; i++)
       gpir_create_reg(comp);
 
+   for (int i = 0; i < GPIR_VECTOR_SSA_NUM; i++)
+      comp->vector_ssa[i].ssa = -1;
+
    comp->var_nodes = rzalloc_array(comp, gpir_node *, num_ssa);
    comp->prog = prog;
    return comp;