From 7b687751ccf3f2fd016e0b02f16c67ef7aa4bb41 Mon Sep 17 00:00:00 2001 From: Francisco Casas Date: Thu, 10 Feb 2022 21:48:18 -0600 Subject: [PATCH] vkd3d-shader/hlsl: Move replace_node() to hlsl.c. Also rename it to hlsl_replace_node(). Signed-off-by: Francisco Casas Signed-off-by: Zebediah Figura Signed-off-by: Giovanni Mascellani Signed-off-by: Henri Verbeet Signed-off-by: Matteo Bruni Signed-off-by: Alexandre Julliard --- libs/vkd3d-shader/hlsl.c | 14 ++++++++++++++ libs/vkd3d-shader/hlsl.h | 2 ++ libs/vkd3d-shader/hlsl_codegen.c | 25 ++++++------------------- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 8a0f4b01..a9a42770 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -1400,6 +1400,20 @@ void hlsl_dump_function(struct hlsl_ctx *ctx, const struct hlsl_ir_function_decl vkd3d_string_buffer_cleanup(&buffer); } +void hlsl_replace_node(struct hlsl_ir_node *old, struct hlsl_ir_node *new) +{ + struct hlsl_src *src, *next; + + LIST_FOR_EACH_ENTRY_SAFE(src, next, &old->uses, struct hlsl_src, entry) + { + hlsl_src_remove(src); + hlsl_src_from_node(src, new); + } + list_remove(&old->entry); + hlsl_free_instr(old); +} + + void hlsl_free_type(struct hlsl_type *type) { struct hlsl_struct_field *field, *next_field; diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 3a69165e..67fe1a8d 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -713,6 +713,8 @@ void hlsl_dump_function(struct hlsl_ctx *ctx, const struct hlsl_ir_function_decl int hlsl_emit_dxbc(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_func, struct vkd3d_shader_code *out); +void hlsl_replace_node(struct hlsl_ir_node *old, struct hlsl_ir_node *new); + void hlsl_free_instr(struct hlsl_ir_node *node); void hlsl_free_instr_list(struct list *list); void hlsl_free_type(struct hlsl_type *type); diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index eac3513c..77ddd979 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -224,19 +224,6 @@ static bool transform_ir(struct hlsl_ctx *ctx, bool (*func)(struct hlsl_ctx *ctx return progress; } -static void replace_node(struct hlsl_ir_node *old, struct hlsl_ir_node *new) -{ - struct hlsl_src *src, *next; - - LIST_FOR_EACH_ENTRY_SAFE(src, next, &old->uses, struct hlsl_src, entry) - { - hlsl_src_remove(src); - hlsl_src_from_node(src, new); - } - list_remove(&old->entry); - hlsl_free_instr(old); -} - /* Lower casts from vec1 to vecN to swizzles. */ static bool lower_broadcasts(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context) { @@ -267,7 +254,7 @@ static bool lower_broadcasts(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, v return false; list_add_after(&new_cast->node.entry, &swizzle->node.entry); - replace_node(&cast->node, &swizzle->node); + hlsl_replace_node(&cast->node, &swizzle->node); return true; } @@ -437,7 +424,7 @@ static bool copy_propagation_transform_load(struct hlsl_ctx *ctx, list_add_before(&node->entry, &swizzle_node->node.entry); new_node = &swizzle_node->node; } - replace_node(node, new_node); + hlsl_replace_node(node, new_node); return true; } @@ -566,7 +553,7 @@ static bool fold_redundant_casts(struct hlsl_ctx *ctx, struct hlsl_ir_node *inst if (hlsl_types_are_equal(src_type, dst_type) || (src_type->base_type == dst_type->base_type && is_vec1(src_type) && is_vec1(dst_type))) { - replace_node(&expr->node, expr->operands[0].node); + hlsl_replace_node(&expr->node, expr->operands[0].node); return true; } } @@ -708,7 +695,7 @@ static bool lower_narrowing_casts(struct hlsl_ctx *ctx, struct hlsl_ir_node *ins return false; list_add_after(&new_cast->node.entry, &swizzle->node.entry); - replace_node(&cast->node, &swizzle->node); + hlsl_replace_node(&cast->node, &swizzle->node); return true; } @@ -842,7 +829,7 @@ static bool fold_constants(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, voi } list_add_before(&expr->node.entry, &res->node.entry); - replace_node(&expr->node, &res->node); + hlsl_replace_node(&expr->node, &res->node); return true; } @@ -862,7 +849,7 @@ static bool remove_trivial_swizzles(struct hlsl_ctx *ctx, struct hlsl_ir_node *i if (((swizzle->swizzle >> (2 * i)) & 3) != i) return false; - replace_node(instr, swizzle->val.node); + hlsl_replace_node(instr, swizzle->val.node); return true; }