aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErico Nunes <[email protected]>2020-04-19 19:36:57 +0200
committerErico Nunes <[email protected]>2020-05-16 17:24:00 +0200
commita4b7699d849d28adfd057136812b00a6b4838ed0 (patch)
tree628c740d725baa09e03f81e5f1b6836242bfb7a3
parent92611e21c19b35d1e5c9091614b2659d789558e2 (diff)
lima/ppir: rework tex lowering
Move steps from lowering to emit, since they can be done earlier in a single place, rather than in two-steps. Signed-off-by: Erico Nunes <[email protected]> Reviewed-by: Vasily Khoruzhick <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4975>
-rw-r--r--src/gallium/drivers/lima/ir/pp/lower.c35
-rw-r--r--src/gallium/drivers/lima/ir/pp/nir.c91
-rw-r--r--src/gallium/drivers/lima/ir/pp/ppir.h3
3 files changed, 66 insertions, 63 deletions
diff --git a/src/gallium/drivers/lima/ir/pp/lower.c b/src/gallium/drivers/lima/ir/pp/lower.c
index 3434debe15c..ada735a160e 100644
--- a/src/gallium/drivers/lima/ir/pp/lower.c
+++ b/src/gallium/drivers/lima/ir/pp/lower.c
@@ -160,42 +160,7 @@ static bool ppir_lower_ddxy(ppir_block *block, ppir_node *node)
static bool ppir_lower_texture(ppir_block *block, ppir_node *node)
{
- ppir_load_texture_node *load_tex = ppir_node_to_load_texture(node);
ppir_dest *dest = ppir_node_get_dest(node);
- ppir_node *src_coords = ppir_node_get_src(node, 0)->node;
- ppir_load_node *load = NULL;
-
- if (src_coords && ppir_node_has_single_src_succ(src_coords) &&
- (src_coords->op == ppir_op_load_coords))
- load = ppir_node_to_load(src_coords);
- else {
- /* Create load_coords node */
- load = ppir_node_create(block, ppir_op_load_coords_reg, -1, 0);
- if (!load)
- return false;
- list_addtail(&load->node.list, &node->list);
-
- load->src = load_tex->src[0];
- load->num_src = 1;
- if (load_tex->sampler_dim == GLSL_SAMPLER_DIM_CUBE)
- load->num_components = 3;
- else
- load->num_components = 2;
-
- ppir_debug("%s create load_coords node %d for %d\n",
- __FUNCTION__, load->node.index, node->index);
-
- ppir_node_foreach_pred_safe(node, dep) {
- ppir_node *pred = dep->pred;
- ppir_node_remove_dep(dep);
- ppir_node_add_dep(&load->node, pred, ppir_dep_src);
- }
- ppir_node_add_dep(node, &load->node, ppir_dep_src);
- }
-
- assert(load);
- load_tex->src[0].type = load->dest.type = ppir_target_pipeline;
- load_tex->src[0].pipeline = load->dest.pipeline = ppir_pipeline_reg_discard;
/* Always create move node since there can be successors in other blocks */
ppir_node *move = ppir_node_insert_mov(node);
diff --git a/src/gallium/drivers/lima/ir/pp/nir.c b/src/gallium/drivers/lima/ir/pp/nir.c
index 5b24d610970..bb42c35dd76 100644
--- a/src/gallium/drivers/lima/ir/pp/nir.c
+++ b/src/gallium/drivers/lima/ir/pp/nir.c
@@ -99,20 +99,6 @@ static void ppir_node_add_src(ppir_compiler *comp, ppir_node *node,
if (ns->is_ssa) {
child = comp->var_nodes[ns->ssa->index];
- switch (child->op) {
- case ppir_op_load_varying:
- /* If at least one successor is load_texture, promote it to
- * load_coords to ensure that is has exactly one successor */
- if (node->op == ppir_op_load_texture) {
- nir_tex_src *nts = (nir_tex_src *)ns;
- if (nts->src_type == nir_tex_src_coord)
- child->op = ppir_op_load_coords;
- }
- break;
- default:
- break;
- }
-
if (child->op != ppir_op_undef)
ppir_node_add_dep(node, child, ppir_dep_src);
}
@@ -459,16 +445,6 @@ static bool ppir_emit_tex(ppir_block *block, nir_instr *ni)
return false;
}
- unsigned mask = 0;
- if (!instr->dest.is_ssa)
- mask = u_bit_consecutive(0, nir_tex_instr_dest_size(instr));
-
- node = ppir_node_create_dest(block, ppir_op_load_texture, &instr->dest, mask);
- if (!node)
- return false;
-
- node->sampler = instr->texture_index;
-
switch (instr->sampler_dim) {
case GLSL_SAMPLER_DIM_2D:
case GLSL_SAMPLER_DIM_CUBE:
@@ -477,9 +453,20 @@ static bool ppir_emit_tex(ppir_block *block, nir_instr *ni)
break;
default:
ppir_error("unsupported sampler dim: %d\n", instr->sampler_dim);
- return NULL;
+ return false;
}
+ /* emit ld_tex node */
+
+ unsigned mask = 0;
+ if (!instr->dest.is_ssa)
+ mask = u_bit_consecutive(0, nir_tex_instr_dest_size(instr));
+
+ node = ppir_node_create_dest(block, ppir_op_load_texture, &instr->dest, mask);
+ if (!node)
+ return false;
+
+ node->sampler = instr->texture_index;
node->sampler_dim = instr->sampler_dim;
for (int i = 0; i < instr->coord_components; i++)
@@ -487,11 +474,25 @@ static bool ppir_emit_tex(ppir_block *block, nir_instr *ni)
for (int i = 0; i < instr->num_srcs; i++) {
switch (instr->src[i].src_type) {
- case nir_tex_src_coord:
+ case nir_tex_src_coord: {
+ nir_src *ns = &instr->src[i].src;
+ if (ns->is_ssa) {
+ ppir_node *child = block->comp->var_nodes[ns->ssa->index];
+ if (child->op == ppir_op_load_varying) {
+ /* If the successor is load_texture, promote it to load_coords */
+ nir_tex_src *nts = (nir_tex_src *)ns;
+ if (nts->src_type == nir_tex_src_coord)
+ child->op = ppir_op_load_coords;
+ }
+ }
+
+ /* src[0] is not used by the ld_tex instruction but ensures
+ * correct scheduling due to the pipeline dependency */
ppir_node_add_src(block->comp, &node->node, &node->src[0], &instr->src[i].src,
u_bit_consecutive(0, instr->coord_components));
node->num_src++;
break;
+ }
case nir_tex_src_bias:
case nir_tex_src_lod:
node->lod_bias_en = true;
@@ -506,6 +507,44 @@ static bool ppir_emit_tex(ppir_block *block, nir_instr *ni)
}
list_addtail(&node->node.list, &block->node_list);
+
+ /* validate load coords node */
+
+ ppir_node *src_coords = ppir_node_get_src(&node->node, 0)->node;
+ ppir_load_node *load = NULL;
+
+ if (src_coords && ppir_node_has_single_src_succ(src_coords) &&
+ (src_coords->op == ppir_op_load_coords))
+ load = ppir_node_to_load(src_coords);
+ else {
+ /* Create load_coords node */
+ load = ppir_node_create(block, ppir_op_load_coords_reg, -1, 0);
+ if (!load)
+ return false;
+ list_addtail(&load->node.list, &block->node_list);
+
+ load->src = node->src[0];
+ load->num_src = 1;
+ if (node->sampler_dim == GLSL_SAMPLER_DIM_CUBE)
+ load->num_components = 3;
+ else
+ load->num_components = 2;
+
+ ppir_debug("%s create load_coords node %d for %d\n",
+ __FUNCTION__, load->index, node->node.index);
+
+ ppir_node_foreach_pred_safe((&node->node), dep) {
+ ppir_node *pred = dep->pred;
+ ppir_node_remove_dep(dep);
+ ppir_node_add_dep(&load->node, pred, ppir_dep_src);
+ }
+ ppir_node_add_dep(&node->node, &load->node, ppir_dep_src);
+ }
+
+ assert(load);
+ node->src[0].type = load->dest.type = ppir_target_pipeline;
+ node->src[0].pipeline = load->dest.pipeline = ppir_pipeline_reg_discard;
+
return true;
}
diff --git a/src/gallium/drivers/lima/ir/pp/ppir.h b/src/gallium/drivers/lima/ir/pp/ppir.h
index 775e77ab983..631dcaaad51 100644
--- a/src/gallium/drivers/lima/ir/pp/ppir.h
+++ b/src/gallium/drivers/lima/ir/pp/ppir.h
@@ -270,8 +270,7 @@ typedef struct {
typedef struct {
ppir_node node;
ppir_dest dest;
- ppir_src src[2]; /* src[0] temporarily stores src_coords,
- not to be used after lowering */
+ ppir_src src[2];
int num_src;
int sampler;
int sampler_dim;