From aa9b457062cfcdb29a15e0be73bbc1a75305f89e Mon Sep 17 00:00:00 2001 From: Timothy Arceri Date: Tue, 14 Jan 2020 11:54:27 +1100 Subject: [PATCH] glsl: move get_next_index() earlier in nir link uniforms MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit We will use get_next_index() in more of the helper functions in the following patches. Reviewed-by: Alejandro Piñeiro Part-of: --- src/compiler/glsl/gl_nir_link_uniforms.c | 68 ++++++++++++------------ 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/src/compiler/glsl/gl_nir_link_uniforms.c b/src/compiler/glsl/gl_nir_link_uniforms.c index f311ebcf1ff..311ea0dc0e3 100644 --- a/src/compiler/glsl/gl_nir_link_uniforms.c +++ b/src/compiler/glsl/gl_nir_link_uniforms.c @@ -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. -- 2.30.2