Mesa (master): glsl: implement max3 built-in function

Kenneth Graunke kwg at kemper.freedesktop.org
Mon Jan 6 22:26:57 UTC 2014


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

Author: Maxence Le Doré <maxence.ledore at gmail.com>
Date:   Fri Jan  3 00:09:52 2014 +0100

glsl: implement max3 built-in function

Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>

---

 src/glsl/builtin_functions.cpp |   38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/src/glsl/builtin_functions.cpp b/src/glsl/builtin_functions.cpp
index 95114c8..94ae2a4 100644
--- a/src/glsl/builtin_functions.cpp
+++ b/src/glsl/builtin_functions.cpp
@@ -581,6 +581,11 @@ private:
                                 const glsl_type *y_type,
                                 const glsl_type *z_type);
 
+   ir_function_signature *_max3(builtin_available_predicate avail,
+                                const glsl_type *x_type,
+                                const glsl_type *y_type,
+                                const glsl_type *z_type);
+
 #undef B0
 #undef B1
 #undef B2
@@ -2134,6 +2139,23 @@ builtin_builder::create_builtins()
                 _min3(shader_trinary_minmax, glsl_type::uvec4_type, glsl_type::uvec4_type, glsl_type::uvec4_type),
                 NULL);
 
+   add_function("max3",
+                _max3(shader_trinary_minmax, glsl_type::float_type, glsl_type::float_type, glsl_type::float_type),
+                _max3(shader_trinary_minmax, glsl_type::vec2_type, glsl_type::vec2_type, glsl_type::vec2_type),
+                _max3(shader_trinary_minmax, glsl_type::vec3_type, glsl_type::vec3_type, glsl_type::vec3_type),
+                _max3(shader_trinary_minmax, glsl_type::vec4_type, glsl_type::vec4_type, glsl_type::vec4_type),
+
+                _max3(shader_trinary_minmax, glsl_type::int_type, glsl_type::int_type, glsl_type::int_type),
+                _max3(shader_trinary_minmax, glsl_type::ivec2_type, glsl_type::ivec2_type, glsl_type::ivec2_type),
+                _max3(shader_trinary_minmax, glsl_type::ivec3_type, glsl_type::ivec3_type, glsl_type::ivec3_type),
+                _max3(shader_trinary_minmax, glsl_type::ivec4_type, glsl_type::ivec4_type, glsl_type::ivec4_type),
+
+                _max3(shader_trinary_minmax, glsl_type::uint_type, glsl_type::uint_type, glsl_type::uint_type),
+                _max3(shader_trinary_minmax, glsl_type::uvec2_type, glsl_type::uvec2_type, glsl_type::uvec2_type),
+                _max3(shader_trinary_minmax, glsl_type::uvec3_type, glsl_type::uvec3_type, glsl_type::uvec3_type),
+                _max3(shader_trinary_minmax, glsl_type::uvec4_type, glsl_type::uvec4_type, glsl_type::uvec4_type),
+                NULL);
+
 #undef F
 #undef FI
 #undef FIU
@@ -4035,6 +4057,22 @@ builtin_builder::_min3(builtin_available_predicate avail,
    return sig;
 }
 
+ir_function_signature *
+builtin_builder::_max3(builtin_available_predicate avail,
+                       const glsl_type *x_type, const glsl_type *y_type,
+                       const glsl_type *z_type)
+{
+   ir_variable *x = in_var(x_type, "x");
+   ir_variable *y = in_var(y_type, "y");
+   ir_variable *z = in_var(z_type, "z");
+   MAKE_SIG(x_type, avail, 3, x, y, z);
+
+   ir_expression *max3 = max(x, max(y,z));
+   body.emit(ret(max3));
+
+   return sig;
+}
+
 /** @} */
 
 /******************************************************************************/




More information about the mesa-commit mailing list