Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com
On 23/11/21 02:45, Zebediah Figura wrote:
+/* Lower casts from vec1 to vecN to swizzles. */ +static bool lower_broadcasts(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context) +{
- const struct hlsl_type *src_type, *dst_type;
- struct hlsl_ir_expr *cast;
- if (instr->type != HLSL_IR_EXPR)
return false;
- cast = hlsl_ir_expr(instr);
- src_type = cast->operands[0].node->data_type;
- dst_type = cast->node.data_type;
- if (cast->op == HLSL_OP1_CAST
&& src_type->type <= HLSL_CLASS_VECTOR && dst_type->type <= HLSL_CLASS_VECTOR
&& src_type->dimx == 1)
- {
struct hlsl_ir_swizzle *swizzle;
if (!(swizzle = hlsl_new_swizzle(ctx, HLSL_SWIZZLE(X, X, X, X), dst_type->dimx, &cast->node, &cast->node.loc)))
return false;
list_add_after(&cast->node.entry, &swizzle->node.entry);
cast->node.data_type = hlsl_get_scalar_type(ctx, dst_type->base_type);
replace_node(&cast->node, &swizzle->node);
hlsl_src_remove(&swizzle->val);
hlsl_src_from_node(&swizzle->val, &cast->node);
I guess this answers to the question in my previous email (WRT why you want replace_node to not delete the replaced node).
This solution seems correct, but I cannot refrain from thinking the code would be more readable if you just created a new cast and just removed (and possibly deleted, but that's not very relevant) the old one.
While I am all for avoiding useless allocation round trips, I don't think that doing so at the expense of code readability is a good idea, until it is shown that that allocation really is a performance bottleneck.
Thanks, Giovanni.