Mesa (master): lima/ppir: refactor texture code to simplify scheduler

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Jul 31 19:31:59 UTC 2019


Module: Mesa
Branch: master
Commit: 7f8ff686b73b057ea38d4e88009d4543fedfa455
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=7f8ff686b73b057ea38d4e88009d4543fedfa455

Author: Erico Nunes <nunes.erico at gmail.com>
Date:   Sun Jul 28 21:27:46 2019 +0200

lima/ppir: refactor texture code to simplify scheduler

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 at gmail.com>
Reviewed-by: Qiang Yu <yuq825 at gmail.com>

---

 src/gallium/drivers/lima/ir/pp/lower.c         | 27 +++-----------------------
 src/gallium/drivers/lima/ir/pp/nir.c           |  6 +++---
 src/gallium/drivers/lima/ir/pp/node_to_instr.c |  8 --------
 src/gallium/drivers/lima/ir/pp/ppir.h          |  2 +-
 src/gallium/drivers/lima/ir/pp/regalloc.c      | 24 -----------------------
 5 files changed, 7 insertions(+), 60 deletions(-)

diff --git a/src/gallium/drivers/lima/ir/pp/lower.c b/src/gallium/drivers/lima/ir/pp/lower.c
index 11a0027c768..5854576121a 100644
--- a/src/gallium/drivers/lima/ir/pp/lower.c
+++ b/src/gallium/drivers/lima/ir/pp/lower.c
@@ -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);
diff --git a/src/gallium/drivers/lima/ir/pp/nir.c b/src/gallium/drivers/lima/ir/pp/nir.c
index c7858640f01..ed5a6e78c97 100644
--- a/src/gallium/drivers/lima/ir/pp/nir.c
+++ b/src/gallium/drivers/lima/ir/pp/nir.c
@@ -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;
       }
    }
diff --git a/src/gallium/drivers/lima/ir/pp/node_to_instr.c b/src/gallium/drivers/lima/ir/pp/node_to_instr.c
index c5f55472f78..478c4f66f2d 100644
--- a/src/gallium/drivers/lima/ir/pp/node_to_instr.c
+++ b/src/gallium/drivers/lima/ir/pp/node_to_instr.c
@@ -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;
diff --git a/src/gallium/drivers/lima/ir/pp/ppir.h b/src/gallium/drivers/lima/ir/pp/ppir.h
index 3395a13ee56..6e8bb0be9d6 100644
--- a/src/gallium/drivers/lima/ir/pp/ppir.h
+++ b/src/gallium/drivers/lima/ir/pp/ppir.h
@@ -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;
diff --git a/src/gallium/drivers/lima/ir/pp/regalloc.c b/src/gallium/drivers/lima/ir/pp/regalloc.c
index a03f075fac2..46903840099 100644
--- a/src/gallium/drivers/lima/ir/pp/regalloc.c
+++ b/src/gallium/drivers/lima/ir/pp/regalloc.c
@@ -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);




More information about the mesa-commit mailing list