compiler/nir: move find_state_var to common code

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>
This commit is contained in:
Erik Faye-Lund 2023-05-04 08:20:41 +02:00 committed by Marge Bot
parent 5e997beeb7
commit a37051304a
3 changed files with 17 additions and 14 deletions

View 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

View 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 *),

View file

@ -293,19 +293,6 @@ struct tnl_program {
GLuint color_materials;
};
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,
@ -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;