[Mesa-dev] [PATCH] glsl: skip mul by zero opt for floating point expression

Ian Romanick idr at freedesktop.org
Mon Jul 2 22:56:01 UTC 2018


On 07/02/2018 08:22 AM, vadym.shovkoplias wrote:
> From: Vadym Shovkoplias <vadym.shovkoplias at globallogic.com>
> 
> One of the operands can be NaN and multiplication by zero
> should also result to NaN value. E.g:
> 
> float Temp = 0.0;
> void main()
> {
> 	Temp = log2(Temp);
> 	Temp = Temp * 0.0;
>         isnan(Temp);
>         ...
> }
> 
> here Temp should be NaN and isnan() should return true.

In GLSL, the NaN or Inf behavior that you seek requires the use of the
precise keyword.  We go to some lengths to obey this in
nir_opt_algebraic.  It's possible that some cases in glsl/opt_algebraic.
miss it.

> Signed-off-by: Vadym Shovkoplias <vadym.shovkoplias at globallogic.com>
> ---
>  src/compiler/glsl/opt_algebraic.cpp | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/src/compiler/glsl/opt_algebraic.cpp b/src/compiler/glsl/opt_algebraic.cpp
> index ff4be26957..2d01575bb3 100644
> --- a/src/compiler/glsl/opt_algebraic.cpp
> +++ b/src/compiler/glsl/opt_algebraic.cpp
> @@ -590,7 +590,8 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
>        if (is_vec_one(op_const[1]))
>  	 return ir->operands[0];
>  
> -      if (is_vec_zero(op_const[0]) || is_vec_zero(op_const[1]))
> +      if ((is_vec_zero(op_const[0]) || is_vec_zero(op_const[1])) &&
> +	!ir->type->is_float() && !ir->type->is_double())
>  	 return ir_constant::zero(ir, ir->type);
>  
>        if (is_vec_negative_one(op_const[0]))


More information about the mesa-dev mailing list