From: Francisco Casas fcasas@codeweavers.com
Signed-off-by: Francisco Casas fcasas@codeweavers.com Signed-off-by: Zebediah Figura zfigura@codeweavers.com Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- v6: Recover the lost tests...
Makefile.am | 2 ++ libs/vkd3d-shader/hlsl.y | 55 ++++++++++++++++++++++++++++++++++++ tests/hlsl-cross.shader_test | 28 ++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 tests/hlsl-cross.shader_test
diff --git a/Makefile.am b/Makefile.am index 6d392e1d..be3d8ec1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -64,6 +64,7 @@ vkd3d_shader_tests = \ tests/hlsl-bool-cast.shader_test \ tests/hlsl-clamp.shader_test \ tests/hlsl-comma.shader_test \ + tests/hlsl-cross.shader_test \ tests/hlsl-duplicate-modifiers.shader_test \ tests/hlsl-for.shader_test \ tests/hlsl-function-overload.shader_test \ @@ -290,6 +291,7 @@ XFAIL_TESTS = \ tests/hlsl-array-dimension.shader_test \ tests/hlsl-bool-cast.shader_test \ tests/hlsl-comma.shader_test \ + tests/hlsl-cross.shader_test \ tests/hlsl-duplicate-modifiers.shader_test \ tests/hlsl-for.shader_test \ tests/hlsl-function-overload.shader_test \ diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index abf5da91..ff35c09e 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1586,6 +1586,60 @@ static bool intrinsic_clamp(struct hlsl_ctx *ctx, return !!add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_MIN, &max->node, params->args[2], &loc); }
+static bool intrinsic_cross(struct hlsl_ctx *ctx, + const struct parse_initializer *params, struct vkd3d_shader_location loc) +{ + struct hlsl_ir_swizzle *arg1_swzl1, *arg1_swzl2, *arg2_swzl1, *arg2_swzl2; + struct hlsl_ir_node *arg1 = params->args[0], *arg2 = params->args[1]; + struct hlsl_ir_node *arg1_cast, *arg2_cast, *mul1_neg; + struct hlsl_ir_expr *mul1, *mul2; + struct hlsl_type *cast_type; + enum hlsl_base_type base; + + if (arg1->data_type->base_type == HLSL_TYPE_HALF && arg2->data_type->base_type == HLSL_TYPE_HALF) + base = HLSL_TYPE_HALF; + else + base = HLSL_TYPE_FLOAT; + + cast_type = hlsl_get_vector_type(ctx, base, 3); + + if (!(arg1_cast = add_implicit_conversion(ctx, params->instrs, arg1, cast_type, &loc))) + return false; + + if (!(arg2_cast = add_implicit_conversion(ctx, params->instrs, arg2, cast_type, &loc))) + return false; + + if (!(arg1_swzl1 = hlsl_new_swizzle(ctx, HLSL_SWIZZLE(Z, X, Y, Z), 3, arg1_cast, &loc))) + return false; + list_add_tail(params->instrs, &arg1_swzl1->node.entry); + + if (!(arg2_swzl1 = hlsl_new_swizzle(ctx, HLSL_SWIZZLE(Y, Z, X, Y), 3, arg2_cast, &loc))) + return false; + list_add_tail(params->instrs, &arg2_swzl1->node.entry); + + if (!(mul1 = add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_MUL, + &arg1_swzl1->node, &arg2_swzl1->node, &loc))) + return false; + + if (!(mul1_neg = hlsl_new_unary_expr(ctx, HLSL_OP1_NEG, &mul1->node, loc))) + return false; + list_add_tail(params->instrs, &mul1_neg->entry); + + if (!(arg1_swzl2 = hlsl_new_swizzle(ctx, HLSL_SWIZZLE(Y, Z, X, Y), 3, arg1_cast, &loc))) + return false; + list_add_tail(params->instrs, &arg1_swzl2->node.entry); + + if (!(arg2_swzl2 = hlsl_new_swizzle(ctx, HLSL_SWIZZLE(Z, X, Y, Z), 3, arg2_cast, &loc))) + return false; + list_add_tail(params->instrs, &arg2_swzl2->node.entry); + + if (!(mul2 = add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_MUL, + &arg1_swzl2->node, &arg2_swzl2->node, &loc))) + return false; + + return !!add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_ADD, &mul2->node, mul1_neg, &loc); +} + static bool intrinsic_max(struct hlsl_ctx *ctx, const struct parse_initializer *params, struct vkd3d_shader_location loc) { @@ -1635,6 +1689,7 @@ intrinsic_functions[] = /* Note: these entries should be kept in alphabetical order. */ {"abs", 1, true, intrinsic_abs}, {"clamp", 3, true, intrinsic_clamp}, + {"cross", 2, true, intrinsic_cross}, {"max", 2, true, intrinsic_max}, {"pow", 2, true, intrinsic_pow}, {"round", 1, true, intrinsic_round}, diff --git a/tests/hlsl-cross.shader_test b/tests/hlsl-cross.shader_test new file mode 100644 index 00000000..101db607 --- /dev/null +++ b/tests/hlsl-cross.shader_test @@ -0,0 +1,28 @@ +[pixel shader] +float4 main(uniform float4 u, uniform float4 v) : sv_target +{ + float4 res = float4(0, 0, 0, 0); + res.xyz = cross(u, v); + return res; +} + +[test] +uniform 0 float4 1 -2 3 4 +uniform 4 float4 10 100 1000 10000 +draw quad +probe all rgba (-2300, -970, 120, 0) + + + +[pixel shader] +float4 main(uniform float4 u) : sv_target +{ + float4 res = float4(0, 0, 0, 3.5); + res.xyz = cross(u, 4); + return res; +} + +[test] +uniform 0 float4 1 -2 3 4 +draw quad +probe all rgba (-20, 8, 12, 3.5)
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com
On 19/11/21 18:33, Matteo Bruni wrote:
From: Francisco Casas fcasas@codeweavers.com
Signed-off-by: Francisco Casas fcasas@codeweavers.com Signed-off-by: Zebediah Figura zfigura@codeweavers.com Signed-off-by: Matteo Bruni mbruni@codeweavers.com
v6: Recover the lost tests...
Makefile.am | 2 ++ libs/vkd3d-shader/hlsl.y | 55 ++++++++++++++++++++++++++++++++++++ tests/hlsl-cross.shader_test | 28 ++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 tests/hlsl-cross.shader_test
diff --git a/Makefile.am b/Makefile.am index 6d392e1d..be3d8ec1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -64,6 +64,7 @@ vkd3d_shader_tests = \ tests/hlsl-bool-cast.shader_test \ tests/hlsl-clamp.shader_test \ tests/hlsl-comma.shader_test \
- tests/hlsl-cross.shader_test \ tests/hlsl-duplicate-modifiers.shader_test \ tests/hlsl-for.shader_test \ tests/hlsl-function-overload.shader_test \
@@ -290,6 +291,7 @@ XFAIL_TESTS = \ tests/hlsl-array-dimension.shader_test \ tests/hlsl-bool-cast.shader_test \ tests/hlsl-comma.shader_test \
- tests/hlsl-cross.shader_test \ tests/hlsl-duplicate-modifiers.shader_test \ tests/hlsl-for.shader_test \ tests/hlsl-function-overload.shader_test \
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index abf5da91..ff35c09e 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1586,6 +1586,60 @@ static bool intrinsic_clamp(struct hlsl_ctx *ctx, return !!add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_MIN, &max->node, params->args[2], &loc); }
+static bool intrinsic_cross(struct hlsl_ctx *ctx,
const struct parse_initializer *params, struct vkd3d_shader_location loc)
+{
- struct hlsl_ir_swizzle *arg1_swzl1, *arg1_swzl2, *arg2_swzl1, *arg2_swzl2;
- struct hlsl_ir_node *arg1 = params->args[0], *arg2 = params->args[1];
- struct hlsl_ir_node *arg1_cast, *arg2_cast, *mul1_neg;
- struct hlsl_ir_expr *mul1, *mul2;
- struct hlsl_type *cast_type;
- enum hlsl_base_type base;
- if (arg1->data_type->base_type == HLSL_TYPE_HALF && arg2->data_type->base_type == HLSL_TYPE_HALF)
base = HLSL_TYPE_HALF;
- else
base = HLSL_TYPE_FLOAT;
- cast_type = hlsl_get_vector_type(ctx, base, 3);
- if (!(arg1_cast = add_implicit_conversion(ctx, params->instrs, arg1, cast_type, &loc)))
return false;
- if (!(arg2_cast = add_implicit_conversion(ctx, params->instrs, arg2, cast_type, &loc)))
return false;
- if (!(arg1_swzl1 = hlsl_new_swizzle(ctx, HLSL_SWIZZLE(Z, X, Y, Z), 3, arg1_cast, &loc)))
return false;
- list_add_tail(params->instrs, &arg1_swzl1->node.entry);
- if (!(arg2_swzl1 = hlsl_new_swizzle(ctx, HLSL_SWIZZLE(Y, Z, X, Y), 3, arg2_cast, &loc)))
return false;
- list_add_tail(params->instrs, &arg2_swzl1->node.entry);
- if (!(mul1 = add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_MUL,
&arg1_swzl1->node, &arg2_swzl1->node, &loc)))
return false;
- if (!(mul1_neg = hlsl_new_unary_expr(ctx, HLSL_OP1_NEG, &mul1->node, loc)))
return false;
- list_add_tail(params->instrs, &mul1_neg->entry);
- if (!(arg1_swzl2 = hlsl_new_swizzle(ctx, HLSL_SWIZZLE(Y, Z, X, Y), 3, arg1_cast, &loc)))
return false;
- list_add_tail(params->instrs, &arg1_swzl2->node.entry);
- if (!(arg2_swzl2 = hlsl_new_swizzle(ctx, HLSL_SWIZZLE(Z, X, Y, Z), 3, arg2_cast, &loc)))
return false;
- list_add_tail(params->instrs, &arg2_swzl2->node.entry);
- if (!(mul2 = add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_MUL,
&arg1_swzl2->node, &arg2_swzl2->node, &loc)))
return false;
- return !!add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_ADD, &mul2->node, mul1_neg, &loc);
+}
- static bool intrinsic_max(struct hlsl_ctx *ctx, const struct parse_initializer *params, struct vkd3d_shader_location loc) {
@@ -1635,6 +1689,7 @@ intrinsic_functions[] = /* Note: these entries should be kept in alphabetical order. */ {"abs", 1, true, intrinsic_abs}, {"clamp", 3, true, intrinsic_clamp},
- {"cross", 2, true, intrinsic_cross}, {"max", 2, true, intrinsic_max}, {"pow", 2, true, intrinsic_pow}, {"round", 1, true, intrinsic_round},
diff --git a/tests/hlsl-cross.shader_test b/tests/hlsl-cross.shader_test new file mode 100644 index 00000000..101db607 --- /dev/null +++ b/tests/hlsl-cross.shader_test @@ -0,0 +1,28 @@ +[pixel shader] +float4 main(uniform float4 u, uniform float4 v) : sv_target +{
- float4 res = float4(0, 0, 0, 0);
- res.xyz = cross(u, v);
- return res;
+}
+[test] +uniform 0 float4 1 -2 3 4 +uniform 4 float4 10 100 1000 10000 +draw quad +probe all rgba (-2300, -970, 120, 0)
+[pixel shader] +float4 main(uniform float4 u) : sv_target +{
- float4 res = float4(0, 0, 0, 3.5);
- res.xyz = cross(u, 4);
- return res;
+}
+[test] +uniform 0 float4 1 -2 3 4 +draw quad +probe all rgba (-20, 8, 12, 3.5)