diff options
author | Matt Turner <[email protected]> | 2012-06-04 21:59:34 -0400 |
---|---|---|
committer | Matt Turner <[email protected]> | 2012-06-12 18:51:25 -0400 |
commit | ae419a0159eeba6138d8c72a54737190cb6b1626 (patch) | |
tree | 46584ea7611e3e48ed8a5a60367376cc460c7de4 /src/glsl/opt_algebraic.cpp | |
parent | 9aa3fbcc2e1f46416f1d334427ebe48388584384 (diff) |
glsl: Transform dot product by a basis vector into a swizzle
Reviewed-by: Kenneth Graunke <[email protected]>
Diffstat (limited to 'src/glsl/opt_algebraic.cpp')
-rw-r--r-- | src/glsl/opt_algebraic.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/glsl/opt_algebraic.cpp b/src/glsl/opt_algebraic.cpp index 5a9881dbebe..75948db16fa 100644 --- a/src/glsl/opt_algebraic.cpp +++ b/src/glsl/opt_algebraic.cpp @@ -84,6 +84,12 @@ is_vec_one(ir_constant *ir) return (ir == NULL) ? false : ir->is_one(); } +static inline bool +is_vec_basis(ir_constant *ir) +{ + return (ir == NULL) ? false : ir->is_basis(); +} + static void update_type(ir_expression *ir) { @@ -314,6 +320,24 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir) this->progress = true; return ir_constant::zero(mem_ctx, ir->type); } + if (is_vec_basis(op_const[0])) { + this->progress = true; + unsigned component = 0; + for (unsigned c = 0; c < op_const[0]->type->vector_elements; c++) { + if (op_const[0]->value.f[c] == 1.0) + component = c; + } + return new(mem_ctx) ir_swizzle(ir->operands[1], component, 0, 0, 0, 1); + } + if (is_vec_basis(op_const[1])) { + this->progress = true; + unsigned component = 0; + for (unsigned c = 0; c < op_const[1]->type->vector_elements; c++) { + if (op_const[1]->value.f[c] == 1.0) + component = c; + } + return new(mem_ctx) ir_swizzle(ir->operands[0], component, 0, 0, 0, 1); + } break; case ir_binop_logic_and: |