nir: Rework gather_info to entirely use deref instructions
authorJason Ekstrand <jason.ekstrand@intel.com>
Mon, 26 Mar 2018 22:53:17 +0000 (15:53 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Sat, 23 Jun 2018 03:54:00 +0000 (20:54 -0700)
Acked-by: Rob Clark <robdclark@gmail.com>
Acked-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Acked-by: Dave Airlie <airlied@redhat.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/compiler/nir/nir_gather_info.c

index 2f644773ba49fb7ec9a4e28634caeb9de72ff4b0..2b431e343e926ebbc9bfecf010d984a1e3f0466c 100644 (file)
@@ -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