From 2461ad601b221e58d85da1c8d00d90fec516c3e9 Mon Sep 17 00:00:00 2001 From: Zebediah Figura Date: Mon, 20 Sep 2021 14:20:56 +0200 Subject: [PATCH] vkd3d-shader/hlsl: Parse the pow() intrinsic. Signed-off-by: Zebediah Figura Signed-off-by: Matteo Bruni Signed-off-by: Giovanni Mascellani Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- 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 32b76e19..34617c67 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 0d539600..96473d05 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 9b579b72..ce1f1b75 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 bd266038..2b381dc8 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 00000000..21011e6c --- /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) 4