diff options
author | Connor Abbott <[email protected]> | 2015-10-30 23:32:50 -0400 |
---|---|---|
committer | Connor Abbott <[email protected]> | 2015-11-10 13:55:14 -0500 |
commit | 30fe8eaa8e65e656d2bc95f499791eebea7d7dc9 (patch) | |
tree | b1e3a771a3e4e179b4290f03dc4e44e3eacc2c62 /src | |
parent | 6f4216232921370e513e56d38cf894c94ae63fa6 (diff) |
nir/glsl: make evaluate_rvalue() return a nir_ssa_def *
A long time ago, before NIR was even merged to master, glsl_to_nir used
registers and these sources were actually register sources. But nowadays
everything in glsl_to_nir is an SSA value, so stop pretending that by
evaluating an rvalue we can get an arbitrary nir_src. Most importantly,
we need this since the builder takes nir_ssa_def * sources directly.
Signed-off-by: Connor Abbott <[email protected]>
Reviewed-by: Kenneth Graunke <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/glsl/nir/glsl_to_nir.cpp | 90 |
1 files changed, 53 insertions, 37 deletions
diff --git a/src/glsl/nir/glsl_to_nir.cpp b/src/glsl/nir/glsl_to_nir.cpp index ec6bdc8acb0..3b8fb00abcf 100644 --- a/src/glsl/nir/glsl_to_nir.cpp +++ b/src/glsl/nir/glsl_to_nir.cpp @@ -73,7 +73,7 @@ public: private: void create_overload(ir_function_signature *ir, nir_function *function); void add_instr(nir_instr *instr, unsigned num_components); - nir_src evaluate_rvalue(ir_rvalue *ir); + nir_ssa_def *evaluate_rvalue(ir_rvalue *ir); nir_alu_instr *emit(nir_op op, unsigned dest_size, nir_src *srcs); nir_alu_instr *emit(nir_op op, unsigned dest_size, nir_src src1); @@ -560,7 +560,8 @@ nir_visitor::visit(ir_loop *ir) void nir_visitor::visit(ir_if *ir) { - nir_src condition = evaluate_rvalue(ir->condition); + nir_src condition = + nir_src_for_ssa(evaluate_rvalue(ir->condition)); exec_list *old_list = this->cf_node_list; @@ -591,7 +592,8 @@ nir_visitor::visit(ir_discard *ir) if (ir->condition) { discard = nir_intrinsic_instr_create(this->shader, nir_intrinsic_discard_if); - discard->src[0] = evaluate_rvalue(ir->condition); + discard->src[0] = + nir_src_for_ssa(evaluate_rvalue(ir->condition)); } else { discard = nir_intrinsic_instr_create(this->shader, nir_intrinsic_discard); } @@ -792,7 +794,8 @@ nir_visitor::visit(ir_call *ir) /* Set the address argument, extending the coordinate vector to four * components. */ - const nir_src src_addr = evaluate_rvalue((ir_dereference *)param); + const nir_src src_addr = + nir_src_for_ssa(evaluate_rvalue((ir_dereference *)param)); nir_alu_instr *instr_addr = nir_alu_instr_create(shader, nir_op_vec4); nir_ssa_dest_init(&instr_addr->instr, &instr_addr->dest.dest, 4, NULL); @@ -813,7 +816,8 @@ nir_visitor::visit(ir_call *ir) * images. */ if (type->sampler_dimensionality == GLSL_SAMPLER_DIM_MS) { - instr->src[1] = evaluate_rvalue((ir_dereference *)param); + instr->src[1] = + nir_src_for_ssa(evaluate_rvalue((ir_dereference *)param)); param = param->get_next(); } else { instr->src[1] = nir_src_for_ssa(&instr_undef->def); @@ -821,12 +825,14 @@ nir_visitor::visit(ir_call *ir) /* Set the intrinsic parameters. */ if (!param->is_tail_sentinel()) { - instr->src[2] = evaluate_rvalue((ir_dereference *)param); + instr->src[2] = + nir_src_for_ssa(evaluate_rvalue((ir_dereference *)param)); param = param->get_next(); } if (!param->is_tail_sentinel()) { - instr->src[3] = evaluate_rvalue((ir_dereference *)param); + instr->src[3] = + nir_src_for_ssa(evaluate_rvalue((ir_dereference *)param)); param = param->get_next(); } nir_instr_insert_after_cf_list(this->cf_node_list, &instr->instr); @@ -864,7 +870,7 @@ nir_visitor::visit(ir_call *ir) op = nir_intrinsic_store_ssbo_indirect; ralloc_free(instr); instr = nir_intrinsic_instr_create(shader, op); - instr->src[2] = evaluate_rvalue(offset); + instr->src[2] = nir_src_for_ssa(evaluate_rvalue(offset)); instr->const_index[0] = 0; } else { instr->const_index[0] = const_offset->value.u[0]; @@ -872,10 +878,10 @@ nir_visitor::visit(ir_call *ir) instr->const_index[1] = write_mask->value.u[0]; - instr->src[0] = evaluate_rvalue(val); + instr->src[0] = nir_src_for_ssa(evaluate_rvalue(val)); instr->num_components = val->type->vector_elements; - instr->src[1] = evaluate_rvalue(block); + instr->src[1] = nir_src_for_ssa(evaluate_rvalue(block)); nir_instr_insert_after_cf_list(this->cf_node_list, &instr->instr); break; } @@ -892,14 +898,14 @@ nir_visitor::visit(ir_call *ir) op = nir_intrinsic_load_ssbo_indirect; ralloc_free(instr); instr = nir_intrinsic_instr_create(shader, op); - instr->src[1] = evaluate_rvalue(offset); + instr->src[1] = nir_src_for_ssa(evaluate_rvalue(offset)); instr->const_index[0] = 0; dest = &instr->dest; } else { instr->const_index[0] = const_offset->value.u[0]; } - instr->src[0] = evaluate_rvalue(block); + instr->src[0] = nir_src_for_ssa(evaluate_rvalue(block)); const glsl_type *type = ir->return_deref->var->type; instr->num_components = type->vector_elements; @@ -959,24 +965,24 @@ nir_visitor::visit(ir_call *ir) /* Block index */ exec_node *param = ir->actual_parameters.get_head(); ir_instruction *inst = (ir_instruction *) param; - instr->src[0] = evaluate_rvalue(inst->as_rvalue()); + instr->src[0] = nir_src_for_ssa(evaluate_rvalue(inst->as_rvalue())); /* Offset */ param = param->get_next(); inst = (ir_instruction *) param; - instr->src[1] = evaluate_rvalue(inst->as_rvalue()); + instr->src[1] = nir_src_for_ssa(evaluate_rvalue(inst->as_rvalue())); /* data1 parameter (this is always present) */ param = param->get_next(); inst = (ir_instruction *) param; - instr->src[2] = evaluate_rvalue(inst->as_rvalue()); + instr->src[2] = nir_src_for_ssa(evaluate_rvalue(inst->as_rvalue())); /* data2 parameter (only with atomic_comp_swap) */ if (param_count == 4) { assert(op == nir_intrinsic_ssbo_atomic_comp_swap); param = param->get_next(); inst = (ir_instruction *) param; - instr->src[3] = evaluate_rvalue(inst->as_rvalue()); + instr->src[3] = nir_src_for_ssa(evaluate_rvalue(inst->as_rvalue())); } /* Atomic result */ @@ -1039,7 +1045,7 @@ nir_visitor::visit(ir_assignment *ir) if (ir->condition) { nir_if *if_stmt = nir_if_create(this->shader); - if_stmt->condition = evaluate_rvalue(ir->condition); + if_stmt->condition = nir_src_for_ssa(evaluate_rvalue(ir->condition)); nir_cf_node_insert_end(this->cf_node_list, &if_stmt->cf_node); nir_instr_insert_after_cf_list(&if_stmt->then_list, ©->instr); } else { @@ -1052,7 +1058,7 @@ nir_visitor::visit(ir_assignment *ir) ir->lhs->accept(this); nir_deref_var *lhs_deref = this->deref_head; - nir_src src = evaluate_rvalue(ir->rhs); + nir_src src = nir_src_for_ssa(evaluate_rvalue(ir->rhs)); if (ir->write_mask != (1 << num_components) - 1 && ir->write_mask != 0) { /* @@ -1115,7 +1121,7 @@ nir_visitor::visit(ir_assignment *ir) if (ir->condition) { nir_if *if_stmt = nir_if_create(this->shader); - if_stmt->condition = evaluate_rvalue(ir->condition); + if_stmt->condition = nir_src_for_ssa(evaluate_rvalue(ir->condition)); nir_cf_node_insert_end(this->cf_node_list, &if_stmt->cf_node); nir_instr_insert_after_cf_list(&if_stmt->then_list, &store->instr); } else { @@ -1171,7 +1177,7 @@ nir_visitor::add_instr(nir_instr *instr, unsigned num_components) this->result = instr; } -nir_src +nir_ssa_def * nir_visitor::evaluate_rvalue(ir_rvalue* ir) { ir->accept(this); @@ -1192,7 +1198,7 @@ nir_visitor::evaluate_rvalue(ir_rvalue* ir) nir_dest *dest = get_instr_dest(this->result); assert(dest->is_ssa); - return nir_src_for_ssa(&dest->ssa); + return &dest->ssa; } nir_alu_instr * @@ -1248,9 +1254,9 @@ nir_visitor::visit(ir_expression *ir) nir_intrinsic_instr *load = nir_intrinsic_instr_create(this->shader, op); load->num_components = ir->type->vector_elements; load->const_index[0] = const_index ? const_index->value.u[0] : 0; /* base offset */ - load->src[0] = evaluate_rvalue(ir->operands[0]); + load->src[0] = nir_src_for_ssa(evaluate_rvalue(ir->operands[0])); if (!const_index) - load->src[1] = evaluate_rvalue(ir->operands[1]); + load->src[1] = nir_src_for_ssa(evaluate_rvalue(ir->operands[1])); add_instr(&load->instr, ir->type->vector_elements); /* @@ -1328,7 +1334,7 @@ nir_visitor::visit(ir_expression *ir) if (intrin->intrinsic == nir_intrinsic_interp_var_at_offset || intrin->intrinsic == nir_intrinsic_interp_var_at_sample) - intrin->src[0] = evaluate_rvalue(ir->operands[1]); + intrin->src[0] = nir_src_for_ssa(evaluate_rvalue(ir->operands[1])); add_instr(&intrin->instr, deref->type->vector_elements); @@ -1357,7 +1363,7 @@ nir_visitor::visit(ir_expression *ir) nir_src srcs[4]; for (unsigned i = 0; i < ir->get_num_operands(); i++) - srcs[i] = evaluate_rvalue(ir->operands[i]); + srcs[i] = nir_src_for_ssa(evaluate_rvalue(ir->operands[i])); glsl_base_type types[4]; for (unsigned i = 0; i < ir->get_num_operands(); i++) @@ -1565,7 +1571,7 @@ nir_visitor::visit(ir_expression *ir) this->shader, nir_intrinsic_get_buffer_size); load->num_components = ir->type->vector_elements; - load->src[0] = evaluate_rvalue(ir->operands[0]); + load->src[0] = nir_src_for_ssa(evaluate_rvalue(ir->operands[0])); add_instr(&load->instr, ir->type->vector_elements); return; } @@ -1908,7 +1914,7 @@ nir_visitor::visit(ir_swizzle *ir) { nir_alu_instr *instr = emit(supports_ints ? nir_op_imov : nir_op_fmov, ir->type->vector_elements, - evaluate_rvalue(ir->val)); + nir_src_for_ssa(evaluate_rvalue(ir->val))); unsigned swizzle[4] = { ir->mask.x, ir->mask.y, ir->mask.z, ir->mask.w }; for (unsigned i = 0; i < ir->type->vector_elements; i++) @@ -2018,19 +2024,22 @@ nir_visitor::visit(ir_texture *ir) if (ir->coordinate != NULL) { instr->coord_components = ir->coordinate->type->vector_elements; - instr->src[src_number].src = evaluate_rvalue(ir->coordinate); + instr->src[src_number].src = + nir_src_for_ssa(evaluate_rvalue(ir->coordinate)); instr->src[src_number].src_type = nir_tex_src_coord; src_number++; } if (ir->projector != NULL) { - instr->src[src_number].src = evaluate_rvalue(ir->projector); + instr->src[src_number].src = + nir_src_for_ssa(evaluate_rvalue(ir->projector)); instr->src[src_number].src_type = nir_tex_src_projector; src_number++; } if (ir->shadow_comparitor != NULL) { - instr->src[src_number].src = evaluate_rvalue(ir->shadow_comparitor); + instr->src[src_number].src = + nir_src_for_ssa(evaluate_rvalue(ir->shadow_comparitor)); instr->src[src_number].src_type = nir_tex_src_comparitor; src_number++; } @@ -2044,7 +2053,8 @@ nir_visitor::visit(ir_texture *ir) for (unsigned i = 0; i < const_offset->type->vector_elements; i++) instr->const_offset[i] = const_offset->value.i[i]; } else { - instr->src[src_number].src = evaluate_rvalue(ir->offset); + instr->src[src_number].src = + nir_src_for_ssa(evaluate_rvalue(ir->offset)); instr->src[src_number].src_type = nir_tex_src_offset; src_number++; } @@ -2052,7 +2062,8 @@ nir_visitor::visit(ir_texture *ir) switch (ir->op) { case ir_txb: - instr->src[src_number].src = evaluate_rvalue(ir->lod_info.bias); + instr->src[src_number].src = + nir_src_for_ssa(evaluate_rvalue(ir->lod_info.bias)); instr->src[src_number].src_type = nir_tex_src_bias; src_number++; break; @@ -2061,23 +2072,27 @@ nir_visitor::visit(ir_texture *ir) case ir_txf: case ir_txs: if (ir->lod_info.lod != NULL) { - instr->src[src_number].src = evaluate_rvalue(ir->lod_info.lod); + instr->src[src_number].src = + nir_src_for_ssa(evaluate_rvalue(ir->lod_info.lod)); instr->src[src_number].src_type = nir_tex_src_lod; src_number++; } break; case ir_txd: - instr->src[src_number].src = evaluate_rvalue(ir->lod_info.grad.dPdx); + instr->src[src_number].src = + nir_src_for_ssa(evaluate_rvalue(ir->lod_info.grad.dPdx)); instr->src[src_number].src_type = nir_tex_src_ddx; src_number++; - instr->src[src_number].src = evaluate_rvalue(ir->lod_info.grad.dPdy); + instr->src[src_number].src = + nir_src_for_ssa(evaluate_rvalue(ir->lod_info.grad.dPdy)); instr->src[src_number].src_type = nir_tex_src_ddy; src_number++; break; case ir_txf_ms: - instr->src[src_number].src = evaluate_rvalue(ir->lod_info.sample_index); + instr->src[src_number].src = + nir_src_for_ssa(evaluate_rvalue(ir->lod_info.sample_index)); instr->src[src_number].src_type = nir_tex_src_ms_index; src_number++; break; @@ -2152,7 +2167,8 @@ nir_visitor::visit(ir_dereference_array *ir) deref->base_offset = const_index->value.u[0]; } else { deref->deref_array_type = nir_deref_array_type_indirect; - deref->indirect = evaluate_rvalue(ir->array_index); + deref->indirect = + nir_src_for_ssa(evaluate_rvalue(ir->array_index)); } ir->array->accept(this); |