[Mesa-dev] [PATCH 2/3] glsl: Optimize clamp(x, 0.0, b), where b < 1.0 as saturate(min(x, b))
Ilia Mirkin
imirkin at alum.mit.edu
Tue Jun 24 06:27:13 PDT 2014
On Tue, Jun 24, 2014 at 1:32 AM, Abdiel Janulgue
<abdiel.janulgue at linux.intel.com> wrote:
> Signed-off-by: Abdiel Janulgue <abdiel.janulgue at linux.intel.com>
> ---
> src/glsl/opt_algebraic.cpp | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/src/glsl/opt_algebraic.cpp b/src/glsl/opt_algebraic.cpp
> index 8d7609d..0d694b6 100644
> --- a/src/glsl/opt_algebraic.cpp
> +++ b/src/glsl/opt_algebraic.cpp
> @@ -589,6 +589,10 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
> /* Found a min (max(x, 0), 1.0) */
> if (outer_const->is_one() && inner_val_a->is_zero())
> return saturate(inner_val_b);
> +
> + /* Found a min (max(x, 0.0) b), where b < 1.0 */
> + if ((outer_const->get_float_component(0) < 1.0f) && inner_val_b->is_zero())
> + return saturate(expr(ir_binop_min, inner_val_a, outer_const));
Not sure about other GPU's, but on reasonably modern nvidia gpu's, in
addition to being able to just saturate a single var, some other
instructions take a "saturate" modifier (like fp add/multiply). But
not min/max. If you were to write this as
min(saturate(a), b)
then it would be easier to propagate the saturate as a modifier to
whatever expression produces 'a' without having a clever optimization
that moves it through min/max.
Cheers,
-ilia
> }
> }
>
> --
> 1.9.1
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
More information about the mesa-dev
mailing list