mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-01-28 13:05:02 -08:00
vkd3d-shader/hlsl: Avoid hardcoding the size of the operands array.
Signed-off-by: Zebediah Figura <zfigura@codeweavers.com> Signed-off-by: Matteo Bruni <mbruni@codeweavers.com> Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com> Signed-off-by: Giovanni Mascellani <gmascellani@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
897ba6a3c7
commit
98cfd7b09f
@ -1108,7 +1108,7 @@ static void dump_ir_expr(struct vkd3d_string_buffer *buffer, const struct hlsl_i
|
|||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
vkd3d_string_buffer_printf(buffer, "%s (", debug_hlsl_expr_op(expr->op));
|
vkd3d_string_buffer_printf(buffer, "%s (", debug_hlsl_expr_op(expr->op));
|
||||||
for (i = 0; i < 3 && expr->operands[i].node; ++i)
|
for (i = 0; i < HLSL_MAX_OPERANDS && expr->operands[i].node; ++i)
|
||||||
{
|
{
|
||||||
dump_src(buffer, &expr->operands[i]);
|
dump_src(buffer, &expr->operands[i]);
|
||||||
vkd3d_string_buffer_printf(buffer, " ");
|
vkd3d_string_buffer_printf(buffer, " ");
|
||||||
|
@ -323,11 +323,13 @@ enum hlsl_ir_expr_op
|
|||||||
HLSL_OP3_LERP,
|
HLSL_OP3_LERP,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define HLSL_MAX_OPERANDS 3
|
||||||
|
|
||||||
struct hlsl_ir_expr
|
struct hlsl_ir_expr
|
||||||
{
|
{
|
||||||
struct hlsl_ir_node node;
|
struct hlsl_ir_node node;
|
||||||
enum hlsl_ir_expr_op op;
|
enum hlsl_ir_expr_op op;
|
||||||
struct hlsl_src operands[3];
|
struct hlsl_src operands[HLSL_MAX_OPERANDS];
|
||||||
};
|
};
|
||||||
|
|
||||||
enum hlsl_ir_jump_type
|
enum hlsl_ir_jump_type
|
||||||
|
@ -1022,15 +1022,15 @@ static struct hlsl_type *expr_common_type(struct hlsl_ctx *ctx, struct hlsl_type
|
|||||||
return hlsl_new_type(ctx, NULL, type, base, dimx, dimy);
|
return hlsl_new_type(ctx, NULL, type, base, dimx, dimy);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct hlsl_ir_expr *add_expr(struct hlsl_ctx *ctx, struct list *instrs,
|
static struct hlsl_ir_expr *add_expr(struct hlsl_ctx *ctx, struct list *instrs, enum hlsl_ir_expr_op op,
|
||||||
enum hlsl_ir_expr_op op, struct hlsl_ir_node *operands[3], struct vkd3d_shader_location *loc)
|
struct hlsl_ir_node *operands[HLSL_MAX_OPERANDS], struct vkd3d_shader_location *loc)
|
||||||
{
|
{
|
||||||
struct hlsl_ir_expr *expr;
|
struct hlsl_ir_expr *expr;
|
||||||
struct hlsl_type *type;
|
struct hlsl_type *type;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
type = operands[0]->data_type;
|
type = operands[0]->data_type;
|
||||||
for (i = 1; i <= 2; ++i)
|
for (i = 1; i < HLSL_MAX_OPERANDS; ++i)
|
||||||
{
|
{
|
||||||
if (!operands[i])
|
if (!operands[i])
|
||||||
break;
|
break;
|
||||||
@ -1038,7 +1038,7 @@ static struct hlsl_ir_expr *add_expr(struct hlsl_ctx *ctx, struct list *instrs,
|
|||||||
if (!type)
|
if (!type)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
for (i = 0; i <= 2; ++i)
|
for (i = 0; i < HLSL_MAX_OPERANDS; ++i)
|
||||||
{
|
{
|
||||||
struct hlsl_ir_expr *cast;
|
struct hlsl_ir_expr *cast;
|
||||||
|
|
||||||
@ -1062,7 +1062,7 @@ static struct hlsl_ir_expr *add_expr(struct hlsl_ctx *ctx, struct list *instrs,
|
|||||||
return NULL;
|
return NULL;
|
||||||
init_node(&expr->node, HLSL_IR_EXPR, type, *loc);
|
init_node(&expr->node, HLSL_IR_EXPR, type, *loc);
|
||||||
expr->op = op;
|
expr->op = op;
|
||||||
for (i = 0; i <= 2; ++i)
|
for (i = 0; i < HLSL_MAX_OPERANDS; ++i)
|
||||||
hlsl_src_from_node(&expr->operands[i], operands[i]);
|
hlsl_src_from_node(&expr->operands[i], operands[i]);
|
||||||
list_add_tail(instrs, &expr->node.entry);
|
list_add_tail(instrs, &expr->node.entry);
|
||||||
|
|
||||||
@ -1083,7 +1083,7 @@ static struct list *add_unary_expr(struct hlsl_ctx *ctx, struct list *instrs,
|
|||||||
static struct list *add_binary_expr(struct hlsl_ctx *ctx, struct list *list1, struct list *list2,
|
static struct list *add_binary_expr(struct hlsl_ctx *ctx, struct list *list1, struct list *list2,
|
||||||
enum hlsl_ir_expr_op op, struct vkd3d_shader_location loc)
|
enum hlsl_ir_expr_op op, struct vkd3d_shader_location loc)
|
||||||
{
|
{
|
||||||
struct hlsl_ir_node *args[3] = {node_from_list(list1), node_from_list(list2)};
|
struct hlsl_ir_node *args[HLSL_MAX_OPERANDS] = {node_from_list(list1), node_from_list(list2)};
|
||||||
|
|
||||||
list_move_tail(list1, list2);
|
list_move_tail(list1, list2);
|
||||||
vkd3d_free(list2);
|
vkd3d_free(list2);
|
||||||
@ -1157,7 +1157,7 @@ static struct hlsl_ir_node *add_assignment(struct hlsl_ctx *ctx, struct list *in
|
|||||||
|
|
||||||
if (assign_op == ASSIGN_OP_SUB)
|
if (assign_op == ASSIGN_OP_SUB)
|
||||||
{
|
{
|
||||||
struct hlsl_ir_node *args[3] = {rhs};
|
struct hlsl_ir_node *args[HLSL_MAX_OPERANDS] = {rhs};
|
||||||
struct hlsl_ir_expr *expr;
|
struct hlsl_ir_expr *expr;
|
||||||
|
|
||||||
if (!(expr = add_expr(ctx, instrs, HLSL_OP1_NEG, args, &rhs->loc)))
|
if (!(expr = add_expr(ctx, instrs, HLSL_OP1_NEG, args, &rhs->loc)))
|
||||||
@ -1167,8 +1167,8 @@ static struct hlsl_ir_node *add_assignment(struct hlsl_ctx *ctx, struct list *in
|
|||||||
}
|
}
|
||||||
if (assign_op != ASSIGN_OP_ASSIGN)
|
if (assign_op != ASSIGN_OP_ASSIGN)
|
||||||
{
|
{
|
||||||
|
struct hlsl_ir_node *args[HLSL_MAX_OPERANDS] = {lhs, rhs};
|
||||||
enum hlsl_ir_expr_op op = op_from_assignment(assign_op);
|
enum hlsl_ir_expr_op op = op_from_assignment(assign_op);
|
||||||
struct hlsl_ir_node *args[3] = {lhs, rhs};
|
|
||||||
struct hlsl_ir_expr *expr;
|
struct hlsl_ir_expr *expr;
|
||||||
|
|
||||||
assert(op);
|
assert(op);
|
||||||
@ -1556,7 +1556,7 @@ static const struct hlsl_ir_function_decl *find_function_call(struct hlsl_ctx *c
|
|||||||
static bool intrinsic_abs(struct hlsl_ctx *ctx,
|
static bool intrinsic_abs(struct hlsl_ctx *ctx,
|
||||||
const struct parse_initializer *params, struct vkd3d_shader_location loc)
|
const struct parse_initializer *params, struct vkd3d_shader_location loc)
|
||||||
{
|
{
|
||||||
struct hlsl_ir_node *args[3] = {params->args[0]};
|
struct hlsl_ir_node *args[HLSL_MAX_OPERANDS] = {params->args[0]};
|
||||||
|
|
||||||
return !!add_expr(ctx, params->instrs, HLSL_OP1_ABS, args, &loc);
|
return !!add_expr(ctx, params->instrs, HLSL_OP1_ABS, args, &loc);
|
||||||
}
|
}
|
||||||
@ -1564,7 +1564,7 @@ static bool intrinsic_abs(struct hlsl_ctx *ctx,
|
|||||||
static bool intrinsic_clamp(struct hlsl_ctx *ctx,
|
static bool intrinsic_clamp(struct hlsl_ctx *ctx,
|
||||||
const struct parse_initializer *params, struct vkd3d_shader_location loc)
|
const struct parse_initializer *params, struct vkd3d_shader_location loc)
|
||||||
{
|
{
|
||||||
struct hlsl_ir_node *args[3] = {params->args[0], params->args[1]};
|
struct hlsl_ir_node *args[HLSL_MAX_OPERANDS] = {params->args[0], params->args[1]};
|
||||||
struct hlsl_ir_expr *max;
|
struct hlsl_ir_expr *max;
|
||||||
|
|
||||||
if (!(max = add_expr(ctx, params->instrs, HLSL_OP2_MAX, args, &loc)))
|
if (!(max = add_expr(ctx, params->instrs, HLSL_OP2_MAX, args, &loc)))
|
||||||
@ -1578,7 +1578,7 @@ static bool intrinsic_clamp(struct hlsl_ctx *ctx,
|
|||||||
static bool intrinsic_max(struct hlsl_ctx *ctx,
|
static bool intrinsic_max(struct hlsl_ctx *ctx,
|
||||||
const struct parse_initializer *params, struct vkd3d_shader_location loc)
|
const struct parse_initializer *params, struct vkd3d_shader_location loc)
|
||||||
{
|
{
|
||||||
struct hlsl_ir_node *args[3] = {params->args[0], params->args[1]};
|
struct hlsl_ir_node *args[HLSL_MAX_OPERANDS] = {params->args[0], params->args[1]};
|
||||||
|
|
||||||
return !!add_expr(ctx, params->instrs, HLSL_OP2_MAX, args, &loc);
|
return !!add_expr(ctx, params->instrs, HLSL_OP2_MAX, args, &loc);
|
||||||
}
|
}
|
||||||
@ -1586,7 +1586,7 @@ static bool intrinsic_max(struct hlsl_ctx *ctx,
|
|||||||
static bool intrinsic_pow(struct hlsl_ctx *ctx,
|
static bool intrinsic_pow(struct hlsl_ctx *ctx,
|
||||||
const struct parse_initializer *params, struct vkd3d_shader_location loc)
|
const struct parse_initializer *params, struct vkd3d_shader_location loc)
|
||||||
{
|
{
|
||||||
struct hlsl_ir_node *args[3] = {0};
|
struct hlsl_ir_node *args[HLSL_MAX_OPERANDS] = {0};
|
||||||
struct hlsl_ir_node *log, *exp;
|
struct hlsl_ir_node *log, *exp;
|
||||||
struct hlsl_ir_expr *mul;
|
struct hlsl_ir_expr *mul;
|
||||||
|
|
||||||
@ -1608,7 +1608,7 @@ static bool intrinsic_pow(struct hlsl_ctx *ctx,
|
|||||||
static bool intrinsic_saturate(struct hlsl_ctx *ctx,
|
static bool intrinsic_saturate(struct hlsl_ctx *ctx,
|
||||||
const struct parse_initializer *params, struct vkd3d_shader_location loc)
|
const struct parse_initializer *params, struct vkd3d_shader_location loc)
|
||||||
{
|
{
|
||||||
struct hlsl_ir_node *args[3] = {params->args[0]};
|
struct hlsl_ir_node *args[HLSL_MAX_OPERANDS] = {params->args[0]};
|
||||||
|
|
||||||
return !!add_expr(ctx, params->instrs, HLSL_OP1_SAT, args, &loc);
|
return !!add_expr(ctx, params->instrs, HLSL_OP1_SAT, args, &loc);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user