Giovanni Mascellani : vkd3d-shader/hlsl: Fold constant integral min().

Alexandre Julliard julliard at winehq.org
Tue Jun 28 15:52:45 CDT 2022


Module: vkd3d
Branch: master
Commit: 4a692dca4e53dcf90b0e0694cc5bf4f5fe7080d3
URL:    https://source.winehq.org/git/vkd3d.git/?a=commit;h=4a692dca4e53dcf90b0e0694cc5bf4f5fe7080d3

Author: Giovanni Mascellani <gmascellani at codeweavers.com>
Date:   Mon Jun 27 17:22:40 2022 +0200

vkd3d-shader/hlsl: Fold constant integral min().

Signed-off-by: Giovanni Mascellani <gmascellani at codeweavers.com>
Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 libs/vkd3d-shader/hlsl_constant_ops.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/libs/vkd3d-shader/hlsl_constant_ops.c b/libs/vkd3d-shader/hlsl_constant_ops.c
index 95bed02a..01f394b8 100644
--- a/libs/vkd3d-shader/hlsl_constant_ops.c
+++ b/libs/vkd3d-shader/hlsl_constant_ops.c
@@ -398,6 +398,35 @@ static bool fold_max(struct hlsl_ctx *ctx, struct hlsl_ir_constant *dst,
     return true;
 }
 
+static bool fold_min(struct hlsl_ctx *ctx, struct hlsl_ir_constant *dst,
+        struct hlsl_ir_constant *src1, struct hlsl_ir_constant *src2)
+{
+    enum hlsl_base_type type = dst->node.data_type->base_type;
+    unsigned int k;
+
+    assert(type == src1->node.data_type->base_type);
+    assert(type == src2->node.data_type->base_type);
+
+    for (k = 0; k < dst->node.data_type->dimx; ++k)
+    {
+        switch (type)
+        {
+            case HLSL_TYPE_INT:
+                dst->value[k].i = min(src1->value[k].i, src2->value[k].i);
+                break;
+
+            case HLSL_TYPE_UINT:
+                dst->value[k].u = min(src1->value[k].u, src2->value[k].u);
+                break;
+
+            default:
+                FIXME("Fold min for type %s.\n", debug_hlsl_type(ctx, dst->node.data_type));
+                return false;
+        }
+    }
+    return true;
+}
+
 bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
 {
     struct hlsl_ir_constant *arg1, *arg2 = NULL, *res;
@@ -463,6 +492,10 @@ bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr,
             success = fold_max(ctx, res, arg1, arg2);
             break;
 
+        case HLSL_OP2_MIN:
+            success = fold_min(ctx, res, arg1, arg2);
+            break;
+
         default:
             FIXME("Fold \"%s\" expression.\n", debug_hlsl_expr_op(expr->op));
             success = false;




More information about the wine-cvs mailing list