BORING
-- v2: vkd3d-shader/hlsl: Return an hlsl_ir_node pointer from hlsl_new_constant(). vkd3d-shader/hlsl: Pass a hlsl_constant_value pointer to hlsl_new_constant(). vkd3d-shader/hlsl: Pass hlsl_constant_value and hlsl_type pointers to fold_bit_or(). vkd3d-shader/hlsl: Pass hlsl_constant_value and hlsl_type pointers to fold_bit_and(). vkd3d-shader/hlsl: Pass hlsl_constant_value and hlsl_type pointers to fold_bit_xor(). vkd3d-shader/hlsl: Only read used coordinates in encode_texel_offset_as_aoffimmi(). vkd3d-shader/hlsl: Use the writemask to map the coords swizzle for load instructions.
From: Zebediah Figura zfigura@codeweavers.com
Instead of modifying the swizzle after calling sm4_src_from_node().
This fixes the case where sm4_src_from_node() returns an immediate constant.
Fixes: a471c5567acaf467292cdfb9c061e2213b348805 --- libs/vkd3d-shader/tpf.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/libs/vkd3d-shader/tpf.c b/libs/vkd3d-shader/tpf.c index 60948d64..b252270c 100644 --- a/libs/vkd3d-shader/tpf.c +++ b/libs/vkd3d-shader/tpf.c @@ -4012,8 +4012,8 @@ static void write_sm4_ld(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *buf bool multisampled = resource_type->base_type == HLSL_TYPE_TEXTURE && (resource_type->sampler_dim == HLSL_SAMPLER_DIM_2DMS || resource_type->sampler_dim == HLSL_SAMPLER_DIM_2DMSARRAY); bool uav = (hlsl_type_get_regset(resource_type) == HLSL_REGSET_UAVS); + unsigned int coords_writemask = VKD3DSP_WRITEMASK_ALL; struct sm4_instruction instr; - unsigned int dim_count;
memset(&instr, 0, sizeof(instr)); if (uav) @@ -4034,19 +4034,20 @@ static void write_sm4_ld(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *buf sm4_dst_from_node(&instr.dsts[0], dst); instr.dst_count = 1;
- sm4_src_from_node(&instr.srcs[0], coords, VKD3DSP_WRITEMASK_ALL); - if (!uav) { /* Mipmap level is in the last component in the IR, but needs to be in the W * component in the instruction. */ - dim_count = hlsl_sampler_dim_count(dim); + unsigned int dim_count = hlsl_sampler_dim_count(dim); + if (dim_count == 1) - instr.srcs[0].swizzle = hlsl_combine_swizzles(instr.srcs[0].swizzle, HLSL_SWIZZLE(X, X, X, Y), 4); + coords_writemask = VKD3DSP_WRITEMASK_0 | VKD3DSP_WRITEMASK_3; if (dim_count == 2) - instr.srcs[0].swizzle = hlsl_combine_swizzles(instr.srcs[0].swizzle, HLSL_SWIZZLE(X, Y, X, Z), 4); + coords_writemask = VKD3DSP_WRITEMASK_0 | VKD3DSP_WRITEMASK_1 | VKD3DSP_WRITEMASK_3; }
+ sm4_src_from_node(&instr.srcs[0], coords, coords_writemask); + sm4_src_from_deref(ctx, &instr.srcs[1], resource, resource_type, instr.dsts[0].writemask);
instr.src_count = 2;
From: Zebediah Figura zfigura@codeweavers.com
The V and W offsets may be uninitialized, which may spuriously trigger "out of range" errors. --- libs/vkd3d-shader/tpf.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/libs/vkd3d-shader/tpf.c b/libs/vkd3d-shader/tpf.c index b252270c..d066b13e 100644 --- a/libs/vkd3d-shader/tpf.c +++ b/libs/vkd3d-shader/tpf.c @@ -3657,8 +3657,12 @@ static bool encode_texel_offset_as_aoffimmi(struct sm4_instruction *instr,
modif.type = VKD3D_SM4_MODIFIER_AOFFIMMI; modif.u.aoffimmi.u = offset->value.u[0].i; - modif.u.aoffimmi.v = offset->value.u[1].i; - modif.u.aoffimmi.w = offset->value.u[2].i; + modif.u.aoffimmi.v = 0; + modif.u.aoffimmi.w = 0; + if (offset->node.data_type->dimx > 1) + modif.u.aoffimmi.v = offset->value.u[1].i; + if (offset->node.data_type->dimx > 2) + modif.u.aoffimmi.w = offset->value.u[2].i; if (modif.u.aoffimmi.u < -8 || modif.u.aoffimmi.u > 7 || modif.u.aoffimmi.v < -8 || modif.u.aoffimmi.v > 7 || modif.u.aoffimmi.w < -8 || modif.u.aoffimmi.w > 7)
From: Zebediah Figura zfigura@codeweavers.com
--- libs/vkd3d-shader/hlsl_constant_ops.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl_constant_ops.c b/libs/vkd3d-shader/hlsl_constant_ops.c index 9fa2acd5..6dab6741 100644 --- a/libs/vkd3d-shader/hlsl_constant_ops.c +++ b/libs/vkd3d-shader/hlsl_constant_ops.c @@ -464,26 +464,26 @@ static bool fold_min(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, cons return true; }
-static bool fold_bit_xor(struct hlsl_ctx *ctx, struct hlsl_ir_constant *dst, - struct hlsl_ir_constant *src1, struct hlsl_ir_constant *src2) +static bool fold_bit_xor(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, const struct hlsl_type *dst_type, + const struct hlsl_ir_constant *src1, const struct hlsl_ir_constant *src2) { - enum hlsl_base_type type = dst->node.data_type->base_type; + enum hlsl_base_type type = dst_type->base_type; unsigned int k;
assert(type == src1->node.data_type->base_type); assert(type == src2->node.data_type->base_type);
- for (k = 0; k < dst->node.data_type->dimx; ++k) + for (k = 0; k < dst_type->dimx; ++k) { switch (type) { case HLSL_TYPE_INT: case HLSL_TYPE_UINT: - dst->value.u[k].u = src1->value.u[k].u ^ src2->value.u[k].u; + dst->u[k].u = src1->value.u[k].u ^ src2->value.u[k].u; break;
default: - FIXME("Fold bit xor for type %s.\n", debug_hlsl_type(ctx, dst->node.data_type)); + FIXME("Fold bit xor for type %s.\n", debug_hlsl_type(ctx, dst_type)); return false; } } @@ -617,7 +617,7 @@ bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, break;
case HLSL_OP2_BIT_XOR: - success = fold_bit_xor(ctx, res, arg1, arg2); + success = fold_bit_xor(ctx, &res->value, instr->data_type, arg1, arg2); break;
case HLSL_OP2_BIT_AND:
From: Zebediah Figura zfigura@codeweavers.com
--- libs/vkd3d-shader/hlsl_constant_ops.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl_constant_ops.c b/libs/vkd3d-shader/hlsl_constant_ops.c index 6dab6741..a00d017a 100644 --- a/libs/vkd3d-shader/hlsl_constant_ops.c +++ b/libs/vkd3d-shader/hlsl_constant_ops.c @@ -490,26 +490,26 @@ static bool fold_bit_xor(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, return true; }
-static bool fold_bit_and(struct hlsl_ctx *ctx, struct hlsl_ir_constant *dst, - struct hlsl_ir_constant *src1, struct hlsl_ir_constant *src2) +static bool fold_bit_and(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, const struct hlsl_type *dst_type, + const struct hlsl_ir_constant *src1, const struct hlsl_ir_constant *src2) { - enum hlsl_base_type type = dst->node.data_type->base_type; + enum hlsl_base_type type = dst_type->base_type; unsigned int k;
assert(type == src1->node.data_type->base_type); assert(type == src2->node.data_type->base_type);
- for (k = 0; k < dst->node.data_type->dimx; ++k) + for (k = 0; k < dst_type->dimx; ++k) { switch (type) { case HLSL_TYPE_INT: case HLSL_TYPE_UINT: - dst->value.u[k].u = src1->value.u[k].u & src2->value.u[k].u; + dst->u[k].u = src1->value.u[k].u & src2->value.u[k].u; break;
default: - FIXME("Fold bit and for type %s.\n", debug_hlsl_type(ctx, dst->node.data_type)); + FIXME("Fold bit and for type %s.\n", debug_hlsl_type(ctx, dst_type)); return false; } } @@ -621,7 +621,7 @@ bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, break;
case HLSL_OP2_BIT_AND: - success = fold_bit_and(ctx, res, arg1, arg2); + success = fold_bit_and(ctx, &res->value, instr->data_type, arg1, arg2); break;
case HLSL_OP2_BIT_OR:
From: Zebediah Figura zfigura@codeweavers.com
--- libs/vkd3d-shader/hlsl_constant_ops.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl_constant_ops.c b/libs/vkd3d-shader/hlsl_constant_ops.c index a00d017a..9c521215 100644 --- a/libs/vkd3d-shader/hlsl_constant_ops.c +++ b/libs/vkd3d-shader/hlsl_constant_ops.c @@ -516,26 +516,26 @@ static bool fold_bit_and(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, return true; }
-static bool fold_bit_or(struct hlsl_ctx *ctx, struct hlsl_ir_constant *dst, - struct hlsl_ir_constant *src1, struct hlsl_ir_constant *src2) +static bool fold_bit_or(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, const struct hlsl_type *dst_type, + const struct hlsl_ir_constant *src1, const struct hlsl_ir_constant *src2) { - enum hlsl_base_type type = dst->node.data_type->base_type; + enum hlsl_base_type type = dst_type->base_type; unsigned int k;
assert(type == src1->node.data_type->base_type); assert(type == src2->node.data_type->base_type);
- for (k = 0; k < dst->node.data_type->dimx; ++k) + for (k = 0; k < dst_type->dimx; ++k) { switch (type) { case HLSL_TYPE_INT: case HLSL_TYPE_UINT: - dst->value.u[k].u = src1->value.u[k].u | src2->value.u[k].u; + dst->u[k].u = src1->value.u[k].u | src2->value.u[k].u; break;
default: - FIXME("Fold bit or for type %s.\n", debug_hlsl_type(ctx, dst->node.data_type)); + FIXME("Fold bit or for type %s.\n", debug_hlsl_type(ctx, dst_type)); return false; } } @@ -625,7 +625,7 @@ bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, break;
case HLSL_OP2_BIT_OR: - success = fold_bit_or(ctx, res, arg1, arg2); + success = fold_bit_or(ctx, &res->value, instr->data_type, arg1, arg2); break;
default:
From: Zebediah Figura zfigura@codeweavers.com
--- libs/vkd3d-shader/hlsl.c | 38 ++++++++--------- libs/vkd3d-shader/hlsl.h | 2 +- libs/vkd3d-shader/hlsl.y | 22 +++++----- libs/vkd3d-shader/hlsl_codegen.c | 36 +++++++++------- libs/vkd3d-shader/hlsl_constant_ops.c | 60 +++++++++++++-------------- 5 files changed, 79 insertions(+), 79 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 152ec627..203b86fd 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -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, - const struct vkd3d_shader_location *loc) + const struct hlsl_constant_value *value, const struct vkd3d_shader_location *loc) { 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;
init_node(&c->node, HLSL_IR_CONSTANT, type, loc); + c->value = *value;
return c; }
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;
- if ((c = hlsl_new_constant(ctx, hlsl_get_scalar_type(ctx, HLSL_TYPE_BOOL), loc))) - c->value.u[0].u = b ? ~0u : 0; - + 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; }
struct hlsl_ir_node *hlsl_new_float_constant(struct hlsl_ctx *ctx, float f, const struct vkd3d_shader_location *loc) { + struct hlsl_constant_value value; struct hlsl_ir_constant *c;
- if ((c = hlsl_new_constant(ctx, hlsl_get_scalar_type(ctx, HLSL_TYPE_FLOAT), loc))) - c->value.u[0].f = f; - + 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; }
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;
- c = hlsl_new_constant(ctx, hlsl_get_scalar_type(ctx, HLSL_TYPE_INT), loc); - - if (c) - c->value.u[0].i = n; - + value.u[0].i = n; + if (!(c = hlsl_new_constant(ctx, hlsl_get_scalar_type(ctx, HLSL_TYPE_INT), &value, loc))) + return NULL; return &c->node; }
struct hlsl_ir_node *hlsl_new_uint_constant(struct hlsl_ctx *ctx, unsigned int n, const struct vkd3d_shader_location *loc) { + struct hlsl_constant_value value; struct hlsl_ir_constant *c;
- c = hlsl_new_constant(ctx, hlsl_get_scalar_type(ctx, HLSL_TYPE_UINT), loc); - - if (c) - c->value.u[0].u = n; - + value.u[0].u = n; + if (!(c = hlsl_new_constant(ctx, hlsl_get_scalar_type(ctx, HLSL_TYPE_UINT), &value, loc))) + return NULL; return &c->node; }
@@ -1548,9 +1549,8 @@ static struct hlsl_ir_node *clone_constant(struct hlsl_ctx *ctx, struct hlsl_ir_ { 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; - dst->value = src->value; return &dst->node; }
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 7d02448e..d0227f0d 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -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, const struct vkd3d_shader_location *loc); 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_expr(struct hlsl_ctx *ctx, enum hlsl_ir_expr_op op, struct hlsl_ir_node *operands[HLSL_MAX_OPERANDS], diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index cf483d82..f5a4a751 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -2697,8 +2697,8 @@ static bool intrinsic_fmod(struct hlsl_ctx *ctx, const struct parse_initializer const struct vkd3d_shader_location *loc) { 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; - unsigned int count, i;
if (!(x = intrinsic_float_convert_arg(ctx, params, params->args[0], loc))) 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))) 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; 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))) 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, *n_h, *m, *diffuse, *zero, *store; + struct hlsl_constant_value init_value; struct hlsl_ir_constant *init; struct hlsl_ir_load *var_load; struct hlsl_deref var_deref; @@ -2855,12 +2852,12 @@ static bool intrinsic_lit(struct hlsl_ctx *ctx, return false; 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; - 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);
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) { 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_type *int_type = hlsl_get_numeric_type(ctx, arg->data_type->class, HLSL_TYPE_INT, 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; list_add_tail(params->instrs, &zero->node.entry);
diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index 2b6c595a..d92b0ac9 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -1342,9 +1342,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]; }
- 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; - cons->value = values; list_add_before(&instr->entry, &cons->node.entry);
TRACE("Load from %s[%u-%u]%s turned into a constant %p.\n", @@ -2107,6 +2106,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_type *type = instr->data_type; + struct hlsl_constant_value half_value; unsigned int i, component_count; struct hlsl_ir_constant *half; struct hlsl_ir_expr *expr; @@ -2119,12 +2119,12 @@ static bool lower_round(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void * if (expr->op != HLSL_OP1_ROUND) return false;
- if (!(half = hlsl_new_constant(ctx, type, &expr->node.loc))) - return false; - component_count = hlsl_type_component_count(type); 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);
if (!(sum = hlsl_new_binary_expr(ctx, HLSL_OP2_ADD, arg, &half->node))) @@ -2150,6 +2150,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) { 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_expr *expr;
@@ -2167,7 +2168,7 @@ static bool lower_casts_to_bool(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr /* Narrowing casts should have already been lowered. */ 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) return false; list_add_before(&instr->entry, &zero->node.entry); @@ -2217,6 +2218,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_type *type = instr->data_type, *utype; + struct hlsl_constant_value high_bit_value; struct hlsl_ir_constant *high_bit; struct hlsl_ir_expr *expr; unsigned int i; @@ -2238,10 +2240,10 @@ static bool lower_int_division(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, return false; 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) - 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);
if (!(and = hlsl_new_binary_expr(ctx, HLSL_OP2_BIT_AND, xor, &high_bit->node))) @@ -2287,6 +2289,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_type *type = instr->data_type, *utype; + struct hlsl_constant_value high_bit_value; struct hlsl_ir_constant *high_bit; struct hlsl_ir_expr *expr; unsigned int i; @@ -2304,10 +2307,10 @@ static bool lower_int_modulus(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, return false; 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) - 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);
if (!(and = hlsl_new_binary_expr(ctx, HLSL_OP2_BIT_AND, arg1, &high_bit->node))) @@ -2382,6 +2385,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_type *type = instr->data_type, *btype; + struct hlsl_constant_value one_value; struct hlsl_ir_constant *one; struct hlsl_ir_expr *expr; unsigned int i; @@ -2419,10 +2423,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))) return false;
- if (!(one = hlsl_new_constant(ctx, type, &instr->loc))) - return false; 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);
if (!(div = hlsl_new_binary_expr(ctx, HLSL_OP2_DIV, &one->node, cond))) diff --git a/libs/vkd3d-shader/hlsl_constant_ops.c b/libs/vkd3d-shader/hlsl_constant_ops.c index 9c521215..a30ebffd 100644 --- a/libs/vkd3d-shader/hlsl_constant_ops.c +++ b/libs/vkd3d-shader/hlsl_constant_ops.c @@ -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) { - 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; unsigned int i; 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) arg2 = hlsl_ir_constant(expr->operands[1].node);
- if (!(res = hlsl_new_constant(ctx, instr->data_type, &instr->loc))) - return false; - switch (expr->op) { case HLSL_OP1_ABS: - success = fold_abs(ctx, &res->value, instr->data_type, arg1); + success = fold_abs(ctx, &res, instr->data_type, arg1); break;
case HLSL_OP1_CAST: - success = fold_cast(ctx, &res->value, instr->data_type, arg1); + success = fold_cast(ctx, &res, instr->data_type, arg1); break;
case HLSL_OP1_NEG: - success = fold_neg(ctx, &res->value, instr->data_type, arg1); + success = fold_neg(ctx, &res, instr->data_type, arg1); break;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
default: @@ -636,19 +634,19 @@ bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr,
if (success) { - list_add_before(&expr->node.entry, &res->node.entry); - hlsl_replace_node(&expr->node, &res->node); - } - else - { - vkd3d_free(res); + if (!(res_node = hlsl_new_constant(ctx, instr->data_type, &res, &instr->loc))) + return false; + + list_add_before(&expr->node.entry, &res_node->node.entry); + hlsl_replace_node(&expr->node, &res_node->node); } return success; }
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; 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); if (swizzle->val.node->type != HLSL_IR_CONSTANT) return false; - value = hlsl_ir_constant(swizzle->val.node); - - if (!(res = hlsl_new_constant(ctx, instr->data_type, &instr->loc))) - return false; + src = hlsl_ir_constant(swizzle->val.node);
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)]; + + if (!(dst = hlsl_new_constant(ctx, instr->data_type, &value, &instr->loc))) + return false;
- list_add_before(&swizzle->node.entry, &res->node.entry); - hlsl_replace_node(&swizzle->node, &res->node); + list_add_before(&swizzle->node.entry, &dst->node.entry); + hlsl_replace_node(&swizzle->node, &dst->node); return true; }
From: Zebediah Figura zfigura@codeweavers.com
--- libs/vkd3d-shader/hlsl.c | 30 +++++--------------- libs/vkd3d-shader/hlsl.h | 2 +- libs/vkd3d-shader/hlsl.y | 23 +++++++-------- libs/vkd3d-shader/hlsl_codegen.c | 40 ++++++++++++--------------- libs/vkd3d-shader/hlsl_constant_ops.c | 15 +++++----- 5 files changed, 44 insertions(+), 66 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 203b86fd..7910c13c 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -1146,7 +1146,7 @@ struct hlsl_ir_node *hlsl_new_call(struct hlsl_ctx *ctx, struct hlsl_ir_function return &call->node; }
-struct hlsl_ir_constant *hlsl_new_constant(struct hlsl_ctx *ctx, struct hlsl_type *type, +struct hlsl_ir_node *hlsl_new_constant(struct hlsl_ctx *ctx, struct hlsl_type *type, const struct hlsl_constant_value *value, const struct vkd3d_shader_location *loc) { struct hlsl_ir_constant *c; @@ -1159,53 +1159,41 @@ struct hlsl_ir_constant *hlsl_new_constant(struct hlsl_ctx *ctx, struct hlsl_typ init_node(&c->node, HLSL_IR_CONSTANT, type, loc); c->value = *value;
- return c; + return &c->node; }
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;
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 hlsl_new_constant(ctx, hlsl_get_scalar_type(ctx, HLSL_TYPE_BOOL), &value, loc); }
struct hlsl_ir_node *hlsl_new_float_constant(struct hlsl_ctx *ctx, float f, const struct vkd3d_shader_location *loc) { struct hlsl_constant_value value; - struct hlsl_ir_constant *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 hlsl_new_constant(ctx, hlsl_get_scalar_type(ctx, HLSL_TYPE_FLOAT), &value, 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;
value.u[0].i = n; - if (!(c = hlsl_new_constant(ctx, hlsl_get_scalar_type(ctx, HLSL_TYPE_INT), &value, loc))) - return NULL; - return &c->node; + return hlsl_new_constant(ctx, hlsl_get_scalar_type(ctx, HLSL_TYPE_INT), &value, loc); }
struct hlsl_ir_node *hlsl_new_uint_constant(struct hlsl_ctx *ctx, unsigned int n, const struct vkd3d_shader_location *loc) { struct hlsl_constant_value value; - struct hlsl_ir_constant *c;
value.u[0].u = n; - if (!(c = hlsl_new_constant(ctx, hlsl_get_scalar_type(ctx, HLSL_TYPE_UINT), &value, loc))) - return NULL; - return &c->node; + return hlsl_new_constant(ctx, hlsl_get_scalar_type(ctx, HLSL_TYPE_UINT), &value, loc); }
struct hlsl_ir_node *hlsl_new_expr(struct hlsl_ctx *ctx, enum hlsl_ir_expr_op op, @@ -1547,11 +1535,7 @@ static struct hlsl_ir_node *clone_call(struct hlsl_ctx *ctx, struct hlsl_ir_call
static struct hlsl_ir_node *clone_constant(struct hlsl_ctx *ctx, struct hlsl_ir_constant *src) { - struct hlsl_ir_constant *dst; - - if (!(dst = hlsl_new_constant(ctx, src->node.data_type, &src->value, &src->node.loc))) - return NULL; - return &dst->node; + return hlsl_new_constant(ctx, src->node.data_type, &src->value, &src->node.loc); }
static struct hlsl_ir_node *clone_expr(struct hlsl_ctx *ctx, struct clone_instr_map *map, struct hlsl_ir_expr *src) diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index d0227f0d..54dc201d 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -1106,7 +1106,7 @@ struct hlsl_ir_node *hlsl_new_call(struct hlsl_ctx *ctx, struct hlsl_ir_function const struct vkd3d_shader_location *loc); 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); -struct hlsl_ir_constant *hlsl_new_constant(struct hlsl_ctx *ctx, struct hlsl_type *type, +struct hlsl_ir_node *hlsl_new_constant(struct hlsl_ctx *ctx, struct hlsl_type *type, 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_expr(struct hlsl_ctx *ctx, enum hlsl_ir_expr_op op, diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index f5a4a751..7fddd321 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -2696,9 +2696,8 @@ static bool intrinsic_floor(struct hlsl_ctx *ctx, static bool intrinsic_fmod(struct hlsl_ctx *ctx, const struct parse_initializer *params, 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, *zero; static const struct hlsl_constant_value zero_value; - struct hlsl_ir_constant *zero;
if (!(x = intrinsic_float_convert_arg(ctx, params, params->args[0], loc))) return false; @@ -2711,7 +2710,7 @@ static bool intrinsic_fmod(struct hlsl_ctx *ctx, const struct parse_initializer
if (!(zero = hlsl_new_constant(ctx, div->data_type, &zero_value, loc))) return false; - list_add_tail(params->instrs, &zero->node.entry); + list_add_tail(params->instrs, &zero->entry);
if (!(abs = add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_ABS, div, loc))) return false; @@ -2722,7 +2721,7 @@ static bool intrinsic_fmod(struct hlsl_ctx *ctx, const struct parse_initializer if (!(neg_frac = add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_NEG, frac, loc))) return false;
- if (!(ge = add_binary_comparison_expr(ctx, params->instrs, HLSL_OP2_GEQUAL, div, &zero->node, loc))) + if (!(ge = add_binary_comparison_expr(ctx, params->instrs, HLSL_OP2_GEQUAL, div, zero, loc))) return false;
if (!(select = hlsl_add_conditional(ctx, params->instrs, ge, frac, neg_frac))) @@ -2820,9 +2819,8 @@ static bool intrinsic_lit(struct hlsl_ctx *ctx, const struct parse_initializer *params, const struct vkd3d_shader_location *loc) { 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, *init; struct hlsl_constant_value init_value; - struct hlsl_ir_constant *init; struct hlsl_ir_load *var_load; struct hlsl_deref var_deref; struct hlsl_type *ret_type; @@ -2858,9 +2856,9 @@ static bool intrinsic_lit(struct hlsl_ctx *ctx, init_value.u[3].f = 1.0f; if (!(init = hlsl_new_constant(ctx, ret_type, &init_value, loc))) return false; - list_add_tail(params->instrs, &init->node.entry); + list_add_tail(params->instrs, &init->entry);
- if (!(store = hlsl_new_simple_store(ctx, var, &init->node))) + if (!(store = hlsl_new_simple_store(ctx, var, init))) return false; list_add_tail(params->instrs, &store->entry);
@@ -3158,20 +3156,19 @@ static bool intrinsic_saturate(struct hlsl_ctx *ctx, static bool intrinsic_sign(struct hlsl_ctx *ctx, 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, *zero, *arg = params->args[0]; static const struct hlsl_constant_value zero_value; - struct hlsl_ir_constant *zero;
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);
if (!(zero = hlsl_new_constant(ctx, hlsl_get_scalar_type(ctx, arg->data_type->base_type), &zero_value, loc))) return false; - list_add_tail(params->instrs, &zero->node.entry); + list_add_tail(params->instrs, &zero->entry);
/* Check if 0 < arg, cast bool to int */
- if (!(lt = add_binary_comparison_expr(ctx, params->instrs, HLSL_OP2_LESS, &zero->node, arg, loc))) + if (!(lt = add_binary_comparison_expr(ctx, params->instrs, HLSL_OP2_LESS, zero, arg, loc))) return false;
if (!(op1 = add_implicit_conversion(ctx, params->instrs, lt, int_type, loc))) @@ -3179,7 +3176,7 @@ static bool intrinsic_sign(struct hlsl_ctx *ctx,
/* Check if arg < 0, cast bool to int and invert (meaning true is -1) */
- if (!(lt = add_binary_comparison_expr(ctx, params->instrs, HLSL_OP2_LESS, arg, &zero->node, loc))) + if (!(lt = add_binary_comparison_expr(ctx, params->instrs, HLSL_OP2_LESS, arg, zero, loc))) return false;
if (!(op2 = add_implicit_conversion(ctx, params->instrs, lt, int_type, loc))) diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index d92b0ac9..4cb194cd 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -1325,8 +1325,8 @@ static bool copy_propagation_replace_with_constant_vector(struct hlsl_ctx *ctx, const unsigned int instr_component_count = hlsl_type_component_count(instr->data_type); const struct hlsl_ir_var *var = deref->var; struct hlsl_constant_value values = {0}; - struct hlsl_ir_constant *cons; unsigned int start, count, i; + struct hlsl_ir_node *cons;
if (!hlsl_component_index_range_from_deref(ctx, deref, &start, &count)) return false; @@ -1344,12 +1344,12 @@ static bool copy_propagation_replace_with_constant_vector(struct hlsl_ctx *ctx,
if (!(cons = hlsl_new_constant(ctx, instr->data_type, &values, &instr->loc))) return false; - list_add_before(&instr->entry, &cons->node.entry); + list_add_before(&instr->entry, &cons->entry);
TRACE("Load from %s[%u-%u]%s turned into a constant %p.\n", var->name, start, start + count, debug_hlsl_swizzle(swizzle, instr_component_count), cons);
- hlsl_replace_node(instr, &cons->node); + hlsl_replace_node(instr, cons); return true; }
@@ -2104,11 +2104,10 @@ static bool lower_abs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *co /* Lower ROUND using FRC, ROUND(x) -> ((x + 0.5) - FRC(x + 0.5)). */ static bool lower_round(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context) { - struct hlsl_ir_node *arg, *neg, *sum, *frc, *replacement; + struct hlsl_ir_node *arg, *neg, *sum, *frc, *half, *replacement; struct hlsl_type *type = instr->data_type; struct hlsl_constant_value half_value; unsigned int i, component_count; - struct hlsl_ir_constant *half; struct hlsl_ir_expr *expr;
if (instr->type != HLSL_IR_EXPR) @@ -2125,9 +2124,9 @@ static bool lower_round(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void * 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->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))) return false; list_add_before(&instr->entry, &sum->entry);
@@ -2151,7 +2150,7 @@ static bool lower_casts_to_bool(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr { 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_node *zero; struct hlsl_ir_expr *expr;
if (instr->type != HLSL_IR_EXPR) @@ -2171,10 +2170,10 @@ static bool lower_casts_to_bool(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr zero = hlsl_new_constant(ctx, arg_type, &zero_value, &instr->loc); if (!zero) return false; - list_add_before(&instr->entry, &zero->node.entry); + list_add_before(&instr->entry, &zero->entry);
expr->op = HLSL_OP2_NEQUAL; - hlsl_src_from_node(&expr->operands[1], &zero->node); + hlsl_src_from_node(&expr->operands[1], zero);
return true; } @@ -2216,10 +2215,9 @@ struct hlsl_ir_node *hlsl_add_conditional(struct hlsl_ctx *ctx, struct list *ins
static bool lower_int_division(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context) { - 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, *high_bit; struct hlsl_type *type = instr->data_type, *utype; struct hlsl_constant_value high_bit_value; - struct hlsl_ir_constant *high_bit; struct hlsl_ir_expr *expr; unsigned int i;
@@ -2244,9 +2242,9 @@ static bool lower_int_division(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, 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->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))) return false; list_add_before(&instr->entry, &and->entry);
@@ -2287,10 +2285,9 @@ static bool lower_int_division(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr,
static bool lower_int_modulus(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context) { - 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, *high_bit; struct hlsl_type *type = instr->data_type, *utype; struct hlsl_constant_value high_bit_value; - struct hlsl_ir_constant *high_bit; struct hlsl_ir_expr *expr; unsigned int i;
@@ -2311,9 +2308,9 @@ static bool lower_int_modulus(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, 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->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))) return false; list_add_before(&instr->entry, &and->entry);
@@ -2383,10 +2380,9 @@ static bool lower_int_abs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void
static bool lower_float_modulus(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context) { - 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, *one; struct hlsl_type *type = instr->data_type, *btype; struct hlsl_constant_value one_value; - struct hlsl_ir_constant *one; struct hlsl_ir_expr *expr; unsigned int i;
@@ -2427,9 +2423,9 @@ static bool lower_float_modulus(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr 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->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, cond))) return false; list_add_before(&instr->entry, &div->entry);
diff --git a/libs/vkd3d-shader/hlsl_constant_ops.c b/libs/vkd3d-shader/hlsl_constant_ops.c index a30ebffd..301113c8 100644 --- a/libs/vkd3d-shader/hlsl_constant_ops.c +++ b/libs/vkd3d-shader/hlsl_constant_ops.c @@ -544,8 +544,9 @@ 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) { - struct hlsl_ir_constant *arg1, *arg2 = NULL, *res_node; + struct hlsl_ir_constant *arg1, *arg2 = NULL; struct hlsl_constant_value res = {0}; + struct hlsl_ir_node *res_node; struct hlsl_ir_expr *expr; unsigned int i; bool success; @@ -636,18 +637,18 @@ bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, { if (!(res_node = hlsl_new_constant(ctx, instr->data_type, &res, &instr->loc))) return false; - - list_add_before(&expr->node.entry, &res_node->node.entry); - hlsl_replace_node(&expr->node, &res_node->node); + list_add_before(&expr->node.entry, &res_node->entry); + hlsl_replace_node(&expr->node, res_node); } return success; }
bool hlsl_fold_constant_swizzles(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context) { - struct hlsl_ir_constant *src, *dst; struct hlsl_constant_value value; struct hlsl_ir_swizzle *swizzle; + struct hlsl_ir_constant *src; + struct hlsl_ir_node *dst; unsigned int i;
if (instr->type != HLSL_IR_SWIZZLE) @@ -663,7 +664,7 @@ bool hlsl_fold_constant_swizzles(struct hlsl_ctx *ctx, struct hlsl_ir_node *inst if (!(dst = hlsl_new_constant(ctx, instr->data_type, &value, &instr->loc))) return false;
- list_add_before(&swizzle->node.entry, &dst->node.entry); - hlsl_replace_node(&swizzle->node, &dst->node); + list_add_before(&swizzle->node.entry, &dst->entry); + hlsl_replace_node(&swizzle->node, dst); return true; }
Looks like uninitialized memory, I added two commits to the beginning to fix it.
This merge request was approved by Giovanni Mascellani.
Thanks for fixing my bug! :-)
BTW, I think it would eventually make sense to have some `hlsl_new_zero_constant(hlsl_ir_type*)` helper. We do that quite often.
Yeah, after rebasing this for a severalth time I'm also thinking we need hlsl_new_float4_constant() et al. I'll write some patches after this one.
This will need an update after !207.