vkd3d-shader/hlsl: Ensure that TERNARY condition is always bool.

Also, properly casting it to float in lower_ternary() for SM1
avoids creating ABS and NEG on bool types.
This commit is contained in:
Francisco Casas
2024-03-01 16:01:03 -03:00
committed by Alexandre Julliard
parent 9c0d04c862
commit 19fd43214b
Notes: Alexandre Julliard 2024-04-09 15:44:37 -05:00
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Zebediah Figura (@zfigura)
Approved-by: Henri Verbeet (@hverbeet)
Approved-by: Alexandre Julliard (@julliard)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/744
11 changed files with 114 additions and 122 deletions

View File

@@ -4405,26 +4405,34 @@ static bool add_ternary(struct hlsl_ctx *ctx, struct hlsl_block *block,
if (!(cond = add_implicit_conversion(ctx, block, cond, cond_type, &cond->loc)))
return false;
}
else if (common_type->dimx == 1 && common_type->dimy == 1)
else
{
common_type = hlsl_get_numeric_type(ctx, cond_type->class,
common_type->base_type, cond_type->dimx, cond_type->dimy);
}
else if (cond_type->dimx != common_type->dimx || cond_type->dimy != common_type->dimy)
{
/* This condition looks wrong but is correct.
* floatN is compatible with float1xN, but not with floatNx1. */
cond_type = hlsl_get_numeric_type(ctx, cond_type->class, HLSL_TYPE_BOOL,
cond_type->dimx, cond_type->dimy);
if (!(cond = add_implicit_conversion(ctx, block, cond, cond_type, &cond->loc)))
return false;
struct vkd3d_string_buffer *cond_string, *value_string;
if (common_type->dimx == 1 && common_type->dimy == 1)
{
common_type = hlsl_get_numeric_type(ctx, cond_type->class,
common_type->base_type, cond_type->dimx, cond_type->dimy);
}
else if (cond_type->dimx != common_type->dimx || cond_type->dimy != common_type->dimy)
{
/* This condition looks wrong but is correct.
* floatN is compatible with float1xN, but not with floatNx1. */
cond_string = hlsl_type_to_string(ctx, cond_type);
value_string = hlsl_type_to_string(ctx, common_type);
if (cond_string && value_string)
hlsl_error(ctx, &first->loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
"Ternary condition type '%s' is not compatible with value type '%s'.",
cond_string->buffer, value_string->buffer);
hlsl_release_string_buffer(ctx, cond_string);
hlsl_release_string_buffer(ctx, value_string);
struct vkd3d_string_buffer *cond_string, *value_string;
cond_string = hlsl_type_to_string(ctx, cond_type);
value_string = hlsl_type_to_string(ctx, common_type);
if (cond_string && value_string)
hlsl_error(ctx, &first->loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
"Ternary condition type '%s' is not compatible with value type '%s'.",
cond_string->buffer, value_string->buffer);
hlsl_release_string_buffer(ctx, cond_string);
hlsl_release_string_buffer(ctx, value_string);
}
}
if (!(first = add_implicit_conversion(ctx, block, first, common_type, &first->loc)))
@@ -4449,9 +4457,16 @@ static bool add_ternary(struct hlsl_ctx *ctx, struct hlsl_block *block,
hlsl_release_string_buffer(ctx, second_string);
}
cond_type = hlsl_get_numeric_type(ctx, cond_type->class, HLSL_TYPE_BOOL,
cond_type->dimx, cond_type->dimy);
if (!(cond = add_implicit_conversion(ctx, block, cond, cond_type, &cond->loc)))
return false;
common_type = first->data_type;
}
assert(cond->data_type->base_type == HLSL_TYPE_BOOL);
args[0] = cond;
args[1] = first;
args[2] = second;