A following patch is going to merge the gl_fragment_program struct into
a common gl_program and we want to avoid all stages having this array.
---
 src/gallium/include/pipe/p_shader_tokens.h |  1 +
 src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 33 +++++++++++++++++++++++-
 src/mesa/state_tracker/st_program.c        | 40 ++++++++----------------------
 3 files changed, 43 insertions(+), 31 deletions(-)

diff --git a/src/gallium/include/pipe/p_shader_tokens.h 
b/src/gallium/include/pipe/p_shader_tokens.h
index 4a259db..4632468 100644
--- a/src/gallium/include/pipe/p_shader_tokens.h
+++ b/src/gallium/include/pipe/p_shader_tokens.h
@@ -97,6 +97,7 @@ enum tgsi_file_type {
 #define TGSI_WRITEMASK_XYZW     0x0F
 
 enum tgsi_interpolate_mode {
+   TGSI_INTERPOLATE_NONE,
    TGSI_INTERPOLATE_CONSTANT,
    TGSI_INTERPOLATE_LINEAR,
    TGSI_INTERPOLATE_PERSPECTIVE,
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index a87c65b..ccca718 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -365,6 +365,7 @@ struct inout_decl {
    unsigned mesa_index;
    unsigned array_id; /* TGSI ArrayID; 1-based: 0 means not an array */
    unsigned size;
+   enum glsl_interp_mode interp;
    enum glsl_base_type base_type;
    ubyte usage_mask; /* GLSL-style usage-mask,  i.e. single bit per double */
 };
@@ -2450,6 +2451,7 @@ glsl_to_tgsi_visitor::visit(ir_dereference_variable *ir)
             num_components = 4;
 
          decl->mesa_index = var->data.location;
+         decl->interp = (glsl_interp_mode) var->data.interpolation;
          decl->base_type = type_without_array->base_type;
          decl->usage_mask = u_bit_consecutive(component, num_components);
 
@@ -6096,6 +6098,27 @@ emit_compute_block_size(const struct gl_program *prog,
                  prog->info.cs.local_size[2]);
 }
 
+
+static unsigned
+st_translate_interp(enum glsl_interp_mode glsl_qual, GLuint varying)
+{
+   switch (glsl_qual) {
+   case INTERP_MODE_NONE:
+      if (varying == VARYING_SLOT_COL0 || varying == VARYING_SLOT_COL1)
+         return TGSI_INTERPOLATE_COLOR;
+      return TGSI_INTERPOLATE_PERSPECTIVE;
+   case INTERP_MODE_SMOOTH:
+      return TGSI_INTERPOLATE_PERSPECTIVE;
+   case INTERP_MODE_FLAT:
+      return TGSI_INTERPOLATE_CONSTANT;
+   case INTERP_MODE_NOPERSPECTIVE:
+      return TGSI_INTERPOLATE_LINEAR;
+   default:
+      assert(0 && "unexpected interp mode in st_translate_interp()");
+      return TGSI_INTERPOLATE_PERSPECTIVE;
+   }
+}
+
 /**
  * Translate intermediate IR (glsl_to_tgsi_instruction) to TGSI format.
  * \param program  the program to translate
@@ -6183,9 +6206,17 @@ st_translate_program(
                tgsi_usage_mask = TGSI_WRITEMASK_XYZW;
          }
 
+         unsigned interp_mode = 0;
+         if (procType == PIPE_SHADER_FRAGMENT) {
+            assert(interpMode);
+            interp_mode = interpMode[slot] != TGSI_INTERPOLATE_NONE ?
+               interpMode[slot] :
+               st_translate_interp(decl->interp, inputSlotToAttr[slot]);
+         }
+
          src = ureg_DECL_fs_input_cyl_centroid_layout(ureg,
                   inputSemanticName[slot], inputSemanticIndex[slot],
-                  interpMode ? interpMode[slot] : 0, 0, interpLocation ? 
interpLocation[slot] : 0,
+                  interp_mode, 0, interpLocation ? interpLocation[slot] : 0,
                   slot, tgsi_usage_mask, decl->array_id, decl->size);
 
          for (unsigned j = 0; j < decl->size; ++j) {
diff --git a/src/mesa/state_tracker/st_program.c 
b/src/mesa/state_tracker/st_program.c
index 55cf572..8880636 100644
--- a/src/mesa/state_tracker/st_program.c
+++ b/src/mesa/state_tracker/st_program.c
@@ -558,27 +558,6 @@ st_get_vp_variant(struct st_context *st,
 }
 
 
-static unsigned
-st_translate_interp(enum glsl_interp_mode glsl_qual, bool is_color)
-{
-   switch (glsl_qual) {
-   case INTERP_MODE_NONE:
-      if (is_color)
-         return TGSI_INTERPOLATE_COLOR;
-      return TGSI_INTERPOLATE_PERSPECTIVE;
-   case INTERP_MODE_SMOOTH:
-      return TGSI_INTERPOLATE_PERSPECTIVE;
-   case INTERP_MODE_FLAT:
-      return TGSI_INTERPOLATE_CONSTANT;
-   case INTERP_MODE_NOPERSPECTIVE:
-      return TGSI_INTERPOLATE_LINEAR;
-   default:
-      assert(0 && "unexpected interp mode in st_translate_interp()");
-      return TGSI_INTERPOLATE_PERSPECTIVE;
-   }
-}
-
-
 /**
  * Translate a Mesa fragment shader into a TGSI shader.
  */
@@ -660,14 +639,14 @@ st_translate_fragment_program(struct st_context *st,
          case VARYING_SLOT_COL0:
             input_semantic_name[slot] = TGSI_SEMANTIC_COLOR;
             input_semantic_index[slot] = 0;
-            interpMode[slot] = 
st_translate_interp(stfp->Base.InterpQualifier[attr],
-                                                   TRUE);
+            interpMode[slot] = stfp->glsl_to_tgsi ?
+               TGSI_INTERPOLATE_NONE : TGSI_INTERPOLATE_COLOR;
             break;
          case VARYING_SLOT_COL1:
             input_semantic_name[slot] = TGSI_SEMANTIC_COLOR;
             input_semantic_index[slot] = 1;
-            interpMode[slot] = 
st_translate_interp(stfp->Base.InterpQualifier[attr],
-                                                   TRUE);
+            interpMode[slot] = stfp->glsl_to_tgsi ?
+               TGSI_INTERPOLATE_NONE : TGSI_INTERPOLATE_COLOR;
             break;
          case VARYING_SLOT_FOGC:
             input_semantic_name[slot] = TGSI_SEMANTIC_FOG;
@@ -743,8 +722,8 @@ st_translate_fragment_program(struct st_context *st,
             if (st->needs_texcoord_semantic) {
                input_semantic_name[slot] = TGSI_SEMANTIC_TEXCOORD;
                input_semantic_index[slot] = attr - VARYING_SLOT_TEX0;
-               interpMode[slot] =
-                  st_translate_interp(stfp->Base.InterpQualifier[attr], FALSE);
+               interpMode[slot] = stfp->glsl_to_tgsi ?
+                  TGSI_INTERPOLATE_NONE : TGSI_INTERPOLATE_PERSPECTIVE;
                break;
             }
             /* fall through */
@@ -766,9 +745,10 @@ st_translate_fragment_program(struct st_context *st,
             input_semantic_index[slot] = st_get_generic_varying_index(st, 
attr);
             if (attr == VARYING_SLOT_PNTC)
                interpMode[slot] = TGSI_INTERPOLATE_LINEAR;
-            else
-               interpMode[slot] = 
st_translate_interp(stfp->Base.InterpQualifier[attr],
-                                                      FALSE);
+            else {
+               interpMode[slot] = stfp->glsl_to_tgsi ?
+                  TGSI_INTERPOLATE_NONE : TGSI_INTERPOLATE_PERSPECTIVE;
+            }
             break;
          }
       }
-- 
2.7.4

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to