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

Giovanni Mascellani gmascellani at codeweavers.com
Mon Sep 20 02:54:31 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.c |  1 -
>   libs/vkd3d-shader/hlsl.h |  1 -
>   libs/vkd3d-shader/hlsl.y | 23 +++++++++++++++++++++++
>   tests/pow.shader_test    | 10 ++++++++++
>   5 files changed, 35 insertions(+), 2 deletions(-)
>   create mode 100644 tests/pow.shader_test
> 
> diff --git a/Makefile.am b/Makefile.am
> index 32b76e19d..34617c672 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -82,6 +82,7 @@ vkd3d_shader_tests = \
>   	tests/hlsl-vector-indexing-uniform.shader_test \
>   	tests/math.shader_test \
>   	tests/max.shader_test \
> +	tests/pow.shader_test \
>   	tests/preproc-if.shader_test \
>   	tests/preproc-ifdef.shader_test \
>   	tests/preproc-if-expr.shader_test \
> @@ -297,6 +298,7 @@ XFAIL_TESTS = \
>   	tests/hlsl-vector-indexing-uniform.shader_test \
>   	tests/math.shader_test \
>   	tests/max.shader_test \
> +	tests/pow.shader_test \
>   	tests/trigonometry.shader_test \
>   	tests/writemask-assignop-1.shader_test
>   endif
> diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c
> index 0d5396003..96473d057 100644
> --- a/libs/vkd3d-shader/hlsl.c
> +++ b/libs/vkd3d-shader/hlsl.c
> @@ -1093,7 +1093,6 @@ const char *debug_hlsl_expr_op(enum hlsl_ir_expr_op op)
>           [HLSL_OP2_MOD]         = "%",
>           [HLSL_OP2_MUL]         = "*",
>           [HLSL_OP2_NEQUAL]      = "!=",
> -        [HLSL_OP2_POW]         = "pow",
>           [HLSL_OP2_RSHIFT]      = ">>",
>   
>           [HLSL_OP3_LERP]        = "lerp",
> diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h
> index 9b579b724..ce1f1b756 100644
> --- a/libs/vkd3d-shader/hlsl.h
> +++ b/libs/vkd3d-shader/hlsl.h
> @@ -318,7 +318,6 @@ enum hlsl_ir_expr_op
>       HLSL_OP2_MOD,
>       HLSL_OP2_MUL,
>       HLSL_OP2_NEQUAL,
> -    HLSL_OP2_POW,
>       HLSL_OP2_RSHIFT,
>   
>       HLSL_OP3_LERP,
> diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y
> index bd2660389..2b381dc8a 100644
> --- a/libs/vkd3d-shader/hlsl.y
> +++ b/libs/vkd3d-shader/hlsl.y
> @@ -1585,6 +1585,28 @@ static bool intrinsic_max(struct hlsl_ctx *ctx,
>       return !!add_expr(ctx, params->instrs, HLSL_OP2_MAX, args, &loc);
>   }
>   
> +static bool intrinsic_pow(struct hlsl_ctx *ctx,
> +        const struct parse_initializer *params, struct vkd3d_shader_location loc)
> +{
> +    struct hlsl_ir_node *args[3] = {0};
> +    struct hlsl_ir_node *log, *exp;
> +    struct hlsl_ir_expr *mul;
> +
> +    if (!(log = hlsl_new_unary_expr(ctx, HLSL_OP1_LOG2, params->args[0], loc)))
> +        return false;
> +    list_add_tail(params->instrs, &log->entry);
> +
> +    args[0] = params->args[1];
> +    args[1] = log;
> +    if (!(mul = add_expr(ctx, params->instrs, HLSL_OP2_MUL, args, &loc)))
> +        return false;
> +
> +    if (!(exp = hlsl_new_unary_expr(ctx, HLSL_OP1_EXP2, &mul->node, loc)))
> +        return false;
> +    list_add_tail(params->instrs, &exp->entry);
> +    return true;
> +}
> +
>   static bool intrinsic_saturate(struct hlsl_ctx *ctx,
>           const struct parse_initializer *params, struct vkd3d_shader_location loc)
>   {
> @@ -1605,6 +1627,7 @@ intrinsic_functions[] =
>       {"abs",                                 1, true,  intrinsic_abs},
>       {"clamp",                               3, true,  intrinsic_clamp},
>       {"max",                                 2, true,  intrinsic_max},
> +    {"pow",                                 2, true,  intrinsic_pow},
>       {"saturate",                            1, true,  intrinsic_saturate},
>   };
>   
> diff --git a/tests/pow.shader_test b/tests/pow.shader_test
> new file mode 100644
> index 000000000..aa6df21ca
> --- /dev/null
> +++ b/tests/pow.shader_test
> @@ -0,0 +1,10 @@
> +[pixel shader]
> +float4 main(uniform float2 u, uniform float2 v) : sv_target
> +{
> +    return float4(pow(u.y, 3), pow(u, v), pow(0.5, v.y));
> +}
> +
> +[test]
> +uniform 0 float4 0.4 0.8 2.5 2.0
> +draw quad
> +probe all rgba (0.512, 0.101192884, 0.64, 0.25)
> 



More information about the wine-devel mailing list