glsl: Convert mix() to use a new ir_triop_lrp opcode.

Many GPUs have an instruction to do linear interpolation which is more
efficient than simply performing the algebra necessary (two multiplies,
an add, and a subtract).

Pattern matching or peepholing this is more desirable, but can be
tricky.  By using an opcode, we can at least make shaders which use the
mix() built-in get the more efficient behavior.

Currently, all consumers lower ir_triop_lrp.  Subsequent patches will
actually generate different code.

v2 [mattst88]:
   - Add LRP_TO_ARITH flag to ir_to_mesa.cpp. Will be removed in a
     subsequent patch and ir_triop_lrp translated directly.
v3 [mattst88]:
   - Move changes from the next patch to opt_algebraic.cpp to accept
     3-src operations.

Reviewed-by: Matt Turner <mattst88@gmail.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
This commit is contained in:
Kenneth Graunke
2012-12-01 23:49:26 -08:00
committed by Matt Turner
parent 18281d6088
commit 93066ce129
11 changed files with 84 additions and 12 deletions

View File

@@ -1248,6 +1248,19 @@ ir_expression::constant_expression_value(struct hash_table *variable_context)
}
break;
case ir_triop_lrp: {
assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
assert(op[1]->type->base_type == GLSL_TYPE_FLOAT);
assert(op[2]->type->base_type == GLSL_TYPE_FLOAT);
unsigned c2_inc = op[2]->type->is_scalar() ? 0 : 1;
for (unsigned c = 0, c2 = 0; c < components; c2 += c2_inc, c++) {
data.f[c] = op[0]->value.f[c] * (1.0f - op[2]->value.f[c2]) +
(op[1]->value.f[c] * op[2]->value.f[c2]);
}
break;
}
case ir_quadop_vector:
for (unsigned c = 0; c < this->type->vector_elements; c++) {
switch (this->type->base_type) {