glsl: move get_next_index() earlier in nir link uniforms

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>
This commit is contained in:
Timothy Arceri 2020-01-14 11:54:27 +11:00 committed by Marge Bot
parent 219cefe24f
commit aa9b457062
1 changed files with 34 additions and 34 deletions

View 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 weve 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 weve 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.