vkd3d-shader/hlsl: Introduce a helper to validate that an instruction has integer type.

Signed-off-by: Zebediah Figura <zfigura@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Giovanni Mascellani <gmascellani@codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni@codeweavers.com>
Signed-off-by: Francisco Casas <fcasas@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2022-02-24 12:45:15 -06:00 committed by Alexandre Julliard
parent ffbc40ee20
commit 5548d5fe6d

View File

@ -1014,6 +1014,27 @@ static struct hlsl_ir_expr *add_expr(struct hlsl_ctx *ctx, struct list *instrs,
return expr; return expr;
} }
static void check_integer_type(struct hlsl_ctx *ctx, const struct hlsl_ir_node *instr)
{
const struct hlsl_type *type = instr->data_type;
struct vkd3d_string_buffer *string;
switch (type->base_type)
{
case HLSL_TYPE_BOOL:
case HLSL_TYPE_INT:
case HLSL_TYPE_UINT:
break;
default:
if ((string = hlsl_type_to_string(ctx, type)))
hlsl_error(ctx, &instr->loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
"Expression type '%s' is not integer.", string->buffer);
hlsl_release_string_buffer(ctx, string);
break;
}
}
static struct hlsl_ir_expr *add_unary_arithmetic_expr(struct hlsl_ctx *ctx, struct list *instrs, static struct hlsl_ir_expr *add_unary_arithmetic_expr(struct hlsl_ctx *ctx, struct list *instrs,
enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg, const struct vkd3d_shader_location *loc) enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg, const struct vkd3d_shader_location *loc)
{ {
@ -1061,29 +1082,8 @@ static struct hlsl_ir_expr *add_binary_bitwise_expr(struct hlsl_ctx *ctx, struct
enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg1, struct hlsl_ir_node *arg2, enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg1, struct hlsl_ir_node *arg2,
const struct vkd3d_shader_location *loc) const struct vkd3d_shader_location *loc)
{ {
if (arg1->data_type->base_type != HLSL_TYPE_INT && arg1->data_type->base_type != HLSL_TYPE_UINT check_integer_type(ctx, arg1);
&& arg1->data_type->base_type != HLSL_TYPE_BOOL) check_integer_type(ctx, arg2);
{
struct vkd3d_string_buffer *type_str = hlsl_type_to_string(ctx, arg1->data_type);
if (type_str)
hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
"The first argument has type '%s', which is not integer.", type_str->buffer);
hlsl_release_string_buffer(ctx, type_str);
return NULL;
}
if (arg2->data_type->base_type != HLSL_TYPE_INT && arg2->data_type->base_type != HLSL_TYPE_UINT
&& arg2->data_type->base_type != HLSL_TYPE_BOOL)
{
struct vkd3d_string_buffer *type_str = hlsl_type_to_string(ctx, arg2->data_type);
if (type_str)
hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
"The second argument has type '%s', which is not integer.", type_str->buffer);
hlsl_release_string_buffer(ctx, type_str);
return NULL;
}
return add_binary_arithmetic_expr(ctx, instrs, op, arg1, arg2, loc); return add_binary_arithmetic_expr(ctx, instrs, op, arg1, arg2, loc);
} }