[PATCH vkd3d 8/8] vkd3d-shader/hlsl: Support multiplication for all numeric types in fold_constants().
Francisco Casas
fcasas at codeweavers.com
Thu Jan 6 11:39:49 CST 2022
Signed-off-by: Francisco Casas <fcasas at codeweavers.com>
---
libs/vkd3d-shader/hlsl_constant_ops.c | 75 +++++++++++++++------------
1 file changed, 43 insertions(+), 32 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl_constant_ops.c b/libs/vkd3d-shader/hlsl_constant_ops.c
index 2f34a730..b36448de 100644
--- a/libs/vkd3d-shader/hlsl_constant_ops.c
+++ b/libs/vkd3d-shader/hlsl_constant_ops.c
@@ -173,6 +173,43 @@ static int constant_op2_add(struct hlsl_ctx *ctx, struct hlsl_ir_constant *tgt,
return 1;
}
+static int constant_op2_mul(struct hlsl_ctx *ctx, struct hlsl_ir_constant *tgt,
+ struct hlsl_ir_constant *src1, struct hlsl_ir_constant *src2)
+{
+ enum hlsl_base_type type = tgt->node.data_type->base_type;
+ uint32_t u1, u2;
+
+ assert(type == src1->node.data_type->base_type);
+ assert(type == src2->node.data_type->base_type);
+
+ for (int k = 0; k < 4; k++)
+ {
+ switch (type)
+ {
+ case HLSL_TYPE_FLOAT:
+ case HLSL_TYPE_HALF:
+ tgt->value[k].f = src1->value[k].f * src2->value[k].f;
+ break;
+ case HLSL_TYPE_DOUBLE:
+ tgt->value[k].d = src1->value[k].d * src2->value[k].d;
+ break;
+ case HLSL_TYPE_INT:
+ u1 = src1->value[k].i;
+ u2 = src2->value[k].i;
+ tgt->value[k].i = (int32_t)(u1 * u2);
+ break;
+ case HLSL_TYPE_UINT:
+ tgt->value[k].u = src1->value[k].u * src2->value[k].u;
+ break;
+ default:
+ FIXME("Fold \"%s\" for type %s.", debug_hlsl_expr_op(HLSL_OP2_MUL),
+ debug_hlsl_type(ctx, tgt->node.data_type));
+ return 0;
+ }
+ }
+ return 1;
+}
+
bool fold_constants(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
{
struct hlsl_ir_constant *arg1, *arg2 = NULL, *res;
@@ -210,8 +247,13 @@ bool fold_constants(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *cont
case HLSL_OP2_ADD:
success = constant_op2_add(ctx, res, arg1, arg2);
break;
+ case HLSL_OP2_MUL:
+ success = constant_op2_mul(ctx, res, arg1, arg2);
+ break;
default:
- goto fallback;
+ FIXME("Fold op %#x.\n", expr->op);
+ success = 0;
+ break;
}
if (success)
@@ -225,35 +267,4 @@ bool fold_constants(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *cont
vkd3d_free(res);
return false;
}
-
-fallback:
-
- switch (instr->data_type->base_type)
- {
- case HLSL_TYPE_UINT:
- {
- switch (expr->op)
- {
- case HLSL_OP2_MUL:
- for (i = 0; i < instr->data_type->dimx; ++i)
- res->value[i].u = arg1->value[i].u * arg2->value[i].u;
- break;
-
- default:
- FIXME("Fold uint op %#x.\n", expr->op);
- vkd3d_free(res);
- return false;
- }
- break;
- }
-
- default:
- FIXME("Fold type %#x op %#x.\n", instr->data_type->base_type, expr->op);
- vkd3d_free(res);
- return false;
- }
-
- list_add_before(&expr->node.entry, &res->node.entry);
- hlsl_replace_node(&expr->node, &res->node);
- return true;
}
\ No newline at end of file
--
2.25.1
More information about the wine-devel
mailing list