Giovanni Mascellani : vkd3d-shader/hlsl: Do not cast types in add_expr.

Alexandre Julliard julliard at winehq.org
Mon Nov 1 16:33:18 CDT 2021


Module: vkd3d
Branch: master
Commit: 6658da886178d8e80982eb186b99bb61fa3238a2
URL:    https://source.winehq.org/git/vkd3d.git/?a=commit;h=6658da886178d8e80982eb186b99bb61fa3238a2

Author: Giovanni Mascellani <gmascellani at codeweavers.com>
Date:   Fri Oct 15 10:37:03 2021 +0200

vkd3d-shader/hlsl: Do not cast types in add_expr.

Determining cast types and return type is now delegated to higher level
helpers, which are differentiated according to the operation category.

Signed-off-by: Giovanni Mascellani <gmascellani at codeweavers.com>
Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 libs/vkd3d-shader/hlsl.y | 51 +++---------------------------------------------
 1 file changed, 3 insertions(+), 48 deletions(-)

diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y
index b785c88..528a122 100644
--- a/libs/vkd3d-shader/hlsl.y
+++ b/libs/vkd3d-shader/hlsl.y
@@ -996,57 +996,12 @@ static bool expr_common_shape(struct hlsl_ctx *ctx, struct hlsl_type *t1, struct
     return true;
 }
 
-static struct hlsl_type *expr_common_type(struct hlsl_ctx *ctx, struct hlsl_type *t1, struct hlsl_type *t2,
-        struct vkd3d_shader_location *loc)
-{
-    enum hlsl_type_class type;
-    enum hlsl_base_type base;
-    unsigned int dimx, dimy;
-
-    if (!expr_common_shape(ctx, t1, t2, loc, &type, &dimx, &dimy))
-        return NULL;
-
-    base = expr_common_base_type(t1->base_type, t2->base_type);
-
-    return hlsl_get_numeric_type(ctx, type, base, dimx, dimy);
-}
-
 static struct hlsl_ir_expr *add_expr(struct hlsl_ctx *ctx, struct list *instrs, enum hlsl_ir_expr_op op,
-        struct hlsl_ir_node *operands[HLSL_MAX_OPERANDS], struct vkd3d_shader_location *loc)
+        struct hlsl_ir_node *operands[HLSL_MAX_OPERANDS], struct hlsl_type *type, struct vkd3d_shader_location *loc)
 {
     struct hlsl_ir_expr *expr;
-    struct hlsl_type *type;
     unsigned int i;
 
-    type = operands[0]->data_type;
-    for (i = 1; i < HLSL_MAX_OPERANDS; ++i)
-    {
-        if (!operands[i])
-            break;
-        type = expr_common_type(ctx, type, operands[i]->data_type, loc);
-        if (!type)
-            return NULL;
-    }
-    for (i = 0; i < HLSL_MAX_OPERANDS; ++i)
-    {
-        struct hlsl_ir_expr *cast;
-
-        if (!operands[i])
-            break;
-        if (hlsl_types_are_equal(operands[i]->data_type, type))
-            continue;
-        if (operands[i]->data_type->dimx * operands[i]->data_type->dimy != 1
-                && operands[i]->data_type->dimx * operands[i]->data_type->dimy != type->dimx * type->dimy)
-            hlsl_warning(ctx, operands[i]->loc, VKD3D_SHADER_WARNING_HLSL_IMPLICIT_TRUNCATION,
-                    "Implicit truncation of %s type.",
-                    operands[i]->data_type->type == HLSL_CLASS_VECTOR ? "vector" : "matrix");
-
-        if (!(cast = hlsl_new_cast(ctx, operands[i], type, &operands[i]->loc)))
-            return NULL;
-        list_add_after(&operands[i]->entry, &cast->node.entry);
-        operands[i] = &cast->node;
-    }
-
     if (!(expr = hlsl_alloc(ctx, sizeof(*expr))))
         return NULL;
     init_node(&expr->node, HLSL_IR_EXPR, type, *loc);
@@ -1063,7 +1018,7 @@ static struct hlsl_ir_expr *add_unary_arithmetic_expr(struct hlsl_ctx *ctx, stru
 {
     struct hlsl_ir_node *args[HLSL_MAX_OPERANDS] = {arg};
 
-    return add_expr(ctx, instrs, op, args, loc);
+    return add_expr(ctx, instrs, op, args, arg->data_type, loc);
 }
 
 static struct hlsl_ir_expr *add_binary_arithmetic_expr(struct hlsl_ctx *ctx, struct list *instrs,
@@ -1087,7 +1042,7 @@ static struct hlsl_ir_expr *add_binary_arithmetic_expr(struct hlsl_ctx *ctx, str
     if (!(args[1] = add_implicit_conversion(ctx, instrs, arg2, common_type, loc)))
         return NULL;
 
-    return add_expr(ctx, instrs, op, args, loc);
+    return add_expr(ctx, instrs, op, args, common_type, loc);
 }
 
 static struct list *add_binary_arithmetic_expr_merge(struct hlsl_ctx *ctx, struct list *list1, struct list *list2,




More information about the wine-cvs mailing list