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>
This commit is contained in:
Caio Marcelo de Oliveira Filho
2021-01-21 08:41:15 -08:00
committed by Marge Bot
parent f1cffe2394
commit cb7352ae95
3 changed files with 23 additions and 9 deletions

View File

@@ -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);
}
}

View File

@@ -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);

View File

@@ -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;
}
}