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:

committed by
Marge Bot

parent
f1cffe2394
commit
cb7352ae95
@@ -35,7 +35,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static bool
|
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
|
/* Section 2.11.6 (Uniform Variables) of the OpenGL ES 3.0.3 spec
|
||||||
* says:
|
* 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++) {
|
for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
|
||||||
struct gl_linked_shader *shader = prog->_LinkedShaders[i];
|
struct gl_linked_shader *shader = prog->_LinkedShaders[i];
|
||||||
if (shader) {
|
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,
|
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++) {
|
for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
|
||||||
struct gl_linked_shader *shader = prog->_LinkedShaders[i];
|
struct gl_linked_shader *shader = prog->_LinkedShaders[i];
|
||||||
if (shader) {
|
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,
|
nir_remove_dead_variables(shader->Program->nir, nir_var_uniform,
|
||||||
&can_remove_uniform);
|
&opts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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(nir_shader *shader);
|
||||||
bool nir_remove_dead_derefs_impl(nir_function_impl *impl);
|
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 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,
|
bool nir_lower_variable_initializers(nir_shader *shader,
|
||||||
nir_variable_mode modes);
|
nir_variable_mode modes);
|
||||||
|
|
||||||
|
@@ -152,7 +152,7 @@ remove_dead_var_writes(nir_shader *shader)
|
|||||||
|
|
||||||
static bool
|
static bool
|
||||||
remove_dead_vars(struct exec_list *var_list, nir_variable_mode modes,
|
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;
|
bool progress = false;
|
||||||
|
|
||||||
@@ -160,7 +160,8 @@ remove_dead_vars(struct exec_list *var_list, nir_variable_mode modes,
|
|||||||
if (!(var->data.mode & modes))
|
if (!(var->data.mode & modes))
|
||||||
continue;
|
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;
|
continue;
|
||||||
|
|
||||||
struct set_entry *entry = _mesa_set_search(live, var);
|
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
|
bool
|
||||||
nir_remove_dead_variables(nir_shader *shader, nir_variable_mode modes,
|
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;
|
bool progress = false;
|
||||||
struct set *live = _mesa_pointer_set_create(NULL);
|
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) {
|
if (modes & ~nir_var_function_temp) {
|
||||||
progress = remove_dead_vars(&shader->variables, modes,
|
progress = remove_dead_vars(&shader->variables, modes,
|
||||||
live, can_remove_var) || progress;
|
live, opts) || progress;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (modes & nir_var_function_temp) {
|
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 (function->impl) {
|
||||||
if (remove_dead_vars(&function->impl->locals,
|
if (remove_dead_vars(&function->impl->locals,
|
||||||
nir_var_function_temp,
|
nir_var_function_temp,
|
||||||
live, can_remove_var))
|
live, opts))
|
||||||
progress = true;
|
progress = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user