From 5f66257b8b79da142489495f65e9d1b57e0e54a4 Mon Sep 17 00:00:00 2001 From: Zebediah Figura Date: Tue, 9 Mar 2021 19:42:46 -0600 Subject: [PATCH] vkd3d-shader: Don't use assignment instructions as sources. Signed-off-by: Zebediah Figura Signed-off-by: Matteo Bruni Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- libs/vkd3d-shader/hlsl.y | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index ce4bd626..a9c9dd02 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1261,6 +1261,7 @@ static struct hlsl_ir_node *add_assignment(struct hlsl_ctx *ctx, struct list *in { struct hlsl_ir_assignment *assign; struct hlsl_type *lhs_type; + struct hlsl_ir_expr *copy; DWORD writemask = 0; lhs_type = lhs->data_type; @@ -1321,7 +1322,7 @@ static struct hlsl_ir_node *add_assignment(struct hlsl_ctx *ctx, struct list *in lhs = lhs_inner; } - init_node(&assign->node, HLSL_IR_ASSIGNMENT, lhs_type, lhs->loc); + init_node(&assign->node, HLSL_IR_ASSIGNMENT, NULL, lhs->loc); assign->writemask = writemask; assign->lhs.var = hlsl_ir_load(lhs)->src.var; hlsl_src_from_node(&assign->lhs.offset, hlsl_ir_load(lhs)->src.offset.node); @@ -1337,7 +1338,14 @@ static struct hlsl_ir_node *add_assignment(struct hlsl_ctx *ctx, struct list *in hlsl_src_from_node(&assign->rhs, rhs); list_add_tail(instrs, &assign->node.entry); - return &assign->node; + /* Don't use the instruction itself as a source, as this makes structure + * splitting easier. Instead copy it here. Since we retrieve sources from + * the last instruction in the list, we do need to copy. Use a cast + * instruction to the same type as a makeshift identity expression. */ + if (!(copy = hlsl_new_cast(rhs, rhs->data_type, &lhs->loc))) + return NULL; + list_add_tail(instrs, ©->node.entry); + return ©->node; } static void struct_var_initializer(struct hlsl_ctx *ctx, struct list *list, struct hlsl_ir_var *var,