Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com --- libs/vkd3d-shader/hlsl.y | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index cb4fd7c8..4c3c0676 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -916,6 +916,9 @@ static enum hlsl_base_type expr_common_base_type(enum hlsl_base_type t1, enum hl }; int t1_idx = -1, t2_idx = -1, i;
+ if (t1 == t2) + return t1; + for (i = 0; i < ARRAY_SIZE(types); ++i) { /* Always convert away from HLSL_TYPE_HALF */ @@ -981,10 +984,7 @@ static struct hlsl_type *expr_common_type(struct hlsl_ctx *ctx, struct hlsl_type return NULL; }
- if (t1->base_type == t2->base_type) - base = t1->base_type; - else - base = expr_common_base_type(t1->base_type, t2->base_type); + base = expr_common_base_type(t1->base_type, t2->base_type);
if (t1->dimx == 1 && t1->dimy == 1) {
So does the native d3dcompiler, following the spirit of integer promotion in C.
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com --- libs/vkd3d-shader/hlsl.y | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 4c3c0676..69c42b69 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -917,7 +917,7 @@ static enum hlsl_base_type expr_common_base_type(enum hlsl_base_type t1, enum hl int t1_idx = -1, t2_idx = -1, i;
if (t1 == t2) - return t1; + return t1 == HLSL_TYPE_BOOL ? HLSL_TYPE_INT : t1;
for (i = 0; i < ARRAY_SIZE(types); ++i) {
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com --- libs/vkd3d-shader/hlsl.y | 39 +++++++++++---------------------------- 1 file changed, 11 insertions(+), 28 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 69c42b69..7906356f 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -905,37 +905,20 @@ static bool expr_compatible_data_types(struct hlsl_type *t1, struct hlsl_type *t
static enum hlsl_base_type expr_common_base_type(enum hlsl_base_type t1, enum hlsl_base_type t2) { - static const enum hlsl_base_type types[] = - { - HLSL_TYPE_BOOL, - HLSL_TYPE_INT, - HLSL_TYPE_UINT, - HLSL_TYPE_HALF, - HLSL_TYPE_FLOAT, - HLSL_TYPE_DOUBLE, - }; - int t1_idx = -1, t2_idx = -1, i; - - if (t1 == t2) - return t1 == HLSL_TYPE_BOOL ? HLSL_TYPE_INT : t1; - - for (i = 0; i < ARRAY_SIZE(types); ++i) - { - /* Always convert away from HLSL_TYPE_HALF */ - if (t1 == types[i]) - t1_idx = t1 == HLSL_TYPE_HALF ? i + 1 : i; - if (t2 == types[i]) - t2_idx = t2 == HLSL_TYPE_HALF ? i + 1 : i; - - if (t1_idx != -1 && t2_idx != -1) - break; - } - if (t1_idx == -1 || t2_idx == -1) - { + if (t1 > HLSL_TYPE_LAST_SCALAR || t2 > HLSL_TYPE_LAST_SCALAR) { FIXME("Unexpected base type.\n"); return HLSL_TYPE_FLOAT; } - return t1_idx >= t2_idx ? t1 : t2; + if (t1 == t2) + return t1 == HLSL_TYPE_BOOL ? HLSL_TYPE_INT : t1; + if (t1 == HLSL_TYPE_DOUBLE || t2 == HLSL_TYPE_DOUBLE) + return HLSL_TYPE_DOUBLE; + if (t1 == HLSL_TYPE_FLOAT || t2 == HLSL_TYPE_FLOAT + || t1 == HLSL_TYPE_HALF || t2 == HLSL_TYPE_HALF) + return HLSL_TYPE_FLOAT; + if (t1 == HLSL_TYPE_UINT || t2 == HLSL_TYPE_UINT) + return HLSL_TYPE_UINT; + return HLSL_TYPE_INT; }
static struct hlsl_type *expr_common_type(struct hlsl_ctx *ctx, struct hlsl_type *t1, struct hlsl_type *t2,
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
It'd be nice to have some tests for this (and 2/3), though, even if they don't pass yet for some reason ;-)
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com