Mesa (master): glsl: add can_remove_uniform() helper to the NIR linker

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Jun 3 02:43:24 UTC 2020


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

Author: Timothy Arceri <tarceri at itsqueeze.com>
Date:   Thu May 28 11:08:42 2020 +1000

glsl: add can_remove_uniform() helper to the NIR linker

This helper reflects the rules we follow in the GLSL IR linker when
deciding if we can remove a dead uniform. This check is required to
avoid regressions when turning on NIR dead uniform clean up in the
following patch.

Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
Reviewed-by: Eric Anholt <eric at anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4797>

---

 src/compiler/glsl/gl_nir_linker.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/src/compiler/glsl/gl_nir_linker.c b/src/compiler/glsl/gl_nir_linker.c
index fb8b3e0c340..2fa1290bad4 100644
--- a/src/compiler/glsl/gl_nir_linker.c
+++ b/src/compiler/glsl/gl_nir_linker.c
@@ -34,6 +34,38 @@
  * the counter-part glsl/linker.cpp
  */
 
+static bool
+can_remove_uniform(nir_variable *var)
+{
+   /* Section 2.11.6 (Uniform Variables) of the OpenGL ES 3.0.3 spec
+    * says:
+    *
+    *     "All members of a named uniform block declared with a shared or
+    *     std140 layout qualifier are considered active, even if they are not
+    *     referenced in any shader in the program. The uniform block itself is
+    *     also considered active, even if no member of the block is
+    *     referenced."
+    *
+    * Although the spec doesn't state it std430 layouts are expect to behave
+    * the same way. If the variable is in a uniform block with one of those
+    * layouts, do not eliminate it.
+    */
+   if (nir_variable_is_in_block(var) &&
+       (glsl_get_ifc_packing(var->interface_type) !=
+        GLSL_INTERFACE_PACKING_PACKED))
+      return false;
+
+   if (glsl_get_base_type(glsl_without_array(var->type)) ==
+       GLSL_TYPE_SUBROUTINE)
+      return false;
+
+   /* Uniform initializers could get used by another stage */
+   if (var->constant_initializer)
+      return false;
+
+   return true;
+}
+
 /**
  * Built-in / reserved GL variables names start with "gl_"
  */



More information about the mesa-commit mailing list