[Mesa-dev] [PATCH 33/42] st/mesa: get interpolation location at translation time

Timothy Arceri timothy.arceri at collabora.com
Wed Oct 19 23:09:50 UTC 2016


Rather then messing around creating bitfields and arrays to store
the interpolation location just translate it on the fly.

Reviewed-by: Marek Olšák <marek.olsak at amd.com>
---
 src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 22 ++++++++++++++++++----
 src/mesa/state_tracker/st_glsl_to_tgsi.h   |  1 -
 src/mesa/state_tracker/st_program.c        | 10 ----------
 3 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 3c81095..fc12d03 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -337,6 +337,7 @@ struct inout_decl {
    unsigned mesa_index;
    unsigned array_id; /* TGSI ArrayID; 1-based: 0 means not an array */
    unsigned size;
+   unsigned interp_loc;
    enum glsl_interp_mode interp;
    enum glsl_base_type base_type;
    ubyte usage_mask; /* GLSL-style usage-mask,  i.e. single bit per double */
@@ -2384,6 +2385,17 @@ is_inout_array(unsigned stage, ir_variable *var, bool *remove_array)
    return type->is_array() || type->is_matrix();
 }
 
+static unsigned
+st_translate_interp_loc(ir_variable *var)
+{
+   if (var->data.centroid)
+      return TGSI_INTERPOLATE_LOC_CENTROID;
+   else if (var->data.sample)
+      return TGSI_INTERPOLATE_LOC_SAMPLE;
+   else
+      return TGSI_INTERPOLATE_LOC_CENTER;
+}
+
 void
 glsl_to_tgsi_visitor::visit(ir_dereference_variable *ir)
 {
@@ -2421,6 +2433,7 @@ glsl_to_tgsi_visitor::visit(ir_dereference_variable *ir)
 
          decl->mesa_index = var->data.location;
          decl->interp = (glsl_interp_mode) var->data.interpolation;
+         decl->interp_loc = st_translate_interp_loc(var);
          decl->base_type = type_without_array->base_type;
          decl->usage_mask = u_bit_consecutive(component, num_components);
 
@@ -5900,7 +5913,6 @@ st_translate_interp(enum glsl_interp_mode glsl_qual, GLuint varying)
  * \param inputSemanticIndex  the semantic index (ex: which texcoord) for
  *                            each input
  * \param interpMode  the TGSI_INTERPOLATE_LINEAR/PERSP mode for each input
- * \param interpLocation the TGSI_INTERPOLATE_LOC_* location for each input
  * \param numOutputs  number of output registers used
  * \param outputMapping  maps Mesa fragment program outputs to TGSI
  *                       generic outputs
@@ -5923,7 +5935,6 @@ st_translate_program(
    const ubyte inputSemanticName[],
    const ubyte inputSemanticIndex[],
    const GLuint interpMode[],
-   const GLuint interpLocation[],
    GLuint numOutputs,
    const GLuint outputMapping[],
    const GLuint outputSlotToAttr[],
@@ -5978,17 +5989,20 @@ st_translate_program(
          }
 
          unsigned interp_mode = 0;
+         unsigned interp_location = 0;
          if (procType == PIPE_SHADER_FRAGMENT) {
             assert(interpMode);
             interp_mode = interpMode[slot] != TGSI_INTERPOLATE_COUNT ?
                interpMode[slot] :
                st_translate_interp(decl->interp, inputSlotToAttr[slot]);
+
+            interp_location = decl->interp_loc;
          }
 
          src = ureg_DECL_fs_input_cyl_centroid_layout(ureg,
                   inputSemanticName[slot], inputSemanticIndex[slot],
-                  interp_mode, 0, interpLocation ? interpLocation[slot] : 0,
-                  slot, tgsi_usage_mask, decl->array_id, decl->size);
+                  interp_mode, 0, interp_location, slot, tgsi_usage_mask,
+                  decl->array_id, decl->size);
 
          for (unsigned j = 0; j < decl->size; ++j) {
             if (t->inputs[slot + j].File != TGSI_FILE_INPUT) {
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.h b/src/mesa/state_tracker/st_glsl_to_tgsi.h
index 0f485fb..add534c 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.h
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.h
@@ -47,7 +47,6 @@ enum pipe_error st_translate_program(
    const ubyte inputSemanticName[],
    const ubyte inputSemanticIndex[],
    const GLuint interpMode[],
-   const GLuint interpLocation[],
    GLuint numOutputs,
    const GLuint outputMapping[],
    const GLuint outputSlotToAttr[],
diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c
index 6ea4678..7a4ac26 100644
--- a/src/mesa/state_tracker/st_program.c
+++ b/src/mesa/state_tracker/st_program.c
@@ -425,7 +425,6 @@ st_translate_vertex_program(struct st_context *st,
                                    NULL, /* input semantic name */
                                    NULL, /* input semantic index */
                                    NULL, /* interp mode */
-                                   NULL, /* interp location */
                                    /* outputs */
                                    num_outputs,
                                    stvp->result_to_output,
@@ -569,7 +568,6 @@ st_translate_fragment_program(struct st_context *st,
    GLuint inputMapping[VARYING_SLOT_MAX];
    GLuint inputSlotToAttr[VARYING_SLOT_MAX];
    GLuint interpMode[PIPE_MAX_SHADER_INPUTS];  /* XXX size? */
-   GLuint interpLocation[PIPE_MAX_SHADER_INPUTS];
    GLuint attr;
    GLbitfield64 inputsRead;
    struct ureg_program *ureg;
@@ -623,12 +621,6 @@ st_translate_fragment_program(struct st_context *st,
 
          inputMapping[attr] = slot;
          inputSlotToAttr[slot] = attr;
-         if (stfp->Base.IsCentroid & BITFIELD64_BIT(attr))
-            interpLocation[slot] = TGSI_INTERPOLATE_LOC_CENTROID;
-         else if (stfp->Base.IsSample & BITFIELD64_BIT(attr))
-            interpLocation[slot] = TGSI_INTERPOLATE_LOC_SAMPLE;
-         else
-            interpLocation[slot] = TGSI_INTERPOLATE_LOC_CENTER;
 
          switch (attr) {
          case VARYING_SLOT_POS:
@@ -888,7 +880,6 @@ st_translate_fragment_program(struct st_context *st,
                            input_semantic_name,
                            input_semantic_index,
                            interpMode,
-                           interpLocation,
                            /* outputs */
                            fs_num_outputs,
                            outputMapping,
@@ -1459,7 +1450,6 @@ st_translate_program_common(struct st_context *st,
                         input_semantic_name,
                         input_semantic_index,
                         NULL,
-                        NULL,
                         /* outputs */
                         num_outputs,
                         outputMapping,
-- 
2.7.4



More information about the mesa-dev mailing list