[Mesa-dev] [PATCH 6/6] glsl: Allow dot() on scalars, and throw out dotlike().

Matt Turner mattst88 at gmail.com
Mon Mar 10 15:54:53 PDT 2014


In all uses of dotlike() we're writing generic code that operates on 1-4
component vectors. That our IR requires ir_binop_dot expressions'
operands to be 2+ component vectors is an implementation detail that's
not important when implementing built-in functions with dot(), which is
defined for scalar floats in GLSL.
---
 src/glsl/builtin_functions.cpp | 8 ++++----
 src/glsl/ir_builder.cpp        | 7 +------
 src/glsl/ir_builder.h          | 1 -
 3 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/src/glsl/builtin_functions.cpp b/src/glsl/builtin_functions.cpp
index a52077d..f2e346f 100644
--- a/src/glsl/builtin_functions.cpp
+++ b/src/glsl/builtin_functions.cpp
@@ -3041,7 +3041,7 @@ builtin_builder::_length(const glsl_type *type)
    ir_variable *x = in_var(type, "x");
    MAKE_SIG(glsl_type::float_type, always_available, 1, x);
 
-   body.emit(ret(sqrt(dotlike(x, x))));
+   body.emit(ret(sqrt(dot(x, x))));
 
    return sig;
 }
@@ -3131,7 +3131,7 @@ builtin_builder::_faceforward(const glsl_type *type)
    ir_variable *Nref = in_var(type, "Nref");
    MAKE_SIG(type, always_available, 3, N, I, Nref);
 
-   body.emit(if_tree(less(dotlike(Nref, I), imm(0.0f)),
+   body.emit(if_tree(less(dot(Nref, I), imm(0.0f)),
                      ret(N), ret(neg(N))));
 
    return sig;
@@ -3145,7 +3145,7 @@ builtin_builder::_reflect(const glsl_type *type)
    MAKE_SIG(type, always_available, 2, I, N);
 
    /* I - 2 * dot(N, I) * N */
-   body.emit(ret(sub(I, mul(imm(2.0f), mul(dotlike(N, I), N)))));
+   body.emit(ret(sub(I, mul(imm(2.0f), mul(dot(N, I), N)))));
 
    return sig;
 }
@@ -3159,7 +3159,7 @@ builtin_builder::_refract(const glsl_type *type)
    MAKE_SIG(type, always_available, 3, I, N, eta);
 
    ir_variable *n_dot_i = body.make_temp(glsl_type::float_type, "n_dot_i");
-   body.emit(assign(n_dot_i, dotlike(N, I)));
+   body.emit(assign(n_dot_i, dot(N, I)));
 
    /* From the GLSL 1.10 specification:
     * k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I))
diff --git a/src/glsl/ir_builder.cpp b/src/glsl/ir_builder.cpp
index 7f41ed6..f4a1c6e 100644
--- a/src/glsl/ir_builder.cpp
+++ b/src/glsl/ir_builder.cpp
@@ -251,13 +251,8 @@ ir_expression *round_even(operand a)
    return expr(ir_unop_round_even, a);
 }
 
-ir_expression *dot(operand a, operand b)
-{
-   return expr(ir_binop_dot, a, b);
-}
-
 /* dot for vectors, mul for scalars */
-ir_expression *dotlike(operand a, operand b)
+ir_expression *dot(operand a, operand b)
 {
    assert(a.val->type == b.val->type);
 
diff --git a/src/glsl/ir_builder.h b/src/glsl/ir_builder.h
index f00e6f3..108b53a 100644
--- a/src/glsl/ir_builder.h
+++ b/src/glsl/ir_builder.h
@@ -139,7 +139,6 @@ ir_expression *carry(operand a, operand b);
 ir_expression *borrow(operand a, operand b);
 ir_expression *round_even(operand a);
 ir_expression *dot(operand a, operand b);
-ir_expression *dotlike(operand a, operand b);
 ir_expression *clamp(operand a, operand b, operand c);
 ir_expression *saturate(operand a);
 ir_expression *abs(operand a);
-- 
1.8.3.2



More information about the mesa-dev mailing list