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

Signed-off-by: Zebediah Figura <zfigura@codeweavers.com>
Signed-off-by: Giovanni Mascellani <gmascellani@codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2021-09-17 16:06:37 -05:00 committed by Alexandre Julliard
parent 75a1a24d63
commit c5e50ae658
3 changed files with 24 additions and 0 deletions

View File

@ -54,6 +54,7 @@ vkd3d_shader_runners = \
tests/shader_runner_d3d12
vkd3d_shader_tests = \
tests/abs.shader_test \
tests/cast-to-float.shader_test \
tests/cast-to-half.shader_test \
tests/cast-to-int.shader_test \
@ -273,6 +274,7 @@ tests_vkd3d_api_LDADD = libvkd3d.la @VULKAN_LIBS@
tests_vkd3d_shader_api_LDADD = libvkd3d-shader.la
SHADER_TEST_LOG_COMPILER = tests/shader_runner_d3d12
XFAIL_TESTS = \
tests/abs.shader_test \
tests/cast-to-float.shader_test \
tests/cast-to-half.shader_test \
tests/cast-to-int.shader_test \

View File

@ -1555,6 +1555,14 @@ static const struct hlsl_ir_function_decl *find_function_call(struct hlsl_ctx *c
return args.decl;
}
static bool intrinsic_abs(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_ABS, args, &loc);
}
static bool intrinsic_clamp(struct hlsl_ctx *ctx,
const struct parse_initializer *params, struct vkd3d_shader_location loc)
{
@ -1594,6 +1602,7 @@ static const struct intrinsic_function
}
intrinsic_functions[] =
{
{"abs", 1, true, intrinsic_abs},
{"clamp", 3, true, intrinsic_clamp},
{"max", 2, true, intrinsic_max},
{"saturate", 1, true, intrinsic_saturate},

13
tests/abs.shader_test Normal file
View File

@ -0,0 +1,13 @@
[pixel shader]
float4 main(uniform float2 u) : sv_target
{
return float4(abs(u), abs(u.x - 0.5), abs(-0.4));
}
[test]
uniform 0 float4 0.1 0.7 0.0 0.0
draw quad
probe all rgba (0.1, 0.7, 0.4, 0.4)
uniform 0 float4 -0.7 0.1 0.0 0.0
draw quad
probe all rgba (0.7, 0.1, 1.2, 0.4)