[Mesa-dev] [PATCH 1/4] tgsi/scan: don't set interp flags for inputs only used by INTERP (v2)

Marek Olšák maraeo at gmail.com
Tue Oct 4 22:35:50 UTC 2016


From: Marek Olšák <marek.olsak at amd.com>

(v1 pushed, then reverted)

This fixes 9 randomly failing tests on radeonsi:
  GL45-CTS.shader_multisample_interpolation.render.interpolate_at_centroid.*

v2: use input_interpolate[input] (correct) instead of
    input_interpolate[index] (incorrect)
---
 src/gallium/auxiliary/tgsi/tgsi_scan.c | 105 ++++++++++++++++++---------------
 1 file changed, 57 insertions(+), 48 deletions(-)

diff --git a/src/gallium/auxiliary/tgsi/tgsi_scan.c b/src/gallium/auxiliary/tgsi/tgsi_scan.c
index a3b0d9f..c7745ce 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_scan.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_scan.c
@@ -95,20 +95,21 @@ computes_derivative(unsigned opcode)
 }
 
 
 static void
 scan_instruction(struct tgsi_shader_info *info,
                  const struct tgsi_full_instruction *fullinst,
                  unsigned *current_depth)
 {
    unsigned i;
    bool is_mem_inst = false;
+   bool is_interp_instruction = false;
 
    assert(fullinst->Instruction.Opcode < TGSI_OPCODE_LAST);
    info->opcode_count[fullinst->Instruction.Opcode]++;
 
    switch (fullinst->Instruction.Opcode) {
    case TGSI_OPCODE_IF:
    case TGSI_OPCODE_UIF:
    case TGSI_OPCODE_BGNLOOP:
       (*current_depth)++;
       info->max_depth = MAX2(info->max_depth, *current_depth);
@@ -120,20 +121,22 @@ scan_instruction(struct tgsi_shader_info *info,
    default:
       break;
    }
 
    if (fullinst->Instruction.Opcode == TGSI_OPCODE_INTERP_CENTROID ||
        fullinst->Instruction.Opcode == TGSI_OPCODE_INTERP_OFFSET ||
        fullinst->Instruction.Opcode == TGSI_OPCODE_INTERP_SAMPLE) {
       const struct tgsi_full_src_register *src0 = &fullinst->Src[0];
       unsigned input;
 
+      is_interp_instruction = true;
+
       if (src0->Register.Indirect && src0->Indirect.ArrayID)
          input = info->input_array_first[src0->Indirect.ArrayID];
       else
          input = src0->Register.Index;
 
       /* For the INTERP opcodes, the interpolation is always
        * PERSPECTIVE unless LINEAR is specified.
        */
       switch (info->input_interpolate[input]) {
       case TGSI_INTERPOLATE_COLOR:
@@ -183,43 +186,91 @@ scan_instruction(struct tgsi_shader_info *info,
          if (src->Register.Indirect) {
             for (ind = 0; ind < info->num_inputs; ++ind) {
                info->input_usage_mask[ind] |= usage_mask;
             }
          } else {
             assert(ind >= 0);
             assert(ind < PIPE_MAX_SHADER_INPUTS);
             info->input_usage_mask[ind] |= usage_mask;
          }
 
-         if (info->processor == PIPE_SHADER_FRAGMENT &&
-             !src->Register.Indirect) {
-            unsigned name =
-               info->input_semantic_name[src->Register.Index];
-            unsigned index =
-               info->input_semantic_index[src->Register.Index];
+         if (info->processor == PIPE_SHADER_FRAGMENT) {
+            unsigned name, index, input;
+
+            if (src->Register.Indirect && src->Indirect.ArrayID)
+               input = info->input_array_first[src->Indirect.ArrayID];
+            else
+               input = src->Register.Index;
+
+            name = info->input_semantic_name[input];
+            index = info->input_semantic_index[input];
 
             if (name == TGSI_SEMANTIC_POSITION &&
                 (src->Register.SwizzleX == TGSI_SWIZZLE_Z ||
                  src->Register.SwizzleY == TGSI_SWIZZLE_Z ||
                  src->Register.SwizzleZ == TGSI_SWIZZLE_Z ||
                  src->Register.SwizzleW == TGSI_SWIZZLE_Z))
                info->reads_z = TRUE;
 
             if (name == TGSI_SEMANTIC_COLOR) {
                unsigned mask =
                   (1 << src->Register.SwizzleX) |
                   (1 << src->Register.SwizzleY) |
                   (1 << src->Register.SwizzleZ) |
                   (1 << src->Register.SwizzleW);
 
                info->colors_read |= mask << (index * 4);
             }
+
+            /* Process only interpolated varyings. Don't include POSITION.
+             * Don't include integer varyings, because they are not
+             * interpolated. Don't process inputs interpolated by INTERP
+             * opcodes. Those are tracked separately.
+             */
+            if ((!is_interp_instruction || i != 0) &&
+                (name == TGSI_SEMANTIC_GENERIC ||
+                 name == TGSI_SEMANTIC_TEXCOORD ||
+                 name == TGSI_SEMANTIC_COLOR ||
+                 name == TGSI_SEMANTIC_BCOLOR ||
+                 name == TGSI_SEMANTIC_FOG ||
+                 name == TGSI_SEMANTIC_CLIPDIST)) {
+               switch (info->input_interpolate[input]) {
+               case TGSI_INTERPOLATE_COLOR:
+               case TGSI_INTERPOLATE_PERSPECTIVE:
+                  switch (info->input_interpolate_loc[input]) {
+                  case TGSI_INTERPOLATE_LOC_CENTER:
+                     info->uses_persp_center = TRUE;
+                     break;
+                  case TGSI_INTERPOLATE_LOC_CENTROID:
+                     info->uses_persp_centroid = TRUE;
+                     break;
+                  case TGSI_INTERPOLATE_LOC_SAMPLE:
+                     info->uses_persp_sample = TRUE;
+                     break;
+                  }
+                  break;
+               case TGSI_INTERPOLATE_LINEAR:
+                  switch (info->input_interpolate_loc[input]) {
+                  case TGSI_INTERPOLATE_LOC_CENTER:
+                     info->uses_linear_center = TRUE;
+                     break;
+                  case TGSI_INTERPOLATE_LOC_CENTROID:
+                     info->uses_linear_centroid = TRUE;
+                     break;
+                  case TGSI_INTERPOLATE_LOC_SAMPLE:
+                     info->uses_linear_sample = TRUE;
+                     break;
+                  }
+                  break;
+                  /* TGSI_INTERPOLATE_CONSTANT doesn't do any interpolation. */
+               }
+            }
          }
       }
 
       /* check for indirect register reads */
       if (src->Register.Indirect) {
          info->indirect_files |= (1 << src->Register.File);
          info->indirect_files_read |= (1 << src->Register.File);
       }
 
       /* Texture samplers */
@@ -350,62 +401,20 @@ scan_declaration(struct tgsi_shader_info *info,
          info->input_cylindrical_wrap[reg] = (ubyte)fulldecl->Interp.CylindricalWrap;
 
          /* Vertex shaders can have inputs with holes between them. */
          if (info->processor == PIPE_SHADER_VERTEX)
             info->num_inputs = MAX2(info->num_inputs, reg + 1);
          else {
             info->num_inputs++;
             assert(reg < info->num_inputs);
          }
 
-         /* Only interpolated varyings. Don't include POSITION.
-          * Don't include integer varyings, because they are not
-          * interpolated.
-          */
-         if (semName == TGSI_SEMANTIC_GENERIC ||
-             semName == TGSI_SEMANTIC_TEXCOORD ||
-             semName == TGSI_SEMANTIC_COLOR ||
-             semName == TGSI_SEMANTIC_BCOLOR ||
-             semName == TGSI_SEMANTIC_FOG ||
-             semName == TGSI_SEMANTIC_CLIPDIST) {
-            switch (fulldecl->Interp.Interpolate) {
-            case TGSI_INTERPOLATE_COLOR:
-            case TGSI_INTERPOLATE_PERSPECTIVE:
-               switch (fulldecl->Interp.Location) {
-               case TGSI_INTERPOLATE_LOC_CENTER:
-                  info->uses_persp_center = TRUE;
-                  break;
-               case TGSI_INTERPOLATE_LOC_CENTROID:
-                  info->uses_persp_centroid = TRUE;
-                  break;
-               case TGSI_INTERPOLATE_LOC_SAMPLE:
-                  info->uses_persp_sample = TRUE;
-                  break;
-               }
-               break;
-            case TGSI_INTERPOLATE_LINEAR:
-               switch (fulldecl->Interp.Location) {
-               case TGSI_INTERPOLATE_LOC_CENTER:
-                  info->uses_linear_center = TRUE;
-                  break;
-               case TGSI_INTERPOLATE_LOC_CENTROID:
-                  info->uses_linear_centroid = TRUE;
-                  break;
-               case TGSI_INTERPOLATE_LOC_SAMPLE:
-                  info->uses_linear_sample = TRUE;
-                  break;
-               }
-               break;
-               /* TGSI_INTERPOLATE_CONSTANT doesn't do any interpolation. */
-            }
-         }
-
          if (semName == TGSI_SEMANTIC_PRIMID)
             info->uses_primid = TRUE;
          else if (procType == PIPE_SHADER_FRAGMENT) {
             if (semName == TGSI_SEMANTIC_POSITION)
                info->reads_position = TRUE;
             else if (semName == TGSI_SEMANTIC_FACE)
                info->uses_frontface = TRUE;
          }
       }
       else if (file == TGSI_FILE_SYSTEM_VALUE) {
-- 
2.7.4



More information about the mesa-dev mailing list