Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com --- v2: * Fixed test case for SM1 --- Makefile.am | 1 + tests/hlsl-dot.shader_test | 96 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 tests/hlsl-dot.shader_test
diff --git a/Makefile.am b/Makefile.am index ad6a0a41..400e79e1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -68,6 +68,7 @@ vkd3d_shader_tests = \ tests/hlsl-clamp.shader_test \ tests/hlsl-comma.shader_test \ tests/hlsl-cross.shader_test \ + tests/hlsl-dot.shader_test \ tests/hlsl-duplicate-modifiers.shader_test \ tests/hlsl-for.shader_test \ tests/hlsl-function.shader_test \ diff --git a/tests/hlsl-dot.shader_test b/tests/hlsl-dot.shader_test new file mode 100644 index 00000000..cb117d15 --- /dev/null +++ b/tests/hlsl-dot.shader_test @@ -0,0 +1,96 @@ +[pixel shader] +uniform float4 x; +uniform float4 y; + +float4 main() : SV_TARGET +{ + return dot(x, y); +} + +[test] +uniform 0 float4 2.0 3.0 4.0 5.0 +uniform 4 float4 10.0 11.0 12.0 13.0 +todo draw quad +probe all rgba (166.0, 166.0, 166.0, 166.0) + +[pixel shader] +uniform float2 x; +uniform float4 y; + +float4 main() : SV_TARGET +{ + return dot(x, y); +} + +[test] +uniform 0 float4 2.0 3.0 0.0 0.0 +uniform 4 float4 10.0 11.0 12.0 13.0 +todo draw quad +probe all rgba (53.0, 53.0, 53.0, 53.0) + +[pixel shader] +uniform float x; +uniform float4 y; + +float4 main() : SV_TARGET +{ + return dot(x, y); +} + +[test] +uniform 0 float4 2.0 0.0 0.0 0.0 +uniform 4 float4 10.0 11.0 12.0 13.0 +todo draw quad +probe all rgba (92.0, 92.0, 92.0, 92.0) + +[pixel shader] +uniform float x; +uniform float y; + +float4 main() : SV_TARGET +{ + return dot(x, y); +} + +[test] +% Account for both the SM1 and SM4 uniform layout +uniform 0 float4 2.0 3.0 0.0 0.0 +uniform 4 float4 3.0 0.0 0.0 0.0 +todo draw quad +probe all rgba (6.0, 6.0, 6.0, 6.0) + +[pixel shader fail] +uniform float1x1 x; +uniform float4 y; + +float4 main() : SV_TARGET +{ + return dot(x, y); +} + +[pixel shader fail] +uniform float1x4 x; +uniform float4 y; + +float4 main() : SV_TARGET +{ + return dot(x, y); +} + +[pixel shader fail] +uniform float4x1 x; +uniform float4 y; + +float4 main() : SV_TARGET +{ + return dot(x, y); +} + +[pixel shader fail] +uniform float4x4 x; +uniform float4 y; + +float4 main() : SV_TARGET +{ + return dot(x, y); +}
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com --- Makefile.am | 1 + tests/hlsl-ldexp.shader_test | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 tests/hlsl-ldexp.shader_test
diff --git a/Makefile.am b/Makefile.am index 400e79e1..ff900a6c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -88,6 +88,7 @@ vkd3d_shader_tests = \ tests/hlsl-initializer-struct.shader_test \ tests/hlsl-intrinsic-override.shader_test \ tests/hlsl-invalid.shader_test \ + tests/hlsl-ldexp.shader_test \ tests/hlsl-majority-pragma.shader_test \ tests/hlsl-majority-typedef.shader_test \ tests/hlsl-matrix-indexing.shader_test \ diff --git a/tests/hlsl-ldexp.shader_test b/tests/hlsl-ldexp.shader_test new file mode 100644 index 00000000..46b87a38 --- /dev/null +++ b/tests/hlsl-ldexp.shader_test @@ -0,0 +1,32 @@ +[pixel shader] +uniform float4 x; +uniform float4 y; + +float4 main() : SV_TARGET +{ + return ldexp(x, y); +} + +[test] +uniform 0 float4 2.0 3.0 4.0 5.0 +uniform 4 float4 0.0 -10.0 10.0 100.0 +todo draw quad +probe all rgba (2.0, 0.00292968750, 4096.0, 6.33825300e+030) + +[require] +shader model >= 4.0 + +[pixel shader] +uniform int4 x; +uniform int4 y; + +float4 main() : SV_TARGET +{ + return ldexp(x, y); +} + +[test] +uniform 0 int4 2 3 4 5 +uniform 4 int4 0 -10 10 100 +todo draw quad +probe all rgba (2.0, 0.00292968750, 4096.0, 6.33825300e+030)
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com --- Makefile.am | 1 + tests/hlsl-lerp.shader_test | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 tests/hlsl-lerp.shader_test
diff --git a/Makefile.am b/Makefile.am index ff900a6c..0cb90b2b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -89,6 +89,7 @@ vkd3d_shader_tests = \ tests/hlsl-intrinsic-override.shader_test \ tests/hlsl-invalid.shader_test \ tests/hlsl-ldexp.shader_test \ + tests/hlsl-lerp.shader_test \ tests/hlsl-majority-pragma.shader_test \ tests/hlsl-majority-typedef.shader_test \ tests/hlsl-matrix-indexing.shader_test \ diff --git a/tests/hlsl-lerp.shader_test b/tests/hlsl-lerp.shader_test new file mode 100644 index 00000000..a472379b --- /dev/null +++ b/tests/hlsl-lerp.shader_test @@ -0,0 +1,36 @@ +[pixel shader] +uniform float4 x; +uniform float4 y; +uniform float4 s; + +float4 main() : SV_TARGET +{ + return lerp(x, y, s); +} + +[test] +uniform 0 float4 2.0 3.0 4.0 5.0 +uniform 4 float4 0.0 -10.0 10.0 100.0 +uniform 8 float4 0.0 1.0 -1.0 0.75 +todo draw quad +probe all rgba (2.0, -10.0, -2.0, 76.25) + +[require] +shader model >= 4.0 + +[pixel shader] +uniform int4 x; +uniform int4 y; +uniform int4 s; + +float4 main() : SV_TARGET +{ + return lerp(x, y, s); +} + +[test] +uniform 0 int4 2 3 4 0 +uniform 4 int4 0 -10 10 1000000 +uniform 8 int4 0 1 -1 1000000 +todo draw quad +probe all rgba (2.0, -10.0, -2.0, 1e12)
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com --- libs/vkd3d-shader/hlsl.y | 62 ++++++++++++++++++++++++++++++++++++++ tests/hlsl-dot.shader_test | 2 +- 2 files changed, 63 insertions(+), 1 deletion(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index df5fda47..391cf890 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1516,6 +1516,61 @@ static struct list *add_binary_shift_expr_merge(struct hlsl_ctx *ctx, struct lis return list1; }
+static struct hlsl_ir_node *add_binary_dot_expr(struct hlsl_ctx *ctx, struct list *instrs, + struct hlsl_ir_node *arg1, struct hlsl_ir_node *arg2, const struct vkd3d_shader_location *loc) +{ + enum hlsl_base_type base = expr_common_base_type(arg1->data_type->base_type, arg2->data_type->base_type); + struct hlsl_ir_node *args[HLSL_MAX_OPERANDS] = {0}; + struct hlsl_type *common_type, *ret_type; + enum hlsl_ir_expr_op op; + unsigned dim; + + if (arg1->data_type->type == HLSL_CLASS_MATRIX) + { + struct vkd3d_string_buffer *string; + + if ((string = hlsl_type_to_string(ctx, arg1->data_type))) + hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE, + "Invalid type %s.\n", string->buffer); + hlsl_release_string_buffer(ctx, string); + return NULL; + } + + if (arg2->data_type->type == HLSL_CLASS_MATRIX) + { + struct vkd3d_string_buffer *string; + + if ((string = hlsl_type_to_string(ctx, arg2->data_type))) + hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE, + "Invalid type %s.\n", string->buffer); + hlsl_release_string_buffer(ctx, string); + return NULL; + } + + if (arg1->data_type->type == HLSL_CLASS_SCALAR) + dim = arg2->data_type->dimx; + else if (arg1->data_type->type == HLSL_CLASS_SCALAR) + dim = arg1->data_type->dimx; + else + dim = min(arg1->data_type->dimx, arg2->data_type->dimx); + + if (dim == 1) + op = HLSL_OP2_MUL; + else + op = HLSL_OP2_DOT; + + common_type = hlsl_get_vector_type(ctx, base, dim); + ret_type = hlsl_get_scalar_type(ctx, base); + + if (!(args[0] = add_implicit_conversion(ctx, instrs, arg1, common_type, loc))) + return NULL; + + if (!(args[1] = add_implicit_conversion(ctx, instrs, arg2, common_type, loc))) + return NULL; + + return add_expr(ctx, instrs, op, args, ret_type, loc); +} + static enum hlsl_ir_expr_op op_from_assignment(enum parse_assign_op op) { static const enum hlsl_ir_expr_op ops[] = @@ -2023,6 +2078,12 @@ static bool intrinsic_cross(struct hlsl_ctx *ctx, return !!add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_ADD, mul2, mul1_neg, loc); }
+static bool intrinsic_dot(struct hlsl_ctx *ctx, + const struct parse_initializer *params, const struct vkd3d_shader_location *loc) +{ + return !!add_binary_dot_expr(ctx, params->instrs, params->args[0], params->args[1], loc); +} + static bool intrinsic_floor(struct hlsl_ctx *ctx, const struct parse_initializer *params, const struct vkd3d_shader_location *loc) { @@ -2220,6 +2281,7 @@ intrinsic_functions[] = {"abs", 1, true, intrinsic_abs}, {"clamp", 3, true, intrinsic_clamp}, {"cross", 2, true, intrinsic_cross}, + {"dot", 2, true, intrinsic_dot}, {"floor", 1, true, intrinsic_floor}, {"max", 2, true, intrinsic_max}, {"min", 2, true, intrinsic_min}, diff --git a/tests/hlsl-dot.shader_test b/tests/hlsl-dot.shader_test index cb117d15..74a85ca0 100644 --- a/tests/hlsl-dot.shader_test +++ b/tests/hlsl-dot.shader_test @@ -56,7 +56,7 @@ float4 main() : SV_TARGET % Account for both the SM1 and SM4 uniform layout uniform 0 float4 2.0 3.0 0.0 0.0 uniform 4 float4 3.0 0.0 0.0 0.0 -todo draw quad +draw quad probe all rgba (6.0, 6.0, 6.0, 6.0)
[pixel shader fail]
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com --- libs/vkd3d-shader/hlsl_sm4.c | 51 ++++++++++++++++++++++++++++++++++++ tests/hlsl-dot.shader_test | 6 ++--- 2 files changed, 54 insertions(+), 3 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl_sm4.c b/libs/vkd3d-shader/hlsl_sm4.c index a6ac2aa3..79027169 100644 --- a/libs/vkd3d-shader/hlsl_sm4.c +++ b/libs/vkd3d-shader/hlsl_sm4.c @@ -1314,6 +1314,25 @@ static void write_sm4_binary_op(struct vkd3d_bytecode_buffer *buffer, enum vkd3d write_sm4_instruction(buffer, &instr); }
+/* dp# instructions don't map the swizzle. */ +static void write_sm4_binary_op_dot(struct vkd3d_bytecode_buffer *buffer, enum vkd3d_sm4_opcode opcode, + const struct hlsl_ir_node *dst, const struct hlsl_ir_node *src1, const struct hlsl_ir_node *src2) +{ + struct sm4_instruction instr; + + memset(&instr, 0, sizeof(instr)); + instr.opcode = opcode; + + sm4_dst_from_node(&instr.dsts[0], dst); + instr.dst_count = 1; + + sm4_src_from_node(&instr.srcs[0], src1, VKD3DSP_WRITEMASK_ALL); + sm4_src_from_node(&instr.srcs[1], src2, VKD3DSP_WRITEMASK_ALL); + instr.src_count = 2; + + write_sm4_instruction(buffer, &instr); +} + static void write_sm4_binary_op_with_two_destinations(struct vkd3d_bytecode_buffer *buffer, enum vkd3d_sm4_opcode opcode, const struct hlsl_ir_node *dst, unsigned dst_idx, const struct hlsl_ir_node *src1, const struct hlsl_ir_node *src2) @@ -1679,6 +1698,38 @@ static void write_sm4_expr(struct hlsl_ctx *ctx, } break;
+ case HLSL_OP2_DOT: + switch (dst_type->base_type) + { + case HLSL_TYPE_FLOAT: + switch (arg1->data_type->dimx) + { + case 4: + write_sm4_binary_op_dot(buffer, VKD3D_SM4_OP_DP4, &expr->node, arg1, arg2); + break; + + case 3: + write_sm4_binary_op_dot(buffer, VKD3D_SM4_OP_DP3, &expr->node, arg1, arg2); + break; + + case 2: + write_sm4_binary_op_dot(buffer, VKD3D_SM4_OP_DP2, &expr->node, arg1, arg2); + break; + + case 1: + assert(0); + break; + + default: + assert(0); + } + break; + + default: + hlsl_fixme(ctx, &expr->node.loc, "SM4 %s dot expression.", dst_type_string->buffer); + } + break; + case HLSL_OP2_EQUAL: { const struct hlsl_type *src_type = arg1->data_type; diff --git a/tests/hlsl-dot.shader_test b/tests/hlsl-dot.shader_test index 74a85ca0..a83c2488 100644 --- a/tests/hlsl-dot.shader_test +++ b/tests/hlsl-dot.shader_test @@ -10,7 +10,7 @@ float4 main() : SV_TARGET [test] uniform 0 float4 2.0 3.0 4.0 5.0 uniform 4 float4 10.0 11.0 12.0 13.0 -todo draw quad +draw quad probe all rgba (166.0, 166.0, 166.0, 166.0)
[pixel shader] @@ -25,7 +25,7 @@ float4 main() : SV_TARGET [test] uniform 0 float4 2.0 3.0 0.0 0.0 uniform 4 float4 10.0 11.0 12.0 13.0 -todo draw quad +draw quad probe all rgba (53.0, 53.0, 53.0, 53.0)
[pixel shader] @@ -40,7 +40,7 @@ float4 main() : SV_TARGET [test] uniform 0 float4 2.0 0.0 0.0 0.0 uniform 4 float4 10.0 11.0 12.0 13.0 -todo draw quad +draw quad probe all rgba (92.0, 92.0, 92.0, 92.0)
[pixel shader]
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
From: Zebediah Figura zfigura@codeweavers.com
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com --- libs/vkd3d-shader/hlsl.y | 15 +++++++++++++++ tests/hlsl-ldexp.shader_test | 4 ++-- 2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 391cf890..7469b525 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -2095,6 +2095,20 @@ static bool intrinsic_floor(struct hlsl_ctx *ctx, return !!add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_FLOOR, arg, loc); }
+static bool intrinsic_ldexp(struct hlsl_ctx *ctx, + const struct parse_initializer *params, const struct vkd3d_shader_location *loc) +{ + struct hlsl_ir_node *arg; + + if (!(arg = intrinsic_float_convert_arg(ctx, params, params->args[1], loc))) + return false; + + if (!(arg = add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_EXP2, arg, loc))) + return false; + + return !!add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_MUL, params->args[0], arg, loc); +} + static bool intrinsic_max(struct hlsl_ctx *ctx, const struct parse_initializer *params, const struct vkd3d_shader_location *loc) { @@ -2283,6 +2297,7 @@ intrinsic_functions[] = {"cross", 2, true, intrinsic_cross}, {"dot", 2, true, intrinsic_dot}, {"floor", 1, true, intrinsic_floor}, + {"ldexp", 2, true, intrinsic_ldexp}, {"max", 2, true, intrinsic_max}, {"min", 2, true, intrinsic_min}, {"mul", 2, true, intrinsic_mul}, diff --git a/tests/hlsl-ldexp.shader_test b/tests/hlsl-ldexp.shader_test index 46b87a38..0873fc9e 100644 --- a/tests/hlsl-ldexp.shader_test +++ b/tests/hlsl-ldexp.shader_test @@ -10,7 +10,7 @@ float4 main() : SV_TARGET [test] uniform 0 float4 2.0 3.0 4.0 5.0 uniform 4 float4 0.0 -10.0 10.0 100.0 -todo draw quad +draw quad probe all rgba (2.0, 0.00292968750, 4096.0, 6.33825300e+030)
[require] @@ -28,5 +28,5 @@ float4 main() : SV_TARGET [test] uniform 0 int4 2 3 4 5 uniform 4 int4 0 -10 10 100 -todo draw quad +draw quad probe all rgba (2.0, 0.00292968750, 4096.0, 6.33825300e+030)
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com --- libs/vkd3d-shader/hlsl.y | 21 +++++++++++++++++++++ tests/hlsl-lerp.shader_test | 4 ++-- 2 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 7469b525..09a01c6d 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -2109,6 +2109,26 @@ static bool intrinsic_ldexp(struct hlsl_ctx *ctx, return !!add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_MUL, params->args[0], arg, loc); }
+static bool intrinsic_lerp(struct hlsl_ctx *ctx, + const struct parse_initializer *params, const struct vkd3d_shader_location *loc) +{ + struct hlsl_ir_node *arg, *neg, *add, *mul; + + if (!(arg = intrinsic_float_convert_arg(ctx, params, params->args[0], loc))) + return false; + + if (!(neg = add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_NEG, arg, loc))) + return false; + + if (!(add = add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_ADD, params->args[1], neg, loc))) + return false; + + if (!(mul = add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_MUL, params->args[2], add, loc))) + return false; + + return !!add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_ADD, arg, mul, loc); +} + static bool intrinsic_max(struct hlsl_ctx *ctx, const struct parse_initializer *params, const struct vkd3d_shader_location *loc) { @@ -2298,6 +2318,7 @@ intrinsic_functions[] = {"dot", 2, true, intrinsic_dot}, {"floor", 1, true, intrinsic_floor}, {"ldexp", 2, true, intrinsic_ldexp}, + {"lerp", 3, true, intrinsic_lerp}, {"max", 2, true, intrinsic_max}, {"min", 2, true, intrinsic_min}, {"mul", 2, true, intrinsic_mul}, diff --git a/tests/hlsl-lerp.shader_test b/tests/hlsl-lerp.shader_test index a472379b..3f93b02d 100644 --- a/tests/hlsl-lerp.shader_test +++ b/tests/hlsl-lerp.shader_test @@ -12,7 +12,7 @@ float4 main() : SV_TARGET uniform 0 float4 2.0 3.0 4.0 5.0 uniform 4 float4 0.0 -10.0 10.0 100.0 uniform 8 float4 0.0 1.0 -1.0 0.75 -todo draw quad +draw quad probe all rgba (2.0, -10.0, -2.0, 76.25)
[require] @@ -32,5 +32,5 @@ float4 main() : SV_TARGET uniform 0 int4 2 3 4 0 uniform 4 int4 0 -10 10 1000000 uniform 8 int4 0 1 -1 1000000 -todo draw quad +draw quad probe all rgba (2.0, -10.0, -2.0, 1e12)
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com