From: Jason Ekstrand Date: Tue, 21 Jul 2020 20:15:43 +0000 (-0500) Subject: nir/dead_variables: Respect the modes passed to remove_dead_vars X-Git-Url: https://git.libre-soc.org/?p=mesa.git;a=commitdiff_plain;h=9bf8572222044638866c8b5d9079a439ff39beb1 nir/dead_variables: Respect the modes passed to remove_dead_vars For the most part, this doesn't actually matter today. We already only call remove_dead_vars on the lists that are specified in the modes. The only functional change here is for the uniform, mem_ubo, and mem_ssbo modes because they share a list. If nir_remove_dead_variables is called with a mode of nir_var_uniform, it will no longer remove UBOs or SSBOs, for instance. Reviewed-by: Gert Wollny Part-of: --- diff --git a/src/compiler/nir/nir_remove_dead_variables.c b/src/compiler/nir/nir_remove_dead_variables.c index 6baa66a5767..dfeaa249590 100644 --- a/src/compiler/nir/nir_remove_dead_variables.c +++ b/src/compiler/nir/nir_remove_dead_variables.c @@ -143,12 +143,15 @@ remove_dead_var_writes(nir_shader *shader, struct set *live) } static bool -remove_dead_vars(struct exec_list *var_list, struct set *live, - bool (*can_remove_var)(nir_variable *var)) +remove_dead_vars(struct exec_list *var_list, nir_variable_mode modes, + struct set *live, bool (*can_remove_var)(nir_variable *var)) { bool progress = false; - foreach_list_typed_safe(nir_variable, var, node, var_list) { + nir_foreach_variable_safe(var, var_list) { + if (!(var->data.mode & modes)) + continue; + if (can_remove_var && !can_remove_var(var)) continue; @@ -174,40 +177,41 @@ nir_remove_dead_variables(nir_shader *shader, nir_variable_mode modes, add_var_use_shader(shader, live, modes); if (modes & nir_var_uniform) { - progress = remove_dead_vars(&shader->uniforms, live, can_remove_var) || + progress = remove_dead_vars(&shader->uniforms, modes, live, can_remove_var) || progress; } if (modes & nir_var_shader_in) { - progress = remove_dead_vars(&shader->inputs, live, can_remove_var) || + progress = remove_dead_vars(&shader->inputs, modes, live, can_remove_var) || progress; } if (modes & nir_var_shader_out) { - progress = remove_dead_vars(&shader->outputs, live, can_remove_var) || + progress = remove_dead_vars(&shader->outputs, modes, live, can_remove_var) || progress; } if (modes & nir_var_shader_temp) { - progress = remove_dead_vars(&shader->globals, live, can_remove_var) || + progress = remove_dead_vars(&shader->globals, modes, live, can_remove_var) || progress; } if (modes & nir_var_system_value) { - progress = remove_dead_vars(&shader->system_values, live, + progress = remove_dead_vars(&shader->system_values, modes, live, can_remove_var) || progress; } if (modes & nir_var_mem_shared) { - progress = remove_dead_vars(&shader->shared, live, can_remove_var) || + progress = remove_dead_vars(&shader->shared, modes, live, can_remove_var) || progress; } if (modes & nir_var_function_temp) { nir_foreach_function(function, shader) { if (function->impl) { - if (remove_dead_vars(&function->impl->locals, live, - can_remove_var)) + if (remove_dead_vars(&function->impl->locals, + nir_var_function_temp, + live, can_remove_var)) progress = true; } }