vkd3d-shader/hlsl: Use replace_ir() for hlsl_fold_constant_swizzles().

This commit is contained in:
Elizabeth Figura
2025-08-20 17:45:44 -05:00
committed by Henri Verbeet
parent deb7a67d67
commit bdb31a4983
Notes: Henri Verbeet 2025-10-28 16:58:15 +01:00
Approved-by: Francisco Casas (@fcasas)
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1794
3 changed files with 8 additions and 12 deletions

View File

@@ -1838,7 +1838,8 @@ bool hlsl_copy_propagation_execute(struct hlsl_ctx *ctx, struct hlsl_block *bloc
bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context); bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context);
bool hlsl_fold_constant_identities(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context); bool hlsl_fold_constant_identities(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context);
bool hlsl_normalize_binary_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context); bool hlsl_normalize_binary_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context);
bool hlsl_fold_constant_swizzles(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context); struct hlsl_ir_node *hlsl_fold_constant_swizzles(struct hlsl_ctx *ctx,
struct hlsl_ir_node *instr, struct hlsl_block *block);
bool hlsl_transform_ir(struct hlsl_ctx *ctx, bool (*func)(struct hlsl_ctx *ctx, struct hlsl_ir_node *, void *), bool hlsl_transform_ir(struct hlsl_ctx *ctx, bool (*func)(struct hlsl_ctx *ctx, struct hlsl_ir_node *, void *),
struct hlsl_block *block, void *context); struct hlsl_block *block, void *context);

View File

@@ -8475,7 +8475,7 @@ static bool simplify_exprs(struct hlsl_ctx *ctx, struct hlsl_block *block)
progress |= hlsl_transform_ir(ctx, fold_unary_identities, block, NULL); progress |= hlsl_transform_ir(ctx, fold_unary_identities, block, NULL);
progress |= hlsl_transform_ir(ctx, fold_conditional_identities, block, NULL); progress |= hlsl_transform_ir(ctx, fold_conditional_identities, block, NULL);
progress |= hlsl_transform_ir(ctx, hlsl_fold_constant_identities, block, NULL); progress |= hlsl_transform_ir(ctx, hlsl_fold_constant_identities, block, NULL);
progress |= hlsl_transform_ir(ctx, hlsl_fold_constant_swizzles, block, NULL); progress |= replace_ir(ctx, hlsl_fold_constant_swizzles, block);
any_progress |= progress; any_progress |= progress;
} while (progress); } while (progress);

View File

@@ -1961,28 +1961,23 @@ bool hlsl_normalize_binary_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *inst
return progress; return progress;
} }
bool hlsl_fold_constant_swizzles(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context) struct hlsl_ir_node *hlsl_fold_constant_swizzles(struct hlsl_ctx *ctx,
struct hlsl_ir_node *instr, struct hlsl_block *block)
{ {
struct hlsl_constant_value value; struct hlsl_constant_value value;
struct hlsl_ir_swizzle *swizzle; struct hlsl_ir_swizzle *swizzle;
struct hlsl_ir_constant *src; struct hlsl_ir_constant *src;
struct hlsl_ir_node *dst;
unsigned int i; unsigned int i;
if (instr->type != HLSL_IR_SWIZZLE) if (instr->type != HLSL_IR_SWIZZLE)
return false; return NULL;
swizzle = hlsl_ir_swizzle(instr); swizzle = hlsl_ir_swizzle(instr);
if (swizzle->val.node->type != HLSL_IR_CONSTANT) if (swizzle->val.node->type != HLSL_IR_CONSTANT)
return false; return NULL;
src = hlsl_ir_constant(swizzle->val.node); src = hlsl_ir_constant(swizzle->val.node);
for (i = 0; i < swizzle->node.data_type->e.numeric.dimx; ++i) for (i = 0; i < swizzle->node.data_type->e.numeric.dimx; ++i)
value.u[i] = src->value.u[hlsl_swizzle_get_component(swizzle->u.vector, i)]; value.u[i] = src->value.u[hlsl_swizzle_get_component(swizzle->u.vector, i)];
if (!(dst = hlsl_new_constant(ctx, instr->data_type, &value, &instr->loc))) return hlsl_block_add_constant(ctx, block, instr->data_type, &value, &instr->loc);
return false;
list_add_before(&swizzle->node.entry, &dst->entry);
hlsl_replace_node(&swizzle->node, dst);
return true;
} }