From e5cabeafe5995efb4d9b5aceade4fdaef6a66a3f Mon Sep 17 00:00:00 2001 From: Elizabeth Figura Date: Mon, 9 Dec 2024 15:11:20 -0600 Subject: [PATCH] vkd3d-shader/hlsl: Add a hlsl_block_add_loop() helper. --- libs/vkd3d-shader/hlsl.c | 14 +++++++++++++- libs/vkd3d-shader/hlsl.h | 6 +++--- libs/vkd3d-shader/hlsl.y | 5 +---- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 07213fc1..e451a177 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -2253,7 +2253,7 @@ void hlsl_block_add_jump(struct hlsl_ctx *ctx, struct hlsl_block *block, enum hl append_new_instr(ctx, block, hlsl_new_jump(ctx, type, condition, loc)); } -struct hlsl_ir_node *hlsl_new_loop(struct hlsl_ctx *ctx, struct hlsl_block *iter, +static struct hlsl_ir_node *hlsl_new_loop(struct hlsl_ctx *ctx, struct hlsl_block *iter, struct hlsl_block *block, enum hlsl_loop_unroll_type unroll_type, unsigned int unroll_limit, const struct vkd3d_shader_location *loc) { @@ -2274,6 +2274,18 @@ struct hlsl_ir_node *hlsl_new_loop(struct hlsl_ctx *ctx, struct hlsl_block *iter return &loop->node; } +void hlsl_block_add_loop(struct hlsl_ctx *ctx, struct hlsl_block *block, + struct hlsl_block *iter, struct hlsl_block *body, enum hlsl_loop_unroll_type unroll_type, + unsigned int unroll_limit, const struct vkd3d_shader_location *loc) +{ + struct hlsl_ir_node *instr = hlsl_new_loop(ctx, iter, body, unroll_type, unroll_limit, loc); + + if (instr) + hlsl_block_add_instr(block, instr); + else + hlsl_block_cleanup(body); +} + struct clone_instr_map { struct diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 7fe3938f..f7b4f6d7 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -1525,6 +1525,9 @@ struct hlsl_ir_node *hlsl_block_add_load_component(struct hlsl_ctx *ctx, struct const struct hlsl_deref *deref, unsigned int comp, const struct vkd3d_shader_location *loc); struct hlsl_ir_node *hlsl_block_add_load_index(struct hlsl_ctx *ctx, struct hlsl_block *block, const struct hlsl_deref *deref, struct hlsl_ir_node *idx, const struct vkd3d_shader_location *loc); +void hlsl_block_add_loop(struct hlsl_ctx *ctx, struct hlsl_block *block, + struct hlsl_block *iter, struct hlsl_block *body, enum hlsl_loop_unroll_type unroll_type, + unsigned int unroll_limit, const struct vkd3d_shader_location *loc); struct hlsl_ir_node *hlsl_block_add_simple_load(struct hlsl_ctx *ctx, struct hlsl_block *block, struct hlsl_ir_var *var, const struct vkd3d_shader_location *loc); void hlsl_block_add_simple_store(struct hlsl_ctx *ctx, struct hlsl_block *block, @@ -1646,9 +1649,6 @@ struct hlsl_ir_node *hlsl_new_index(struct hlsl_ctx *ctx, struct hlsl_ir_node *v struct hlsl_ir_node *hlsl_new_interlocked(struct hlsl_ctx *ctx, enum hlsl_interlocked_op op, struct hlsl_type *type, const struct hlsl_deref *dst, struct hlsl_ir_node *coords, struct hlsl_ir_node *cmp_value, struct hlsl_ir_node *value, const struct vkd3d_shader_location *loc); -struct hlsl_ir_node *hlsl_new_loop(struct hlsl_ctx *ctx, struct hlsl_block *iter, - struct hlsl_block *block, enum hlsl_loop_unroll_type unroll_type, - unsigned int unroll_limit, const struct vkd3d_shader_location *loc); struct hlsl_ir_node *hlsl_new_matrix_swizzle(struct hlsl_ctx *ctx, struct hlsl_matrix_swizzle s, unsigned int width, struct hlsl_ir_node *val, const struct vkd3d_shader_location *loc); struct hlsl_ir_node *hlsl_new_resource_load(struct hlsl_ctx *ctx, diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 15ed6095..1f218cdf 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -655,7 +655,6 @@ static struct hlsl_block *create_loop(struct hlsl_ctx *ctx, enum hlsl_loop_type { enum hlsl_loop_unroll_type unroll_type = HLSL_LOOP_UNROLL; unsigned int i, unroll_limit = 0; - struct hlsl_ir_node *loop; check_attribute_list_for_duplicates(ctx, attributes); check_loop_attributes(ctx, attributes, loc); @@ -714,9 +713,7 @@ static struct hlsl_block *create_loop(struct hlsl_ctx *ctx, enum hlsl_loop_type else list_move_head(&body->instrs, &cond->instrs); - if (!(loop = hlsl_new_loop(ctx, iter, body, unroll_type, unroll_limit, loc))) - goto oom; - hlsl_block_add_instr(init, loop); + hlsl_block_add_loop(ctx, init, iter, body, unroll_type, unroll_limit, loc); destroy_block(cond); destroy_block(body);