From: Rob Clark Date: Sat, 11 Apr 2015 19:25:58 +0000 (-0400) Subject: gallium/ttn: minor cleanup X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8efe20467b2710cc502cbfec19c1e543e572f864;p=mesa.git gallium/ttn: minor cleanup v2: also use ttn_src_for_indirect() everywhere for addr access, rather than open-coding it for INPUT/CONST srcs v3: move ralloc out of ttn_src_for_indirect() into the one call site that needs a ptr Signed-off-by: Rob Clark Reviewed-by: Eric Anholt --- diff --git a/src/gallium/auxiliary/nir/tgsi_to_nir.c b/src/gallium/auxiliary/nir/tgsi_to_nir.c index 42671c8bb18..b6123e036f2 100644 --- a/src/gallium/auxiliary/nir/tgsi_to_nir.c +++ b/src/gallium/auxiliary/nir/tgsi_to_nir.c @@ -52,7 +52,6 @@ struct ttn_reg_info { struct ttn_compile { union tgsi_full_token *token; nir_builder build; - struct nir_shader *s; struct tgsi_shader_info *scan; struct ttn_reg_info *output_regs; @@ -256,7 +255,7 @@ ttn_emit_immediate(struct ttn_compile *c) nir_instr_insert_after_cf_list(b->cf_node_list, &load_const->instr); } -static nir_src * +static nir_src ttn_src_for_indirect(struct ttn_compile *c, struct tgsi_ind_register *indirect); /* generate either a constant or indirect deref chain for accessing an @@ -275,7 +274,7 @@ ttn_array_deref(struct ttn_compile *c, nir_intrinsic_instr *instr, if (indirect) { arr->deref_array_type = nir_deref_array_type_indirect; - arr->indirect = *ttn_src_for_indirect(c, indirect); + arr->indirect = ttn_src_for_indirect(c, indirect); } else { arr->deref_array_type = nir_deref_array_type_direct; } @@ -361,35 +360,29 @@ ttn_src_for_file_and_index(struct ttn_compile *c, unsigned file, unsigned index, case TGSI_FILE_INPUT: case TGSI_FILE_CONSTANT: { nir_intrinsic_instr *load; + nir_intrinsic_op op; switch (file) { case TGSI_FILE_INPUT: - load = nir_intrinsic_instr_create(b->shader, - indirect ? - nir_intrinsic_load_input_indirect : - nir_intrinsic_load_input); + op = indirect ? nir_intrinsic_load_input_indirect : + nir_intrinsic_load_input; break; case TGSI_FILE_CONSTANT: - load = nir_intrinsic_instr_create(b->shader, - indirect ? - nir_intrinsic_load_uniform_indirect : - nir_intrinsic_load_uniform); + op = indirect ? nir_intrinsic_load_uniform_indirect : + nir_intrinsic_load_uniform; break; default: unreachable("No other load files supported"); break; } + load = nir_intrinsic_instr_create(b->shader, op); + load->num_components = 4; load->const_index[0] = index; load->const_index[1] = 1; if (indirect) { - nir_alu_src indirect_address; - memset(&indirect_address, 0, sizeof(indirect_address)); - indirect_address.src = nir_src_for_reg(c->addr_reg); - for (int i = 0; i < 4; i++) - indirect_address.swizzle[i] = indirect->Swizzle; - load->src[0] = nir_src_for_ssa(nir_imov_alu(b, indirect_address, 1)); + load->src[0] = ttn_src_for_indirect(c, indirect); } nir_ssa_dest_init(&load->instr, &load->dest, 4, NULL); nir_instr_insert_after_cf_list(b->cf_node_list, &load->instr); @@ -406,7 +399,7 @@ ttn_src_for_file_and_index(struct ttn_compile *c, unsigned file, unsigned index, return src; } -static nir_src * +static nir_src ttn_src_for_indirect(struct ttn_compile *c, struct tgsi_ind_register *indirect) { nir_builder *b = &c->build; @@ -417,9 +410,7 @@ ttn_src_for_indirect(struct ttn_compile *c, struct tgsi_ind_register *indirect) src.src = ttn_src_for_file_and_index(c, indirect->File, indirect->Index, NULL); - nir_src *result = ralloc(b->shader, nir_src); - *result = nir_src_for_ssa(nir_imov_alu(b, src, 1)); - return result; + return nir_src_for_ssa(nir_imov_alu(b, src, 1)); } static nir_alu_dest @@ -486,8 +477,11 @@ ttn_get_dest(struct ttn_compile *c, struct tgsi_full_dst_register *tgsi_fdst) dest.write_mask = tgsi_dst->WriteMask; dest.saturate = false; - if (tgsi_dst->Indirect && (tgsi_dst->File != TGSI_FILE_TEMPORARY)) - dest.dest.reg.indirect = ttn_src_for_indirect(c, &tgsi_fdst->Indirect); + if (tgsi_dst->Indirect && (tgsi_dst->File != TGSI_FILE_TEMPORARY)) { + nir_src *indirect = ralloc(c->build.shader, nir_src); + *indirect = ttn_src_for_indirect(c, &tgsi_fdst->Indirect); + dest.dest.reg.indirect = indirect; + } return dest; }