mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-04-13 05:43:18 -07:00
vkd3d-shader/hlsl: Add a hlsl_block_add_jump() helper.
This commit is contained in:
committed by
Henri Verbeet
parent
5d55a5894c
commit
20aa37237d
Notes:
Henri Verbeet
2025-03-10 15:23:02 +01:00
Approved-by: Francisco Casas (@fcasas) Approved-by: Henri Verbeet (@hverbeet) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1404
@@ -2217,7 +2217,7 @@ struct hlsl_ir_node *hlsl_new_index(struct hlsl_ctx *ctx, struct hlsl_ir_node *v
|
||||
return &index->node;
|
||||
}
|
||||
|
||||
struct hlsl_ir_node *hlsl_new_jump(struct hlsl_ctx *ctx, enum hlsl_ir_jump_type type,
|
||||
static struct hlsl_ir_node *hlsl_new_jump(struct hlsl_ctx *ctx, enum hlsl_ir_jump_type type,
|
||||
struct hlsl_ir_node *condition, const struct vkd3d_shader_location *loc)
|
||||
{
|
||||
struct hlsl_ir_jump *jump;
|
||||
@@ -2230,6 +2230,12 @@ struct hlsl_ir_node *hlsl_new_jump(struct hlsl_ctx *ctx, enum hlsl_ir_jump_type
|
||||
return &jump->node;
|
||||
}
|
||||
|
||||
void hlsl_block_add_jump(struct hlsl_ctx *ctx, struct hlsl_block *block, enum hlsl_ir_jump_type type,
|
||||
struct hlsl_ir_node *condition, const struct vkd3d_shader_location *loc)
|
||||
{
|
||||
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,
|
||||
struct hlsl_block *block, enum hlsl_loop_unroll_type unroll_type,
|
||||
unsigned int unroll_limit, const struct vkd3d_shader_location *loc)
|
||||
|
@@ -1517,6 +1517,8 @@ struct hlsl_ir_node *hlsl_block_add_float_constant(struct hlsl_ctx *ctx, struct
|
||||
float f, const struct vkd3d_shader_location *loc);
|
||||
struct hlsl_ir_node *hlsl_block_add_int_constant(struct hlsl_ctx *ctx, struct hlsl_block *block,
|
||||
int32_t n, const struct vkd3d_shader_location *loc);
|
||||
void hlsl_block_add_jump(struct hlsl_ctx *ctx, struct hlsl_block *block, enum hlsl_ir_jump_type type,
|
||||
struct hlsl_ir_node *condition, const struct vkd3d_shader_location *loc);
|
||||
struct hlsl_ir_node *hlsl_block_add_load_component(struct hlsl_ctx *ctx, struct hlsl_block *block,
|
||||
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,
|
||||
@@ -1610,8 +1612,6 @@ struct hlsl_ir_function_decl *hlsl_new_func_decl(struct hlsl_ctx *ctx,
|
||||
const struct hlsl_semantic *semantic, const struct vkd3d_shader_location *loc);
|
||||
struct hlsl_ir_node *hlsl_new_if(struct hlsl_ctx *ctx, struct hlsl_ir_node *condition,
|
||||
struct hlsl_block *then_block, struct hlsl_block *else_block, const struct vkd3d_shader_location *loc);
|
||||
struct hlsl_ir_node *hlsl_new_jump(struct hlsl_ctx *ctx,
|
||||
enum hlsl_ir_jump_type type, struct hlsl_ir_node *condition, const struct vkd3d_shader_location *loc);
|
||||
struct hlsl_type *hlsl_new_stream_output_type(struct hlsl_ctx *ctx,
|
||||
enum hlsl_so_object_type so_type, struct hlsl_type *type);
|
||||
struct hlsl_ir_node *hlsl_new_ternary_expr(struct hlsl_ctx *ctx, enum hlsl_ir_expr_op op,
|
||||
|
@@ -451,7 +451,7 @@ static uint32_t add_modifiers(struct hlsl_ctx *ctx, uint32_t modifiers, uint32_t
|
||||
|
||||
static bool append_conditional_break(struct hlsl_ctx *ctx, struct hlsl_block *cond_block)
|
||||
{
|
||||
struct hlsl_ir_node *condition, *cast, *not, *iff, *jump;
|
||||
struct hlsl_ir_node *condition, *cast, *not, *iff;
|
||||
struct hlsl_block then_block;
|
||||
struct hlsl_type *bool_type;
|
||||
|
||||
@@ -472,10 +472,7 @@ static bool append_conditional_break(struct hlsl_ctx *ctx, struct hlsl_block *co
|
||||
not = hlsl_block_add_unary_expr(ctx, cond_block, HLSL_OP1_LOGIC_NOT, cast, &condition->loc);
|
||||
|
||||
hlsl_block_init(&then_block);
|
||||
|
||||
if (!(jump = hlsl_new_jump(ctx, HLSL_IR_JUMP_BREAK, NULL, &condition->loc)))
|
||||
return false;
|
||||
hlsl_block_add_instr(&then_block, jump);
|
||||
hlsl_block_add_jump(ctx, &then_block, HLSL_IR_JUMP_BREAK, NULL, &condition->loc);
|
||||
|
||||
if (!(iff = hlsl_new_if(ctx, not, &then_block, NULL, &condition->loc)))
|
||||
return false;
|
||||
@@ -851,7 +848,6 @@ static bool add_return(struct hlsl_ctx *ctx, struct hlsl_block *block,
|
||||
struct hlsl_ir_node *return_value, const struct vkd3d_shader_location *loc)
|
||||
{
|
||||
struct hlsl_type *return_type = ctx->cur_function->return_type;
|
||||
struct hlsl_ir_node *jump;
|
||||
|
||||
if (ctx->cur_function->return_var)
|
||||
{
|
||||
@@ -877,10 +873,7 @@ static bool add_return(struct hlsl_ctx *ctx, struct hlsl_block *block,
|
||||
hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_RETURN, "Void functions cannot return a value.");
|
||||
}
|
||||
|
||||
if (!(jump = hlsl_new_jump(ctx, HLSL_IR_JUMP_RETURN, NULL, loc)))
|
||||
return false;
|
||||
hlsl_block_add_instr(block, jump);
|
||||
|
||||
hlsl_block_add_jump(ctx, block, HLSL_IR_JUMP_RETURN, NULL, loc);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -3578,7 +3571,7 @@ static bool intrinsic_clamp(struct hlsl_ctx *ctx,
|
||||
static bool intrinsic_clip(struct hlsl_ctx *ctx,
|
||||
const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
|
||||
{
|
||||
struct hlsl_ir_node *condition, *jump;
|
||||
struct hlsl_ir_node *condition;
|
||||
|
||||
if (!elementwise_intrinsic_float_convert_args(ctx, params, loc))
|
||||
return false;
|
||||
@@ -3596,10 +3589,7 @@ static bool intrinsic_clip(struct hlsl_ctx *ctx,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(jump = hlsl_new_jump(ctx, HLSL_IR_JUMP_DISCARD_NEG, condition, loc)))
|
||||
return false;
|
||||
hlsl_block_add_instr(params->instrs, jump);
|
||||
|
||||
hlsl_block_add_jump(ctx, params->instrs, HLSL_IR_JUMP_DISCARD_NEG, condition, loc);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -8954,8 +8944,6 @@ statement:
|
||||
jump_statement:
|
||||
KW_BREAK ';'
|
||||
{
|
||||
struct hlsl_ir_node *jump;
|
||||
|
||||
if (!is_break_allowed(ctx->cur_scope))
|
||||
{
|
||||
hlsl_error(ctx, &@1, VKD3D_SHADER_ERROR_HLSL_INVALID_SYNTAX,
|
||||
@@ -8964,22 +8952,15 @@ jump_statement:
|
||||
|
||||
if (!($$ = make_empty_block(ctx)))
|
||||
YYABORT;
|
||||
if (!(jump = hlsl_new_jump(ctx, HLSL_IR_JUMP_BREAK, NULL, &@1)))
|
||||
YYABORT;
|
||||
hlsl_block_add_instr($$, jump);
|
||||
hlsl_block_add_jump(ctx, $$, HLSL_IR_JUMP_BREAK, NULL, &@1);
|
||||
}
|
||||
| KW_CONTINUE ';'
|
||||
{
|
||||
struct hlsl_ir_node *jump;
|
||||
|
||||
check_continue(ctx, ctx->cur_scope, &@1);
|
||||
|
||||
if (!($$ = make_empty_block(ctx)))
|
||||
YYABORT;
|
||||
|
||||
if (!(jump = hlsl_new_jump(ctx, HLSL_IR_JUMP_UNRESOLVED_CONTINUE, NULL, &@1)))
|
||||
YYABORT;
|
||||
hlsl_block_add_instr($$, jump);
|
||||
hlsl_block_add_jump(ctx, $$, HLSL_IR_JUMP_UNRESOLVED_CONTINUE, NULL, &@1);
|
||||
}
|
||||
| KW_RETURN expr ';'
|
||||
{
|
||||
@@ -8996,16 +8977,12 @@ jump_statement:
|
||||
}
|
||||
| KW_DISCARD ';'
|
||||
{
|
||||
struct hlsl_ir_node *discard, *c;
|
||||
struct hlsl_ir_node *c;
|
||||
|
||||
if (!($$ = make_empty_block(ctx)))
|
||||
YYABORT;
|
||||
|
||||
c = hlsl_block_add_uint_constant(ctx, $$, ~0u, &@1);
|
||||
|
||||
if (!(discard = hlsl_new_jump(ctx, HLSL_IR_JUMP_DISCARD_NZ, c, &@1)))
|
||||
return false;
|
||||
hlsl_block_add_instr($$, discard);
|
||||
hlsl_block_add_jump(ctx, $$, HLSL_IR_JUMP_DISCARD_NZ, c, &@1);
|
||||
}
|
||||
|
||||
selection_statement:
|
||||
|
@@ -829,9 +829,9 @@ static bool find_recursive_calls(struct hlsl_ctx *ctx, struct hlsl_ir_node *inst
|
||||
static void insert_early_return_break(struct hlsl_ctx *ctx,
|
||||
struct hlsl_ir_function_decl *func, struct hlsl_ir_node *cf_instr)
|
||||
{
|
||||
struct hlsl_ir_node *iff, *jump;
|
||||
struct hlsl_block then_block;
|
||||
struct hlsl_ir_load *load;
|
||||
struct hlsl_ir_node *iff;
|
||||
|
||||
hlsl_block_init(&then_block);
|
||||
|
||||
@@ -839,9 +839,7 @@ static void insert_early_return_break(struct hlsl_ctx *ctx,
|
||||
return;
|
||||
list_add_after(&cf_instr->entry, &load->node.entry);
|
||||
|
||||
if (!(jump = hlsl_new_jump(ctx, HLSL_IR_JUMP_BREAK, NULL, &cf_instr->loc)))
|
||||
return;
|
||||
hlsl_block_add_instr(&then_block, jump);
|
||||
hlsl_block_add_jump(ctx, &then_block, HLSL_IR_JUMP_BREAK, NULL, &cf_instr->loc);
|
||||
|
||||
if (!(iff = hlsl_new_if(ctx, &load->node, &then_block, NULL, &cf_instr->loc)))
|
||||
return;
|
||||
@@ -2694,16 +2692,9 @@ static bool normalize_switch_cases(struct hlsl_ctx *ctx, struct hlsl_ir_node *in
|
||||
}
|
||||
else
|
||||
{
|
||||
struct hlsl_ir_node *jump;
|
||||
|
||||
if (!(def = hlsl_new_switch_case(ctx, 0, true, NULL, &s->node.loc)))
|
||||
return true;
|
||||
if (!(jump = hlsl_new_jump(ctx, HLSL_IR_JUMP_BREAK, NULL, &s->node.loc)))
|
||||
{
|
||||
hlsl_free_ir_switch_case(def);
|
||||
return true;
|
||||
}
|
||||
hlsl_block_add_instr(&def->body, jump);
|
||||
hlsl_block_add_jump(ctx, &def->body, HLSL_IR_JUMP_BREAK, NULL, &s->node.loc);
|
||||
}
|
||||
list_add_tail(&s->cases, &def->entry);
|
||||
|
||||
|
Reference in New Issue
Block a user