diff --git a/src/compiler/glsl/gl_nir_linker.c b/src/compiler/glsl/gl_nir_linker.c index b45d0c086ba..9a93285c6d3 100644 --- a/src/compiler/glsl/gl_nir_linker.c +++ b/src/compiler/glsl/gl_nir_linker.c @@ -35,7 +35,7 @@ */ static bool -can_remove_uniform(nir_variable *var) +can_remove_uniform(nir_variable *var, UNUSED void *data) { /* Section 2.11.6 (Uniform Variables) of the OpenGL ES 3.0.3 spec * says: @@ -603,8 +603,11 @@ gl_nir_link_spirv(struct gl_context *ctx, struct gl_shader_program *prog, for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) { struct gl_linked_shader *shader = prog->_LinkedShaders[i]; if (shader) { + const nir_remove_dead_variables_options opts = { + .can_remove_var = can_remove_uniform, + }; nir_remove_dead_variables(shader->Program->nir, nir_var_uniform, - &can_remove_uniform); + &opts); } } @@ -664,8 +667,11 @@ gl_nir_link_glsl(struct gl_context *ctx, struct gl_shader_program *prog) for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) { struct gl_linked_shader *shader = prog->_LinkedShaders[i]; if (shader) { + const nir_remove_dead_variables_options opts = { + .can_remove_var = can_remove_uniform, + }; nir_remove_dead_variables(shader->Program->nir, nir_var_uniform, - &can_remove_uniform); + &opts); } } diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 1a27f5ccf10..b65882e619c 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -4472,8 +4472,15 @@ bool nir_lower_vars_to_ssa(nir_shader *shader); bool nir_remove_dead_derefs(nir_shader *shader); bool nir_remove_dead_derefs_impl(nir_function_impl *impl); + +typedef struct nir_remove_dead_variables_options { + bool (*can_remove_var)(nir_variable *var, void *data); + void *can_remove_var_data; +} nir_remove_dead_variables_options; + bool nir_remove_dead_variables(nir_shader *shader, nir_variable_mode modes, - bool (*can_remove_var)(nir_variable *var)); + const nir_remove_dead_variables_options *options); + bool nir_lower_variable_initializers(nir_shader *shader, nir_variable_mode modes); diff --git a/src/compiler/nir/nir_remove_dead_variables.c b/src/compiler/nir/nir_remove_dead_variables.c index fde006f917f..19e56d077d4 100644 --- a/src/compiler/nir/nir_remove_dead_variables.c +++ b/src/compiler/nir/nir_remove_dead_variables.c @@ -152,7 +152,7 @@ remove_dead_var_writes(nir_shader *shader) static bool remove_dead_vars(struct exec_list *var_list, nir_variable_mode modes, - struct set *live, bool (*can_remove_var)(nir_variable *var)) + struct set *live, const nir_remove_dead_variables_options *opts) { bool progress = false; @@ -160,7 +160,8 @@ remove_dead_vars(struct exec_list *var_list, nir_variable_mode modes, if (!(var->data.mode & modes)) continue; - if (can_remove_var && !can_remove_var(var)) + if (opts && opts->can_remove_var && + !opts->can_remove_var(var, opts->can_remove_var_data)) continue; struct set_entry *entry = _mesa_set_search(live, var); @@ -177,7 +178,7 @@ remove_dead_vars(struct exec_list *var_list, nir_variable_mode modes, bool nir_remove_dead_variables(nir_shader *shader, nir_variable_mode modes, - bool (*can_remove_var)(nir_variable *var)) + const nir_remove_dead_variables_options *opts) { bool progress = false; struct set *live = _mesa_pointer_set_create(NULL); @@ -186,7 +187,7 @@ nir_remove_dead_variables(nir_shader *shader, nir_variable_mode modes, if (modes & ~nir_var_function_temp) { progress = remove_dead_vars(&shader->variables, modes, - live, can_remove_var) || progress; + live, opts) || progress; } if (modes & nir_var_function_temp) { @@ -194,7 +195,7 @@ nir_remove_dead_variables(nir_shader *shader, nir_variable_mode modes, if (function->impl) { if (remove_dead_vars(&function->impl->locals, nir_var_function_temp, - live, can_remove_var)) + live, opts)) progress = true; } }