[Mesa-dev] [PATCH 06/12] glsl/linker: Optimize swizzles again after linking

Ian Romanick idr at freedesktop.org
Thu Nov 2 20:25:21 UTC 2017


From: Ian Romanick <ian.d.romanick at intel.com>

Without this, the SPIR-V generator has to deal with a bunch of junk
like:

    (swiz z (swiz xxx (swiz x (var_ref packed:binormal.z,light_dir))))

It seems better to cull that stuff out than to add code to deal with
it.  The problem is the way swizzles to and from scalars have to be
handled in SPIR-V.

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
 src/compiler/glsl/linker.cpp | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp
index 0045291..ff5c4c2 100644
--- a/src/compiler/glsl/linker.cpp
+++ b/src/compiler/glsl/linker.cpp
@@ -5027,6 +5027,16 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
    if(!link_varyings_and_uniforms(first, last, ctx, prog, mem_ctx))
       goto done;
 
+   /* Linking varyings can cause some extra, useless swizzles to be generated
+    * due to packing and unpacking.
+    */
+   for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
+      if (prog->_LinkedShaders[i] == NULL)
+         continue;
+
+      optimize_swizzles(prog->_LinkedShaders[i]->ir);
+   }
+
    /* OpenGL ES < 3.1 requires that a vertex shader and a fragment shader both
     * be present in a linked program. GL_ARB_ES2_compatibility doesn't say
     * anything about shader linking when one of the shaders (vertex or
-- 
2.9.5



More information about the mesa-dev mailing list