lima/ppir: refactor texture code to simplify scheduler
authorErico Nunes <nunes.erico@gmail.com>
Sun, 28 Jul 2019 19:27:46 +0000 (21:27 +0200)
committerErico Nunes <nunes.erico@gmail.com>
Wed, 31 Jul 2019 19:22:41 +0000 (21:22 +0200)
The 'varying fetch' pp instruction deals only with coordinates, and
'texture fetch' deals only with the sampler index.
Previously it was not possible to clearly map ppir_op_load_coords and
ppir_op_load_texture to pp instructions as the source coordinates were
kept in the ppir_op_load_texture node, making this harder to maintain.
The refactor is made with the attempt to clearly map ppir_op_load_coords
to the 'varying fetch' and ppir_op_load_texture to the 'texture fetch'.
The coordinates are still temporarily kept in the ppir_op_load_texture
node as nir has both sampler and coordinates in a single instruction and
it is only possible to output one ppir node during emit. But now after
lowering, the sources are transferred to the (always) created
ppir_op_load_coords node, and it should be possible to directly map them
to their pp instructions from there onwards.

Signed-off-by: Erico Nunes <nunes.erico@gmail.com>
Reviewed-by: Qiang Yu <yuq825@gmail.com>
src/gallium/drivers/lima/ir/pp/lower.c
src/gallium/drivers/lima/ir/pp/nir.c
src/gallium/drivers/lima/ir/pp/node_to_instr.c
src/gallium/drivers/lima/ir/pp/ppir.h
src/gallium/drivers/lima/ir/pp/regalloc.c

index 11a0027c7688eeb4872f742fd096a99954c2323e..5854576121a126d62c692eebb4fdcbd29ae64236 100644 (file)
@@ -242,20 +242,7 @@ static bool ppir_lower_texture(ppir_block *block, ppir_node *node)
 {
    ppir_load_texture_node *load_tex = ppir_node_to_load_texture(node);
 
-   if (ppir_node_has_single_pred(node)) {
-      ppir_node *pred = ppir_node_first_pred(node);
-      if (pred->op == ppir_op_load_varying) {
-         /* If ldtex is the only successor of load_varying node
-          * we're good. Just change load_varying op type to load_coords.
-          */
-         if (ppir_node_has_single_succ(pred)) {
-            pred->op = ppir_op_load_coords;
-            return true;
-         }
-      }
-   }
-
-   /* Otherwise we need to create load_coords node */
+   /* Create load_coords node */
    ppir_load_node *load = ppir_node_create(block, ppir_op_load_coords, -1, 0);
    if (!load)
       return false;
@@ -264,19 +251,11 @@ static bool ppir_lower_texture(ppir_block *block, ppir_node *node)
    ppir_debug("%s create load_coords node %d for %d\n",
               __FUNCTION__, load->node.index, node->index);
 
-   ppir_dest *dest = &load->dest;
-   dest->type = ppir_target_ssa;
-   dest->ssa.num_components = load_tex->src_coords.ssa->num_components;
-   dest->ssa.live_in = INT_MAX;
-   dest->ssa.live_out = 0;
-   dest->write_mask = u_bit_consecutive(0, dest->ssa.num_components);
+   load->dest.type = ppir_target_pipeline;
+   load->dest.pipeline = ppir_pipeline_reg_discard;
 
    load->src = load_tex->src_coords;
 
-   ppir_src *src = &load_tex->src_coords;
-   src->type = ppir_target_ssa;
-   src->ssa = &dest->ssa;
-
    ppir_node_foreach_pred_safe(node, dep) {
       ppir_node *pred = dep->pred;
       ppir_node_remove_dep(dep);
index c7858640f01afa65d36f234b962a5b58ed97a1a9..ed5a6e78c97820810a1b55ef88dbf82d64785f42 100644 (file)
@@ -382,7 +382,7 @@ static ppir_node *ppir_emit_tex(ppir_block *block, nir_instr *ni)
    case GLSL_SAMPLER_DIM_EXTERNAL:
       break;
    default:
-      ppir_debug("unsupported sampler dim: %d\n", instr->sampler_dim);
+      ppir_error("unsupported sampler dim: %d\n", instr->sampler_dim);
       return NULL;
    }
 
@@ -391,7 +391,6 @@ static ppir_node *ppir_emit_tex(ppir_block *block, nir_instr *ni)
    for (int i = 0; i < instr->coord_components; i++)
          node->src_coords.swizzle[i] = i;
 
-   assert(instr->num_srcs == 1);
    for (int i = 0; i < instr->num_srcs; i++) {
       switch (instr->src[i].src_type) {
       case nir_tex_src_coord:
@@ -399,7 +398,8 @@ static ppir_node *ppir_emit_tex(ppir_block *block, nir_instr *ni)
                            u_bit_consecutive(0, instr->coord_components));
          break;
       default:
-         ppir_debug("unknown texture source");
+         ppir_error("unsupported texture source type\n");
+         assert(0);
          return NULL;
       }
    }
