From a37051304a4671d8d67c3135194b81014bf992a2 Mon Sep 17 00:00:00 2001 From: Erik Faye-Lund Date: Thu, 4 May 2023 08:20:41 +0200 Subject: [PATCH] compiler/nir: move find_state_var to common code MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Emma Anholt Part-of: --- src/compiler/nir/nir.c | 13 +++++++++++++ src/compiler/nir/nir.h | 3 +++ src/mesa/main/ffvertex_prog.c | 15 +-------------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c index 231147b..1295f34 100644 --- a/src/compiler/nir/nir.c +++ b/src/compiler/nir/nir.c @@ -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 diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 96bc3a1..9e5b9ab 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -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 *), diff --git a/src/mesa/main/ffvertex_prog.c b/src/mesa/main/ffvertex_prog.c index 31fea0c..13f2b11 100644 --- a/src/mesa/main/ffvertex_prog.c +++ b/src/mesa/main/ffvertex_prog.c @@ -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; -- 2.7.4