[Mesa-dev] [PATCH 3/5] nir: implement GLSL.std.450 NMin operation
Juan A. Suarez Romero
jasuarez at igalia.com
Mon Jun 12 16:33:56 UTC 2017
---
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 96e3407..5e75c3c 100644
--- a/src/compiler/spirv/vtn_glsl450.c
+++ b/src/compiler/spirv/vtn_glsl450.c
@@ -206,6 +206,25 @@ build_log(nir_builder *b, nir_ssa_def *x)
}
/**
+ * Returns
+ * if (isNan(x))
+ * return y
+ * else if (isNan(y))
+ * return x
+ * else
+ * return min(x, y)
+ */
+static nir_ssa_def *
+build_nmin(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_fmin(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))))
*
@@ -532,6 +551,10 @@ handle_glsl450_alu(struct vtn_builder *b, enum GLSLstd450 entrypoint,
val->ssa->def = build_exp(nb, src[0]);
return;
+ case GLSLstd450NMin:
+ val->ssa->def = build_nmin(nb, src[0], src[1]);
+ return;
+
case GLSLstd450Log:
val->ssa->def = build_log(nb, src[0]);
return;
--
2.9.4
More information about the mesa-dev
mailing list