Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- Makefile.am | 2 ++ libs/vkd3d-shader/hlsl.y | 15 +++++++++++++++ tests/hlsl-clamp.shader_test | 10 ++++++++++ 3 files changed, 27 insertions(+) create mode 100644 tests/hlsl-clamp.shader_test
diff --git a/Makefile.am b/Makefile.am index 09d3755b..3c18c318 100644 --- a/Makefile.am +++ b/Makefile.am @@ -56,6 +56,7 @@ vkd3d_shader_runners = \ vkd3d_shader_tests = \ tests/conditional.shader_test \ tests/hlsl-array-dimension.shader_test \ + tests/hlsl-clamp.shader_test \ tests/hlsl-comma.shader_test \ tests/hlsl-duplicate-modifiers.shader_test \ tests/hlsl-function-overload.shader_test \ @@ -266,6 +267,7 @@ SHADER_TEST_LOG_COMPILER = tests/shader_runner_d3d12 XFAIL_TESTS = \ tests/conditional.shader_test \ tests/hlsl-array-dimension.shader_test \ + tests/hlsl-clamp.shader_test \ tests/hlsl-comma.shader_test \ tests/hlsl-duplicate-modifiers.shader_test \ tests/hlsl-function-overload.shader_test \ diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index d374f64b..8f634728 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1555,6 +1555,20 @@ static const struct hlsl_ir_function_decl *find_function_call(struct hlsl_ctx *c return args.decl; }
+static bool intrinsic_clamp(struct hlsl_ctx *ctx, + const struct parse_initializer *params, struct vkd3d_shader_location loc) +{ + struct hlsl_ir_node *args[3] = {params->args[0], params->args[1]}; + struct hlsl_ir_expr *max; + + if (!(max = add_expr(ctx, params->instrs, HLSL_OP2_MAX, args, &loc))) + return false; + + args[0] = &max->node; + args[1] = params->args[2]; + return !!add_expr(ctx, params->instrs, HLSL_OP2_MIN, args, &loc); +} + static bool intrinsic_max(struct hlsl_ctx *ctx, const struct parse_initializer *params, struct vkd3d_shader_location loc) { @@ -1572,6 +1586,7 @@ static const struct intrinsic_function } intrinsic_functions[] = { + {"clamp", 3, true, intrinsic_clamp}, {"max", 2, true, intrinsic_max}, };
diff --git a/tests/hlsl-clamp.shader_test b/tests/hlsl-clamp.shader_test new file mode 100644 index 00000000..73f396ff --- /dev/null +++ b/tests/hlsl-clamp.shader_test @@ -0,0 +1,10 @@ +[pixel shader] +float4 main(uniform float u, uniform float v, uniform float w) : sv_target +{ + return float4(clamp(u, v, w), clamp(0.9, v, w), clamp(u, -0.5, w), clamp(0.6, -0.4, 0.3)); +} + +[test] +uniform 0 float4 -0.3 -0.1 0.7 0.0 +draw quad +probe all rgba (-0.1, 0.7, -0.3, 0.3)