Mesa (staging/20.3): nir: Add a data pointer to the callback in nir_remove_dead_variables

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Jan 26 17:53:55 UTC 2021


Module: Mesa
Branch: staging/20.3
Commit: 74b1a83cab00168861e4098e234649e741a2c54d
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=74b1a83cab00168861e4098e234649e741a2c54d

Author: Caio Marcelo de Oliveira Filho <caio.oliveira at intel.com>
Date:   Thu Jan 21 08:41:15 2021 -0800

nir: Add a data pointer to the callback in nir_remove_dead_variables

Reviewed-by: Rhys Perry <pendingchaos02 at gmail.com>
Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8706>
(cherry picked from commit cb7352ae95a48ba4f20286a59bea184072f52785)

---

 .pick_status.json                            |  2 +-
 src/compiler/glsl/gl_nir_linker.c            | 12 +++++++++---
 src/compiler/nir/nir.h                       |  9 ++++++++-
 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 256d0d46bec..faddda2647b 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 aa8f0f3083b..e9dd3bba12c 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 5f98baabd31..118fb5d1252 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -4590,8 +4590,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 5555ca3f811..037c7de9047 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, struct set *live)
 
 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;
          }
       }



More information about the mesa-commit mailing list