[PATCH 0/7] MR232: vkd3d-shader/hlsl: Fold a few missing constant operations.
Mostly a rage reaction to being fed up by warnings in logs. -- https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/232
From: Giovanni Mascellani <gmascellani(a)codeweavers.com> So that operations are more or less grouped by category (unary, arithmetic, comparison, min/max, bitwise). --- libs/vkd3d-shader/hlsl_constant_ops.c | 80 +++++++++++++-------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/libs/vkd3d-shader/hlsl_constant_ops.c b/libs/vkd3d-shader/hlsl_constant_ops.c index 301113c8..8bf21f8d 100644 --- a/libs/vkd3d-shader/hlsl_constant_ops.c +++ b/libs/vkd3d-shader/hlsl_constant_ops.c @@ -258,42 +258,6 @@ static bool fold_mul(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, cons return true; } -static bool fold_nequal(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_div(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, const struct vkd3d_shader_location *loc) @@ -406,6 +370,42 @@ static bool fold_mod(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, cons return true; } +static bool fold_nequal(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) { @@ -595,10 +595,6 @@ bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, success = fold_mul(ctx, &res, instr->data_type, arg1, arg2); break; - case HLSL_OP2_NEQUAL: - success = fold_nequal(ctx, &res, instr->data_type, arg1, arg2); - break; - case HLSL_OP2_DIV: success = fold_div(ctx, &res, instr->data_type, arg1, arg2, &instr->loc); break; @@ -607,6 +603,10 @@ bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, success = fold_mod(ctx, &res, instr->data_type, arg1, arg2, &instr->loc); break; + case HLSL_OP2_NEQUAL: + success = fold_nequal(ctx, &res, instr->data_type, arg1, arg2); + break; + case HLSL_OP2_MAX: success = fold_max(ctx, &res, instr->data_type, arg1, arg2); break; -- GitLab https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/232
From: Giovanni Mascellani <gmascellani(a)codeweavers.com> --- 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 8bf21f8d..c36c7c18 100644 --- a/libs/vkd3d-shader/hlsl_constant_ops.c +++ b/libs/vkd3d-shader/hlsl_constant_ops.c @@ -370,6 +370,42 @@ static bool fold_mod(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_nequal(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) { @@ -603,6 +639,10 @@ bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, success = fold_mod(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_NEQUAL: success = fold_nequal(ctx, &res, instr->data_type, arg1, arg2); break; -- GitLab https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/232
From: Giovanni Mascellani <gmascellani(a)codeweavers.com> --- libs/vkd3d-shader/hlsl_constant_ops.c | 43 +++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/libs/vkd3d-shader/hlsl_constant_ops.c b/libs/vkd3d-shader/hlsl_constant_ops.c index c36c7c18..6d09ff10 100644 --- a/libs/vkd3d-shader/hlsl_constant_ops.c +++ b/libs/vkd3d-shader/hlsl_constant_ops.c @@ -442,6 +442,45 @@ static bool fold_nequal(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, c return true; } +static bool fold_less(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: + dst->u[k].u = src1->value.u[k].i < src2->value.u[k].i; + break; + + 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) { @@ -647,6 +686,10 @@ bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, success = fold_nequal(ctx, &res, instr->data_type, arg1, arg2); break; + case HLSL_OP2_LESS: + success = fold_less(ctx, &res, instr->data_type, arg1, arg2); + break; + case HLSL_OP2_MAX: success = fold_max(ctx, &res, instr->data_type, arg1, arg2); break; -- GitLab https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/232
From: Giovanni Mascellani <gmascellani(a)codeweavers.com> --- libs/vkd3d-shader/hlsl_constant_ops.c | 43 +++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/libs/vkd3d-shader/hlsl_constant_ops.c b/libs/vkd3d-shader/hlsl_constant_ops.c index 6d09ff10..7df6d671 100644 --- a/libs/vkd3d-shader/hlsl_constant_ops.c +++ b/libs/vkd3d-shader/hlsl_constant_ops.c @@ -481,6 +481,45 @@ static bool fold_less(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, con return true; } +static bool fold_gequal(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: + dst->u[k].u = src1->value.u[k].i >= src2->value.u[k].i; + break; + + 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) { @@ -690,6 +729,10 @@ bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, success = fold_less(ctx, &res, instr->data_type, arg1, arg2); break; + case HLSL_OP2_GEQUAL: + success = fold_gequal(ctx, &res, instr->data_type, arg1, arg2); + break; + case HLSL_OP2_MAX: success = fold_max(ctx, &res, instr->data_type, arg1, arg2); break; -- GitLab https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/232
From: Giovanni Mascellani <gmascellani(a)codeweavers.com> --- libs/vkd3d-shader/hlsl_constant_ops.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libs/vkd3d-shader/hlsl_constant_ops.c b/libs/vkd3d-shader/hlsl_constant_ops.c index 7df6d671..773cf8de 100644 --- a/libs/vkd3d-shader/hlsl_constant_ops.c +++ b/libs/vkd3d-shader/hlsl_constant_ops.c @@ -533,6 +533,15 @@ static bool fold_max(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, cons { switch (type) { + case HLSL_TYPE_FLOAT: + case HLSL_TYPE_HALF: + dst->u[k].f = fmaxf(src1->value.u[k].f, src2->value.u[k].f); + break; + + case HLSL_TYPE_DOUBLE: + dst->u[k].d = fmax(src1->value.u[k].d, src2->value.u[k].d); + break; + case HLSL_TYPE_INT: dst->u[k].i = max(src1->value.u[k].i, src2->value.u[k].i); break; -- GitLab https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/232
From: Giovanni Mascellani <gmascellani(a)codeweavers.com> --- libs/vkd3d-shader/hlsl_constant_ops.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libs/vkd3d-shader/hlsl_constant_ops.c b/libs/vkd3d-shader/hlsl_constant_ops.c index 773cf8de..28562700 100644 --- a/libs/vkd3d-shader/hlsl_constant_ops.c +++ b/libs/vkd3d-shader/hlsl_constant_ops.c @@ -571,6 +571,15 @@ static bool fold_min(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, cons { switch (type) { + case HLSL_TYPE_FLOAT: + case HLSL_TYPE_HALF: + dst->u[k].f = fminf(src1->value.u[k].f, src2->value.u[k].f); + break; + + case HLSL_TYPE_DOUBLE: + dst->u[k].d = fmin(src1->value.u[k].d, src2->value.u[k].d); + break; + case HLSL_TYPE_INT: dst->u[k].i = min(src1->value.u[k].i, src2->value.u[k].i); break; -- GitLab https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/232
From: Giovanni Mascellani <gmascellani(a)codeweavers.com> --- libs/vkd3d-shader/hlsl_constant_ops.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/libs/vkd3d-shader/hlsl_constant_ops.c b/libs/vkd3d-shader/hlsl_constant_ops.c index 28562700..dd07c51d 100644 --- a/libs/vkd3d-shader/hlsl_constant_ops.c +++ b/libs/vkd3d-shader/hlsl_constant_ops.c @@ -622,7 +622,7 @@ static bool fold_bit_xor(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, return true; } -static bool fold_bit_and(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, const struct hlsl_type *dst_type, +static bool fold_and(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) { enum hlsl_base_type type = dst_type->base_type; @@ -637,18 +637,19 @@ static bool fold_bit_and(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, { 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: - FIXME("Fold bit and for type %s.\n", debug_hlsl_type(ctx, dst_type)); + FIXME("Fold bit/logic and for type %s.\n", debug_hlsl_type(ctx, dst_type)); return false; } } return true; } -static bool fold_bit_or(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, const struct hlsl_type *dst_type, +static bool fold_or(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) { enum hlsl_base_type type = dst_type->base_type; @@ -663,11 +664,12 @@ static bool fold_bit_or(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, c { 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: - FIXME("Fold bit or for type %s.\n", debug_hlsl_type(ctx, dst_type)); + FIXME("Fold bit/logic or for type %s.\n", debug_hlsl_type(ctx, dst_type)); return false; } } @@ -764,11 +766,13 @@ bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, break; case HLSL_OP2_BIT_AND: - success = fold_bit_and(ctx, &res, instr->data_type, arg1, arg2); + case HLSL_OP2_LOGIC_AND: + success = fold_and(ctx, &res, instr->data_type, arg1, arg2); break; case HLSL_OP2_BIT_OR: - success = fold_bit_or(ctx, &res, instr->data_type, arg1, arg2); + case HLSL_OP2_LOGIC_OR: + success = fold_or(ctx, &res, instr->data_type, arg1, arg2); break; default: -- GitLab https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/232
vkd3d-shader/hlsl: Reorder constant folding helpers.
So that operations are more or less grouped by category (unary, arithmetic, comparison, min/max, bitwise).
Once upon a time these were alphabetical... -- https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/232#note_35501
participants (3)
-
Giovanni Mascellani -
Giovanni Mascellani (@giomasce) -
Zebediah Figura (@zfigura)