From 3ca9656e84b41c34a746378f20bd7ec2e512edd1 Mon Sep 17 00:00:00 2001 From: Zebediah Figura Date: Thu, 10 Nov 2022 20:35:35 -0600 Subject: [PATCH] vkd3d-shader/hlsl: Pass an hlsl_block pointer to hlsl_new_loop(). --- libs/vkd3d-shader/hlsl.c | 12 ++++++++---- libs/vkd3d-shader/hlsl.h | 3 ++- libs/vkd3d-shader/hlsl.y | 21 ++++++++++++--------- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index fbe555c9..71bf0daa 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -1403,7 +1403,8 @@ struct hlsl_ir_node *hlsl_new_jump(struct hlsl_ctx *ctx, enum hlsl_ir_jump_type return &jump->node; } -struct hlsl_ir_loop *hlsl_new_loop(struct hlsl_ctx *ctx, const struct vkd3d_shader_location *loc) +struct hlsl_ir_loop *hlsl_new_loop(struct hlsl_ctx *ctx, + struct hlsl_block *block, const struct vkd3d_shader_location *loc) { struct hlsl_ir_loop *loop; @@ -1411,6 +1412,7 @@ struct hlsl_ir_loop *hlsl_new_loop(struct hlsl_ctx *ctx, const struct vkd3d_shad return NULL; init_node(&loop->node, HLSL_IR_LOOP, NULL, loc); hlsl_block_init(&loop->body); + hlsl_block_add_block(&loop->body, block); return loop; } @@ -1572,12 +1574,14 @@ static struct hlsl_ir_node *clone_load(struct hlsl_ctx *ctx, struct clone_instr_ static struct hlsl_ir_node *clone_loop(struct hlsl_ctx *ctx, struct clone_instr_map *map, struct hlsl_ir_loop *src) { struct hlsl_ir_loop *dst; + struct hlsl_block body; - if (!(dst = hlsl_new_loop(ctx, &src->node.loc))) + if (!clone_block(ctx, &body, &src->body, map)) return NULL; - if (!clone_block(ctx, &dst->body, &src->body, map)) + + if (!(dst = hlsl_new_loop(ctx, &body, &src->node.loc))) { - hlsl_free_instr(&dst->node); + hlsl_block_cleanup(&body); return NULL; } return &dst->node; diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 0256339c..68e3850c 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -1109,7 +1109,8 @@ bool hlsl_index_is_noncontiguous(struct hlsl_ir_index *index); struct hlsl_ir_node *hlsl_new_index(struct hlsl_ctx *ctx, struct hlsl_ir_node *val, struct hlsl_ir_node *idx, const struct vkd3d_shader_location *loc); -struct hlsl_ir_loop *hlsl_new_loop(struct hlsl_ctx *ctx, const struct vkd3d_shader_location *loc); +struct hlsl_ir_loop *hlsl_new_loop(struct hlsl_ctx *ctx, + struct hlsl_block *block, const struct vkd3d_shader_location *loc); struct hlsl_ir_resource_load *hlsl_new_resource_load(struct hlsl_ctx *ctx, const struct hlsl_resource_load_params *params, const struct vkd3d_shader_location *loc); struct hlsl_ir_resource_store *hlsl_new_resource_store(struct hlsl_ctx *ctx, const struct hlsl_deref *resource, diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 598f21f3..c2f47b80 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -459,6 +459,7 @@ static struct list *create_loop(struct hlsl_ctx *ctx, enum loop_type type, const struct list *iter, struct list *body, const struct vkd3d_shader_location *loc) { struct hlsl_ir_loop *loop = NULL; + struct hlsl_block body_block; unsigned int i; if (attribute_list_has_duplicates(attributes)) @@ -494,23 +495,25 @@ static struct list *create_loop(struct hlsl_ctx *ctx, enum loop_type type, const if (!init && !(init = make_empty_list(ctx))) goto oom; - if (!(loop = hlsl_new_loop(ctx, loc))) - goto oom; - list_add_tail(init, &loop->node.entry); - if (!append_conditional_break(ctx, cond)) goto oom; - if (type != LOOP_DO_WHILE) - list_move_tail(&loop->body.instrs, cond); + hlsl_block_init(&body_block); - list_move_tail(&loop->body.instrs, body); + if (type != LOOP_DO_WHILE) + list_move_tail(&body_block.instrs, cond); + + list_move_tail(&body_block.instrs, body); if (iter) - list_move_tail(&loop->body.instrs, iter); + list_move_tail(&body_block.instrs, iter); if (type == LOOP_DO_WHILE) - list_move_tail(&loop->body.instrs, cond); + list_move_tail(&body_block.instrs, cond); + + if (!(loop = hlsl_new_loop(ctx, &body_block, loc))) + goto oom; + list_add_tail(init, &loop->node.entry); vkd3d_free(cond); vkd3d_free(body);