vkd3d-shader/hlsl: Pass a hlsl_constant_value pointer to hlsl_new_constant().

This commit is contained in:
Zebediah Figura
2022-11-11 19:10:14 -06:00
committed by Alexandre Julliard
parent 79f443d131
commit 740b0ad807
Notes: Alexandre Julliard 2023-06-08 23:22:36 +02:00
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Henri Verbeet (@hverbeet)
Approved-by: Alexandre Julliard (@julliard)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/223
5 changed files with 85 additions and 84 deletions

View File

@@ -1147,7 +1147,7 @@ struct hlsl_ir_node *hlsl_new_call(struct hlsl_ctx *ctx, struct hlsl_ir_function
} }
struct hlsl_ir_constant *hlsl_new_constant(struct hlsl_ctx *ctx, struct hlsl_type *type, struct hlsl_ir_constant *hlsl_new_constant(struct hlsl_ctx *ctx, struct hlsl_type *type,
const struct vkd3d_shader_location *loc) const struct hlsl_constant_value *value, const struct vkd3d_shader_location *loc)
{ {
struct hlsl_ir_constant *c; struct hlsl_ir_constant *c;
@@ -1157,53 +1157,54 @@ struct hlsl_ir_constant *hlsl_new_constant(struct hlsl_ctx *ctx, struct hlsl_typ
return NULL; return NULL;
init_node(&c->node, HLSL_IR_CONSTANT, type, loc); init_node(&c->node, HLSL_IR_CONSTANT, type, loc);
c->value = *value;
return c; return c;
} }
struct hlsl_ir_node *hlsl_new_bool_constant(struct hlsl_ctx *ctx, bool b, const struct vkd3d_shader_location *loc) struct hlsl_ir_node *hlsl_new_bool_constant(struct hlsl_ctx *ctx, bool b, const struct vkd3d_shader_location *loc)
{ {
struct hlsl_constant_value value;
struct hlsl_ir_constant *c; struct hlsl_ir_constant *c;
if ((c = hlsl_new_constant(ctx, hlsl_get_scalar_type(ctx, HLSL_TYPE_BOOL), loc))) value.u[0].u = b ? ~0u : 0;
c->value.u[0].u = b ? ~0u : 0; if (!(c = hlsl_new_constant(ctx, hlsl_get_scalar_type(ctx, HLSL_TYPE_BOOL), &value, loc)))
return NULL;
return &c->node; return &c->node;
} }
struct hlsl_ir_node *hlsl_new_float_constant(struct hlsl_ctx *ctx, float f, struct hlsl_ir_node *hlsl_new_float_constant(struct hlsl_ctx *ctx, float f,
const struct vkd3d_shader_location *loc) const struct vkd3d_shader_location *loc)
{ {
struct hlsl_constant_value value;
struct hlsl_ir_constant *c; struct hlsl_ir_constant *c;
if ((c = hlsl_new_constant(ctx, hlsl_get_scalar_type(ctx, HLSL_TYPE_FLOAT), loc))) value.u[0].f = f;
c->value.u[0].f = f; if (!(c = hlsl_new_constant(ctx, hlsl_get_scalar_type(ctx, HLSL_TYPE_FLOAT), &value, loc)))
return NULL;
return &c->node; return &c->node;
} }
struct hlsl_ir_node *hlsl_new_int_constant(struct hlsl_ctx *ctx, int32_t n, const struct vkd3d_shader_location *loc) struct hlsl_ir_node *hlsl_new_int_constant(struct hlsl_ctx *ctx, int32_t n, const struct vkd3d_shader_location *loc)
{ {
struct hlsl_constant_value value;
struct hlsl_ir_constant *c; struct hlsl_ir_constant *c;
c = hlsl_new_constant(ctx, hlsl_get_scalar_type(ctx, HLSL_TYPE_INT), loc); value.u[0].i = n;
if (!(c = hlsl_new_constant(ctx, hlsl_get_scalar_type(ctx, HLSL_TYPE_INT), &value, loc)))
if (c) return NULL;
c->value.u[0].i = n;
return &c->node; return &c->node;
} }
struct hlsl_ir_node *hlsl_new_uint_constant(struct hlsl_ctx *ctx, unsigned int n, struct hlsl_ir_node *hlsl_new_uint_constant(struct hlsl_ctx *ctx, unsigned int n,
const struct vkd3d_shader_location *loc) const struct vkd3d_shader_location *loc)
{ {
struct hlsl_constant_value value;
struct hlsl_ir_constant *c; struct hlsl_ir_constant *c;
c = hlsl_new_constant(ctx, hlsl_get_scalar_type(ctx, HLSL_TYPE_UINT), loc); value.u[0].u = n;
if (!(c = hlsl_new_constant(ctx, hlsl_get_scalar_type(ctx, HLSL_TYPE_UINT), &value, loc)))
if (c) return NULL;
c->value.u[0].u = n;
return &c->node; return &c->node;
} }
@@ -1561,9 +1562,8 @@ static struct hlsl_ir_node *clone_constant(struct hlsl_ctx *ctx, struct hlsl_ir_
{ {
struct hlsl_ir_constant *dst; struct hlsl_ir_constant *dst;
if (!(dst = hlsl_new_constant(ctx, src->node.data_type, &src->node.loc))) if (!(dst = hlsl_new_constant(ctx, src->node.data_type, &src->value, &src->node.loc)))
return NULL; return NULL;
dst->value = src->value;
return &dst->node; return &dst->node;
} }

View File

@@ -1107,7 +1107,7 @@ struct hlsl_ir_node *hlsl_new_call(struct hlsl_ctx *ctx, struct hlsl_ir_function
struct hlsl_ir_node *hlsl_new_cast(struct hlsl_ctx *ctx, struct hlsl_ir_node *node, struct hlsl_type *type, struct hlsl_ir_node *hlsl_new_cast(struct hlsl_ctx *ctx, struct hlsl_ir_node *node, struct hlsl_type *type,
const struct vkd3d_shader_location *loc); const struct vkd3d_shader_location *loc);
struct hlsl_ir_constant *hlsl_new_constant(struct hlsl_ctx *ctx, struct hlsl_type *type, struct hlsl_ir_constant *hlsl_new_constant(struct hlsl_ctx *ctx, struct hlsl_type *type,
const struct vkd3d_shader_location *loc); const struct hlsl_constant_value *value, const struct vkd3d_shader_location *loc);
struct hlsl_ir_node *hlsl_new_copy(struct hlsl_ctx *ctx, struct hlsl_ir_node *node); struct hlsl_ir_node *hlsl_new_copy(struct hlsl_ctx *ctx, struct hlsl_ir_node *node);
struct hlsl_ir_node *hlsl_new_expr(struct hlsl_ctx *ctx, enum hlsl_ir_expr_op op, struct hlsl_ir_node *hlsl_new_expr(struct hlsl_ctx *ctx, enum hlsl_ir_expr_op op,
struct hlsl_ir_node *operands[HLSL_MAX_OPERANDS], struct hlsl_ir_node *operands[HLSL_MAX_OPERANDS],

View File

@@ -2697,8 +2697,8 @@ static bool intrinsic_fmod(struct hlsl_ctx *ctx, const struct parse_initializer
const struct vkd3d_shader_location *loc) const struct vkd3d_shader_location *loc)
{ {
struct hlsl_ir_node *x, *y, *div, *abs, *frac, *neg_frac, *ge, *select; struct hlsl_ir_node *x, *y, *div, *abs, *frac, *neg_frac, *ge, *select;
static const struct hlsl_constant_value zero_value;
struct hlsl_ir_constant *zero; struct hlsl_ir_constant *zero;
unsigned int count, i;
if (!(x = intrinsic_float_convert_arg(ctx, params, params->args[0], loc))) if (!(x = intrinsic_float_convert_arg(ctx, params, params->args[0], loc)))
return false; return false;
@@ -2709,14 +2709,10 @@ static bool intrinsic_fmod(struct hlsl_ctx *ctx, const struct parse_initializer
if (!(div = add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_DIV, x, y, loc))) if (!(div = add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_DIV, x, y, loc)))
return false; return false;
if (!(zero = hlsl_new_constant(ctx, div->data_type, loc))) if (!(zero = hlsl_new_constant(ctx, div->data_type, &zero_value, loc)))
return false; return false;
list_add_tail(params->instrs, &zero->node.entry); list_add_tail(params->instrs, &zero->node.entry);
count = hlsl_type_element_count(div->data_type);
for (i = 0; i < count; ++i)
zero->value.u[i].f = 0.0f;
if (!(abs = add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_ABS, div, loc))) if (!(abs = add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_ABS, div, loc)))
return false; return false;
@@ -2825,6 +2821,7 @@ static bool intrinsic_lit(struct hlsl_ctx *ctx,
{ {
struct hlsl_ir_node *n_l_neg, *n_h_neg, *specular_or, *specular_pow, *load; struct hlsl_ir_node *n_l_neg, *n_h_neg, *specular_or, *specular_pow, *load;
struct hlsl_ir_node *n_l, *n_h, *m, *diffuse, *zero, *store; struct hlsl_ir_node *n_l, *n_h, *m, *diffuse, *zero, *store;
struct hlsl_constant_value init_value;
struct hlsl_ir_constant *init; struct hlsl_ir_constant *init;
struct hlsl_ir_load *var_load; struct hlsl_ir_load *var_load;
struct hlsl_deref var_deref; struct hlsl_deref var_deref;
@@ -2855,12 +2852,12 @@ static bool intrinsic_lit(struct hlsl_ctx *ctx,
return false; return false;
hlsl_init_simple_deref_from_var(&var_deref, var); hlsl_init_simple_deref_from_var(&var_deref, var);
if (!(init = hlsl_new_constant(ctx, ret_type, loc))) init_value.u[0].f = 1.0f;
init_value.u[1].f = 0.0f;
init_value.u[2].f = 0.0f;
init_value.u[3].f = 1.0f;
if (!(init = hlsl_new_constant(ctx, ret_type, &init_value, loc)))
return false; return false;
init->value.u[0].f = 1.0f;
init->value.u[1].f = 0.0f;
init->value.u[2].f = 0.0f;
init->value.u[3].f = 1.0f;
list_add_tail(params->instrs, &init->node.entry); list_add_tail(params->instrs, &init->node.entry);
if (!(store = hlsl_new_simple_store(ctx, var, &init->node))) if (!(store = hlsl_new_simple_store(ctx, var, &init->node)))
@@ -3162,12 +3159,13 @@ static bool intrinsic_sign(struct hlsl_ctx *ctx,
const struct parse_initializer *params, const struct vkd3d_shader_location *loc) const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
{ {
struct hlsl_ir_node *lt, *neg, *op1, *op2, *arg = params->args[0]; struct hlsl_ir_node *lt, *neg, *op1, *op2, *arg = params->args[0];
static const struct hlsl_constant_value zero_value;
struct hlsl_ir_constant *zero; struct hlsl_ir_constant *zero;
struct hlsl_type *int_type = hlsl_get_numeric_type(ctx, arg->data_type->class, HLSL_TYPE_INT, struct hlsl_type *int_type = hlsl_get_numeric_type(ctx, arg->data_type->class, HLSL_TYPE_INT,
arg->data_type->dimx, arg->data_type->dimy); arg->data_type->dimx, arg->data_type->dimy);
if (!(zero = hlsl_new_constant(ctx, hlsl_get_scalar_type(ctx, arg->data_type->base_type), loc))) if (!(zero = hlsl_new_constant(ctx, hlsl_get_scalar_type(ctx, arg->data_type->base_type), &zero_value, loc)))
return false; return false;
list_add_tail(params->instrs, &zero->node.entry); list_add_tail(params->instrs, &zero->node.entry);

View File

@@ -1353,9 +1353,8 @@ static bool copy_propagation_replace_with_constant_vector(struct hlsl_ctx *ctx,
values.u[i] = hlsl_ir_constant(value->node)->value.u[value->component]; values.u[i] = hlsl_ir_constant(value->node)->value.u[value->component];
} }
if (!(cons = hlsl_new_constant(ctx, instr->data_type, &instr->loc))) if (!(cons = hlsl_new_constant(ctx, instr->data_type, &values, &instr->loc)))
return false; return false;
cons->value = values;
list_add_before(&instr->entry, &cons->node.entry); list_add_before(&instr->entry, &cons->node.entry);
TRACE("Load from %s[%u-%u]%s turned into a constant %p.\n", TRACE("Load from %s[%u-%u]%s turned into a constant %p.\n",
@@ -2017,6 +2016,7 @@ static bool lower_nonconstant_vector_derefs(struct hlsl_ctx *ctx, struct hlsl_ir
if (type->class == HLSL_CLASS_VECTOR && idx->type != HLSL_IR_CONSTANT) if (type->class == HLSL_CLASS_VECTOR && idx->type != HLSL_IR_CONSTANT)
{ {
struct hlsl_ir_node *eq, *swizzle, *dot, *operands[HLSL_MAX_OPERANDS] = {0}; struct hlsl_ir_node *eq, *swizzle, *dot, *operands[HLSL_MAX_OPERANDS] = {0};
struct hlsl_constant_value value;
struct hlsl_ir_load *vector_load; struct hlsl_ir_load *vector_load;
struct hlsl_ir_constant *c; struct hlsl_ir_constant *c;
enum hlsl_ir_expr_op op; enum hlsl_ir_expr_op op;
@@ -2029,12 +2029,12 @@ static bool lower_nonconstant_vector_derefs(struct hlsl_ctx *ctx, struct hlsl_ir
return false; return false;
list_add_before(&instr->entry, &swizzle->entry); list_add_before(&instr->entry, &swizzle->entry);
if (!(c = hlsl_new_constant(ctx, hlsl_get_vector_type(ctx, HLSL_TYPE_UINT, type->dimx), &instr->loc))) value.u[0].u = 0;
value.u[1].u = 1;
value.u[2].u = 2;
value.u[3].u = 3;
if (!(c = hlsl_new_constant(ctx, hlsl_get_vector_type(ctx, HLSL_TYPE_UINT, type->dimx), &value, &instr->loc)))
return false; return false;
c->value.u[0].u = 0;
c->value.u[1].u = 1;
c->value.u[2].u = 2;
c->value.u[3].u = 3;
list_add_before(&instr->entry, &c->node.entry); list_add_before(&instr->entry, &c->node.entry);
operands[0] = swizzle; operands[0] = swizzle;
@@ -2193,6 +2193,7 @@ static bool lower_round(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *
{ {
struct hlsl_ir_node *arg, *neg, *sum, *frc, *replacement; struct hlsl_ir_node *arg, *neg, *sum, *frc, *replacement;
struct hlsl_type *type = instr->data_type; struct hlsl_type *type = instr->data_type;
struct hlsl_constant_value half_value;
unsigned int i, component_count; unsigned int i, component_count;
struct hlsl_ir_constant *half; struct hlsl_ir_constant *half;
struct hlsl_ir_expr *expr; struct hlsl_ir_expr *expr;
@@ -2205,12 +2206,12 @@ static bool lower_round(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *
if (expr->op != HLSL_OP1_ROUND) if (expr->op != HLSL_OP1_ROUND)
return false; return false;
if (!(half = hlsl_new_constant(ctx, type, &expr->node.loc)))
return false;
component_count = hlsl_type_component_count(type); component_count = hlsl_type_component_count(type);
for (i = 0; i < component_count; ++i) for (i = 0; i < component_count; ++i)
half->value.u[i].f = 0.5f; half_value.u[i].f = 0.5f;
if (!(half = hlsl_new_constant(ctx, type, &half_value, &expr->node.loc)))
return false;
list_add_before(&instr->entry, &half->node.entry); list_add_before(&instr->entry, &half->node.entry);
if (!(sum = hlsl_new_binary_expr(ctx, HLSL_OP2_ADD, arg, &half->node))) if (!(sum = hlsl_new_binary_expr(ctx, HLSL_OP2_ADD, arg, &half->node)))
@@ -2236,6 +2237,7 @@ static bool lower_round(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *
static bool lower_casts_to_bool(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context) static bool lower_casts_to_bool(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
{ {
struct hlsl_type *type = instr->data_type, *arg_type; struct hlsl_type *type = instr->data_type, *arg_type;
static const struct hlsl_constant_value zero_value;
struct hlsl_ir_constant *zero; struct hlsl_ir_constant *zero;
struct hlsl_ir_expr *expr; struct hlsl_ir_expr *expr;
@@ -2253,7 +2255,7 @@ static bool lower_casts_to_bool(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr
/* Narrowing casts should have already been lowered. */ /* Narrowing casts should have already been lowered. */
assert(type->dimx == arg_type->dimx); assert(type->dimx == arg_type->dimx);
zero = hlsl_new_constant(ctx, arg_type, &instr->loc); zero = hlsl_new_constant(ctx, arg_type, &zero_value, &instr->loc);
if (!zero) if (!zero)
return false; return false;
list_add_before(&instr->entry, &zero->node.entry); list_add_before(&instr->entry, &zero->node.entry);
@@ -2303,6 +2305,7 @@ static bool lower_int_division(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr,
{ {
struct hlsl_ir_node *arg1, *arg2, *xor, *and, *abs1, *abs2, *div, *neg, *cast1, *cast2, *cast3, *cond; struct hlsl_ir_node *arg1, *arg2, *xor, *and, *abs1, *abs2, *div, *neg, *cast1, *cast2, *cast3, *cond;
struct hlsl_type *type = instr->data_type, *utype; struct hlsl_type *type = instr->data_type, *utype;
struct hlsl_constant_value high_bit_value;
struct hlsl_ir_constant *high_bit; struct hlsl_ir_constant *high_bit;
struct hlsl_ir_expr *expr; struct hlsl_ir_expr *expr;
unsigned int i; unsigned int i;
@@ -2324,10 +2327,10 @@ static bool lower_int_division(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr,
return false; return false;
list_add_before(&instr->entry, &xor->entry); list_add_before(&instr->entry, &xor->entry);
if (!(high_bit = hlsl_new_constant(ctx, type, &instr->loc)))
return false;
for (i = 0; i < type->dimx; ++i) for (i = 0; i < type->dimx; ++i)
high_bit->value.u[i].u = 0x80000000; high_bit_value.u[i].u = 0x80000000;
if (!(high_bit = hlsl_new_constant(ctx, type, &high_bit_value, &instr->loc)))
return false;
list_add_before(&instr->entry, &high_bit->node.entry); list_add_before(&instr->entry, &high_bit->node.entry);
if (!(and = hlsl_new_binary_expr(ctx, HLSL_OP2_BIT_AND, xor, &high_bit->node))) if (!(and = hlsl_new_binary_expr(ctx, HLSL_OP2_BIT_AND, xor, &high_bit->node)))
@@ -2373,6 +2376,7 @@ static bool lower_int_modulus(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr,
{ {
struct hlsl_ir_node *arg1, *arg2, *and, *abs1, *abs2, *div, *neg, *cast1, *cast2, *cast3, *cond; struct hlsl_ir_node *arg1, *arg2, *and, *abs1, *abs2, *div, *neg, *cast1, *cast2, *cast3, *cond;
struct hlsl_type *type = instr->data_type, *utype; struct hlsl_type *type = instr->data_type, *utype;
struct hlsl_constant_value high_bit_value;
struct hlsl_ir_constant *high_bit; struct hlsl_ir_constant *high_bit;
struct hlsl_ir_expr *expr; struct hlsl_ir_expr *expr;
unsigned int i; unsigned int i;
@@ -2390,10 +2394,10 @@ static bool lower_int_modulus(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr,
return false; return false;
utype = hlsl_get_numeric_type(ctx, type->class, HLSL_TYPE_UINT, type->dimx, type->dimy); utype = hlsl_get_numeric_type(ctx, type->class, HLSL_TYPE_UINT, type->dimx, type->dimy);
if (!(high_bit = hlsl_new_constant(ctx, type, &instr->loc)))
return false;
for (i = 0; i < type->dimx; ++i) for (i = 0; i < type->dimx; ++i)
high_bit->value.u[i].u = 0x80000000; high_bit_value.u[i].u = 0x80000000;
if (!(high_bit = hlsl_new_constant(ctx, type, &high_bit_value, &instr->loc)))
return false;
list_add_before(&instr->entry, &high_bit->node.entry); list_add_before(&instr->entry, &high_bit->node.entry);
if (!(and = hlsl_new_binary_expr(ctx, HLSL_OP2_BIT_AND, arg1, &high_bit->node))) if (!(and = hlsl_new_binary_expr(ctx, HLSL_OP2_BIT_AND, arg1, &high_bit->node)))
@@ -2520,6 +2524,7 @@ static bool lower_float_modulus(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr
{ {
struct hlsl_ir_node *arg1, *arg2, *mul1, *neg1, *ge, *neg2, *div, *mul2, *frc, *cond; struct hlsl_ir_node *arg1, *arg2, *mul1, *neg1, *ge, *neg2, *div, *mul2, *frc, *cond;
struct hlsl_type *type = instr->data_type, *btype; struct hlsl_type *type = instr->data_type, *btype;
struct hlsl_constant_value one_value;
struct hlsl_ir_constant *one; struct hlsl_ir_constant *one;
struct hlsl_ir_expr *expr; struct hlsl_ir_expr *expr;
unsigned int i; unsigned int i;
@@ -2557,10 +2562,10 @@ static bool lower_float_modulus(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr
if (!(cond = hlsl_add_conditional(ctx, &instr->entry, ge, arg2, neg2))) if (!(cond = hlsl_add_conditional(ctx, &instr->entry, ge, arg2, neg2)))
return false; return false;
if (!(one = hlsl_new_constant(ctx, type, &instr->loc)))
return false;
for (i = 0; i < type->dimx; ++i) for (i = 0; i < type->dimx; ++i)
one->value.u[i].f = 1.0f; one_value.u[i].f = 1.0f;
if (!(one = hlsl_new_constant(ctx, type, &one_value, &instr->loc)))
return false;
list_add_before(&instr->entry, &one->node.entry); list_add_before(&instr->entry, &one->node.entry);
if (!(div = hlsl_new_binary_expr(ctx, HLSL_OP2_DIV, &one->node, cond))) if (!(div = hlsl_new_binary_expr(ctx, HLSL_OP2_DIV, &one->node, cond)))

View File

@@ -544,7 +544,8 @@ static bool fold_bit_or(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, c
bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context) bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
{ {
struct hlsl_ir_constant *arg1, *arg2 = NULL, *res; struct hlsl_ir_constant *arg1, *arg2 = NULL, *res_node;
struct hlsl_constant_value res = {0};
struct hlsl_ir_expr *expr; struct hlsl_ir_expr *expr;
unsigned int i; unsigned int i;
bool success; bool success;
@@ -571,61 +572,58 @@ bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr,
if (expr->operands[1].node) if (expr->operands[1].node)
arg2 = hlsl_ir_constant(expr->operands[1].node); arg2 = hlsl_ir_constant(expr->operands[1].node);
if (!(res = hlsl_new_constant(ctx, instr->data_type, &instr->loc)))
return false;
switch (expr->op) switch (expr->op)
{ {
case HLSL_OP1_ABS: case HLSL_OP1_ABS:
success = fold_abs(ctx, &res->value, instr->data_type, arg1); success = fold_abs(ctx, &res, instr->data_type, arg1);
break; break;
case HLSL_OP1_CAST: case HLSL_OP1_CAST:
success = fold_cast(ctx, &res->value, instr->data_type, arg1); success = fold_cast(ctx, &res, instr->data_type, arg1);
break; break;
case HLSL_OP1_NEG: case HLSL_OP1_NEG:
success = fold_neg(ctx, &res->value, instr->data_type, arg1); success = fold_neg(ctx, &res, instr->data_type, arg1);
break; break;
case HLSL_OP2_ADD: case HLSL_OP2_ADD:
success = fold_add(ctx, &res->value, instr->data_type, arg1, arg2); success = fold_add(ctx, &res, instr->data_type, arg1, arg2);
break; break;
case HLSL_OP2_MUL: case HLSL_OP2_MUL:
success = fold_mul(ctx, &res->value, instr->data_type, arg1, arg2); success = fold_mul(ctx, &res, instr->data_type, arg1, arg2);
break; break;
case HLSL_OP2_NEQUAL: case HLSL_OP2_NEQUAL:
success = fold_nequal(ctx, &res->value, instr->data_type, arg1, arg2); success = fold_nequal(ctx, &res, instr->data_type, arg1, arg2);
break; break;
case HLSL_OP2_DIV: case HLSL_OP2_DIV:
success = fold_div(ctx, &res->value, instr->data_type, arg1, arg2, &instr->loc); success = fold_div(ctx, &res, instr->data_type, arg1, arg2, &instr->loc);
break; break;
case HLSL_OP2_MOD: case HLSL_OP2_MOD:
success = fold_mod(ctx, &res->value, instr->data_type, arg1, arg2, &instr->loc); success = fold_mod(ctx, &res, instr->data_type, arg1, arg2, &instr->loc);
break; break;
case HLSL_OP2_MAX: case HLSL_OP2_MAX:
success = fold_max(ctx, &res->value, instr->data_type, arg1, arg2); success = fold_max(ctx, &res, instr->data_type, arg1, arg2);
break; break;
case HLSL_OP2_MIN: case HLSL_OP2_MIN:
success = fold_min(ctx, &res->value, instr->data_type, arg1, arg2); success = fold_min(ctx, &res, instr->data_type, arg1, arg2);
break; break;
case HLSL_OP2_BIT_XOR: case HLSL_OP2_BIT_XOR:
success = fold_bit_xor(ctx, &res->value, instr->data_type, arg1, arg2); success = fold_bit_xor(ctx, &res, instr->data_type, arg1, arg2);
break; break;
case HLSL_OP2_BIT_AND: case HLSL_OP2_BIT_AND:
success = fold_bit_and(ctx, &res->value, instr->data_type, arg1, arg2); success = fold_bit_and(ctx, &res, instr->data_type, arg1, arg2);
break; break;
case HLSL_OP2_BIT_OR: case HLSL_OP2_BIT_OR:
success = fold_bit_or(ctx, &res->value, instr->data_type, arg1, arg2); success = fold_bit_or(ctx, &res, instr->data_type, arg1, arg2);
break; break;
default: default:
@@ -636,19 +634,19 @@ bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr,
if (success) if (success)
{ {
list_add_before(&expr->node.entry, &res->node.entry); if (!(res_node = hlsl_new_constant(ctx, instr->data_type, &res, &instr->loc)))
hlsl_replace_node(&expr->node, &res->node); return false;
}
else list_add_before(&expr->node.entry, &res_node->node.entry);
{ hlsl_replace_node(&expr->node, &res_node->node);
vkd3d_free(res);
} }
return success; return success;
} }
bool hlsl_fold_constant_swizzles(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context) bool hlsl_fold_constant_swizzles(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
{ {
struct hlsl_ir_constant *value, *res; struct hlsl_ir_constant *src, *dst;
struct hlsl_constant_value value;
struct hlsl_ir_swizzle *swizzle; struct hlsl_ir_swizzle *swizzle;
unsigned int i; unsigned int i;
@@ -657,15 +655,15 @@ bool hlsl_fold_constant_swizzles(struct hlsl_ctx *ctx, struct hlsl_ir_node *inst
swizzle = hlsl_ir_swizzle(instr); swizzle = hlsl_ir_swizzle(instr);
if (swizzle->val.node->type != HLSL_IR_CONSTANT) if (swizzle->val.node->type != HLSL_IR_CONSTANT)
return false; return false;
value = hlsl_ir_constant(swizzle->val.node); src = hlsl_ir_constant(swizzle->val.node);
if (!(res = hlsl_new_constant(ctx, instr->data_type, &instr->loc)))
return false;
for (i = 0; i < swizzle->node.data_type->dimx; ++i) for (i = 0; i < swizzle->node.data_type->dimx; ++i)
res->value.u[i] = value->value.u[hlsl_swizzle_get_component(swizzle->swizzle, i)]; value.u[i] = src->value.u[hlsl_swizzle_get_component(swizzle->swizzle, i)];
list_add_before(&swizzle->node.entry, &res->node.entry); if (!(dst = hlsl_new_constant(ctx, instr->data_type, &value, &instr->loc)))
hlsl_replace_node(&swizzle->node, &res->node); return false;
list_add_before(&swizzle->node.entry, &dst->node.entry);
hlsl_replace_node(&swizzle->node, &dst->node);
return true; return true;
} }