glsl: move get_next_index() earlier in nir link uniforms
authorTimothy Arceri <tarceri@itsqueeze.com>
Tue, 14 Jan 2020 00:54:27 +0000 (11:54 +1100)
committerMarge Bot <eric+marge@anholt.net>
Fri, 6 Mar 2020 23:22:14 +0000 (23:22 +0000)
We will use get_next_index() in more of the helper functions in
the following patches.

Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4050>

src/compiler/glsl/gl_nir_link_uniforms.c

index f311ebcf1ff6644669451cd6ea99f931885a7526..311ea0dc0e33f60a24080e96f09b514b05daad8b 100644 (file)
@@ -243,6 +243,40 @@ add_parameter(struct gl_uniform_storage *uniform,
    }
 }
 
+static unsigned
+get_next_index(struct nir_link_uniforms_state *state,
+               const struct gl_uniform_storage *uniform,
+               unsigned *next_index, bool *initialised)
+{
+   /* If we’ve already calculated an index for this member then we can just
+    * offset from there.
+    */
+   if (state->current_type->next_index == UINT_MAX) {
+      /* Otherwise we need to reserve enough indices for all of the arrays
+       * enclosing this member.
+       */
+
+      unsigned array_size = 1;
+
+      for (const struct type_tree_entry *p = state->current_type;
+           p;
+           p = p->parent) {
+         array_size *= p->array_size;
+      }
+
+      state->current_type->next_index = *next_index;
+      *next_index += array_size;
+      *initialised = true;
+   } else
+      *initialised = false;
+
+   unsigned index = state->current_type->next_index;
+
+   state->current_type->next_index += MAX2(1, uniform->array_elements);
+
+   return index;
+}
+
 /**
  * Finds, returns, and updates the stage info for any uniform in UniformStorage
  * defined by @var. In general this is done using the explicit location,
@@ -366,40 +400,6 @@ free_type_tree(struct type_tree_entry *entry)
    free(entry);
 }
 
-static unsigned
-get_next_index(struct nir_link_uniforms_state *state,
-               const struct gl_uniform_storage *uniform,
-               unsigned *next_index, bool *initialised)
-{
-   /* If we’ve already calculated an index for this member then we can just
-    * offset from there.
-    */
-   if (state->current_type->next_index == UINT_MAX) {
-      /* Otherwise we need to reserve enough indices for all of the arrays
-       * enclosing this member.
-       */
-
-      unsigned array_size = 1;
-
-      for (const struct type_tree_entry *p = state->current_type;
-           p;
-           p = p->parent) {
-         array_size *= p->array_size;
-      }
-
-      state->current_type->next_index = *next_index;
-      *next_index += array_size;
-      *initialised = true;
-   } else
-      *initialised = false;
-
-   unsigned index = state->current_type->next_index;
-
-   state->current_type->next_index += MAX2(1, uniform->array_elements);
-
-   return index;
-}
-
 /**
  * Creates the neccessary entries in UniformStorage for the uniform. Returns
  * the number of locations used or -1 on failure.