[Mesa-dev] [PATCH 03/50] glsl: Add "built-in" function to do sign(fp64) (v2)
Roland Scheidegger
sroland at vmware.com
Wed Mar 14 00:46:08 UTC 2018
Am 13.03.2018 um 05:24 schrieb Dave Airlie:
> From: Elie Tournier <tournier.elie at gmail.com>
>
> v2: use mix.
>
> Signed-off-by: Elie Tournier <elie.tournier at collabora.com>
> ---
> src/compiler/glsl/builtin_float64.h | 28 ++++++++++++++++++++++++++++
> src/compiler/glsl/builtin_functions.cpp | 4 ++++
> src/compiler/glsl/builtin_functions.h | 3 +++
> src/compiler/glsl/float64.glsl | 9 +++++++++
> src/compiler/glsl/glcpp/glcpp-parse.y | 1 +
> 5 files changed, 45 insertions(+)
>
> diff --git a/src/compiler/glsl/builtin_float64.h b/src/compiler/glsl/builtin_float64.h
> index 2898fc9..8546048 100644
> --- a/src/compiler/glsl/builtin_float64.h
> +++ b/src/compiler/glsl/builtin_float64.h
> @@ -68,3 +68,31 @@ fneg64(void *mem_ctx, builtin_available_predicate avail)
> sig->replace_parameters(&sig_parameters);
> return sig;
> }
> +ir_function_signature *
> +fsign64(void *mem_ctx, builtin_available_predicate avail)
> +{
> + ir_function_signature *const sig =
> + new(mem_ctx) ir_function_signature(glsl_type::uvec2_type, avail);
> + ir_factory body(&sig->body, mem_ctx);
> + sig->is_defined = true;
> +
> + exec_list sig_parameters;
> +
> + ir_variable *const r001D = new(mem_ctx) ir_variable(glsl_type::uvec2_type, "a", ir_var_function_in);
> + sig_parameters.push_tail(r001D);
> + ir_variable *const r001E = new(mem_ctx) ir_variable(glsl_type::uvec2_type, "retval", ir_var_auto);
> + body.emit(r001E);
> + body.emit(assign(r001E, body.constant(0u), 0x01));
> +
> + ir_expression *const r001F = lshift(swizzle_y(r001D), body.constant(int(1)));
> + ir_expression *const r0020 = bit_or(r001F, swizzle_x(r001D));
> + ir_expression *const r0021 = equal(r0020, body.constant(0u));
> + ir_expression *const r0022 = bit_and(swizzle_y(r001D), body.constant(2147483648u));
> + ir_expression *const r0023 = bit_or(r0022, body.constant(1072693248u));
> + body.emit(assign(r001E, expr(ir_triop_csel, r0021, body.constant(0u), r0023), 0x02));
> +
> + body.emit(ret(r001E));
> +
> + sig->replace_parameters(&sig_parameters);
> + return sig;
> +}
> diff --git a/src/compiler/glsl/builtin_functions.cpp b/src/compiler/glsl/builtin_functions.cpp
> index 9d88a31..17aa868 100644
> --- a/src/compiler/glsl/builtin_functions.cpp
> +++ b/src/compiler/glsl/builtin_functions.cpp
> @@ -3350,6 +3350,10 @@ builtin_builder::create_builtins()
> generate_ir::fneg64(mem_ctx, integer_functions_supported),
> NULL);
>
> + add_function("__builtin_fsign64",
> + generate_ir::fsign64(mem_ctx, integer_functions_supported),
> + NULL);
> +
> #undef F
> #undef FI
> #undef FIUD_VEC
> diff --git a/src/compiler/glsl/builtin_functions.h b/src/compiler/glsl/builtin_functions.h
> index adec424..7954373 100644
> --- a/src/compiler/glsl/builtin_functions.h
> +++ b/src/compiler/glsl/builtin_functions.h
> @@ -73,6 +73,9 @@ fabs64(void *mem_ctx, builtin_available_predicate avail);
> ir_function_signature *
> fneg64(void *mem_ctx, builtin_available_predicate avail);
>
> +ir_function_signature *
> +fsign64(void *mem_ctx, builtin_available_predicate avail);
> +
> }
>
> #endif /* BULITIN_FUNCTIONS_H */
> diff --git a/src/compiler/glsl/float64.glsl b/src/compiler/glsl/float64.glsl
> index fedf8b7..f8eb1f3 100644
> --- a/src/compiler/glsl/float64.glsl
> +++ b/src/compiler/glsl/float64.glsl
> @@ -51,3 +51,12 @@ fneg64(uvec2 a)
> a.y = mix(t, a.y, is_nan(a));
> return a;
> }
> +
I think a function comment indicating what this returns would be quite
useful here(I had to look quite a long time at it to realize it returns
-1.0/1.0/0.0 depending on sign).
Roland
> +uvec2
> +fsign64(uvec2 a)
> +{
> + uvec2 retval;
> + retval.x = 0u;
> + retval.y = mix((a.y & 0x80000000u) | 0x3FF00000u, 0u, (a.y << 1 | a.x) == 0u);
> + return retval;
> +}
> diff --git a/src/compiler/glsl/glcpp/glcpp-parse.y b/src/compiler/glsl/glcpp/glcpp-parse.y
> index b9506d8..666543b 100644
> --- a/src/compiler/glsl/glcpp/glcpp-parse.y
> +++ b/src/compiler/glsl/glcpp/glcpp-parse.y
> @@ -2370,6 +2370,7 @@ _glcpp_parser_handle_version_declaration(glcpp_parser_t *parser, intmax_t versio
> add_builtin_define(parser, "__have_builtin_builtin_imod64", 1);
> add_builtin_define(parser, "__have_builtin_builtin_fabs64", 1);
> add_builtin_define(parser, "__have_builtin_builtin_fneg64", 1);
> + add_builtin_define(parser, "__have_builtin_builtin_fsign64", 1);
> }
> }
>
>
More information about the mesa-dev
mailing list