[PATCH vkd3d 4/8] vkd3d-shader/hlsl: Prepare to swap switch order on fold_constants().

Francisco Casas fcasas at codeweavers.com
Thu Jan 6 11:39:45 CST 2022


Signed-off-by: Francisco Casas <fcasas at codeweavers.com>

---

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 <fcasas at codeweavers.com>
---
 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




More information about the wine-devel mailing list