[PATCH vkd3d v2 8/9] vkd3d-shader/hlsl: Fold constant not-equal expressions.

Giovanni Mascellani gmascellani at codeweavers.com
Mon Mar 28 03:59:13 CDT 2022


Signed-off-by: Giovanni Mascellani <gmascellani at codeweavers.com>
--
v2:
 * Use unsigned int for iteration
 * Do not uselessly store the bool type in a variable
 * Assert (instead of emitting an error) when there is a type inconsistency
---
 libs/vkd3d-shader/hlsl_constant_ops.c | 41 +++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/libs/vkd3d-shader/hlsl_constant_ops.c b/libs/vkd3d-shader/hlsl_constant_ops.c
index 87b5bc90..e282dbd4 100644
--- a/libs/vkd3d-shader/hlsl_constant_ops.c
+++ b/libs/vkd3d-shader/hlsl_constant_ops.c
@@ -223,6 +223,43 @@ static bool fold_mul(struct hlsl_ctx *ctx, struct hlsl_ir_constant *dst,
     return true;
 }
 
+static bool fold_nequal(struct hlsl_ctx *ctx, struct hlsl_ir_constant *dst,
+        struct hlsl_ir_constant *src1, struct hlsl_ir_constant *src2)
+{
+    unsigned int k;
+
+    assert(dst->node.data_type->base_type == HLSL_TYPE_BOOL);
+    assert(src1->node.data_type->base_type == src2->node.data_type->base_type);
+
+    for (k = 0; k < 4; ++k)
+    {
+        switch (src1->node.data_type->base_type)
+        {
+            case HLSL_TYPE_FLOAT:
+            case HLSL_TYPE_HALF:
+                dst->value[k].u = src1->value[k].f != src2->value[k].f;
+                break;
+
+            case HLSL_TYPE_DOUBLE:
+                dst->value[k].u = src1->value[k].d != src2->value[k].d;
+                break;
+
+            case HLSL_TYPE_INT:
+            case HLSL_TYPE_UINT:
+            case HLSL_TYPE_BOOL:
+                dst->value[k].u = src1->value[k].u != src2->value[k].u;
+                break;
+
+            default:
+                assert(0);
+                return false;
+        }
+
+        dst->value[k].u *= ~0u;
+    }
+    return true;
+}
+
 bool hlsl_fold_constants(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
 {
     struct hlsl_ir_constant *arg1, *arg2 = NULL, *res;
@@ -272,6 +309,10 @@ bool hlsl_fold_constants(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void
             success = fold_mul(ctx, res, arg1, arg2);
             break;
 
+        case HLSL_OP2_NEQUAL:
+            success = fold_nequal(ctx, res, arg1, arg2);
+            break;
+
         default:
             FIXME("Fold \"%s\" expression.\n", debug_hlsl_expr_op(expr->op));
             success = false;
-- 
2.35.1




More information about the wine-devel mailing list