Module: vkd3d Branch: master Commit: 488af1414431692eb16b1b43701db739198f9f15 URL: https://gitlab.winehq.org/wine/vkd3d/-/commit/488af1414431692eb16b1b43701db7...
Author: Giovanni Mascellani gmascellani@codeweavers.com Date: Fri Jun 9 22:23:40 2023 +0200
vkd3d-shader/hlsl: Fold equality comparisons.
---
libs/vkd3d-shader/hlsl_constant_ops.c | 40 +++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)
diff --git a/libs/vkd3d-shader/hlsl_constant_ops.c b/libs/vkd3d-shader/hlsl_constant_ops.c index 1ae338fe..6ba059fa 100644 --- a/libs/vkd3d-shader/hlsl_constant_ops.c +++ b/libs/vkd3d-shader/hlsl_constant_ops.c @@ -370,6 +370,42 @@ static bool fold_div(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, cons return true; }
+static bool fold_equal(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, const struct hlsl_type *dst_type, + const struct hlsl_ir_constant *src1, const struct hlsl_ir_constant *src2) +{ + unsigned int k; + + assert(dst_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->u[k].u = src1->value.u[k].f == src2->value.u[k].f; + break; + + case HLSL_TYPE_DOUBLE: + dst->u[k].u = src1->value.u[k].d == src2->value.u[k].d; + break; + + case HLSL_TYPE_INT: + case HLSL_TYPE_UINT: + case HLSL_TYPE_BOOL: + dst->u[k].u = src1->value.u[k].u == src2->value.u[k].u; + break; + + default: + vkd3d_unreachable(); + } + + dst->u[k].u *= ~0u; + } + return true; +} + static bool fold_max(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, const struct hlsl_type *dst_type, const struct hlsl_ir_constant *src1, const struct hlsl_ir_constant *src2) { @@ -607,6 +643,10 @@ bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, success = fold_div(ctx, &res, instr->data_type, arg1, arg2, &instr->loc); break;
+ case HLSL_OP2_EQUAL: + success = fold_equal(ctx, &res, instr->data_type, arg1, arg2); + break; + case HLSL_OP2_MAX: success = fold_max(ctx, &res, instr->data_type, arg1, arg2); break;