[PATCH vkd3d 1/5] vkd3d-shader/hlsl: Parse the abs() intrinsic.

Giovanni Mascellani gmascellani at codeweavers.com
Mon Sep 20 02:54:21 CDT 2021


Signed-off-by: Giovanni Mascellani <gmascellani at codeweavers.com>

Il 17/09/21 23:06, Zebediah Figura ha scritto:
> Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
> ---
>   Makefile.am              |  2 ++
>   libs/vkd3d-shader/hlsl.y |  9 +++++++++
>   tests/abs.shader_test    | 13 +++++++++++++
>   3 files changed, 24 insertions(+)
>   create mode 100644 tests/abs.shader_test
> 
> diff --git a/Makefile.am b/Makefile.am
> index c9ad38893..3287ec75a 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -54,6 +54,7 @@ vkd3d_shader_runners = \
>   	tests/shader_runner_d3d12
>   
>   vkd3d_shader_tests = \
> +	tests/abs.shader_test \
>   	tests/cast-to-float.shader_test \
>   	tests/cast-to-half.shader_test \
>   	tests/cast-to-int.shader_test \
> @@ -273,6 +274,7 @@ tests_vkd3d_api_LDADD = libvkd3d.la @VULKAN_LIBS@
>   tests_vkd3d_shader_api_LDADD = libvkd3d-shader.la
>   SHADER_TEST_LOG_COMPILER = tests/shader_runner_d3d12
>   XFAIL_TESTS = \
> +	tests/abs.shader_test \
>   	tests/cast-to-float.shader_test \
>   	tests/cast-to-half.shader_test \
>   	tests/cast-to-int.shader_test \
> diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y
> index fe3c3289d..bd2660389 100644
> --- a/libs/vkd3d-shader/hlsl.y
> +++ b/libs/vkd3d-shader/hlsl.y
> @@ -1555,6 +1555,14 @@ static const struct hlsl_ir_function_decl *find_function_call(struct hlsl_ctx *c
>       return args.decl;
>   }
>   
> +static bool intrinsic_abs(struct hlsl_ctx *ctx,
> +        const struct parse_initializer *params, struct vkd3d_shader_location loc)
> +{
> +    struct hlsl_ir_node *args[3] = {params->args[0]};
> +
> +    return !!add_expr(ctx, params->instrs, HLSL_OP1_ABS, args, &loc);
> +}
> +
>   static bool intrinsic_clamp(struct hlsl_ctx *ctx,
>           const struct parse_initializer *params, struct vkd3d_shader_location loc)
>   {
> @@ -1594,6 +1602,7 @@ static const struct intrinsic_function
>   }
>   intrinsic_functions[] =
>   {
> +    {"abs",                                 1, true,  intrinsic_abs},
>       {"clamp",                               3, true,  intrinsic_clamp},
>       {"max",                                 2, true,  intrinsic_max},
>       {"saturate",                            1, true,  intrinsic_saturate},
> diff --git a/tests/abs.shader_test b/tests/abs.shader_test
> new file mode 100644
> index 000000000..6fa6d1ca7
> --- /dev/null
> +++ b/tests/abs.shader_test
> @@ -0,0 +1,13 @@
> +[pixel shader]
> +float4 main(uniform float2 u) : sv_target
> +{
> +    return float4(abs(u), abs(u.x - 0.5), abs(-0.4));
> +}
> +
> +[test]
> +uniform 0 float4 0.1 0.7 0.0 0.0
> +draw quad
> +probe all rgba (0.1, 0.7, 0.4, 0.4)
> +uniform 0 float4 -0.7 0.1 0.0 0.0
> +draw quad
> +probe all rgba (0.7, 0.1, 1.2, 0.4)
> 



More information about the wine-devel mailing list