mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-12-15 08:03:30 -08:00
vkd3d-shader/hlsl: Use replace_ir() for hlsl_fold_constant_identities().
This commit is contained in:
committed by
Henri Verbeet
parent
bdb31a4983
commit
6e8eeb8f7a
Notes:
Henri Verbeet
2025-10-28 16:58:15 +01:00
Approved-by: Francisco Casas (@fcasas) Approved-by: Henri Verbeet (@hverbeet) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1794
@@ -1836,7 +1836,8 @@ struct hlsl_reg hlsl_reg_from_deref(struct hlsl_ctx *ctx, const struct hlsl_dere
|
||||
|
||||
bool hlsl_copy_propagation_execute(struct hlsl_ctx *ctx, struct hlsl_block *block);
|
||||
bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context);
|
||||
bool hlsl_fold_constant_identities(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context);
|
||||
struct hlsl_ir_node *hlsl_fold_constant_identities(struct hlsl_ctx *ctx,
|
||||
struct hlsl_ir_node *instr, struct hlsl_block *block);
|
||||
bool hlsl_normalize_binary_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context);
|
||||
struct hlsl_ir_node *hlsl_fold_constant_swizzles(struct hlsl_ctx *ctx,
|
||||
struct hlsl_ir_node *instr, struct hlsl_block *block);
|
||||
|
||||
@@ -8474,7 +8474,7 @@ static bool simplify_exprs(struct hlsl_ctx *ctx, struct hlsl_block *block)
|
||||
progress |= hlsl_transform_ir(ctx, hlsl_normalize_binary_exprs, block, NULL);
|
||||
progress |= hlsl_transform_ir(ctx, fold_unary_identities, block, NULL);
|
||||
progress |= hlsl_transform_ir(ctx, fold_conditional_identities, block, NULL);
|
||||
progress |= hlsl_transform_ir(ctx, hlsl_fold_constant_identities, block, NULL);
|
||||
progress |= replace_ir(ctx, hlsl_fold_constant_identities, block);
|
||||
progress |= replace_ir(ctx, hlsl_fold_constant_swizzles, block);
|
||||
|
||||
any_progress |= progress;
|
||||
|
||||
@@ -1647,27 +1647,27 @@ bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr,
|
||||
return success;
|
||||
}
|
||||
|
||||
bool hlsl_fold_constant_identities(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
|
||||
struct hlsl_ir_node *hlsl_fold_constant_identities(struct hlsl_ctx *ctx,
|
||||
struct hlsl_ir_node *instr, struct hlsl_block *block)
|
||||
{
|
||||
static const struct hlsl_constant_value zero;
|
||||
struct hlsl_ir_constant *const_arg = NULL;
|
||||
struct hlsl_ir_node *mut_arg = NULL;
|
||||
struct hlsl_ir_node *res_node;
|
||||
struct hlsl_ir_expr *expr;
|
||||
unsigned int i;
|
||||
|
||||
if (instr->type != HLSL_IR_EXPR)
|
||||
return false;
|
||||
return NULL;
|
||||
expr = hlsl_ir_expr(instr);
|
||||
|
||||
if (instr->data_type->class > HLSL_CLASS_VECTOR)
|
||||
return false;
|
||||
return NULL;
|
||||
|
||||
/* Verify that the expression has two operands. */
|
||||
for (i = 0; i < ARRAY_SIZE(expr->operands); ++i)
|
||||
{
|
||||
if (!!expr->operands[i].node != (i < 2))
|
||||
return false;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (expr->operands[0].node->type == HLSL_IR_CONSTANT)
|
||||
@@ -1682,34 +1682,33 @@ bool hlsl_fold_constant_identities(struct hlsl_ctx *ctx, struct hlsl_ir_node *in
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
res_node = NULL;
|
||||
switch (expr->op)
|
||||
{
|
||||
case HLSL_OP2_ADD:
|
||||
if (hlsl_constant_is_zero(const_arg))
|
||||
res_node = mut_arg;
|
||||
return mut_arg;
|
||||
break;
|
||||
|
||||
case HLSL_OP2_MUL:
|
||||
if (hlsl_constant_is_one(const_arg))
|
||||
res_node = mut_arg;
|
||||
return mut_arg;
|
||||
break;
|
||||
|
||||
case HLSL_OP2_LOGIC_AND:
|
||||
if (hlsl_constant_is_zero(const_arg))
|
||||
res_node = &const_arg->node;
|
||||
return &const_arg->node;
|
||||
else if (hlsl_constant_is_one(const_arg))
|
||||
res_node = mut_arg;
|
||||
return mut_arg;
|
||||
break;
|
||||
|
||||
case HLSL_OP2_LOGIC_OR:
|
||||
if (hlsl_constant_is_zero(const_arg))
|
||||
res_node = mut_arg;
|
||||
return mut_arg;
|
||||
else if (hlsl_constant_is_one(const_arg))
|
||||
res_node = &const_arg->node;
|
||||
return &const_arg->node;
|
||||
break;
|
||||
|
||||
case HLSL_OP2_LESS:
|
||||
@@ -1718,21 +1717,13 @@ bool hlsl_fold_constant_identities(struct hlsl_ctx *ctx, struct hlsl_ir_node *in
|
||||
|| expr->operands[1].node->type != HLSL_IR_CONSTANT
|
||||
|| !hlsl_constant_is_zero(hlsl_ir_constant(expr->operands[1].node)))
|
||||
break;
|
||||
if (!(res_node = hlsl_new_constant(ctx, instr->data_type, &zero, &instr->loc)))
|
||||
break;
|
||||
list_add_before(&expr->node.entry, &res_node->entry);
|
||||
break;
|
||||
return hlsl_block_add_constant(ctx, block, instr->data_type, &zero, &instr->loc);
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (res_node)
|
||||
{
|
||||
hlsl_replace_node(&expr->node, res_node);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static bool is_op_associative(enum hlsl_ir_expr_op op, enum hlsl_base_type type)
|
||||
|
||||
Reference in New Issue
Block a user