[Mesa-dev] [PATCH 3/3] glsl: Mark gl_GlobalInvocationID dependencies as used

Jordan Justen jordan.l.justen at intel.com
Thu Aug 6 11:01:54 PDT 2015


gl_GlobalInvocationID =
  gl_WorkGroupID * gl_WorkGroupSize + gl_LocalInvocationID

Therefore, if gl_GlobalInvocationID is used, then we mark these other
variables as being used. This prevents them from being considered dead
variables and being removed.

Signed-off-by: Jordan Justen <jordan.l.justen at intel.com>
---
 src/glsl/glsl_parser_extras.cpp | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp
index 46896d7..49fc12d 100644
--- a/src/glsl/glsl_parser_extras.cpp
+++ b/src/glsl/glsl_parser_extras.cpp
@@ -1568,6 +1568,36 @@ set_shader_inout_layout(struct gl_shader *shader,
    }
 }
 
+static void
+set_cs_variable_deps_as_used(struct gl_shader *shader,
+                             struct _mesa_glsl_parse_state *state)
+{
+   /* gl_GlobalInvocationID only exists in the compute shader.
+    */
+   if (shader->Stage != MESA_SHADER_COMPUTE)
+      return;
+
+   ir_variable *gl_GlobalInvocationID =
+      state->symbols->get_variable("gl_GlobalInvocationID");
+   assert(gl_GlobalInvocationID);
+
+   if (!gl_GlobalInvocationID->data.used)
+      return;
+
+   static const char *dep_var_names[] = {
+      "gl_WorkGroupSize",
+      "gl_WorkGroupID",
+      "gl_LocalInvocationID"
+   };
+
+   for (unsigned i = 0; i < ARRAY_SIZE(dep_var_names); i++) {
+      ir_variable *var =
+         state->symbols->get_variable(dep_var_names[i]);
+      assert(var);
+      var->data.used = true;
+   }
+}
+
 extern "C" {
 
 void
@@ -1618,6 +1648,9 @@ _mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *shader,
          &ctx->Const.ShaderCompilerOptions[shader->Stage];
 
       lower_subroutine(shader->ir, state);
+
+      set_cs_variable_deps_as_used(shader, state);
+
       /* Do some optimization at compile time to reduce shader IR size
        * and reduce later work if the same shader is linked multiple times
        */
-- 
2.1.4



More information about the mesa-dev mailing list