vkd3d-shader/hlsl: Parse the clamp() intrinsic.

Signed-off-by: Zebediah Figura <zfigura@codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Giovanni Mascellani <gmascellani@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2021-09-01 17:20:55 -05:00 committed by Alexandre Julliard
parent 99674ab60f
commit d035f3c2ff
3 changed files with 27 additions and 0 deletions

View File

@ -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 \

View File

@ -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},
};

View File

@ -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)