vkd3d-shader/hlsl: Do not generate useless swizzles.

Signed-off-by: Giovanni Mascellani <gmascellani@codeweavers.com>
Signed-off-by: Zebediah Figura <zfigura@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Giovanni Mascellani 2022-04-27 10:56:22 +02:00 committed by Alexandre Julliard
parent 6b6ff48ece
commit c5c50a8b9b

View File

@ -246,6 +246,7 @@ static bool lower_broadcasts(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, v
&& src_type->type <= HLSL_CLASS_VECTOR && dst_type->type <= HLSL_CLASS_VECTOR && src_type->type <= HLSL_CLASS_VECTOR && dst_type->type <= HLSL_CLASS_VECTOR
&& src_type->dimx == 1) && src_type->dimx == 1)
{ {
struct hlsl_ir_node *replacement;
struct hlsl_ir_swizzle *swizzle; struct hlsl_ir_swizzle *swizzle;
struct hlsl_ir_expr *new_cast; struct hlsl_ir_expr *new_cast;
@ -255,11 +256,17 @@ static bool lower_broadcasts(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, v
if (!(new_cast = hlsl_new_cast(ctx, cast->operands[0].node, dst_scalar_type, &cast->node.loc))) if (!(new_cast = hlsl_new_cast(ctx, cast->operands[0].node, dst_scalar_type, &cast->node.loc)))
return false; return false;
list_add_after(&cast->node.entry, &new_cast->node.entry); list_add_after(&cast->node.entry, &new_cast->node.entry);
if (!(swizzle = hlsl_new_swizzle(ctx, HLSL_SWIZZLE(X, X, X, X), dst_type->dimx, &new_cast->node, &cast->node.loc))) replacement = &new_cast->node;
return false;
list_add_after(&new_cast->node.entry, &swizzle->node.entry);
hlsl_replace_node(&cast->node, &swizzle->node); if (dst_type->dimx != 1)
{
if (!(swizzle = hlsl_new_swizzle(ctx, HLSL_SWIZZLE(X, X, X, X), dst_type->dimx, replacement, &cast->node.loc)))
return false;
list_add_after(&new_cast->node.entry, &swizzle->node.entry);
replacement = &swizzle->node;
}
hlsl_replace_node(&cast->node, replacement);
return true; return true;
} }