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_binary_expr() helper.
This commit is contained in:
committed by
Henri Verbeet
parent
858b6a3e0b
commit
2989373212
Notes:
Henri Verbeet
2025-02-24 16:27:47 +01:00
Approved-by: Francisco Casas (@fcasas) Approved-by: Henri Verbeet (@hverbeet) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1386
@@ -1677,6 +1677,12 @@ struct hlsl_ir_node *hlsl_new_binary_expr(struct hlsl_ctx *ctx, enum hlsl_ir_exp
|
||||
return hlsl_new_expr(ctx, op, operands, arg1->data_type, &arg1->loc);
|
||||
}
|
||||
|
||||
struct hlsl_ir_node *hlsl_block_add_binary_expr(struct hlsl_ctx *ctx, struct hlsl_block *block,
|
||||
enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg1, struct hlsl_ir_node *arg2)
|
||||
{
|
||||
return append_new_instr(ctx, block, hlsl_new_binary_expr(ctx, op, arg1, arg2));
|
||||
}
|
||||
|
||||
struct hlsl_ir_node *hlsl_new_ternary_expr(struct hlsl_ctx *ctx, enum hlsl_ir_expr_op op,
|
||||
struct hlsl_ir_node *arg1, struct hlsl_ir_node *arg2, struct hlsl_ir_node *arg3)
|
||||
{
|
||||
|
@@ -1505,6 +1505,8 @@ struct hlsl_ir_node *hlsl_add_conditional(struct hlsl_ctx *ctx, struct hlsl_bloc
|
||||
void hlsl_add_function(struct hlsl_ctx *ctx, char *name, struct hlsl_ir_function_decl *decl);
|
||||
void hlsl_add_var(struct hlsl_ctx *ctx, struct hlsl_ir_var *decl);
|
||||
|
||||
struct hlsl_ir_node *hlsl_block_add_binary_expr(struct hlsl_ctx *ctx, struct hlsl_block *block,
|
||||
enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg1, struct hlsl_ir_node *arg2);
|
||||
struct hlsl_ir_node *hlsl_block_add_cast(struct hlsl_ctx *ctx, struct hlsl_block *block,
|
||||
struct hlsl_ir_node *arg, struct hlsl_type *type, const struct vkd3d_shader_location *loc);
|
||||
struct hlsl_ir_node *hlsl_block_add_float_constant(struct hlsl_ctx *ctx, struct hlsl_block *block,
|
||||
|
@@ -3433,9 +3433,7 @@ static bool add_combine_components(struct hlsl_ctx *ctx, const struct parse_init
|
||||
if (!(load = hlsl_add_load_component(ctx, params->instrs, arg, i, loc)))
|
||||
return false;
|
||||
|
||||
if (!(res = hlsl_new_binary_expr(ctx, op, res, load)))
|
||||
return NULL;
|
||||
hlsl_block_add_instr(params->instrs, res);
|
||||
res = hlsl_block_add_binary_expr(ctx, params->instrs, op, res, load);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -1593,9 +1593,9 @@ static struct hlsl_ir_node *collect_exprs(struct hlsl_ctx *ctx, struct hlsl_bloc
|
||||
{
|
||||
enum hlsl_base_type type = instr->data_type->e.numeric.type;
|
||||
struct hlsl_ir_node *operands[HLSL_MAX_OPERANDS] = {0};
|
||||
struct hlsl_ir_node *ab, *res;
|
||||
struct hlsl_ir_expr *e1, *e2;
|
||||
enum hlsl_ir_expr_op opl;
|
||||
struct hlsl_ir_node *res;
|
||||
|
||||
if (!node1 || !node2 || node1->type != HLSL_IR_EXPR || node2->type != HLSL_IR_EXPR)
|
||||
return NULL;
|
||||
@@ -1610,13 +1610,8 @@ static struct hlsl_ir_node *collect_exprs(struct hlsl_ctx *ctx, struct hlsl_bloc
|
||||
if (e1->operands[1].node->type != HLSL_IR_CONSTANT || e2->operands[1].node->type != HLSL_IR_CONSTANT)
|
||||
return NULL;
|
||||
|
||||
if (!(ab = hlsl_new_binary_expr(ctx, opr, e1->operands[1].node, e2->operands[1].node)))
|
||||
return NULL;
|
||||
hlsl_block_add_instr(block, ab);
|
||||
|
||||
operands[0] = e1->operands[0].node;
|
||||
operands[1] = ab;
|
||||
|
||||
operands[1] = hlsl_block_add_binary_expr(ctx, block, opr, e1->operands[1].node, e2->operands[1].node);
|
||||
if (!(res = hlsl_new_expr(ctx, opl, operands, instr->data_type, &instr->loc)))
|
||||
return NULL;
|
||||
hlsl_block_add_instr(block, res);
|
||||
@@ -1677,26 +1672,14 @@ bool hlsl_normalize_binary_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *inst
|
||||
if (arg2->type == HLSL_IR_CONSTANT)
|
||||
{
|
||||
/* (x OP a) OP b -> x OP (a OP b) */
|
||||
struct hlsl_ir_node *ab;
|
||||
|
||||
if (!(ab = hlsl_new_binary_expr(ctx, op, e1->operands[1].node, arg2)))
|
||||
goto fail;
|
||||
hlsl_block_add_instr(&block, ab);
|
||||
|
||||
arg1 = e1->operands[0].node;
|
||||
arg2 = ab;
|
||||
arg2 = hlsl_block_add_binary_expr(ctx, &block, op, e1->operands[1].node, arg2);
|
||||
progress = true;
|
||||
}
|
||||
else if (is_op_commutative(op))
|
||||
{
|
||||
/* (x OP a) OP y -> (x OP y) OP a */
|
||||
struct hlsl_ir_node *xy;
|
||||
|
||||
if (!(xy = hlsl_new_binary_expr(ctx, op, e1->operands[0].node, arg2)))
|
||||
goto fail;
|
||||
hlsl_block_add_instr(&block, xy);
|
||||
|
||||
arg1 = xy;
|
||||
arg1 = hlsl_block_add_binary_expr(ctx, &block, op, e1->operands[0].node, arg2);
|
||||
arg2 = e1->operands[1].node;
|
||||
progress = true;
|
||||
}
|
||||
@@ -1706,13 +1689,7 @@ bool hlsl_normalize_binary_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *inst
|
||||
&& e2->operands[0].node->type != HLSL_IR_CONSTANT && e2->operands[1].node->type == HLSL_IR_CONSTANT)
|
||||
{
|
||||
/* x OP (y OP a) -> (x OP y) OP a */
|
||||
struct hlsl_ir_node *xy;
|
||||
|
||||
if (!(xy = hlsl_new_binary_expr(ctx, op, arg1, e2->operands[0].node)))
|
||||
goto fail;
|
||||
hlsl_block_add_instr(&block, xy);
|
||||
|
||||
arg1 = xy;
|
||||
arg1 = hlsl_block_add_binary_expr(ctx, &block, op, arg1, e2->operands[0].node);
|
||||
arg2 = e2->operands[1].node;
|
||||
progress = true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user