From: Nikolay Sivov nsivov@codeweavers.com
Tests authored by Giovanni. --- Makefile.am | 1 + libs/vkd3d-shader/hlsl.y | 22 +++++++++ tests/reflect.shader_test | 101 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 tests/reflect.shader_test
diff --git a/Makefile.am b/Makefile.am index f9199472..8822e9eb 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 \ diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 76b0eae7..2f001611 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -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}, diff --git a/tests/reflect.shader_test b/tests/reflect.shader_test new file mode 100644 index 00000000..02488589 --- /dev/null +++ b/tests/reflect.shader_test @@ -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