Mesa (master): glsl: Use conditional-select in mix().

Matt Turner mattst88 at kemper.freedesktop.org
Mon Sep 9 22:07:59 UTC 2013


Module: Mesa
Branch: master
Commit: fd183fa02c4430e439faf6a5195f5008d34db987
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=fd183fa02c4430e439faf6a5195f5008d34db987

Author: Matt Turner <mattst88 at gmail.com>
Date:   Fri Sep  6 12:36:48 2013 -0700

glsl: Use conditional-select in mix().

Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>

---

 src/glsl/builtin_functions.cpp |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/glsl/builtin_functions.cpp b/src/glsl/builtin_functions.cpp
index 662fc1e..0139b6f 100644
--- a/src/glsl/builtin_functions.cpp
+++ b/src/glsl/builtin_functions.cpp
@@ -2262,14 +2262,14 @@ builtin_builder::_mix_sel(const glsl_type *val_type, const glsl_type *blend_type
    ir_variable *a = in_var(blend_type, "a");
    MAKE_SIG(val_type, v130, 3, x, y, a);
 
-   if (blend_type->vector_elements == 1) {
-      body.emit(assign(x, y, a));
-   } else {
-      for (int i = 0; i < blend_type->vector_elements; i++) {
-         body.emit(assign(x, swizzle(y, i, 1), swizzle(a, i, 1), 1 << i));
-      }
-   }
-   body.emit(ret(x));
+   /* csel matches the ternary operator in that a selector of true choses the
+    * first argument. This differs from mix(x, y, false) which choses the
+    * second argument (to remain consistent with the interpolating version of
+    * mix() which takes a blend factor from 0.0 to 1.0 where 0.0 is only x.
+    *
+    * To handle the behavior mismatch, reverse the x and y arguments.
+    */
+   body.emit(ret(csel(a, y, x)));
 
    return sig;
 }




More information about the mesa-commit mailing list