From: Giovanni Mascellani Subject: [PATCH vkd3d v3 3/7] vkd3d-shader/hlsl: Introduce add_cast() helper. Message-Id: <20220602140609.3419134-3-gmascellani@codeweavers.com> Date: Thu, 2 Jun 2022 16:06:05 +0200 In-Reply-To: <20220602140609.3419134-1-gmascellani@codeweavers.com> References: <20220602140609.3419134-1-gmascellani@codeweavers.com> Signed-off-by: Giovanni Mascellani --- There is another call to hlsl_new_cast() in hlsl.y that I didn't redirect to add_cast(), because it doesn't require the upcoming matrix conversion patch. I don't know if you want it to be redirected too. v3: * add back some mistakenly removed lines --- libs/vkd3d-shader/hlsl.y | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index faac562a..23c48cdc 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -266,7 +266,7 @@ static bool implicit_compatible_data_types(struct hlsl_type *t1, struct hlsl_typ return false; } -static struct hlsl_ir_node *add_implicit_conversion(struct hlsl_ctx *ctx, struct list *instrs, +static struct hlsl_ir_node *add_cast(struct hlsl_ctx *ctx, struct list *instrs, struct hlsl_ir_node *node, struct hlsl_type *dst_type, const struct vkd3d_shader_location *loc) { struct hlsl_type *src_type = node->data_type; @@ -275,6 +275,17 @@ static struct hlsl_ir_node *add_implicit_conversion(struct hlsl_ctx *ctx, struct if (hlsl_types_are_equal(src_type, dst_type)) return node; + if (!(cast = hlsl_new_cast(ctx, node, dst_type, loc))) + return NULL; + list_add_tail(instrs, &cast->node.entry); + return &cast->node; +} + +static struct hlsl_ir_node *add_implicit_conversion(struct hlsl_ctx *ctx, struct list *instrs, + struct hlsl_ir_node *node, struct hlsl_type *dst_type, const struct vkd3d_shader_location *loc) +{ + struct hlsl_type *src_type = node->data_type; + if (!implicit_compatible_data_types(src_type, dst_type)) { struct vkd3d_string_buffer *src_string, *dst_string; @@ -293,10 +304,7 @@ static struct hlsl_ir_node *add_implicit_conversion(struct hlsl_ctx *ctx, struct hlsl_warning(ctx, loc, VKD3D_SHADER_WARNING_HLSL_IMPLICIT_TRUNCATION, "Implicit truncation of %s type.", src_type->type == HLSL_CLASS_VECTOR ? "vector" : "matrix"); - if (!(cast = hlsl_new_cast(ctx, node, dst_type, loc))) - return NULL; - list_add_tail(instrs, &cast->node.entry); - return &cast->node; + return add_cast(ctx, instrs, node, dst_type, loc); } static DWORD add_modifiers(struct hlsl_ctx *ctx, DWORD modifiers, DWORD mod, const struct vkd3d_shader_location loc) @@ -3718,7 +3726,6 @@ unary_expr: { struct hlsl_type *src_type = node_from_list($6)->data_type; struct hlsl_type *dst_type; - struct hlsl_ir_expr *cast; unsigned int i; if ($2) @@ -3746,12 +3753,11 @@ unary_expr: YYABORT; } - if (!(cast = hlsl_new_cast(ctx, node_from_list($6), dst_type, &@3))) + if (!add_cast(ctx, $6, node_from_list($6), dst_type, &@3)) { hlsl_free_instr_list($6); YYABORT; } - list_add_tail($6, &cast->node.entry); $$ = $6; } -- 2.36.1