+
+static void
+exec_interp_at_sample(struct tgsi_exec_machine *mach,
+ const struct tgsi_full_instruction *inst)
+{
+ union tgsi_exec_channel index;
+ union tgsi_exec_channel index2D;
+ union tgsi_exec_channel result[TGSI_NUM_CHANNELS];
+ const struct tgsi_full_src_register *reg = &inst->Src[0];
+
+ assert(reg->Register.File == TGSI_FILE_INPUT);
+ assert(inst->Src[1].Register.File == TGSI_FILE_IMMEDIATE);
+
+ get_index_registers(mach, reg, &index, &index2D);
+ float sample = mach->Imms[inst->Src[1].Register.Index][inst->Src[1].Register.SwizzleX];
+
+ /* Short cut: sample 0 is like a normal fetch */
+ for (unsigned chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
+ if (!(inst->Dst[0].Register.WriteMask & (1 << chan)))
+ continue;
+
+ fetch_src_file_channel(mach, TGSI_FILE_INPUT, chan, &index, &index2D,
+ &result[chan]);
+ if (sample != 0.0f) {
+
+ /* TODO: define the samples > 0, but so far we only do fake MSAA */
+ float x = 0;
+ float y = 0;
+
+ unsigned pos = index2D.i[chan] * TGSI_EXEC_MAX_INPUT_ATTRIBS + index.i[chan];
+ assert(pos >= 0);
+ assert(pos < TGSI_MAX_PRIM_VERTICES * PIPE_MAX_ATTRIBS);
+ mach->InputSampleOffsetApply[pos](mach, pos, chan, x, y, &result[chan]);
+ }
+ store_dest(mach, &result[chan], &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT);
+ }
+}
+
+
+static void
+exec_interp_at_offset(struct tgsi_exec_machine *mach,
+ const struct tgsi_full_instruction *inst)
+{
+ union tgsi_exec_channel index;
+ union tgsi_exec_channel index2D;
+ union tgsi_exec_channel ofsx;
+ union tgsi_exec_channel ofsy;
+ const struct tgsi_full_src_register *reg = &inst->Src[0];
+
+ assert(reg->Register.File == TGSI_FILE_INPUT);
+
+ get_index_registers(mach, reg, &index, &index2D);
+ unsigned pos = index2D.i[0] * TGSI_EXEC_MAX_INPUT_ATTRIBS + index.i[0];
+
+ fetch_source(mach, &ofsx, &inst->Src[1], TGSI_CHAN_X, TGSI_EXEC_DATA_FLOAT);
+ fetch_source(mach, &ofsy, &inst->Src[1], TGSI_CHAN_Y, TGSI_EXEC_DATA_FLOAT);
+
+ for (int chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
+ if (!(inst->Dst[0].Register.WriteMask & (1 << chan)))
+ continue;
+ union tgsi_exec_channel result;
+ fetch_src_file_channel(mach, TGSI_FILE_INPUT, chan, &index, &index2D, &result);
+ mach->InputSampleOffsetApply[pos](mach, pos, chan, ofsx.f[chan], ofsy.f[chan], &result);
+ store_dest(mach, &result, &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT);
+ }
+}
+
+
+static void
+exec_interp_at_centroid(struct tgsi_exec_machine *mach,
+ const struct tgsi_full_instruction *inst)
+{
+ union tgsi_exec_channel index;
+ union tgsi_exec_channel index2D;
+ union tgsi_exec_channel result[TGSI_NUM_CHANNELS];
+ const struct tgsi_full_src_register *reg = &inst->Src[0];
+
+ assert(reg->Register.File == TGSI_FILE_INPUT);
+ get_index_registers(mach, reg, &index, &index2D);
+
+ for (unsigned chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
+ if (!(inst->Dst[0].Register.WriteMask & (1 << chan)))
+ continue;
+
+ /* Here we should add the change to use a sample that lies within the
+ * primitive (Section 15.2):
+ *
+ * "When interpolating variables declared using centroid in ,
+ * the variable is sampled at a location within the pixel covered
+ * by the primitive generating the fragment.
+ * ...
+ * The built-in functions interpolateAtCentroid ... will sample
+ * variables as though they were declared with the centroid ...
+ * qualifier[s]."
+ *
+ * Since we only support 1 sample currently, this is just a pass-through.
+ */
+ fetch_src_file_channel(mach, TGSI_FILE_INPUT, chan, &index, &index2D,
+ &result[chan]);
+ store_dest(mach, &result[chan], &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT);
+ }
+
+}
+
+