[PATCH vkd3d 6/6] vkd3d-shader/hlsl: Properly compute types of comparison expressions.
Giovanni Mascellani
gmascellani at codeweavers.com
Thu Oct 14 08:37:12 CDT 2021
Signed-off-by: Giovanni Mascellani <gmascellani at codeweavers.com>
---
libs/vkd3d-shader/hlsl.y | 44 ++++++++++++++++++++++++++++++++++------
1 file changed, 38 insertions(+), 6 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y
index baff757e..100aa96f 100644
--- a/libs/vkd3d-shader/hlsl.y
+++ b/libs/vkd3d-shader/hlsl.y
@@ -1077,6 +1077,38 @@ static struct list *add_binary_arithmetic_expr_last(struct hlsl_ctx *ctx, struct
return instrs1;
}
+static struct hlsl_ir_expr *add_binary_comparison_expr(struct hlsl_ctx *ctx, struct list *instrs,
+ enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg1, struct hlsl_ir_node *arg2,
+ struct vkd3d_shader_location *loc)
+{
+ struct hlsl_type *cast_types[HLSL_MAX_OPERANDS], *ret_type;
+ enum hlsl_base_type base = expr_common_base_type(arg1->data_type->base_type, arg2->data_type->base_type);
+ enum hlsl_type_class type;
+ unsigned int dimx, dimy;
+ struct hlsl_ir_node *args[HLSL_MAX_OPERANDS] = {arg1, arg2};
+
+ if (!expr_common_shape(ctx, arg1->data_type, arg2->data_type, loc, &type, &dimx, &dimy))
+ return NULL;
+
+ cast_types[0] = get_numeric_type(ctx, type, base, dimx, dimy);
+ cast_types[1] = cast_types[0];
+ ret_type = get_numeric_type(ctx, type, HLSL_TYPE_BOOL, dimx, dimy);
+
+ return add_expr(ctx, instrs, op, args, cast_types, ret_type, loc);
+}
+
+static struct list *add_binary_comparison_expr_last(struct hlsl_ctx *ctx, struct list *instrs1, struct list *instrs2,
+ enum hlsl_ir_expr_op op, struct vkd3d_shader_location *loc)
+{
+ struct hlsl_ir_node *arg1 = node_from_list(instrs1), *arg2 = node_from_list(instrs2);
+
+ list_move_tail(instrs1, instrs2);
+ vkd3d_free(instrs2);
+ add_binary_comparison_expr(ctx, instrs1, op, arg1, arg2, loc);
+
+ return instrs1;
+}
+
static enum hlsl_ir_expr_op op_from_assignment(enum parse_assign_op op)
{
static const enum hlsl_ir_expr_op ops[] =
@@ -3274,30 +3306,30 @@ relational_expr:
shift_expr
| relational_expr '<' shift_expr
{
- $$ = add_binary_arithmetic_expr_last(ctx, $1, $3, HLSL_OP2_LESS, &@2);
+ $$ = add_binary_comparison_expr_last(ctx, $1, $3, HLSL_OP2_LESS, &@2);
}
| relational_expr '>' shift_expr
{
- $$ = add_binary_arithmetic_expr_last(ctx, $1, $3, HLSL_OP2_GREATER, &@2);
+ $$ = add_binary_comparison_expr_last(ctx, $1, $3, HLSL_OP2_GREATER, &@2);
}
| relational_expr OP_LE shift_expr
{
- $$ = add_binary_arithmetic_expr_last(ctx, $1, $3, HLSL_OP2_LEQUAL, &@2);
+ $$ = add_binary_comparison_expr_last(ctx, $1, $3, HLSL_OP2_LEQUAL, &@2);
}
| relational_expr OP_GE shift_expr
{
- $$ = add_binary_arithmetic_expr_last(ctx, $1, $3, HLSL_OP2_GEQUAL, &@2);
+ $$ = add_binary_comparison_expr_last(ctx, $1, $3, HLSL_OP2_GEQUAL, &@2);
}
equality_expr:
relational_expr
| equality_expr OP_EQ relational_expr
{
- $$ = add_binary_arithmetic_expr_last(ctx, $1, $3, HLSL_OP2_EQUAL, &@2);
+ $$ = add_binary_comparison_expr_last(ctx, $1, $3, HLSL_OP2_EQUAL, &@2);
}
| equality_expr OP_NE relational_expr
{
- $$ = add_binary_arithmetic_expr_last(ctx, $1, $3, HLSL_OP2_NEQUAL, &@2);
+ $$ = add_binary_comparison_expr_last(ctx, $1, $3, HLSL_OP2_NEQUAL, &@2);
}
bitand_expr:
--
2.33.0
More information about the wine-devel
mailing list