[Mesa-dev] [v2 PATCH 11/16] glsl: Optimize clamp(x, b, 1.0), where b > 0.0 as max(saturate(x), b)

Matt Turner mattst88 at gmail.com
Mon Jul 7 10:25:59 PDT 2014


On Mon, Jul 7, 2014 at 6:57 AM, Abdiel Janulgue
<abdiel.janulgue at linux.intel.com> wrote:
> v2: - Output max(saturate(x),b) instead of saturate(max(x,b))
>     - Make sure we do component-wise comparison for vectors (Ian Romanick)
>
> Signed-off-by: Abdiel Janulgue <abdiel.janulgue at linux.intel.com>
> ---
>  src/glsl/opt_algebraic.cpp | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
>
> diff --git a/src/glsl/opt_algebraic.cpp b/src/glsl/opt_algebraic.cpp
> index bcda7a9..7314dbb 100644
> --- a/src/glsl/opt_algebraic.cpp
> +++ b/src/glsl/opt_algebraic.cpp
> @@ -653,6 +653,18 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
>              if ((component == outer_const->type->vector_elements) &&
>                  inner_val_b->is_zero())
>                 return expr(ir_binop_min, saturate(inner_val_a), outer_const);
> +
> +            component = 0;
> +            ir_constant *inner_const = inner_val_b->as_constant();
> +            if (!inner_const)
> +               continue;
> +            for (int c = 0; c < inner_const->type->vector_elements; c++)
> +               if (inner_const->get_float_component(c) > 0.0f)
> +                  component++;
> +            /* Found a min (max(x, b), 1.0), where b > 0.0 */
> +            if (outer_const->is_one() &&
> +                component == inner_const->type->vector_elements)
> +               return expr(ir_binop_max, saturate(inner_val_a), inner_val_b);

Same comments as the previous patch.


More information about the mesa-dev mailing list