nir/spirv: Add a missing break statement
[mesa.git] / src / glsl / opt_dead_builtin_variables.cpp
index 85c75d6f21f740b2973cd4a954f5d832a441fef1..03e578982b9f710591cf50d565a390a0036d0ead 100644 (file)
@@ -52,7 +52,7 @@ optimize_dead_builtin_variables(exec_list *instructions,
           && var->data.how_declared != ir_var_declared_implicitly)
          continue;
 
-      if (strncmp(var->name, "gl_", 3) != 0)
+      if (!is_gl_identifier(var->name))
          continue;
 
       /* gl_ModelViewProjectionMatrix and gl_Vertex are special because they
@@ -62,6 +62,23 @@ optimize_dead_builtin_variables(exec_list *instructions,
        * information, so removing these variables from the user shader will
        * cause problems later.
        *
+       * For compute shaders, gl_GlobalInvocationID has some dependencies, so
+       * we avoid removing these dependencies.
+       *
+       * We also avoid removing gl_GlobalInvocationID at this stage because it
+       * might be used by a linked shader. In this case it still needs to be
+       * initialized by the main function.
+       *
+       *    gl_GlobalInvocationID =
+       *       gl_WorkGroupID * gl_WorkGroupSize + gl_LocalInvocationID
+       *
+       * Similarly, we initialize gl_LocalInvocationIndex in the main function:
+       *
+       *    gl_LocalInvocationIndex =
+       *       gl_LocalInvocationID.z * gl_WorkGroupSize.x * gl_WorkGroupSize.y +
+       *       gl_LocalInvocationID.y * gl_WorkGroupSize.x +
+       *       gl_LocalInvocationID.x;
+       *
        * Matrix uniforms with "Transpose" are not eliminated because there's
        * an optimization pass that can turn references to the regular matrix
        * into references to the transpose matrix.  Eliminating the transpose
@@ -73,6 +90,11 @@ optimize_dead_builtin_variables(exec_list *instructions,
        */
       if (strcmp(var->name, "gl_ModelViewProjectionMatrix") == 0
           || strcmp(var->name, "gl_Vertex") == 0
+          || strcmp(var->name, "gl_WorkGroupID") == 0
+          || strcmp(var->name, "gl_WorkGroupSize") == 0
+          || strcmp(var->name, "gl_LocalInvocationID") == 0
+          || strcmp(var->name, "gl_GlobalInvocationID") == 0
+          || strcmp(var->name, "gl_LocalInvocationIndex") == 0
           || strstr(var->name, "Transpose") != NULL)
          continue;