Zebediah Figura : vkd3d-shader: Fold redundant casts between scalars and 1-dimensional vectors.

Alexandre Julliard julliard at winehq.org
Wed Mar 17 16:19:09 CDT 2021


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

Author: Zebediah Figura <zfigura at codeweavers.com>
Date:   Tue Mar 16 16:31:56 2021 -0500

vkd3d-shader: Fold redundant casts between scalars and 1-dimensional vectors.

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_codegen.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c
index 2df88f5..283a67e 100644
--- a/libs/vkd3d-shader/hlsl_codegen.c
+++ b/libs/vkd3d-shader/hlsl_codegen.c
@@ -57,13 +57,24 @@ static void replace_node(struct hlsl_ir_node *old, struct hlsl_ir_node *new)
     hlsl_free_instr(old);
 }
 
+static bool is_vec1(const struct hlsl_type *type)
+{
+    return (type->type == HLSL_CLASS_SCALAR) || (type->type == HLSL_CLASS_VECTOR && type->dimx == 1);
+}
+
 static bool fold_redundant_casts(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
 {
     if (instr->type == HLSL_IR_EXPR)
     {
         struct hlsl_ir_expr *expr = hlsl_ir_expr(instr);
+        const struct hlsl_type *src_type = expr->operands[0].node->data_type;
+        const struct hlsl_type *dst_type = expr->node.data_type;
+
+        if (expr->op != HLSL_IR_UNOP_CAST)
+            return false;
 
-        if (expr->op == HLSL_IR_UNOP_CAST && hlsl_type_compare(expr->node.data_type, expr->operands[0].node->data_type))
+        if (hlsl_type_compare(src_type, dst_type)
+                || (src_type->base_type == dst_type->base_type && is_vec1(src_type) && is_vec1(dst_type)))
         {
             replace_node(&expr->node, expr->operands[0].node);
             return true;




More information about the wine-cvs mailing list