i965/fs: Don't take an ir_variable for emit_general_interpolation

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>
This commit is contained in:
Jason Ekstrand 2014-10-20 18:05:36 -07:00
parent b600f1a381
commit b1fe8604c6
4 changed files with 41 additions and 35 deletions

View File

@ -1288,35 +1288,41 @@ fs_visitor::emit_linterp(const fs_reg &attr, const fs_reg &interp,
this->delta_y[barycoord_mode], interp); this->delta_y[barycoord_mode], interp);
} }
fs_reg * void
fs_visitor::emit_general_interpolation(ir_variable *ir) 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); attr.type = brw_type_for_base_type(type->get_scalar_type());
reg->type = brw_type_for_base_type(ir->type->get_scalar_type());
fs_reg attr = *reg;
assert(stage == MESA_SHADER_FRAGMENT); assert(stage == MESA_SHADER_FRAGMENT);
brw_wm_prog_data *prog_data = (brw_wm_prog_data*) this->prog_data; brw_wm_prog_data *prog_data = (brw_wm_prog_data*) this->prog_data;
brw_wm_prog_key *key = (brw_wm_prog_key*) this->key; brw_wm_prog_key *key = (brw_wm_prog_key*) this->key;
unsigned int array_elements; unsigned int array_elements;
const glsl_type *type;
if (ir->type->is_array()) { if (type->is_array()) {
array_elements = ir->type->length; array_elements = type->length;
if (array_elements == 0) { 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 { } else {
array_elements = 1; array_elements = 1;
type = ir->type;
} }
glsl_interp_qualifier interpolation_mode = if (interpolation_mode == INTERP_QUALIFIER_NONE) {
ir->determine_interpolation_mode(key->flat_shade); 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 i = 0; i < array_elements; i++) {
for (unsigned int j = 0; j < type->matrix_columns; j++) { for (unsigned int j = 0; j < type->matrix_columns; j++) {
if (prog_data->urb_setup[location] == -1) { 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++) { for (unsigned int k = 0; k < type->vector_elements; k++) {
struct brw_reg interp = interp_reg(location, k); struct brw_reg interp = interp_reg(location, k);
interp = suboffset(interp, 3); interp = suboffset(interp, 3);
interp.type = reg->type; interp.type = attr.type;
emit(FS_OPCODE_CINTERP, attr, fs_reg(interp)); emit(FS_OPCODE_CINTERP, attr, fs_reg(interp));
attr = offset(attr, 1); attr = offset(attr, 1);
} }
@ -1344,7 +1350,7 @@ fs_visitor::emit_general_interpolation(ir_variable *ir)
/* Smooth/noperspective interpolation case. */ /* Smooth/noperspective interpolation case. */
for (unsigned int k = 0; k < type->vector_elements; k++) { for (unsigned int k = 0; k < type->vector_elements; k++) {
struct brw_reg interp = interp_reg(location, 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 /* Get the pixel/sample mask into f0 so that we know
* which pixels are lit. Then, for each channel that is * which pixels are lit. Then, for each channel that is
* unlit, replace the centroid data with non-centroid * 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->no_dd_clear = true;
inst = emit_linterp(attr, fs_reg(interp), interpolation_mode, inst = emit_linterp(attr, fs_reg(interp), interpolation_mode,
ir->data.centroid && !key->persample_shading, mod_centroid && !key->persample_shading,
ir->data.sample || key->persample_shading); mod_sample || key->persample_shading);
inst->predicate = BRW_PREDICATE_NORMAL; inst->predicate = BRW_PREDICATE_NORMAL;
inst->predicate_inverse = false; inst->predicate_inverse = false;
if (brw->has_pln) if (brw->has_pln)
@ -1370,8 +1376,8 @@ fs_visitor::emit_general_interpolation(ir_variable *ir)
} else { } else {
emit_linterp(attr, fs_reg(interp), interpolation_mode, emit_linterp(attr, fs_reg(interp), interpolation_mode,
ir->data.centroid && !key->persample_shading, mod_centroid && !key->persample_shading,
ir->data.sample || key->persample_shading); mod_sample || key->persample_shading);
} }
if (brw->gen < 6 && interpolation_mode == INTERP_QUALIFIER_SMOOTH) { if (brw->gen < 6 && interpolation_mode == INTERP_QUALIFIER_SMOOTH) {
emit(BRW_OPCODE_MUL, attr, attr, this->pixel_w); emit(BRW_OPCODE_MUL, attr, attr, this->pixel_w);
@ -1383,8 +1389,6 @@ fs_visitor::emit_general_interpolation(ir_variable *ir)
location++; location++;
} }
} }
return reg;
} }
fs_reg * fs_reg *

View File

@ -480,7 +480,11 @@ public:
fs_reg *emit_frontfacing_interpolation(); fs_reg *emit_frontfacing_interpolation();
fs_reg *emit_samplepos_setup(); fs_reg *emit_samplepos_setup();
fs_reg *emit_sampleid_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); fs_reg *emit_vs_system_value(enum brw_reg_type type, int location);
void emit_interpolation_setup_gen4(); void emit_interpolation_setup_gen4();
void emit_interpolation_setup_gen6(); void emit_interpolation_setup_gen6();

View File

@ -566,14 +566,6 @@ fs_visitor::setup_fp_regs()
fp_input_regs = rzalloc_array(mem_ctx, fs_reg, VARYING_SLOT_MAX); fp_input_regs = rzalloc_array(mem_ctx, fs_reg, VARYING_SLOT_MAX);
for (int i = 0; i < VARYING_SLOT_MAX; i++) { for (int i = 0; i < VARYING_SLOT_MAX; i++) {
if (prog->InputsRead & BITFIELD64_BIT(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", this->current_annotation = ralloc_asprintf(ctx, "interpolate input %d",
i); i);
@ -582,8 +574,6 @@ fs_visitor::setup_fp_regs()
{ {
assert(stage == MESA_SHADER_FRAGMENT); assert(stage == MESA_SHADER_FRAGMENT);
gl_fragment_program *fp = (gl_fragment_program*) prog; 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] = fp_input_regs[i] =
*emit_fragcoord_interpolation(fp->PixelCenterInteger, *emit_fragcoord_interpolation(fp->PixelCenterInteger,
fp->OriginUpperLeft); fp->OriginUpperLeft);
@ -593,7 +583,11 @@ fs_visitor::setup_fp_regs()
fp_input_regs[i] = *emit_frontfacing_interpolation(); fp_input_regs[i] = *emit_frontfacing_interpolation();
break; break;
default: 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) { if (i == VARYING_SLOT_FOGC) {
emit(MOV(offset(fp_input_regs[i], 1), fs_reg(0.0f))); emit(MOV(offset(fp_input_regs[i], 1), fs_reg(0.0f)));

View File

@ -98,7 +98,11 @@ fs_visitor::visit(ir_variable *ir)
} else if (!strcmp(ir->name, "gl_FrontFacing")) { } else if (!strcmp(ir->name, "gl_FrontFacing")) {
reg = emit_frontfacing_interpolation(); reg = emit_frontfacing_interpolation();
} else { } 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); assert(reg);
hash_table_insert(this->variable_ht, reg, ir); hash_table_insert(this->variable_ht, reg, ir);