From: Francisco Casas Subject: [PATCH vkd3d 4/8] vkd3d-shader/hlsl: Prepare to swap switch order on fold_constants(). Message-Id: <20220106173949.82958-4-fcasas@codeweavers.com> Date: Thu, 6 Jan 2022 14:39:45 -0300 Signed-off-by: Francisco Casas --- Don't mind about the 'goto fallback' too much, it is used transitionally so that the tests still pass. It is removed in later patches. Signed-off-by: Francisco Casas --- libs/vkd3d-shader/hlsl_constant_ops.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/libs/vkd3d-shader/hlsl_constant_ops.c b/libs/vkd3d-shader/hlsl_constant_ops.c index 924e0380..3a778837 100644 --- a/libs/vkd3d-shader/hlsl_constant_ops.c +++ b/libs/vkd3d-shader/hlsl_constant_ops.c @@ -25,6 +25,7 @@ bool fold_constants(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *cont struct hlsl_ir_constant *arg1, *arg2 = NULL, *res; struct hlsl_ir_expr *expr; unsigned int i, dimx; + bool success; if (instr->type != HLSL_IR_EXPR) return false; @@ -44,6 +45,28 @@ bool fold_constants(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *cont return false; init_node(&res->node, HLSL_IR_CONSTANT, instr->data_type, instr->loc); + success = false; + + switch (expr->op) + { + default: + goto fallback; + } + + if (success) + { + list_add_before(&expr->node.entry, &res->node.entry); + hlsl_replace_node(&expr->node, &res->node); + return true; + } + else + { + vkd3d_free(res); + return false; + } + +fallback: + switch (instr->data_type->base_type) { case HLSL_TYPE_FLOAT: -- 2.25.1