[Mesa-dev] [PATCH 5/9] glsl: implement max3 built-in function
Matt Turner
mattst88 at gmail.com
Tue Dec 10 15:52:59 PST 2013
On Tue, Dec 10, 2013 at 2:43 PM, =?UTF-8?q?Maxence=20Le=20Dor=C3=A9?=
<Maxence Le Doré> <maxence.ledore at gmail.com> wrote:
> ---
> src/glsl/builtin_functions.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++
> src/glsl/ir_builder.cpp | 5 +++++
> src/glsl/ir_builder.h | 1 +
> 3 files changed, 50 insertions(+)
>
> diff --git a/src/glsl/builtin_functions.cpp b/src/glsl/builtin_functions.cpp
> index 7399e8f..1f21a37 100644
> --- a/src/glsl/builtin_functions.cpp
> +++ b/src/glsl/builtin_functions.cpp
> @@ -403,6 +403,7 @@ private:
> ir_expression *asin_expr(ir_variable *x);
>
> ir_expression *min3_expr(ir_variable *x, ir_variable *y, ir_variable *z);
> + ir_expression *max3_expr(ir_variable *x, ir_variable *y, ir_variable *z);
>
> /**
> * Call function \param f with parameters specified as the linked
> @@ -583,6 +584,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
> @@ -2136,6 +2142,23 @@ builtin_builder::create_builtins()
> _min3(shader_trinary_mimax, glsl_type::uvec4_type, glsl_type::uvec4_type, glsl_type::uvec4_type),
> NULL);
>
> + add_function("max3",
> + _max3(shader_trinary_mimax, glsl_type::float_type, glsl_type::float_type, glsl_type::float_type),
> + _max3(shader_trinary_mimax, glsl_type::vec2_type, glsl_type::vec2_type, glsl_type::vec2_type),
> + _max3(shader_trinary_mimax, glsl_type::vec3_type, glsl_type::vec3_type, glsl_type::vec3_type),
> + _max3(shader_trinary_mimax, glsl_type::vec4_type, glsl_type::vec4_type, glsl_type::vec4_type),
> +
> + _max3(shader_trinary_mimax, glsl_type::int_type, glsl_type::int_type, glsl_type::int_type),
> + _max3(shader_trinary_mimax, glsl_type::ivec2_type, glsl_type::ivec2_type, glsl_type::ivec2_type),
> + _max3(shader_trinary_mimax, glsl_type::ivec3_type, glsl_type::ivec3_type, glsl_type::ivec3_type),
> + _max3(shader_trinary_mimax, glsl_type::ivec4_type, glsl_type::ivec4_type, glsl_type::ivec4_type),
> +
> + _max3(shader_trinary_mimax, glsl_type::uint_type, glsl_type::uint_type, glsl_type::uint_type),
> + _max3(shader_trinary_mimax, glsl_type::uvec2_type, glsl_type::uvec2_type, glsl_type::uvec2_type),
> + _max3(shader_trinary_mimax, glsl_type::uvec3_type, glsl_type::uvec3_type, glsl_type::uvec3_type),
> + _max3(shader_trinary_mimax, glsl_type::uvec4_type, glsl_type::uvec4_type, glsl_type::uvec4_type),
> + NULL);
> +
> #undef F
> #undef FI
> #undef FIU
> @@ -2357,6 +2380,12 @@ builtin_builder::min3_expr(ir_variable *x, ir_variable *y, ir_variable *z)
> return min(x, min(y,z));
> }
>
> +ir_expression *
> +builtin_builder::max3_expr(ir_variable *x, ir_variable *y, ir_variable *z)
> +{
> + return max(x, max(y,z));
> +}
> +
> ir_call *
> builtin_builder::call(ir_function *f, ir_variable *ret, exec_list params)
> {
> @@ -4042,6 +4071,21 @@ 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);
> +
> + body.emit(ret(max3_expr(x, y, z)));
> +
> + return sig;
> +}
> +
> /** @} */
>
> /******************************************************************************/
> diff --git a/src/glsl/ir_builder.cpp b/src/glsl/ir_builder.cpp
> index 7091e9a..31ed191 100644
> --- a/src/glsl/ir_builder.cpp
> +++ b/src/glsl/ir_builder.cpp
> @@ -216,6 +216,11 @@ ir_expression *min(operand a, operand b)
> return expr(ir_binop_min, a, b);
> }
>
> +ir_expression *max(operand a, operand b)
> +{
> + return expr(ir_binop_max, a, b);
> +}
> +
> ir_expression *mul(operand a, operand b)
> {
> return expr(ir_binop_mul, a, b);
> diff --git a/src/glsl/ir_builder.h b/src/glsl/ir_builder.h
> index f564b07..4b85ea1 100644
> --- a/src/glsl/ir_builder.h
> +++ b/src/glsl/ir_builder.h
> @@ -185,6 +185,7 @@ ir_expression *f2b(operand a);
> ir_expression *b2f(operand a);
>
> ir_expression *min(operand a, operand b);
> +ir_expression *max(operand a, operand b);
>
> ir_expression *fma(operand a, operand b, operand c);
> ir_expression *lrp(operand x, operand y, operand a);
> --
> 1.8.5.1
Same comment: I'd separate the ir_builder changes into a separate patch.
More information about the mesa-dev
mailing list