delete autotools .gitignore files
[mesa.git] / src / compiler / glsl / gl_nir_lower_samplers_as_deref.c
index c8f17ef9aaa184c06b46dd17cf88f000273bd100..5907abfd9a983849db9a2e9680ab74aca6bbbd66 100644 (file)
@@ -104,7 +104,7 @@ remove_struct_derefs_prep(nir_deref_instr **p, char **name,
    }
 
    case nir_deref_type_struct: {
-      *location += glsl_get_record_location_offset(cur->type, next->strct.index);
+      *location += glsl_get_struct_location_offset(cur->type, next->strct.index);
       ralloc_asprintf_append(name, ".%s",
                              glsl_get_struct_elem_name(cur->type, next->strct.index));
 
@@ -177,6 +177,14 @@ lower_deref(nir_builder *b, struct lower_samplers_as_deref_state *state,
    } else {
       var = nir_variable_create(state->shader, nir_var_uniform, type, name);
       var->data.binding = binding;
+
+      /* Don't set var->data.location.  The old structure location could be
+       * used to index into gl_uniform_storage, assuming the full structure
+       * was walked in order.  With the new split variables, this invariant
+       * no longer holds and there's no meaningful way to start from a base
+       * location and access a particular array element.  Just leave it 0.
+       */
+
       _mesa_hash_table_insert_pre_hashed(state->remap_table, hash, name, var);
    }
 
@@ -197,6 +205,26 @@ lower_deref(nir_builder *b, struct lower_samplers_as_deref_state *state,
    return new_deref;
 }
 
+static void
+record_textures_used(struct shader_info *info,
+                     nir_deref_instr *deref,
+                     nir_texop op)
+{
+   nir_variable *var = nir_deref_instr_get_variable(deref);
+
+   /* Structs have been lowered already, so get_aoa_size is sufficient. */
+   const unsigned size =
+      glsl_type_is_array(var->type) ? glsl_get_aoa_size(var->type) : 1;
+   unsigned mask = ((1ull << MAX2(size, 1)) - 1) << var->data.binding;
+
+   info->textures_used |= mask;
+
+   if (op == nir_texop_txf ||
+       op == nir_texop_txf_ms ||
+       op == nir_texop_txf_ms_mcs)
+      info->textures_used_by_txf |= mask;
+}
+
 static bool
 lower_sampler(nir_tex_instr *instr, struct lower_samplers_as_deref_state *state,
               nir_builder *b)
@@ -217,6 +245,7 @@ lower_sampler(nir_tex_instr *instr, struct lower_samplers_as_deref_state *state,
       if (texture_deref) {
          nir_instr_rewrite_src(&instr->instr, &instr->src[texture_idx].src,
                                nir_src_for_ssa(&texture_deref->dest.ssa));
+         record_textures_used(&b->shader->info, texture_deref, instr->op);
       }
    }
 
@@ -297,6 +326,9 @@ gl_nir_lower_samplers_as_deref(nir_shader *shader,
    state.remap_table = _mesa_hash_table_create(NULL, _mesa_key_hash_string,
                                                _mesa_key_string_equal);
 
+   shader->info.textures_used = 0;
+   shader->info.textures_used_by_txf = 0;
+
    nir_foreach_function(function, shader) {
       if (function->impl)
          progress |= lower_impl(function->impl, &state);