vkd3d-shader: Move compatible_data_types() to hlsl.y.

Signed-off-by: Zebediah Figura <zfigura@codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2021-01-30 13:51:36 -06:00 committed by Alexandre Julliard
parent d8dd91e840
commit ab2e95a78c
3 changed files with 54 additions and 60 deletions

View File

@ -312,65 +312,6 @@ struct hlsl_type *clone_hlsl_type(struct hlsl_type *old, unsigned int default_ma
return type;
}
static BOOL convertible_data_type(struct hlsl_type *type)
{
return type->type != HLSL_CLASS_OBJECT;
}
BOOL compatible_data_types(struct hlsl_type *t1, struct hlsl_type *t2)
{
if (!convertible_data_type(t1) || !convertible_data_type(t2))
return FALSE;
if (t1->type <= HLSL_CLASS_LAST_NUMERIC)
{
/* Scalar vars can be cast to pretty much everything */
if (t1->dimx == 1 && t1->dimy == 1)
return TRUE;
if (t1->type == HLSL_CLASS_VECTOR && t2->type == HLSL_CLASS_VECTOR)
return t1->dimx >= t2->dimx;
}
/* The other way around is true too i.e. whatever to scalar */
if (t2->type <= HLSL_CLASS_LAST_NUMERIC && t2->dimx == 1 && t2->dimy == 1)
return TRUE;
if (t1->type == HLSL_CLASS_ARRAY)
{
if (compare_hlsl_types(t1->e.array.type, t2))
/* e.g. float4[3] to float4 is allowed */
return TRUE;
if (t2->type == HLSL_CLASS_ARRAY || t2->type == HLSL_CLASS_STRUCT)
return components_count_type(t1) >= components_count_type(t2);
else
return components_count_type(t1) == components_count_type(t2);
}
if (t1->type == HLSL_CLASS_STRUCT)
return components_count_type(t1) >= components_count_type(t2);
if (t2->type == HLSL_CLASS_ARRAY || t2->type == HLSL_CLASS_STRUCT)
return components_count_type(t1) == components_count_type(t2);
if (t1->type == HLSL_CLASS_MATRIX || t2->type == HLSL_CLASS_MATRIX)
{
if (t1->type == HLSL_CLASS_MATRIX && t2->type == HLSL_CLASS_MATRIX && t1->dimx >= t2->dimx && t1->dimy >= t2->dimy)
return TRUE;
/* Matrix-vector conversion is apparently allowed if they have the same components count */
if ((t1->type == HLSL_CLASS_VECTOR || t2->type == HLSL_CLASS_VECTOR)
&& components_count_type(t1) == components_count_type(t2))
return TRUE;
return FALSE;
}
if (components_count_type(t1) >= components_count_type(t2))
return TRUE;
return FALSE;
}
struct hlsl_ir_expr *new_cast(struct hlsl_ir_node *node, struct hlsl_type *type,
struct source_location *loc)
{

View File

@ -626,7 +626,6 @@ BOOL is_row_major(const struct hlsl_type *type) DECLSPEC_HIDDEN;
BOOL find_function(const char *name) DECLSPEC_HIDDEN;
unsigned int components_count_type(struct hlsl_type *type) DECLSPEC_HIDDEN;
BOOL compare_hlsl_types(const struct hlsl_type *t1, const struct hlsl_type *t2) DECLSPEC_HIDDEN;
BOOL compatible_data_types(struct hlsl_type *s1, struct hlsl_type *s2) DECLSPEC_HIDDEN;
void push_scope(struct hlsl_parse_ctx *ctx) DECLSPEC_HIDDEN;
BOOL pop_scope(struct hlsl_parse_ctx *ctx) DECLSPEC_HIDDEN;
void init_functions_tree(struct rb_tree *funcs) DECLSPEC_HIDDEN;

View File

@ -82,6 +82,60 @@ static BOOL convertible_data_type(struct hlsl_type *type)
return type->type != HLSL_CLASS_OBJECT;
}
static BOOL compatible_data_types(struct hlsl_type *t1, struct hlsl_type *t2)
{
if (!convertible_data_type(t1) || !convertible_data_type(t2))
return FALSE;
if (t1->type <= HLSL_CLASS_LAST_NUMERIC)
{
/* Scalar vars can be cast to pretty much everything */
if (t1->dimx == 1 && t1->dimy == 1)
return TRUE;
if (t1->type == HLSL_CLASS_VECTOR && t2->type == HLSL_CLASS_VECTOR)
return t1->dimx >= t2->dimx;
}
/* The other way around is true too i.e. whatever to scalar */
if (t2->type <= HLSL_CLASS_LAST_NUMERIC && t2->dimx == 1 && t2->dimy == 1)
return TRUE;
if (t1->type == HLSL_CLASS_ARRAY)
{
if (compare_hlsl_types(t1->e.array.type, t2))
/* e.g. float4[3] to float4 is allowed */
return TRUE;
if (t2->type == HLSL_CLASS_ARRAY || t2->type == HLSL_CLASS_STRUCT)
return components_count_type(t1) >= components_count_type(t2);
else
return components_count_type(t1) == components_count_type(t2);
}
if (t1->type == HLSL_CLASS_STRUCT)
return components_count_type(t1) >= components_count_type(t2);
if (t2->type == HLSL_CLASS_ARRAY || t2->type == HLSL_CLASS_STRUCT)
return components_count_type(t1) == components_count_type(t2);
if (t1->type == HLSL_CLASS_MATRIX || t2->type == HLSL_CLASS_MATRIX)
{
if (t1->type == HLSL_CLASS_MATRIX && t2->type == HLSL_CLASS_MATRIX && t1->dimx >= t2->dimx && t1->dimy >= t2->dimy)
return TRUE;
/* Matrix-vector conversion is apparently allowed if they have the same components count */
if ((t1->type == HLSL_CLASS_VECTOR || t2->type == HLSL_CLASS_VECTOR)
&& components_count_type(t1) == components_count_type(t2))
return TRUE;
return FALSE;
}
if (components_count_type(t1) >= components_count_type(t2))
return TRUE;
return FALSE;
}
static BOOL implicit_compatible_data_types(struct hlsl_type *t1, struct hlsl_type *t2)
{
if (!convertible_data_type(t1) || !convertible_data_type(t2))