index c5f55472f78499124d432f6ee44c5c83922c493b..478c4f66f2d2bf91087799ef815bb236d2d3a584 100644 (file)
@@ -42,14 +42,6 @@ static bool insert_to_load_tex(ppir_block *block, ppir_node *load_coords, ppir_n
    ppir_dest *dest = ppir_node_get_dest(ldtex);
    ppir_node *move = NULL;
 
-   ppir_load_node *load = ppir_node_to_load(load_coords);
-   load->dest.type = ppir_target_pipeline;
-   load->dest.pipeline = ppir_pipeline_reg_discard;
-
-   ppir_load_texture_node *load_texture = ppir_node_to_load_texture(ldtex);
-   load_texture->src_coords.type = ppir_target_pipeline;
-   load_texture->src_coords.pipeline = ppir_pipeline_reg_discard;
-
    /* Insert load_coords to ldtex instruction */
    if (!ppir_instr_insert_node(ldtex->instr, load_coords))
       return false;
index 3395a13ee564c438162373c1e2083dbd9d4cab36..6e8bb0be9d630b01093772e25294d89733922efd 100644 (file)
@@ -258,7 +258,7 @@ typedef struct {
 typedef struct {
    ppir_node node;
    ppir_dest dest;
-   ppir_src src_coords;
+   ppir_src src_coords; /* not to be used after lowering */
    int sampler;
    int sampler_dim;
 } ppir_load_texture_node;
index a03f075fac2f67f53a07bc0383faa586860d1a01..46903840099f630c14cb1db690d2c6847f911173 100644 (file)
@@ -231,14 +231,6 @@ static ppir_reg *ppir_regalloc_build_liveness_info(ppir_compiler *comp)
                reg->live_out = node->instr->seq;
             break;
          }
-         case ppir_node_type_load_texture:
-         {
-            ppir_load_texture_node *load_tex = ppir_node_to_load_texture(node);
-            ppir_reg *reg = get_src_reg(&load_tex->src_coords);
-            if (reg && node->instr->seq > reg->live_out)
-               reg->live_out = node->instr->seq;
-            break;
-         }
          case ppir_node_type_branch:
          {
             ppir_branch_node *branch = ppir_node_to_branch(node);
@@ -319,12 +311,6 @@ static void ppir_regalloc_print_result(ppir_compiler *comp)
                   printf("%d", ppir_target_get_src_reg_index(&load->src));
                break;
             }
-            case ppir_node_type_load_texture:
-            {
-               ppir_load_texture_node *load_tex = ppir_node_to_load_texture(node);
-               printf("%d", ppir_target_get_src_reg_index(&load_tex->src_coords));
-               break;
-            }
             case ppir_node_type_branch:
             {
                ppir_branch_node *branch = ppir_node_to_branch(node);
@@ -621,16 +607,6 @@ static bool ppir_regalloc_spill_reg(ppir_compiler *comp, ppir_reg *chosen)
             }
             break;
          }
-         case ppir_node_type_load_texture:
-         {
-            ppir_load_texture_node *load_tex = ppir_node_to_load_texture(node);
-            reg = get_src_reg(&load_tex->src_coords);
-            if (reg == chosen) {
-               ppir_update_spilled_src(comp, block, node, &load_tex->src_coords,
-                                       NULL);
-            }
-            break;
-         }
          case ppir_node_type_branch:
          {
             ppir_branch_node *branch = ppir_node_to_branch(node);