[Mesa-dev] [PATCH 1/6] glsl: Optimize pow(x, 2) into x * x.

Erik Faye-Lund kusmabite at gmail.com
Tue Mar 11 06:50:07 PDT 2014


On Mon, Mar 10, 2014 at 11:54 PM, Matt Turner <mattst88 at gmail.com> wrote:
> Cuts two instructions out of SynMark's Gl32VSInstancing benchmark.
> ---
>  src/glsl/opt_algebraic.cpp | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/src/glsl/opt_algebraic.cpp b/src/glsl/opt_algebraic.cpp
> index 5c49a78..8494bd9 100644
> --- a/src/glsl/opt_algebraic.cpp
> +++ b/src/glsl/opt_algebraic.cpp
> @@ -528,6 +528,14 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
>        if (is_vec_two(op_const[0]))
>           return expr(ir_unop_exp2, ir->operands[1]);
>
> +      if (is_vec_two(op_const[1])) {
> +         ir_variable *x = new(ir) ir_variable(ir->operands[1]->type, "x",
> +                                              ir_var_temporary);
> +         base_ir->insert_before(x);
> +         base_ir->insert_before(assign(x, ir->operands[0]));
> +         return mul(x, x);
> +      }
> +

Is this safe? Since many GPUs implement pow(x, y) as exp2(log2(x) *
y), this will give different results for if y comes from a uniform vs
if it's a constant, no?


More information about the mesa-dev mailing list