glsl: make use of active_shader_mask when building resource list
[mesa.git] / src / compiler / glsl / opt_dead_builtin_varyings.cpp
index 900a09697bb48cd56c42265e5c9c76171c754d91..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 {
 
@@ -89,9 +90,10 @@ public:
           !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();
@@ -537,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);
    }
 
@@ -556,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) {
@@ -568,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) {