diff options
author | Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com> | 2021-01-21 08:41:15 -0800 |
---|---|---|
committer | Dylan Baker <dylan.c.baker@intel.com> | 2021-01-26 09:12:19 -0800 |
commit | 5d8a6fd48d74b04498d8b62e0ffc0ef3fdcc9fb6 (patch) | |
tree | 432e7c0a88ce0d0bd7bf67de5b4af6d9beb1a667 | |
parent | 96de6d77548c3f56fc8cb4d0af0c6d7bfa5f1e6f (diff) |
nir: Add a data pointer to the callback in nir_remove_dead_variables
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8706>
(cherry picked from commit cb7352ae95a48ba4f20286a59bea184072f52785)
-rw-r--r-- | .pick_status.json | 2 | ||||
-rw-r--r-- | src/compiler/glsl/gl_nir_linker.c | 12 | ||||
-rw-r--r-- | src/compiler/nir/nir.h | 9 | ||||
-rw-r--r-- | src/compiler/nir/nir_remove_dead_variables.c | 11 |
4 files changed, 24 insertions, 10 deletions
diff --git a/.pick_status.json b/.pick_status.json index c3fa8f97954..cfe18fc5f75 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -238,7 +238,7 @@ "description": "nir: Add a data pointer to the callback in nir_remove_dead_variables", "nominated": false, "nomination_type": null, - "resolution": 4, + "resolution": 1, "master_sha": null, "because_sha": null }, 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 a60b1c8928b..c6f8f6c9dbf 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -4468,8 +4468,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; } } |