From: Matteo Bruni Subject: [v2 PATCH vkd3d 5/6] vkd3d-shader/hlsl: Parse the saturate() intrinsic. Message-Id: <20210916185557.4045940-5-mbruni@codeweavers.com> Date: Thu, 16 Sep 2021 20:55:56 +0200 In-Reply-To: <20210915224332.71963-4-zfigura@codeweavers.com> References: <20210915224332.71963-4-zfigura@codeweavers.com> From: Zebediah Figura Signed-off-by: Zebediah Figura Signed-off-by: Matteo Bruni --- v2 (Matteo): Fix trivial whitespace error. Makefile.am | 2 ++ libs/vkd3d-shader/hlsl.y | 9 +++++++++ tests/saturate.shader_test | 10 ++++++++++ 3 files changed, 21 insertions(+) create mode 100644 tests/saturate.shader_test diff --git a/Makefile.am b/Makefile.am index 67dcbba4..45db1a16 100644 --- a/Makefile.am +++ b/Makefile.am @@ -87,6 +87,7 @@ vkd3d_shader_tests = \ tests/preproc-invalid.shader_test \ tests/preproc-macro.shader_test \ tests/preproc-misc.shader_test \ + tests/saturate.shader_test \ tests/swizzle-0.shader_test \ tests/swizzle-1.shader_test \ tests/swizzle-2.shader_test \ @@ -295,6 +296,7 @@ XFAIL_TESTS = \ tests/hlsl-vector-indexing-uniform.shader_test \ tests/math.shader_test \ tests/max.shader_test \ + tests/saturate.shader_test \ tests/trigonometry.shader_test \ tests/writemask-assignop-1.shader_test endif diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 8f634728..fe3c3289 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1577,6 +1577,14 @@ static bool intrinsic_max(struct hlsl_ctx *ctx, return !!add_expr(ctx, params->instrs, HLSL_OP2_MAX, args, &loc); } +static bool intrinsic_saturate(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_SAT, args, &loc); +} + static const struct intrinsic_function { const char *name; @@ -1588,6 +1596,7 @@ intrinsic_functions[] = { {"clamp", 3, true, intrinsic_clamp}, {"max", 2, true, intrinsic_max}, + {"saturate", 1, true, intrinsic_saturate}, }; static int intrinsic_function_name_compare(const void *a, const void *b) diff --git a/tests/saturate.shader_test b/tests/saturate.shader_test new file mode 100644 index 00000000..0a954e7f --- /dev/null +++ b/tests/saturate.shader_test @@ -0,0 +1,10 @@ +[pixel shader] +float4 main(uniform float2 u) : sv_target +{ + return float4(saturate(u), saturate(u.x + 0.5), saturate(-1.2)); +} + +[test] +uniform 0 float4 0.7 -0.1 0.0 0.0 +draw quad +probe all rgba (0.7, 0.0, 1.0, 0.0) -- 2.26.3