From 69866af357e0908b41cab4d0db95e2ed8f0ab960 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Mon, 26 Mar 2018 15:53:17 -0700 Subject: [PATCH] nir: Rework gather_info to entirely use deref instructions Acked-by: Rob Clark Acked-by: Bas Nieuwenhuizen Acked-by: Dave Airlie Reviewed-by: Kenneth Graunke --- src/compiler/nir/nir_gather_info.c | 42 ++++++++++-------------------- 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/src/compiler/nir/nir_gather_info.c b/src/compiler/nir/nir_gather_info.c index 2f644773ba4..2b431e343e9 100644 --- a/src/compiler/nir/nir_gather_info.c +++ b/src/compiler/nir/nir_gather_info.c @@ -113,23 +113,19 @@ mark_whole_variable(nir_shader *shader, nir_variable *var, bool is_output_read) } static unsigned -get_io_offset(nir_deref_var *deref, bool is_vertex_input) +get_io_offset(nir_deref_instr *deref, bool is_vertex_input) { unsigned offset = 0; - nir_deref *tail = &deref->deref; - while (tail->child != NULL) { - tail = tail->child; + for (nir_deref_instr *d = deref; d; d = nir_deref_instr_parent(d)) { + if (d->deref_type == nir_deref_type_array) { + nir_const_value *const_index = nir_src_as_const_value(d->arr.index); - if (tail->deref_type == nir_deref_type_array) { - nir_deref_array *deref_array = nir_deref_as_array(tail); - - if (deref_array->deref_array_type == nir_deref_array_type_indirect) { + if (!const_index) return -1; - } - offset += glsl_count_attribute_slots(tail->type, is_vertex_input) * - deref_array->base_offset; + offset += glsl_count_attribute_slots(d->type, is_vertex_input) * + const_index->u32[0]; } /* TODO: we can get the offset for structs here see nir_lower_io() */ } @@ -145,9 +141,9 @@ get_io_offset(nir_deref_var *deref, bool is_vertex_input) * occurs, then nothing will be marked and false will be returned. */ static bool -try_mask_partial_io(nir_shader *shader, nir_deref_var *deref, bool is_output_read) +try_mask_partial_io(nir_shader *shader, nir_variable *var, + nir_deref_instr *deref, bool is_output_read) { - nir_variable *var = deref->var; const struct glsl_type *type = var->type; if (nir_is_per_vertex_io(var, shader->info.stage)) { @@ -232,29 +228,19 @@ gather_intrinsic_info(nir_intrinsic_instr *instr, nir_shader *shader, case nir_intrinsic_interp_deref_at_centroid: case nir_intrinsic_interp_deref_at_sample: case nir_intrinsic_interp_deref_at_offset: - case nir_intrinsic_interp_var_at_centroid: - case nir_intrinsic_interp_var_at_sample: - case nir_intrinsic_interp_var_at_offset: case nir_intrinsic_load_deref: - case nir_intrinsic_load_var: - case nir_intrinsic_store_deref: - case nir_intrinsic_store_var: { - nir_deref_var *deref; - if (nir_intrinsic_infos[instr->intrinsic].num_variables > 0) - deref = instr->variables[0]; - else - deref = nir_deref_instr_to_deref(nir_src_as_deref(instr->src[0]), dead_ctx); - nir_variable *var = deref->var; + case nir_intrinsic_store_deref:{ + nir_deref_instr *deref = nir_src_as_deref(instr->src[0]); + nir_variable *var = nir_deref_instr_get_variable(deref); if (var->data.mode == nir_var_shader_in || var->data.mode == nir_var_shader_out) { bool is_output_read = false; if (var->data.mode == nir_var_shader_out && - (instr->intrinsic == nir_intrinsic_load_var || - instr->intrinsic == nir_intrinsic_load_deref)) + instr->intrinsic == nir_intrinsic_load_deref) is_output_read = true; - if (!try_mask_partial_io(shader, deref, is_output_read)) + if (!try_mask_partial_io(shader, var, deref, is_output_read)) mark_whole_variable(shader, var, is_output_read); /* We need to track which input_reads bits correspond to a -- 2.30.2