From: Zebediah Figura Subject: [PATCH vkd3d 5/6] vkd3d-shader/hlsl: Parse the saturate() intrinsic. Message-Id: <20210915224332.71963-5-zfigura@codeweavers.com> Date: Wed, 15 Sep 2021 17:43:31 -0500 In-Reply-To: <20210915224332.71963-1-zfigura@codeweavers.com> References: <20210915224332.71963-1-zfigura@codeweavers.com> Signed-off-by: Zebediah Figura --- Makefile.am | 2 ++ libs/vkd3d-shader/hlsl.y | 9 +++++++++ tests/saturate.shader_test | 11 +++++++++++ 3 files changed, 22 insertions(+) create mode 100644 tests/saturate.shader_test diff --git a/Makefile.am b/Makefile.am index 67dcbba4e..45db1a16d 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 8f634728c..fe3c3289d 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 000000000..29461e73f --- /dev/null +++ b/tests/saturate.shader_test @@ -0,0 +1,11 @@ +[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.33.0