+ /*
+ * Convert Mesa program inputs to TGSI input register semantics.
+ */
+ inputsRead = stfp->Base.Base.InputsRead;
+ for (attr = 0; attr < VARYING_SLOT_MAX; attr++) {
+ if ((inputsRead & BITFIELD64_BIT(attr)) != 0) {
+ const GLuint slot = fs_num_inputs++;
+
+ 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:
+ input_semantic_name[slot] = TGSI_SEMANTIC_POSITION;
+ input_semantic_index[slot] = 0;
+ interpMode[slot] = TGSI_INTERPOLATE_LINEAR;
+ break;
+ 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);
+ 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);
+ break;
+ case VARYING_SLOT_FOGC:
+ input_semantic_name[slot] = TGSI_SEMANTIC_FOG;
+ input_semantic_index[slot] = 0;
+ interpMode[slot] = TGSI_INTERPOLATE_PERSPECTIVE;
+ break;
+ case VARYING_SLOT_FACE:
+ input_semantic_name[slot] = TGSI_SEMANTIC_FACE;
+ input_semantic_index[slot] = 0;
+ interpMode[slot] = TGSI_INTERPOLATE_CONSTANT;
+ break;
+ case VARYING_SLOT_PRIMITIVE_ID:
+ input_semantic_name[slot] = TGSI_SEMANTIC_PRIMID;
+ input_semantic_index[slot] = 0;
+ interpMode[slot] = TGSI_INTERPOLATE_CONSTANT;
+ break;
+ case VARYING_SLOT_LAYER:
+ input_semantic_name[slot] = TGSI_SEMANTIC_LAYER;
+ input_semantic_index[slot] = 0;
+ interpMode[slot] = TGSI_INTERPOLATE_CONSTANT;
+ break;
+ case VARYING_SLOT_VIEWPORT:
+ input_semantic_name[slot] = TGSI_SEMANTIC_VIEWPORT_INDEX;
+ input_semantic_index[slot] = 0;
+ interpMode[slot] = TGSI_INTERPOLATE_CONSTANT;
+ break;
+ case VARYING_SLOT_CLIP_DIST0:
+ input_semantic_name[slot] = TGSI_SEMANTIC_CLIPDIST;
+ input_semantic_index[slot] = 0;
+ interpMode[slot] = TGSI_INTERPOLATE_PERSPECTIVE;
+ break;
+ case VARYING_SLOT_CLIP_DIST1:
+ input_semantic_name[slot] = TGSI_SEMANTIC_CLIPDIST;
+ input_semantic_index[slot] = 1;
+ interpMode[slot] = TGSI_INTERPOLATE_PERSPECTIVE;
+ break;
+ /* In most cases, there is nothing special about these
+ * inputs, so adopt a convention to use the generic
+ * semantic name and the mesa VARYING_SLOT_ number as the
+ * index.
+ *
+ * All that is required is that the vertex shader labels
+ * its own outputs similarly, and that the vertex shader
+ * generates at least every output required by the
+ * fragment shader plus fixed-function hardware (such as
+ * BFC).
+ *
+ * However, some drivers may need us to identify the PNTC and TEXi
+ * varyings if, for example, their capability to replace them with
+ * sprite coordinates is limited.
+ */
+ case VARYING_SLOT_PNTC:
+ if (st->needs_texcoord_semantic) {
+ input_semantic_name[slot] = TGSI_SEMANTIC_PCOORD;
+ input_semantic_index[slot] = 0;
+ interpMode[slot] = TGSI_INTERPOLATE_LINEAR;
+ break;
+ }
+ /* fall through */
+ case VARYING_SLOT_TEX0:
+ case VARYING_SLOT_TEX1:
+ case VARYING_SLOT_TEX2:
+ case VARYING_SLOT_TEX3:
+ case VARYING_SLOT_TEX4:
+ case VARYING_SLOT_TEX5:
+ case VARYING_SLOT_TEX6:
+ case VARYING_SLOT_TEX7:
+ 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);
+ break;
+ }
+ /* fall through */
+ case VARYING_SLOT_VAR0:
+ default:
+ /* Semantic indices should be zero-based because drivers may choose
+ * to assign a fixed slot determined by that index.
+ * This is useful because ARB_separate_shader_objects uses location
+ * qualifiers for linkage, and if the semantic index corresponds to
+ * these locations, linkage passes in the driver become unecessary.
+ *
+ * If needs_texcoord_semantic is true, no semantic indices will be
+ * consumed for the TEXi varyings, and we can base the locations of
+ * the user varyings on VAR0. Otherwise, we use TEX0 as base index.
+ */
+ assert(attr >= VARYING_SLOT_VAR0 || attr == VARYING_SLOT_PNTC ||
+ (attr >= VARYING_SLOT_TEX0 && attr <= VARYING_SLOT_TEX7));
+ input_semantic_name[slot] = TGSI_SEMANTIC_GENERIC;
+ 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);
+ break;
+ }