Mesa (master): nir: Expose nir_remove_unused_io_vars().

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Oct 16 00:17:42 UTC 2018


Module: Mesa
Branch: master
Commit: 7d77fe1bcc8e84a30ddc5d4bc6b0c571dfd64b22
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=7d77fe1bcc8e84a30ddc5d4bc6b0c571dfd64b22

Author: Eric Anholt <eric at anholt.net>
Date:   Wed Sep 26 09:13:13 2018 -0700

nir: Expose nir_remove_unused_io_vars().

For gallium drivers where you want to do some linking at variant compile
time, you don't have the other producer/consumer shader on hand to modify.
By exposing the inner function, the driver can have the used varyings in
the compiled shader cache key and still do linking.

This is also useful for V3D, where the binning shader wants to only output
position and TF varyings.  We've been removing those after nir_lower_io,
but this will be less driver-specific code and let more of the shader get
DCEed early in NIR.

Reviewed-by: Timothy Arceri <tarceri at itsqueeze.com>

---

 src/compiler/nir/nir.h                 |  3 +++
 src/compiler/nir/nir_linking_helpers.c | 32 ++++++++++++++++++++++++--------
 2 files changed, 27 insertions(+), 8 deletions(-)

diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 9527079a9e..bb772385c9 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -2778,6 +2778,9 @@ void nir_assign_var_locations(struct exec_list *var_list, unsigned *size,
 
 /* Some helpers to do very simple linking */
 bool nir_remove_unused_varyings(nir_shader *producer, nir_shader *consumer);
+bool nir_remove_unused_io_vars(nir_shader *shader, struct exec_list *var_list,
+                               uint64_t *used_by_other_stage,
+                               uint64_t *used_by_other_stage_patches);
 void nir_compact_varyings(nir_shader *producer, nir_shader *consumer,
                           bool default_to_smooth_interp);
 
diff --git a/src/compiler/nir/nir_linking_helpers.c b/src/compiler/nir/nir_linking_helpers.c
index 7446bb826f..85677b7c17 100644
--- a/src/compiler/nir/nir_linking_helpers.c
+++ b/src/compiler/nir/nir_linking_helpers.c
@@ -92,10 +92,26 @@ tcs_add_output_reads(nir_shader *shader, uint64_t *read, uint64_t *patches_read)
    }
 }
 
-static bool
-remove_unused_io_vars(nir_shader *shader, struct exec_list *var_list,
-                      uint64_t *used_by_other_stage,
-                      uint64_t *used_by_other_stage_patches)
+/**
+ * Helper for removing unused shader I/O variables, by demoting them to global
+ * variables (which may then by dead code eliminated).
+ *
+ * Example usage is:
+ *
+ * progress = nir_remove_unused_io_vars(producer,
+ *                                      &producer->outputs,
+ *                                      read, patches_read) ||
+ *                                      progress;
+ *
+ * The "used" should be an array of 4 uint64_ts (probably of VARYING_BIT_*)
+ * representing each .location_frac used.  Note that for vector variables,
+ * only the first channel (.location_frac) is examined for deciding if the
+ * variable is used!
+ */
+bool
+nir_remove_unused_io_vars(nir_shader *shader, struct exec_list *var_list,
+                          uint64_t *used_by_other_stage,
+                          uint64_t *used_by_other_stage_patches)
 {
    bool progress = false;
    uint64_t *used;
@@ -169,11 +185,11 @@ nir_remove_unused_varyings(nir_shader *producer, nir_shader *consumer)
       tcs_add_output_reads(producer, read, patches_read);
 
    bool progress = false;
-   progress = remove_unused_io_vars(producer, &producer->outputs, read,
-                                    patches_read);
+   progress = nir_remove_unused_io_vars(producer, &producer->outputs, read,
+                                        patches_read);
 
-   progress = remove_unused_io_vars(consumer, &consumer->inputs, written,
-                                    patches_written) || progress;
+   progress = nir_remove_unused_io_vars(consumer, &consumer->inputs, written,
+                                        patches_written) || progress;
 
    return progress;
 }




More information about the mesa-commit mailing list