summaryrefslogtreecommitdiffstats
path: root/src/glsl/ir_constant_expression.cpp
diff options
context:
space:
mode:
authorKenneth Graunke <[email protected]>2012-12-01 23:49:26 -0800
committerMatt Turner <[email protected]>2013-02-28 13:18:59 -0800
commit93066ce1299a7be8f670e527f249940c635605b4 (patch)
tree1e7c958b7feb9a605a6c9f482bc68798990c89f4 /src/glsl/ir_constant_expression.cpp
parent18281d60889c7bb0ef14d2aa8a080cdaead7adb3 (diff)
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 <[email protected]> Reviewed-by: Eric Anholt <[email protected]> Signed-off-by: Kenneth Graunke <[email protected]>
Diffstat (limited to 'src/glsl/ir_constant_expression.cpp')
-rw-r--r--src/glsl/ir_constant_expression.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp
index 86b863f3103..c2d0dc46c78 100644
--- a/src/glsl/ir_constant_expression.cpp
+++ b/src/glsl/ir_constant_expression.cpp
@@ -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) {