vkd3d-shader/hlsl: Move fold_constants() to a separate file.

Also rename it to hlsl_fold_constants().

Signed-off-by: Francisco Casas <fcasas@codeweavers.com>
Signed-off-by: Zebediah Figura <zfigura@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni@codeweavers.com>
Signed-off-by: Giovanni Mascellani <gmascellani@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Francisco Casas
2022-02-10 21:48:19 -06:00
committed by Alexandre Julliard
parent 7b687751cc
commit 812123ffbf
4 changed files with 156 additions and 132 deletions

View File

@@ -702,137 +702,6 @@ static bool lower_narrowing_casts(struct hlsl_ctx *ctx, struct hlsl_ir_node *ins
return false;
}
static bool fold_constants(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
{
struct hlsl_ir_constant *arg1, *arg2 = NULL, *res;
struct hlsl_ir_expr *expr;
unsigned int i, dimx;
if (instr->type != HLSL_IR_EXPR)
return false;
expr = hlsl_ir_expr(instr);
for (i = 0; i < ARRAY_SIZE(expr->operands); ++i)
{
if (expr->operands[i].node && expr->operands[i].node->type != HLSL_IR_CONSTANT)
return false;
}
arg1 = hlsl_ir_constant(expr->operands[0].node);
if (expr->operands[1].node)
arg2 = hlsl_ir_constant(expr->operands[1].node);
dimx = instr->data_type->dimx;
if (!(res = hlsl_alloc(ctx, sizeof(*res))))
return false;
init_node(&res->node, HLSL_IR_CONSTANT, instr->data_type, instr->loc);
switch (instr->data_type->base_type)
{
case HLSL_TYPE_FLOAT:
{
switch (expr->op)
{
case HLSL_OP1_CAST:
if (instr->data_type->dimx != arg1->node.data_type->dimx
|| instr->data_type->dimy != arg1->node.data_type->dimy)
{
FIXME("Cast from %s to %s.\n", debug_hlsl_type(ctx, arg1->node.data_type),
debug_hlsl_type(ctx, instr->data_type));
vkd3d_free(res);
return false;
}
switch (arg1->node.data_type->base_type)
{
case HLSL_TYPE_INT:
for (i = 0; i < dimx; ++i)
res->value[i].f = arg1->value[i].i;
break;
case HLSL_TYPE_UINT:
for (i = 0; i < dimx; ++i)
res->value[i].f = arg1->value[i].u;
break;
default:
FIXME("Cast from %s to %s.\n", debug_hlsl_type(ctx, arg1->node.data_type),
debug_hlsl_type(ctx, instr->data_type));
vkd3d_free(res);
return false;
}
break;
default:
FIXME("Fold float op %#x.\n", expr->op);
vkd3d_free(res);
return false;
}
break;
}
case HLSL_TYPE_UINT:
{
switch (expr->op)
{
case HLSL_OP1_CAST:
if (instr->data_type->dimx != arg1->node.data_type->dimx
|| instr->data_type->dimy != arg1->node.data_type->dimy)
{
FIXME("Cast from %s to %s.\n", debug_hlsl_type(ctx, arg1->node.data_type),
debug_hlsl_type(ctx, instr->data_type));
vkd3d_free(res);
return false;
}
switch (arg1->node.data_type->base_type)
{
case HLSL_TYPE_INT:
for (i = 0; i < dimx; ++i)
res->value[i].i = arg1->value[i].u;
break;
default:
FIXME("Cast from %s to %s.\n", debug_hlsl_type(ctx, arg1->node.data_type),
debug_hlsl_type(ctx, instr->data_type));
vkd3d_free(res);
return false;
}
break;
case HLSL_OP1_NEG:
for (i = 0; i < instr->data_type->dimx; ++i)
res->value[i].u = -arg1->value[i].u;
break;
case HLSL_OP2_ADD:
for (i = 0; i < instr->data_type->dimx; ++i)
res->value[i].u = arg1->value[i].u + arg2->value[i].u;
break;
case HLSL_OP2_MUL:
for (i = 0; i < instr->data_type->dimx; ++i)
res->value[i].u = arg1->value[i].u * arg2->value[i].u;
break;
default:
FIXME("Fold uint op %#x.\n", expr->op);
vkd3d_free(res);
return false;
}
break;
}
default:
FIXME("Fold type %#x op %#x.\n", instr->data_type->base_type, expr->op);
vkd3d_free(res);
return false;
}
list_add_before(&expr->node.entry, &res->node.entry);
hlsl_replace_node(&expr->node, &res->node);
return true;
}
static bool remove_trivial_swizzles(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
{
struct hlsl_ir_swizzle *swizzle;
@@ -1785,7 +1654,7 @@ int hlsl_emit_dxbc(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_fun
transform_ir(ctx, lower_narrowing_casts, body, NULL);
do
{
progress = transform_ir(ctx, fold_constants, body, NULL);
progress = transform_ir(ctx, hlsl_fold_constants, body, NULL);
progress |= copy_propagation_execute(ctx, body);
}
while (progress);