<div dir="ltr">Why not computing the max3(min(x,y),min(x,z),min(y,z))?<br><br>For the six possible cases:<br>x < y < z --> max(x, x, y) -> y ==> works<br>
x < z < y --> max(x, z, z) -> z ==> works<br>
y < x < z --> max(y, x, y) -> x ==> works<br>
y < z < x --> max(y, z, y) -> z ==> works<br>
z < x < y --> max(x, z, z) -> x ==> works<br>
z < y < x --> max(y, z, z) -> y ==> works<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/12/11 Kenneth Graunke <span dir="ltr"><<a href="mailto:kenneth@whitecape.org" target="_blank">kenneth@whitecape.org</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 12/10/2013 02:43 PM, =?UTF-8?q?Maxence=20Le=20Dor=C3=A9?= <Maxence Le<br>
<div><div class="h5">Doré> wrote:<br>
> ---<br>
>  src/glsl/builtin_functions.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++<br>
>  1 file changed, 44 insertions(+)<br>
><br>
> diff --git a/src/glsl/builtin_functions.cpp b/src/glsl/builtin_functions.cpp<br>
> index 1f21a37..b9beffd 100644<br>
> --- a/src/glsl/builtin_functions.cpp<br>
> +++ b/src/glsl/builtin_functions.cpp<br>
> @@ -404,6 +404,7 @@ private:<br>
><br>
>     ir_expression *min3_expr(ir_variable *x, ir_variable *y, ir_variable *z);<br>
>     ir_expression *max3_expr(ir_variable *x, ir_variable *y, ir_variable *z);<br>
> +   ir_expression *mid3_expr(ir_variable *x, ir_variable *y, ir_variable *z);<br>
><br>
>     /**<br>
>      * Call function \param f with parameters specified as the linked<br>
> @@ -589,6 +590,11 @@ private:<br>
>                                  const glsl_type *y_type,<br>
>                                  const glsl_type *z_type);<br>
><br>
> +   ir_function_signature *_mid3(builtin_available_predicate avail,<br>
> +                                const glsl_type *x_type,<br>
> +                                const glsl_type *y_type,<br>
> +                                const glsl_type *z_type);<br>
> +<br>
>  #undef B0<br>
>  #undef B1<br>
>  #undef B2<br>
> @@ -2159,6 +2165,23 @@ builtin_builder::create_builtins()<br>
>                  _max3(shader_trinary_mimax, glsl_type::uvec4_type, glsl_type::uvec4_type, glsl_type::uvec4_type),<br>
>                  NULL);<br>
><br>
> +   add_function("mid3",<br>
> +                _mid3(shader_trinary_mimax, glsl_type::float_type, glsl_type::float_type, glsl_type::float_type),<br>
> +                _mid3(shader_trinary_mimax, glsl_type::vec2_type, glsl_type::vec2_type, glsl_type::vec2_type),<br>
> +                _mid3(shader_trinary_mimax, glsl_type::vec3_type, glsl_type::vec3_type, glsl_type::vec3_type),<br>
> +                _mid3(shader_trinary_mimax, glsl_type::vec4_type, glsl_type::vec4_type, glsl_type::vec4_type),<br>
> +<br>
> +                _mid3(shader_trinary_mimax, glsl_type::int_type, glsl_type::int_type, glsl_type::int_type),<br>
> +                _mid3(shader_trinary_mimax, glsl_type::ivec2_type, glsl_type::ivec2_type, glsl_type::ivec2_type),<br>
> +                _mid3(shader_trinary_mimax, glsl_type::ivec3_type, glsl_type::ivec3_type, glsl_type::ivec3_type),<br>
> +                _mid3(shader_trinary_mimax, glsl_type::ivec4_type, glsl_type::ivec4_type, glsl_type::ivec4_type),<br>
> +<br>
> +                _mid3(shader_trinary_mimax, glsl_type::uint_type, glsl_type::uint_type, glsl_type::uint_type),<br>
> +                _mid3(shader_trinary_mimax, glsl_type::uvec2_type, glsl_type::uvec2_type, glsl_type::uvec2_type),<br>
> +                _mid3(shader_trinary_mimax, glsl_type::uvec3_type, glsl_type::uvec3_type, glsl_type::uvec3_type),<br>
> +                _mid3(shader_trinary_mimax, glsl_type::uvec4_type, glsl_type::uvec4_type, glsl_type::uvec4_type),<br>
> +                NULL);<br>
> +<br>
>  #undef F<br>
>  #undef FI<br>
>  #undef FIU<br>
> @@ -2386,6 +2409,12 @@ builtin_builder::max3_expr(ir_variable *x, ir_variable *y, ir_variable *z)<br>
>     return max(x, max(y,z));<br>
>  }<br>
><br>
> +ir_expression *<br>
> +builtin_builder::mid3_expr(ir_variable *x, ir_variable *y, ir_variable *z)<br>
> +{<br>
> +   return max(min(x, y), min(y, z));<br>
<br>
</div></div>This is broken if y is the median.  Consider the following cases:<br>
<br>
x < y < z --> max(x, y) -> y ==> works<br>
x < z < y --> max(x, z) -> z ==> works<br>
y < x < z --> max(y, y) -> y ==> broken (selects least, not median)<br>
y < z < x --> max(y, y) -> y ==> broken (selects least, not median)<br>
z < x < y --> max(x, z) -> x ==> works<br>
z < y < x --> max(y, z) -> y ==> works<br>
<div class="im HOEnZb"><br>
> +}<br>
> +<br>
>  ir_call *<br>
>  builtin_builder::call(ir_function *f, ir_variable *ret, exec_list params)<br>
>  {<br>
> @@ -4086,6 +4115,21 @@ builtin_builder::_max3(builtin_available_predicate avail,<br>
>     return sig;<br>
>  }<br>
><br>
> +ir_function_signature *<br>
> +builtin_builder::_mid3(builtin_available_predicate avail,<br>
> +                       const glsl_type *x_type, const glsl_type *y_type,<br>
> +                       const glsl_type *z_type)<br>
> +{<br>
> +   ir_variable *x = in_var(x_type, "x");<br>
> +   ir_variable *y = in_var(y_type, "y");<br>
> +   ir_variable *z = in_var(z_type, "z");<br>
> +   MAKE_SIG(x_type, avail, 3, x, y, z);<br>
> +<br>
> +   body.emit(ret(mid3_expr(x, y, z)));<br>
> +<br>
> +   return sig;<br>
> +}<br>
> +<br>
>  /** @} */<br>
><br>
>  /******************************************************************************/<br>
><br>
<br>
</div><div class="HOEnZb"><div class="h5">_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</div></div></blockquote></div><br></div>