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);
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);
}
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:
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++)
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;
}
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;
}