[PATCH vkd3d 5/8] vkd3d-shader/hlsl: Support addition for all numeric types in fold_constants().
Francisco Casas
fcasas at codeweavers.com
Thu Jan 6 11:39:46 CST 2022
Signed-off-by: Francisco Casas <fcasas at codeweavers.com>
---
libs/vkd3d-shader/hlsl_constant_ops.c | 45 ++++++++++++++++++++++++---
1 file changed, 40 insertions(+), 5 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl_constant_ops.c b/libs/vkd3d-shader/hlsl_constant_ops.c
index 3a778837..8279c58b 100644
--- a/libs/vkd3d-shader/hlsl_constant_ops.c
+++ b/libs/vkd3d-shader/hlsl_constant_ops.c
@@ -20,6 +20,43 @@
#include "hlsl.h"
+static int constant_op2_add(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_ADD),
+ 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;
@@ -49,6 +86,9 @@ bool fold_constants(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *cont
switch (expr->op)
{
+ case HLSL_OP2_ADD:
+ success = constant_op2_add(ctx, res, arg1, arg2);
+ break;
default:
goto fallback;
}
@@ -120,11 +160,6 @@ fallback:
res->value[i].u = -arg1->value[i].u;
break;
- case HLSL_OP2_ADD:
- for (i = 0; i < instr->data_type->dimx; ++i)
- res->value[i].u = arg1->value[i].u + arg2->value[i].u;
- break;
-
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;
--
2.25.1
More information about the wine-devel
mailing list