compiler/nir: move find_state_var to common code
authorErik Faye-Lund <erik.faye-lund@collabora.com>
Thu, 4 May 2023 06:20:41 +0000 (08:20 +0200)
committerMarge Bot <emma+marge@anholt.net>
Fri, 19 May 2023 13:51:19 +0000 (13:51 +0000)
We're about to need this in another place, so let's move it to common
nir code, and clean up the name a bit.

Acked-by: Marek Olšák <marek.olsak@amd.com>
Reviewed-by: Emma Anholt <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22755>

src/compiler/nir/nir.c
src/compiler/nir/nir.h
src/mesa/main/ffvertex_prog.c

index 231147b..1295f34 100644 (file)
@@ -421,6 +421,19 @@ nir_find_variable_with_driver_location(nir_shader *shader,
    return NULL;
 }
 
+nir_variable *
+nir_find_state_variable(nir_shader *s,
+                        gl_state_index16 tokens[STATE_LENGTH])
+{
+   nir_foreach_variable_with_modes(var, s, nir_var_uniform) {
+      if (var->num_state_slots == 1 &&
+          !memcmp(var->state_slots[0].tokens, tokens,
+                  sizeof(var->state_slots[0].tokens)))
+         return var;
+   }
+   return NULL;
+}
+
 /* Annoyingly, qsort_r is not in the C standard library and, in particular, we
  * can't count on it on MSV and Android.  So we stuff the CMP function into
  * each array element.  It's a bit messy and burns more memory but the list of
index 96bc3a1..9e5b9ab 100644 (file)
@@ -4061,6 +4061,9 @@ nir_variable *nir_find_variable_with_driver_location(nir_shader *shader,
                                                      nir_variable_mode mode,
                                                      unsigned location);
 
+nir_variable *nir_find_state_variable(nir_shader *s,
+                                      gl_state_index16 tokens[STATE_LENGTH]);
+
 void nir_sort_variables_with_modes(nir_shader *shader,
                                    int (*compar)(const nir_variable *,
                                                  const nir_variable *),
index 31fea0c..13f2b11 100644 (file)
@@ -294,19 +294,6 @@ struct tnl_program {
 };
 
 static nir_variable *
-find_state_var(nir_shader *s,
-               gl_state_index16 tokens[STATE_LENGTH])
-{
-   nir_foreach_variable_with_modes(var, s, nir_var_uniform) {
-      if (var->num_state_slots == 1 &&
-          !memcmp(var->state_slots[0].tokens, tokens,
-                  sizeof(var->state_slots[0].tokens)))
-         return var;
-   }
-   return NULL;
-}
-
-static nir_variable *
 register_state_var(struct tnl_program *p,
                    gl_state_index s0,
                    gl_state_index s1,
@@ -319,7 +306,7 @@ register_state_var(struct tnl_program *p,
    tokens[1] = s1;
    tokens[2] = s2;
    tokens[3] = s3;
-   nir_variable *var = find_state_var(p->b->shader, tokens);
+   nir_variable *var = nir_find_state_variable(p->b->shader, tokens);
    if (var)
       return var;