nir: Support deref instructions in gather_info
authorJason Ekstrand <jason.ekstrand@intel.com>
Sun, 18 Mar 2018 04:09:14 +0000 (21:09 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Sat, 23 Jun 2018 03:15:55 +0000 (20:15 -0700)
Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
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 4f4b650ab7ed18512eb8eb0e90c1ca8c82e8f50f..2f644773ba49fb7ec9a4e28634caeb9de72ff4b0 100644 (file)
@@ -219,7 +219,8 @@ try_mask_partial_io(nir_shader *shader, nir_deref_var *deref, bool is_output_rea
 }
 
 static void
-gather_intrinsic_info(nir_intrinsic_instr *instr, nir_shader *shader)
+gather_intrinsic_info(nir_intrinsic_instr *instr, nir_shader *shader,
+                      void *dead_ctx)
 {
    switch (instr->intrinsic) {
    case nir_intrinsic_discard:
@@ -228,21 +229,32 @@ gather_intrinsic_info(nir_intrinsic_instr *instr, nir_shader *shader)
       shader->info.fs.uses_discard = true;
       break;
 
+   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_variable *var = instr->variables[0]->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;
 
       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_var ||
+              instr->intrinsic == nir_intrinsic_load_deref))
             is_output_read = true;
 
-         if (!try_mask_partial_io(shader, instr->variables[0], is_output_read))
+         if (!try_mask_partial_io(shader, deref, is_output_read))
             mark_whole_variable(shader, var, is_output_read);
 
          /* We need to track which input_reads bits correspond to a
@@ -330,7 +342,7 @@ gather_alu_info(nir_alu_instr *instr, nir_shader *shader)
 }
 
 static void
-gather_info_block(nir_block *block, nir_shader *shader)
+gather_info_block(nir_block *block, nir_shader *shader, void *dead_ctx)
 {
    nir_foreach_instr(instr, block) {
       switch (instr->type) {
@@ -338,7 +350,7 @@ gather_info_block(nir_block *block, nir_shader *shader)
          gather_alu_info(nir_instr_as_alu(instr), shader);
          break;
       case nir_instr_type_intrinsic:
-         gather_intrinsic_info(nir_instr_as_intrinsic(instr), shader);
+         gather_intrinsic_info(nir_instr_as_intrinsic(instr), shader, dead_ctx);
          break;
       case nir_instr_type_tex:
          gather_tex_info(nir_instr_as_tex(instr), shader);
@@ -397,8 +409,6 @@ glsl_type_get_image_count(const struct glsl_type *type)
 void
 nir_shader_gather_info(nir_shader *shader, nir_function_impl *entrypoint)
 {
-   nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs | nir_lower_interp_derefs);
-
    shader->info.num_textures = 0;
    shader->info.num_images = 0;
    nir_foreach_variable(var, &shader->uniforms) {
@@ -420,7 +430,10 @@ nir_shader_gather_info(nir_shader *shader, nir_function_impl *entrypoint)
    if (shader->info.stage == MESA_SHADER_FRAGMENT) {
       shader->info.fs.uses_sample_qualifier = false;
    }
+
+   void *dead_ctx = ralloc_context(NULL);
    nir_foreach_block(block, entrypoint) {
-      gather_info_block(block, shader);
+      gather_info_block(block, shader, dead_ctx);
    }
+   ralloc_free(dead_ctx);
 }