vkd3d-shader/hlsl: Support reflect() intrinsic.

Tests authored by Giovanni.
This commit is contained in:
Nikolay Sivov 2023-02-03 11:16:21 +03:00 committed by Alexandre Julliard
parent 7c3dadce6b
commit e7bc634307
Notes: Alexandre Julliard 2023-02-20 22:44:51 +01:00
Approved-by: Zebediah Figura (@zfigura)
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Henri Verbeet (@hverbeet)
Approved-by: Alexandre Julliard (@julliard)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/80
3 changed files with 124 additions and 0 deletions

View File

@ -130,6 +130,7 @@ vkd3d_shader_tests = \
tests/preproc-invalid.shader_test \
tests/preproc-macro.shader_test \
tests/preproc-misc.shader_test \
tests/reflect.shader_test \
tests/return.shader_test \
tests/round.shader_test \
tests/sampler.shader_test \

View File

@ -2774,6 +2774,27 @@ static bool intrinsic_pow(struct hlsl_ctx *ctx,
return true;
}
static bool intrinsic_reflect(struct hlsl_ctx *ctx,
const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
{
struct hlsl_ir_node *i = params->args[0], *n = params->args[1];
struct hlsl_ir_node *dot, *mul_n, *two_dot, *neg;
if (!(dot = add_binary_dot_expr(ctx, params->instrs, i, n, loc)))
return false;
if (!(two_dot = add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_ADD, dot, dot, loc)))
return false;
if (!(mul_n = add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_MUL, n, two_dot, loc)))
return false;
if (!(neg = add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_NEG, mul_n, loc)))
return false;
return !!add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_ADD, i, neg, loc);
}
static bool intrinsic_round(struct hlsl_ctx *ctx,
const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
{
@ -2982,6 +3003,7 @@ intrinsic_functions[] =
{"mul", 2, true, intrinsic_mul},
{"normalize", 1, true, intrinsic_normalize},
{"pow", 2, true, intrinsic_pow},
{"reflect", 2, true, intrinsic_reflect},
{"round", 1, true, intrinsic_round},
{"saturate", 1, true, intrinsic_saturate},
{"sin", 1, true, intrinsic_sin},

101
tests/reflect.shader_test Normal file
View File

@ -0,0 +1,101 @@
[pixel shader]
uniform float4 i;
uniform float4 n;
float4 main() : sv_target
{
return reflect(i, n);
}
[test]
uniform 0 float4 0.5 -0.1 0.2 0.3
uniform 4 float4 0.6 0.4 -0.3 1.0
draw quad
probe all rgba (-0.1, -0.5, 0.5, -0.7) 4
[pixel shader]
uniform float4 i;
uniform float4 n;
float4 main() : sv_target
{
float i1 = i.x;
return reflect(i1, n);
}
[test]
uniform 0 float4 0.5 0.0 0.0 0.0
uniform 4 float4 0.6 0.4 -0.3 1.0
draw quad
probe all rgba (-0.52, -0.18, 1.01, -1.2) 4
[pixel shader]
uniform float4 i;
uniform float4 n;
float4 main() : sv_target
{
float n1 = n.x;
return reflect(i, n1);
}
[test]
uniform 0 float4 0.5 -0.1 0.2 0.3
uniform 4 float4 0.6 0.0 0.0 0.0
draw quad
probe all rgba (-0.148, -0.748, -0.448, -0.348) 4
[pixel shader]
uniform float4 i;
uniform float4 n;
float4 main() : sv_target
{
float i1 = i.x;
float n1 = n.x;
return reflect(i1, n1);
}
[test]
uniform 0 float4 0.5 0.0 0.0 0.0
uniform 4 float4 0.6 0.0 0.0 0.0
draw quad
probe all rgba (0.14, 0.14, 0.14, 0.14) 4
[pixel shader]
uniform float4 i;
uniform float4 n;
float4 main() : sv_target
{
float2 i1 = i.xy;
return float4(reflect(i1, n), 0.0, 0.0);
}
[test]
uniform 0 float4 0.5 -0.1 0.0 0.0
uniform 4 float4 0.6 0.4 -0.3 1.0
draw quad
probe all rgba (0.188, -0.308, 0.0, 0.0) 4
[pixel shader]
uniform float4 i;
uniform float4 n;
float4 main() : sv_target
{
float3 i1 = i.xyz;
float2 n1 = n.xy;
return float4(reflect(i1, n1), 0.0, 0.0);
}
[test]
uniform 0 float4 0.5 -0.1 0.2 0.0
uniform 4 float4 0.6 0.4 0.0 0.0
draw quad
probe all rgba (0.188, -0.308, 0.0, 0.0) 4