i965/fs: Don't take an ir_variable for emit_general_interpolation
authorJason Ekstrand <jason.ekstrand@intel.com>
Tue, 21 Oct 2014 01:05:36 +0000 (18:05 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Thu, 15 Jan 2015 15:18:59 +0000 (07:18 -0800)
Previously, emit_general_interpolation took an ir_variable and pulled the
information it needed from that.  This meant that in fs_fp, we were
constructing a dummy ir_variable just to pass into it.  This commit makes
emit_general_interpolation take only the information it needs and gets rid
of the fs_fp cruft.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
src/mesa/drivers/dri/i965/brw_fs.cpp
src/mesa/drivers/dri/i965/brw_fs.h
src/mesa/drivers/dri/i965/brw_fs_fp.cpp
src/mesa/drivers/dri/i965/brw_fs_visitor.cpp

index cb699d3..5d129fe 100644 (file)
@@ -1288,35 +1288,41 @@ fs_visitor::emit_linterp(const fs_reg &attr, const fs_reg &interp,
                this->delta_y[barycoord_mode], interp);
 }
 
-fs_reg *
-fs_visitor::emit_general_interpolation(ir_variable *ir)
+void
+fs_visitor::emit_general_interpolation(fs_reg attr, const char *name,
+                                       const glsl_type *type,
+                                       glsl_interp_qualifier interpolation_mode,
+                                       int location, bool mod_centroid,
+                                       bool mod_sample)
 {
-   fs_reg *reg = new(this->mem_ctx) fs_reg(this, ir->type);
-   reg->type = brw_type_for_base_type(ir->type->get_scalar_type());
-   fs_reg attr = *reg;
+   attr.type = brw_type_for_base_type(type->get_scalar_type());
 
    assert(stage == MESA_SHADER_FRAGMENT);
    brw_wm_prog_data *prog_data = (brw_wm_prog_data*) this->prog_data;
    brw_wm_prog_key *key = (brw_wm_prog_key*) this->key;
 
    unsigned int array_elements;
-   const glsl_type *type;
 
-   if (ir->type->is_array()) {
-      array_elements = ir->type->length;
+   if (type->is_array()) {
+      array_elements = type->length;
       if (array_elements == 0) {
-        fail("dereferenced array '%s' has length 0\n", ir->name);
+         fail("dereferenced array '%s' has length 0\n", name);
       }
-      type = ir->type->fields.array;
+      type = type->fields.array;
    } else {
       array_elements = 1;
-      type = ir->type;
    }
 
-   glsl_interp_qualifier interpolation_mode =
-      ir->determine_interpolation_mode(key->flat_shade);
+   if (interpolation_mode == INTERP_QUALIFIER_NONE) {
+      bool is_gl_Color =
+         location == VARYING_SLOT_COL0 || location == VARYING_SLOT_COL1;
+      if (key->flat_shade && is_gl_Color) {
+         interpolation_mode = INTERP_QUALIFIER_FLAT;
+      } else {
+         interpolation_mode = INTERP_QUALIFIER_SMOOTH;
+      }
+   }
 
-   int location = ir->data.location;
    for (unsigned int i = 0; i < array_elements; i++) {
       for (unsigned int j = 0; j < type->matrix_columns; j++) {
         if (prog_data->urb_setup[location] == -1) {
@@ -1336,7 +1342,7 @@ fs_visitor::emit_general_interpolation(ir_variable *ir)
            for (unsigned int k = 0; k < type->vector_elements; k++) {
               struct brw_reg interp = interp_reg(location, k);
               interp = suboffset(interp, 3);
-               interp.type = reg->type;
+               interp.type = attr.type;
               emit(FS_OPCODE_CINTERP, attr, fs_reg(interp));
               attr = offset(attr, 1);
            }
@@ -1344,7 +1350,7 @@ fs_visitor::emit_general_interpolation(ir_variable *ir)
            /* Smooth/noperspective interpolation case. */
            for (unsigned int k = 0; k < type->vector_elements; k++) {
                struct brw_reg interp = interp_reg(location, k);
-               if (brw->needs_unlit_centroid_workaround && ir->data.centroid) {
+               if (brw->needs_unlit_centroid_workaround && mod_centroid) {
                   /* Get the pixel/sample mask into f0 so that we know
                    * which pixels are lit.  Then, for each channel that is
                    * unlit, replace the centroid data with non-centroid
@@ -1361,8 +1367,8 @@ fs_visitor::emit_general_interpolation(ir_variable *ir)
                      inst->no_dd_clear = true;
 
                   inst = emit_linterp(attr, fs_reg(interp), interpolation_mode,
-                                      ir->data.centroid && !key->persample_shading,
-                                      ir->data.sample || key->persample_shading);
+                                      mod_centroid && !key->persample_shading,
+                                      mod_sample || key->persample_shading);
                   inst->predicate = BRW_PREDICATE_NORMAL;
                   inst->predicate_inverse = false;
                   if (brw->has_pln)
@@ -1370,8 +1376,8 @@ fs_visitor::emit_general_interpolation(ir_variable *ir)
 
                } else {
                   emit_linterp(attr, fs_reg(interp), interpolation_mode,
-                               ir->data.centroid && !key->persample_shading,
-                               ir->data.sample || key->persample_shading);
+                               mod_centroid && !key->persample_shading,
+                               mod_sample || key->persample_shading);
                }
                if (brw->gen < 6 && interpolation_mode == INTERP_QUALIFIER_SMOOTH) {
                   emit(BRW_OPCODE_MUL, attr, attr, this->pixel_w);
@@ -1383,8 +1389,6 @@ fs_visitor::emit_general_interpolation(ir_variable *ir)
         location++;
       }
    }
-
-   return reg;
 }
 
 fs_reg *
index 1cfe60c..e6ecc08 100644 (file)
@@ -480,7 +480,11 @@ public:
    fs_reg *emit_frontfacing_interpolation();
    fs_reg *emit_samplepos_setup();
    fs_reg *emit_sampleid_setup();
-   fs_reg *emit_general_interpolation(ir_variable *ir);
+   void emit_general_interpolation(fs_reg attr, const char *name,
+                                   const glsl_type *type,
+                                   glsl_interp_qualifier interpolation_mode,
+                                   int location, bool mod_centroid,
+                                   bool mod_sample);
    fs_reg *emit_vs_system_value(enum brw_reg_type type, int location);
    void emit_interpolation_setup_gen4();
    void emit_interpolation_setup_gen6();
index 65ce6cf..4639590 100644 (file)
@@ -566,14 +566,6 @@ fs_visitor::setup_fp_regs()
    fp_input_regs = rzalloc_array(mem_ctx, fs_reg, VARYING_SLOT_MAX);
    for (int i = 0; i < VARYING_SLOT_MAX; i++) {
       if (prog->InputsRead & BITFIELD64_BIT(i)) {
-         /* Make up a dummy instruction to reuse code for emitting
-          * interpolation.
-          */
-         ir_variable *ir = new(mem_ctx) ir_variable(glsl_type::vec4_type,
-                                                    "fp_input",
-                                                    ir_var_shader_in);
-         ir->data.location = i;
-
          this->current_annotation = ralloc_asprintf(ctx, "interpolate input %d",
                                                     i);
 
@@ -582,8 +574,6 @@ fs_visitor::setup_fp_regs()
             {
                assert(stage == MESA_SHADER_FRAGMENT);
                gl_fragment_program *fp = (gl_fragment_program*) prog;
-               ir->data.pixel_center_integer = fp->PixelCenterInteger;
-               ir->data.origin_upper_left = fp->OriginUpperLeft;
                fp_input_regs[i] =
                   *emit_fragcoord_interpolation(fp->PixelCenterInteger,
                                                 fp->OriginUpperLeft);
@@ -593,7 +583,11 @@ fs_visitor::setup_fp_regs()
             fp_input_regs[i] = *emit_frontfacing_interpolation();
             break;
          default:
-            fp_input_regs[i] = *emit_general_interpolation(ir);
+            fp_input_regs[i] = fs_reg(this, glsl_type::vec4_type);
+            emit_general_interpolation(fp_input_regs[i], "fp_input",
+                                       glsl_type::vec4_type,
+                                       INTERP_QUALIFIER_NONE,
+                                       i, false, false);
 
             if (i == VARYING_SLOT_FOGC) {
                emit(MOV(offset(fp_input_regs[i], 1), fs_reg(0.0f)));
index 52aa3fb..a9d3254 100644 (file)
@@ -98,7 +98,11 @@ fs_visitor::visit(ir_variable *ir)
       } else if (!strcmp(ir->name, "gl_FrontFacing")) {
         reg = emit_frontfacing_interpolation();
       } else {
-        reg = emit_general_interpolation(ir);
+         reg = new(this->mem_ctx) fs_reg(this, ir->type);
+         emit_general_interpolation(*reg, ir->name, ir->type,
+                                    (glsl_interp_qualifier) ir->data.interpolation,
+                                    ir->data.location, ir->data.centroid,
+                                    ir->data.sample);
       }
       assert(reg);
       hash_table_insert(this->variable_ht, reg, ir);