glsl: make use of active_shader_mask when building resource list
[mesa.git] / src / compiler / glsl / opt_dead_builtin_varyings.cpp
index 7feea3ba18b5c93076a68c45689e1182efdeb00c..3efe6582322a777204db79e7fad64d7c3087bb4a 100644 (file)
  * The same is done for the gl_FragData fragment shader output.
  */
 
-#include "main/core.h" /* for snprintf and ARRAY_SIZE */
 #include "ir.h"
 #include "ir_rvalue_visitor.h"
 #include "ir_optimization.h"
 #include "ir_print_visitor.h"
 #include "compiler/glsl_types.h"
 #include "link_varyings.h"
+#include "main/mtypes.h"
+#include "util/u_string.h"
 
 namespace {
 
@@ -85,12 +86,14 @@ public:
    {
       ir_variable *var = ir->variable_referenced();
 
-      if (!var || var->data.mode != this->mode || !var->type->is_array())
+      if (!var || var->data.mode != this->mode || !var->type->is_array() ||
+          !is_gl_identifier(var->name))
          return visit_continue;
 
-      /* Only match gl_FragData[], not gl_SecondaryFragDataEXT[] */
-      if (this->find_frag_outputs && var->data.location == FRAG_RESULT_DATA0 &&
-          var->data.index == 0) {
+      /* Only match gl_FragData[], not gl_SecondaryFragDataEXT[] or
+       * gl_LastFragData[].
+       */
+      if (this->find_frag_outputs && strcmp(var->name, "gl_FragData") == 0) {
          this->fragdata_array = var;
 
          ir_constant *index = ir->array_index->as_constant();
@@ -378,7 +381,7 @@ public:
                new_var[i]->data.explicit_index = 0;
             }
 
-            ir->head->insert_before(new_var[i]);
+            ir->get_head_raw()->insert_before(new_var[i]);
          }
       }
    }
@@ -536,7 +539,8 @@ do_dead_builtin_varyings(struct gl_context *ctx,
                          tfeedback_decl *tfeedback_decls)
 {
    /* Lower the gl_FragData array to separate variables. */
-   if (consumer && consumer->Stage == MESA_SHADER_FRAGMENT) {
+   if (consumer && consumer->Stage == MESA_SHADER_FRAGMENT &&
+       !ctx->Const.ShaderCompilerOptions[MESA_SHADER_FRAGMENT].NirOptions) {
       lower_fragdata_array(consumer);
    }
 
@@ -555,6 +559,9 @@ do_dead_builtin_varyings(struct gl_context *ctx,
    if (producer) {
       producer_info.get(producer->ir, num_tfeedback_decls, tfeedback_decls);
 
+      if (producer->Stage == MESA_SHADER_TESS_CTRL)
+         producer_info.lower_texcoord_array = false;
+
       if (!consumer) {
          /* At least eliminate unused gl_TexCoord elements. */
          if (producer_info.lower_texcoord_array) {
@@ -567,6 +574,9 @@ do_dead_builtin_varyings(struct gl_context *ctx,
    if (consumer) {
       consumer_info.get(consumer->ir, 0, NULL);
 
+      if (consumer->Stage != MESA_SHADER_FRAGMENT)
+         consumer_info.lower_texcoord_array = false;
+
       if (!producer) {
          /* At least eliminate unused gl_TexCoord elements. */
          if (consumer_info.lower_texcoord_array) {