vkd3d-shader/hlsl: Cast array indices inside of add_array_load().

Mostly in the interest of keeping the yacc code as simple as possible.
This commit is contained in:
Zebediah Figura
2022-10-13 22:33:08 -05:00
committed by Alexandre Julliard
parent 62fd13059b
commit 7115a94063
Notes: Alexandre Julliard 2022-10-19 22:07:47 +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/30

View File

@@ -748,23 +748,35 @@ static bool add_matrix_index(struct hlsl_ctx *ctx, struct list *instrs,
} }
static bool add_array_load(struct hlsl_ctx *ctx, struct list *instrs, struct hlsl_ir_node *array, static bool add_array_load(struct hlsl_ctx *ctx, struct list *instrs, struct hlsl_ir_node *array,
struct hlsl_ir_node *index, const struct vkd3d_shader_location loc) struct hlsl_ir_node *index, const struct vkd3d_shader_location *loc)
{ {
const struct hlsl_type *expr_type = array->data_type; const struct hlsl_type *expr_type = array->data_type;
struct hlsl_ir_expr *cast;
if (index->data_type->type != HLSL_CLASS_SCALAR)
{
hlsl_error(ctx, &index->loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE, "Array index is not scalar.");
return false;
}
if (!(cast = hlsl_new_cast(ctx, index, hlsl_get_scalar_type(ctx, HLSL_TYPE_UINT), &index->loc)))
return false;
list_add_tail(instrs, &cast->node.entry);
index = &cast->node;
if (expr_type->type == HLSL_CLASS_MATRIX) if (expr_type->type == HLSL_CLASS_MATRIX)
return add_matrix_index(ctx, instrs, array, index, &loc); return add_matrix_index(ctx, instrs, array, index, loc);
if (expr_type->type != HLSL_CLASS_ARRAY && expr_type->type != HLSL_CLASS_VECTOR) if (expr_type->type != HLSL_CLASS_ARRAY && expr_type->type != HLSL_CLASS_VECTOR)
{ {
if (expr_type->type == HLSL_CLASS_SCALAR) if (expr_type->type == HLSL_CLASS_SCALAR)
hlsl_error(ctx, &loc, VKD3D_SHADER_ERROR_HLSL_INVALID_INDEX, "Scalar expressions cannot be array-indexed."); hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_INDEX, "Scalar expressions cannot be array-indexed.");
else else
hlsl_error(ctx, &loc, VKD3D_SHADER_ERROR_HLSL_INVALID_INDEX, "Expression cannot be array-indexed."); hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_INDEX, "Expression cannot be array-indexed.");
return false; return false;
} }
if (!add_load_index(ctx, instrs, array, index, &loc)) if (!add_load_index(ctx, instrs, array, index, loc))
return false; return false;
return true; return true;
@@ -4209,26 +4221,11 @@ postfix_expr:
| postfix_expr '[' expr ']' | postfix_expr '[' expr ']'
{ {
struct hlsl_ir_node *array = node_from_list($1), *index = node_from_list($3); struct hlsl_ir_node *array = node_from_list($1), *index = node_from_list($3);
struct hlsl_ir_expr *cast;
list_move_tail($1, $3); list_move_tail($1, $3);
vkd3d_free($3); vkd3d_free($3);
if (index->data_type->type != HLSL_CLASS_SCALAR) if (!add_array_load(ctx, $1, array, index, &@2))
{
hlsl_error(ctx, &@3, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE, "Array index is not scalar.");
destroy_instr_list($1);
YYABORT;
}
if (!(cast = hlsl_new_cast(ctx, index, hlsl_get_scalar_type(ctx, HLSL_TYPE_UINT), &index->loc)))
{
destroy_instr_list($1);
YYABORT;
}
list_add_tail($1, &cast->node.entry);
if (!add_array_load(ctx, $1, array, &cast->node, @2))
{ {
destroy_instr_list($1); destroy_instr_list($1);
YYABORT; YYABORT;