[Mesa-dev] [PATCH 4/5] nir: implement GLSL.std.450 NMax operation

Connor Abbott cwabbott0 at gmail.com
Mon Jun 12 17:27:03 UTC 2017


The nir fmax opcode already has the semantics you want wrt NaN's, or
at least it should, no need to do all this csel stuff.

On Mon, Jun 12, 2017 at 9:33 AM, Juan A. Suarez Romero
<jasuarez at igalia.com> wrote:
> ---
>  src/compiler/spirv/vtn_glsl450.c | 23 +++++++++++++++++++++++
>  1 file changed, 23 insertions(+)
>
> diff --git a/src/compiler/spirv/vtn_glsl450.c b/src/compiler/spirv/vtn_glsl450.c
> index 5e75c3c..ce80360 100644
> --- a/src/compiler/spirv/vtn_glsl450.c
> +++ b/src/compiler/spirv/vtn_glsl450.c
> @@ -225,6 +225,25 @@ build_nmin(nir_builder *b, nir_ssa_def *x, nir_ssa_def *y)
>  }
>
>  /**
> + * Returns
> + *  if (isNan(x))
> + *    return y
> + *  else if (isNan(y))
> + *    return x
> + *  else
> + *    return min(x, y)
> + */
> +static nir_ssa_def *
> +build_nmax(nir_builder *b, nir_ssa_def *x, nir_ssa_def *y)
> +{
> +   return nir_bcsel(b, nir_fne(b, x, x),
> +                    y,
> +                    nir_bcsel(b, nir_fne(b, y, y),
> +                              x,
> +                              nir_fmax(b, x, y)));
> +}
> +
> +/**
>   * Approximate asin(x) by the formula:
>   *    asin~(x) = sign(x) * (pi/2 - sqrt(1 - |x|) * (pi/2 + |x|(pi/4 - 1 + |x|(p0 + |x|p1))))
>   *
> @@ -555,6 +574,10 @@ handle_glsl450_alu(struct vtn_builder *b, enum GLSLstd450 entrypoint,
>        val->ssa->def = build_nmin(nb, src[0], src[1]);
>        return;
>
> +   case GLSLstd450NMax:
> +      val->ssa->def = build_nmax(nb, src[0], src[1]);
> +      return;
> +
>     case GLSLstd450Log:
>        val->ssa->def = build_log(nb, src[0]);
>        return;
> --
> 2.9.4
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list