[PATCH v2 0/7] MR232: vkd3d-shader/hlsl: Fold a few missing constant operations.
Mostly a rage reaction to being fed up by warnings in logs. -- v2: vkd3d-shader/hlsl: Fold logical expressions. vkd3d-shader/hlsl: Fold floating point minimum expressions. vkd3d-shader/hlsl: Fold floating point maximum expressions. vkd3d-shader/hlsl: Fold greater-than-or-equal comparisons. vkd3d-shader/hlsl: Fold less-than comparisons. vkd3d-shader/hlsl: Fold equality comparisons. vkd3d-shader/hlsl: Sort constant folding helpers alphabetically. https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/232
From: Giovanni Mascellani <gmascellani(a)codeweavers.com> --- libs/vkd3d-shader/hlsl_constant_ops.c | 206 +++++++++++++------------- 1 file changed, 103 insertions(+), 103 deletions(-) diff --git a/libs/vkd3d-shader/hlsl_constant_ops.c b/libs/vkd3d-shader/hlsl_constant_ops.c index 301113c8..1ae338fe 100644 --- a/libs/vkd3d-shader/hlsl_constant_ops.c +++ b/libs/vkd3d-shader/hlsl_constant_ops.c @@ -223,7 +223,7 @@ static bool fold_add(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, cons return true; } -static bool fold_mul(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, const struct hlsl_type *dst_type, +static bool fold_bit_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; @@ -232,64 +232,71 @@ static bool fold_mul(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, cons assert(type == src1->node.data_type->base_type); assert(type == src2->node.data_type->base_type); - for (k = 0; k < 4; ++k) + for (k = 0; k < dst_type->dimx; ++k) { switch (type) { - case HLSL_TYPE_FLOAT: - case HLSL_TYPE_HALF: - dst->u[k].f = src1->value.u[k].f * src2->value.u[k].f; - break; - - case HLSL_TYPE_DOUBLE: - dst->u[k].d = src1->value.u[k].d * src2->value.u[k].d; - break; - case HLSL_TYPE_INT: case HLSL_TYPE_UINT: - dst->u[k].u = src1->value.u[k].u * src2->value.u[k].u; + dst->u[k].u = src1->value.u[k].u & src2->value.u[k].u; break; default: - FIXME("Fold multiplication for type %s.\n", debug_hlsl_type(ctx, dst_type)); + FIXME("Fold bit and for type %s.\n", debug_hlsl_type(ctx, dst_type)); return false; } } return true; } -static bool fold_nequal(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, const struct hlsl_type *dst_type, +static bool fold_bit_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; unsigned int k; - assert(dst_type->base_type == HLSL_TYPE_BOOL); - assert(src1->node.data_type->base_type == src2->node.data_type->base_type); + assert(type == src1->node.data_type->base_type); + assert(type == src2->node.data_type->base_type); - for (k = 0; k < 4; ++k) + for (k = 0; k < dst_type->dimx; ++k) { - switch (src1->node.data_type->base_type) + switch (type) { - case HLSL_TYPE_FLOAT: - case HLSL_TYPE_HALF: - dst->u[k].u = src1->value.u[k].f != src2->value.u[k].f; + case HLSL_TYPE_INT: + case HLSL_TYPE_UINT: + dst->u[k].u = src1->value.u[k].u | src2->value.u[k].u; break; - case HLSL_TYPE_DOUBLE: - dst->u[k].u = src1->value.u[k].d != src2->value.u[k].d; - break; + default: + FIXME("Fold bit or for type %s.\n", debug_hlsl_type(ctx, dst_type)); + return false; + } + } + return true; +} +static bool fold_bit_xor(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; + unsigned int k; + + assert(type == src1->node.data_type->base_type); + assert(type == src2->node.data_type->base_type); + + for (k = 0; k < dst_type->dimx; ++k) + { + switch (type) + { 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; + dst->u[k].u = src1->value.u[k].u ^ src2->value.u[k].u; break; default: - vkd3d_unreachable(); + FIXME("Fold bit xor for type %s.\n", debug_hlsl_type(ctx, dst_type)); + return false; } - - dst->u[k].u *= ~0u; } return true; } @@ -363,49 +370,6 @@ static bool fold_div(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, cons return true; } -static bool fold_mod(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) -{ - enum hlsl_base_type type = dst_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_type->dimx; ++k) - { - switch (type) - { - case HLSL_TYPE_INT: - if (src2->value.u[k].i == 0) - { - hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_DIVISION_BY_ZERO, "Division by zero."); - return false; - } - if (src1->value.u[k].i == INT_MIN && src2->value.u[k].i == -1) - dst->u[k].i = 0; - else - dst->u[k].i = src1->value.u[k].i % src2->value.u[k].i; - break; - - case HLSL_TYPE_UINT: - if (src2->value.u[k].u == 0) - { - hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_DIVISION_BY_ZERO, "Division by zero."); - return false; - } - dst->u[k].u = src1->value.u[k].u % src2->value.u[k].u; - break; - - default: - FIXME("Fold modulus for type %s.\n", debug_hlsl_type(ctx, dst_type)); - return false; - } - } - 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) { @@ -464,8 +428,9 @@ static bool fold_min(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, cons return true; } -static bool fold_bit_xor(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) +static bool fold_mod(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) { enum hlsl_base_type type = dst_type->base_type; unsigned int k; @@ -478,19 +443,35 @@ static bool fold_bit_xor(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, switch (type) { case HLSL_TYPE_INT: + if (src2->value.u[k].i == 0) + { + hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_DIVISION_BY_ZERO, "Division by zero."); + return false; + } + if (src1->value.u[k].i == INT_MIN && src2->value.u[k].i == -1) + dst->u[k].i = 0; + else + dst->u[k].i = src1->value.u[k].i % src2->value.u[k].i; + break; + case HLSL_TYPE_UINT: - dst->u[k].u = src1->value.u[k].u ^ src2->value.u[k].u; + if (src2->value.u[k].u == 0) + { + hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_DIVISION_BY_ZERO, "Division by zero."); + return false; + } + dst->u[k].u = src1->value.u[k].u % src2->value.u[k].u; break; default: - FIXME("Fold bit xor for type %s.\n", debug_hlsl_type(ctx, dst_type)); + FIXME("Fold modulus for type %s.\n", debug_hlsl_type(ctx, dst_type)); return false; } } 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_mul(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; @@ -499,45 +480,64 @@ static bool fold_bit_and(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, assert(type == src1->node.data_type->base_type); assert(type == src2->node.data_type->base_type); - for (k = 0; k < dst_type->dimx; ++k) + for (k = 0; k < 4; ++k) { switch (type) { + case HLSL_TYPE_FLOAT: + case HLSL_TYPE_HALF: + dst->u[k].f = src1->value.u[k].f * src2->value.u[k].f; + break; + + case HLSL_TYPE_DOUBLE: + dst->u[k].d = src1->value.u[k].d * src2->value.u[k].d; + break; + case HLSL_TYPE_INT: case HLSL_TYPE_UINT: - dst->u[k].u = src1->value.u[k].u & src2->value.u[k].u; + 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 multiplication 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_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) { - enum hlsl_base_type type = dst_type->base_type; unsigned int k; - assert(type == src1->node.data_type->base_type); - assert(type == src2->node.data_type->base_type); + 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 < dst_type->dimx; ++k) + for (k = 0; k < 4; ++k) { - switch (type) + 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: - dst->u[k].u = src1->value.u[k].u | src2->value.u[k].u; + 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)); - return false; + vkd3d_unreachable(); } + + dst->u[k].u *= ~0u; } return true; } @@ -591,20 +591,20 @@ bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, success = fold_add(ctx, &res, instr->data_type, arg1, arg2); break; - case HLSL_OP2_MUL: - success = fold_mul(ctx, &res, instr->data_type, arg1, arg2); + case HLSL_OP2_BIT_AND: + success = fold_bit_and(ctx, &res, instr->data_type, arg1, arg2); break; - case HLSL_OP2_NEQUAL: - success = fold_nequal(ctx, &res, instr->data_type, arg1, arg2); + case HLSL_OP2_BIT_OR: + success = fold_bit_or(ctx, &res, instr->data_type, arg1, arg2); break; - case HLSL_OP2_DIV: - success = fold_div(ctx, &res, instr->data_type, arg1, arg2, &instr->loc); + case HLSL_OP2_BIT_XOR: + success = fold_bit_xor(ctx, &res, instr->data_type, arg1, arg2); break; - case HLSL_OP2_MOD: - success = fold_mod(ctx, &res, instr->data_type, arg1, arg2, &instr->loc); + case HLSL_OP2_DIV: + success = fold_div(ctx, &res, instr->data_type, arg1, arg2, &instr->loc); break; case HLSL_OP2_MAX: @@ -615,16 +615,16 @@ bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, success = fold_min(ctx, &res, instr->data_type, arg1, arg2); break; - case HLSL_OP2_BIT_XOR: - success = fold_bit_xor(ctx, &res, instr->data_type, arg1, arg2); + case HLSL_OP2_MOD: + success = fold_mod(ctx, &res, instr->data_type, arg1, arg2, &instr->loc); break; - case HLSL_OP2_BIT_AND: - success = fold_bit_and(ctx, &res, instr->data_type, arg1, arg2); + case HLSL_OP2_MUL: + success = fold_mul(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_NEQUAL: + success = fold_nequal(ctx, &res, instr->data_type, arg1, arg2); break; default: -- 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 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; -- 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 6ba059fa..9232cd77 100644 --- a/libs/vkd3d-shader/hlsl_constant_ops.c +++ b/libs/vkd3d-shader/hlsl_constant_ops.c @@ -406,6 +406,45 @@ static bool fold_equal(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, co 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_equal(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 9232cd77..00bacbf5 100644 --- a/libs/vkd3d-shader/hlsl_constant_ops.c +++ b/libs/vkd3d-shader/hlsl_constant_ops.c @@ -406,6 +406,45 @@ static bool fold_equal(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, co 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_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) { @@ -686,6 +725,10 @@ bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, success = fold_equal(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_LESS: success = fold_less(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 00bacbf5..edfc898e 100644 --- a/libs/vkd3d-shader/hlsl_constant_ops.c +++ b/libs/vkd3d-shader/hlsl_constant_ops.c @@ -497,6 +497,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 edfc898e..b9bca0d3 100644 --- a/libs/vkd3d-shader/hlsl_constant_ops.c +++ b/libs/vkd3d-shader/hlsl_constant_ops.c @@ -535,6 +535,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 b9bca0d3..570773cd 100644 --- a/libs/vkd3d-shader/hlsl_constant_ops.c +++ b/libs/vkd3d-shader/hlsl_constant_ops.c @@ -223,7 +223,7 @@ static bool fold_add(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, cons 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; @@ -238,18 +238,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; @@ -264,11 +265,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; } } @@ -724,11 +726,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; case HLSL_OP2_BIT_XOR: -- GitLab https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/232
On Tue Jun 13 09:56:46 2023 +0000, Zebediah Figura wrote:
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... Now they are again! Their former splendor is fully restored!
-- https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/232#note_35606
This merge request was approved by Zebediah Figura. -- https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/232
Oops, sorry, this somehow got lost in my already-reviewed queue... -- https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/232#note_36884
This merge request was approved by Henri Verbeet. -- https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/232
participants (4)
-
Giovanni Mascellani -
Giovanni Mascellani (@giomasce) -
Henri Verbeet (@hverbeet) -
Zebediah Figura (@zfigura)