diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index a24493e51..4f79f2845 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -1835,7 +1835,8 @@ unsigned int hlsl_offset_from_deref_safe(struct hlsl_ctx *ctx, const struct hlsl struct hlsl_reg hlsl_reg_from_deref(struct hlsl_ctx *ctx, const struct hlsl_deref *deref); bool hlsl_copy_propagation_execute(struct hlsl_ctx *ctx, struct hlsl_block *block); -bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context); +struct hlsl_ir_node *hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, + struct hlsl_ir_node *instr, struct hlsl_block *block); struct hlsl_ir_node *hlsl_fold_constant_identities(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, struct hlsl_block *block); bool hlsl_normalize_binary_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context); diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index 57127403e..5e7219ee3 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -8470,7 +8470,7 @@ static bool simplify_exprs(struct hlsl_ctx *ctx, struct hlsl_block *block) do { - progress = hlsl_transform_ir(ctx, hlsl_fold_constant_exprs, block, NULL); + progress = replace_ir(ctx, hlsl_fold_constant_exprs, block); progress |= hlsl_transform_ir(ctx, hlsl_normalize_binary_exprs, block, NULL); progress |= hlsl_transform_ir(ctx, fold_unary_identities, block, NULL); progress |= hlsl_transform_ir(ctx, fold_conditional_identities, block, NULL); @@ -14849,7 +14849,7 @@ static void process_entry_function(struct hlsl_ctx *ctx, struct list *semantic_v replace_ir(ctx, lower_int_modulus_sm1, body); replace_ir(ctx, lower_division, body); /* Constants casted to float must be folded, and new casts to bool also need to be lowered. */ - hlsl_transform_ir(ctx, hlsl_fold_constant_exprs, body, NULL); + replace_ir(ctx, hlsl_fold_constant_exprs, body); replace_ir(ctx, lower_casts_to_bool, body); replace_ir(ctx, lower_casts_to_int, body); diff --git a/libs/vkd3d-shader/hlsl_constant_ops.c b/libs/vkd3d-shader/hlsl_constant_ops.c index 23da294fc..1c44e5fa3 100644 --- a/libs/vkd3d-shader/hlsl_constant_ops.c +++ b/libs/vkd3d-shader/hlsl_constant_ops.c @@ -1434,11 +1434,11 @@ static bool fold_rshift(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, c return true; } -bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context) +struct hlsl_ir_node *hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, + struct hlsl_ir_node *instr, struct hlsl_block *block) { struct hlsl_ir_constant *arg1, *arg2 = NULL, *arg3 = NULL; struct hlsl_constant_value res = {0}; - struct hlsl_ir_node *res_node; struct hlsl_ir_expr *expr; unsigned int i; bool success; @@ -1638,13 +1638,9 @@ bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, } if (success) - { - if (!(res_node = hlsl_new_constant(ctx, instr->data_type, &res, &instr->loc))) - return false; - list_add_before(&expr->node.entry, &res_node->entry); - hlsl_replace_node(&expr->node, res_node); - } - return success; + return hlsl_block_add_constant(ctx, block, instr->data_type, &res, &instr->loc); + + return NULL; } struct hlsl_ir_node *hlsl_fold_constant_identities(struct hlsl_ctx *ctx,