st/mesa: get interpolation location at translation time
authorTimothy Arceri <timothy.arceri@collabora.com>
Mon, 17 Oct 2016 23:47:14 +0000 (10:47 +1100)
committerTimothy Arceri <timothy.arceri@collabora.com>
Wed, 26 Oct 2016 03:29:36 +0000 (14:29 +1100)
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@amd.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/mesa/state_tracker/st_glsl_to_tgsi.cpp
src/mesa/state_tracker/st_glsl_to_tgsi.h
src/mesa/state_tracker/st_program.c

index d0d2431f9bbdf1da56cb62977ec397bff4e52c38..a58bedc497407577f946de5637bc228d0e78a283 100644 (file)
@@ -338,6 +338,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 */
@@ -2385,6 +2386,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)
 {
@@ -2422,6 +2434,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);
 
@@ -5926,7 +5939,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
@@ -5949,7 +5961,6 @@ st_translate_program(
    const ubyte inputSemanticName[],
    const ubyte inputSemanticIndex[],
    const GLuint interpMode[],
-   const GLuint interpLocation[],
    GLuint numOutputs,
    const GLuint outputMapping[],
    const GLuint outputSlotToAttr[],
@@ -6006,17 +6017,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) {
index 0f485fb2541cf8d6008751b26b57a8a6f6b42bc2..add534ce9973e1d50be3cb4adf5d15e42b8db449 100644 (file)
@@ -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[],
index 6ea4678176225a70a194a89409c9cf3f02ee1b01..7a4ac26066b87f27005bf9540845b4e8148f154a 100644 (file)
@@ -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,