Mesa (main): glsl/nir: allow the nir linker to remove dead uniforms we created

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sat Jun 4 03:57:00 UTC 2022


Module: Mesa
Branch: main
Commit: 64dbc3f03a33554df868902994ce80861bf86e50
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=64dbc3f03a33554df868902994ce80861bf86e50

Author: Timothy Arceri <tarceri at itsqueeze.com>
Date:   Mon Oct 11 15:48:28 2021 +1100

glsl/nir: allow the nir linker to remove dead uniforms we created

Some backends lower constant arrays to uniforms in GLSL IR. These
create so called hidden uniforms. Since we know these are added
per stage it is safe to remove them if we detect they are dead.

Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
Acked-by: Emma Anholt <emma at anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16770>

---

 src/compiler/glsl/gl_nir_linker.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/compiler/glsl/gl_nir_linker.c b/src/compiler/glsl/gl_nir_linker.c
index da2708343ed..9bbef29d0bc 100644
--- a/src/compiler/glsl/gl_nir_linker.c
+++ b/src/compiler/glsl/gl_nir_linker.c
@@ -142,8 +142,11 @@ can_remove_uniform(nir_variable *var, UNUSED void *data)
        GLSL_TYPE_SUBROUTINE)
       return false;
 
-   /* Uniform initializers could get used by another stage */
-   if (var->constant_initializer)
+   /* Uniform initializers could get used by another stage. However if its a
+    * hidden uniform then it should be safe to remove as this was a constant
+    * variable that has been lowered to a uniform.
+    */
+   if (var->constant_initializer && var->data.how_declared != nir_var_hidden)
       return false;
 
    return true;



More information about the mesa-commit mailing list