glsl: add struct to gather more info about uniform array access
authorTimothy Arceri <tarceri@itsqueeze.com>
Tue, 5 May 2020 04:13:51 +0000 (14:13 +1000)
committerMarge Bot <eric+marge@anholt.net>
Wed, 3 Jun 2020 10:34:22 +0000 (10:34 +0000)
This will be used in the following patches to allow the linker
to resize uniform arrays based on array dereferences.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4910>

src/compiler/glsl/gl_nir_link_uniforms.c

index c8d32bdf3384668ef109c0afdfb54328ccb9db94..6682f6ea48e631cc3fbef65873052d527d4d5d70 100644 (file)
 
 #define UNMAPPED_UNIFORM_LOC ~0u
 
+struct uniform_array_info {
+   /** List of dereferences of the uniform array. */
+   struct util_dynarray *deref_list;
+
+   /** Set of bit-flags to note which array elements have been accessed. */
+   BITSET_WORD *indices;
+
+   /** Have we rezized this array yet */
+   bool resized;
+};
+
 /**
  * Built-in / reserved GL variables names start with "gl_"
  */
@@ -349,18 +360,25 @@ add_var_use_deref(nir_deref_instr *deref, struct hash_table *live,
 
    nir_deref_path_finish(&path);
 
-   /** Set of bit-flags to note which array elements have been accessed. */
-   BITSET_WORD *bits = NULL;
+
+   struct uniform_array_info *ainfo = NULL;
 
    struct hash_entry *entry =
       _mesa_hash_table_search(live, deref->var);
    if (!entry && glsl_type_is_array(deref->var->type)) {
+      ainfo = ralloc(live, struct uniform_array_info);
+
       unsigned num_bits = MAX2(1, glsl_get_aoa_size(deref->var->type));
-      bits = rzalloc_array(live, BITSET_WORD, BITSET_WORDS(num_bits));
+      ainfo->indices = rzalloc_array(live, BITSET_WORD, BITSET_WORDS(num_bits));
+
+      ainfo->deref_list = ralloc(live, struct util_dynarray);
+      util_dynarray_init(ainfo->deref_list, live);
+
+      ainfo->resized = false;
    }
 
    if (entry)
-      bits = (BITSET_WORD *) entry->data;
+      ainfo = (struct uniform_array_info *) entry->data;
 
    if (glsl_type_is_array(deref->var->type)) {
       /* Count the "depth" of the arrays-of-arrays. */
@@ -372,11 +390,13 @@ add_var_use_deref(nir_deref_instr *deref, struct hash_table *live,
       }
 
       link_util_mark_array_elements_referenced(*derefs, num_derefs, array_depth,
-                                               bits);
+                                               ainfo->indices);
+
+      util_dynarray_append(ainfo->deref_list, nir_deref_instr *, deref);
    }
 
    assert(deref->mode == deref->var->data.mode);
-   _mesa_hash_table_insert(live, deref->var, bits);
+   _mesa_hash_table_insert(live, deref->var, ainfo);
 }
 
 /* Iterate over the shader and collect infomation about uniform use */
@@ -1546,8 +1566,9 @@ gl_nir_link_uniforms(struct gl_context *ctx,
                      struct hash_entry *entry =
                         _mesa_hash_table_search(state.referenced_uniforms, var);
                      if (entry) {
-                        BITSET_WORD *bits = (BITSET_WORD *) entry->data;
-                        if (BITSET_TEST(bits, blocks[i].linearized_array_index))
+                        struct uniform_array_info *ainfo =
+                           (struct uniform_array_info *) entry->data;
+                        if (BITSET_TEST(ainfo->indices, blocks[i].linearized_array_index))
                            blocks[i].stageref |= 1U << shader_type;
                      }
                   }