}
static void
-index_var_list(struct exec_list *list)
+index_var_list(struct exec_list *list, unsigned *count)
{
- unsigned next_index = 0;
nir_foreach_variable(var, list)
- var->index = next_index++;
+ var->index = (*count)++;
}
-void
-nir_index_vars(nir_shader *shader, nir_function_impl *impl, nir_variable_mode modes)
+unsigned
+nir_shader_index_vars(nir_shader *shader, nir_variable_mode modes)
{
- if ((modes & nir_var_function_temp) && impl)
- index_var_list(&impl->locals);
-
+ unsigned count = 0;
if (modes & nir_var_shader_temp)
- index_var_list(&shader->globals);
+ index_var_list(&shader->globals, &count);
if (modes & nir_var_shader_in)
- index_var_list(&shader->inputs);
+ index_var_list(&shader->inputs, &count);
if (modes & nir_var_shader_out)
- index_var_list(&shader->outputs);
+ index_var_list(&shader->outputs, &count);
if (modes & (nir_var_uniform | nir_var_mem_ubo | nir_var_mem_ssbo))
- index_var_list(&shader->uniforms);
+ index_var_list(&shader->uniforms, &count);
if (modes & nir_var_mem_shared)
- index_var_list(&shader->shared);
+ index_var_list(&shader->shared, &count);
if (modes & nir_var_system_value)
- index_var_list(&shader->system_values);
+ index_var_list(&shader->system_values, &count);
+
+ return count;
+}
+
+unsigned
+nir_function_impl_index_vars(nir_function_impl *impl)
+{
+ unsigned count = 0;
+ index_var_list(&impl->locals, &count);
+ return count;
}
static nir_instr *
void nir_index_blocks(nir_function_impl *impl);
-void nir_index_vars(nir_shader *shader, nir_function_impl *impl, nir_variable_mode modes);
+unsigned nir_shader_index_vars(nir_shader *shader, nir_variable_mode modes);
+unsigned nir_function_impl_index_vars(nir_function_impl *impl);
void nir_print_shader(nir_shader *shader, FILE *fp);
void nir_print_shader_annotated(nir_shader *shader, FILE *fp, struct hash_table *errors);
/* This pass can only be run once */
assert(shader->constant_data == NULL && shader->constant_data_size == 0);
- unsigned num_locals = exec_list_length(&impl->locals);
- nir_index_vars(shader, impl, nir_var_function_temp);
+ unsigned num_locals = nir_function_impl_index_vars(impl);
if (num_locals == 0) {
nir_shader_preserve_all_metadata(shader);
ctx->callback = callback;
ctx->robust_modes = robust_modes;
- nir_index_vars(shader, NULL, modes);
+ nir_shader_index_vars(shader, modes);
nir_foreach_function(function, shader) {
if (function->impl) {
if (modes & nir_var_function_temp)
- nir_index_vars(shader, function->impl, nir_var_function_temp);
+ nir_function_impl_index_vars(function->impl);
nir_foreach_block(block, function->impl)
progress |= process_block(function->impl, ctx, block);