[PATCH vkd3d v2 1/7] vkd3d-shader/hlsl: Introduce a helper to validate that an instruction has integer type.
Signed-off-by: Zebediah Figura <zfigura(a)codeweavers.com> --- libs/vkd3d-shader/hlsl.y | 46 ++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 459ad03bf..01e6b3dfb 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1014,6 +1014,27 @@ static struct hlsl_ir_expr *add_expr(struct hlsl_ctx *ctx, struct list *instrs, 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, 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, const struct vkd3d_shader_location *loc) { - if (arg1->data_type->base_type != HLSL_TYPE_INT && arg1->data_type->base_type != HLSL_TYPE_UINT - && arg1->data_type->base_type != HLSL_TYPE_BOOL) - { - 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; - } + check_integer_type(ctx, arg1); + check_integer_type(ctx, arg2); return add_binary_arithmetic_expr(ctx, instrs, op, arg1, arg2, loc); } -- 2.35.1
From: Giovanni Mascellani <gmascellani(a)codeweavers.com> Signed-off-by: Giovanni Mascellani <gmascellani(a)codeweavers.com> Signed-off-by: Zebediah Figura <zfigura(a)codeweavers.com> --- v2: Constify the "loc" parameter. libs/vkd3d-shader/hlsl.y | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 01e6b3dfb..bb24e39de 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1136,6 +1136,41 @@ static struct list *add_binary_comparison_expr_merge(struct hlsl_ctx *ctx, struc return list1; } +static struct hlsl_ir_expr *add_binary_logical_expr(struct hlsl_ctx *ctx, struct list *instrs, + enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg1, struct hlsl_ir_node *arg2, + const struct vkd3d_shader_location *loc) +{ + struct hlsl_ir_node *args[HLSL_MAX_OPERANDS] = {0}; + struct hlsl_type *common_type; + enum hlsl_type_class type; + unsigned int dimx, dimy; + + if (!expr_common_shape(ctx, arg1->data_type, arg2->data_type, loc, &type, &dimx, &dimy)) + return NULL; + + common_type = hlsl_get_numeric_type(ctx, type, HLSL_TYPE_BOOL, dimx, dimy); + + if (!(args[0] = add_implicit_conversion(ctx, instrs, arg1, common_type, loc))) + return NULL; + + if (!(args[1] = add_implicit_conversion(ctx, instrs, arg2, common_type, loc))) + return NULL; + + return add_expr(ctx, instrs, op, args, common_type, loc); +} + +static struct list *add_binary_logical_expr_merge(struct hlsl_ctx *ctx, struct list *list1, struct list *list2, + enum hlsl_ir_expr_op op, const struct vkd3d_shader_location *loc) +{ + struct hlsl_ir_node *arg1 = node_from_list(list1), *arg2 = node_from_list(list2); + + list_move_tail(list1, list2); + vkd3d_free(list2); + add_binary_logical_expr(ctx, list1, op, arg1, arg2, loc); + + return list1; +} + static enum hlsl_ir_expr_op op_from_assignment(enum parse_assign_op op) { static const enum hlsl_ir_expr_op ops[] = @@ -3664,7 +3699,7 @@ logicand_expr: bitor_expr | logicand_expr OP_AND bitor_expr { - hlsl_fixme(ctx, &@$, "Logical AND."); + $$ = add_binary_logical_expr_merge(ctx, $1, $3, HLSL_OP2_LOGIC_AND, &@2); } logicor_expr: -- 2.35.1
Signed-off-by: Francisco Casas <fcasas(a)codeweavers.com> February 24, 2022 3:45 PM, "Zebediah Figura" <zfigura(a)codeweavers.com> wrote:
From: Giovanni Mascellani <gmascellani(a)codeweavers.com>
Signed-off-by: Giovanni Mascellani <gmascellani(a)codeweavers.com> Signed-off-by: Zebediah Figura <zfigura(a)codeweavers.com> --- v2: Constify the "loc" parameter.
libs/vkd3d-shader/hlsl.y | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 01e6b3dfb..bb24e39de 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1136,6 +1136,41 @@ static struct list *add_binary_comparison_expr_merge(struct hlsl_ctx *ctx, struc return list1; }
+static struct hlsl_ir_expr *add_binary_logical_expr(struct hlsl_ctx *ctx, struct list *instrs, + enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg1, struct hlsl_ir_node *arg2, + const struct vkd3d_shader_location *loc) +{ + struct hlsl_ir_node *args[HLSL_MAX_OPERANDS] = {0}; + struct hlsl_type *common_type; + enum hlsl_type_class type; + unsigned int dimx, dimy; + + if (!expr_common_shape(ctx, arg1->data_type, arg2->data_type, loc, &type, &dimx, &dimy)) + return NULL; + + common_type = hlsl_get_numeric_type(ctx, type, HLSL_TYPE_BOOL, dimx, dimy); + + if (!(args[0] = add_implicit_conversion(ctx, instrs, arg1, common_type, loc))) + return NULL; + + if (!(args[1] = add_implicit_conversion(ctx, instrs, arg2, common_type, loc))) + return NULL; + + return add_expr(ctx, instrs, op, args, common_type, loc); +} + +static struct list *add_binary_logical_expr_merge(struct hlsl_ctx *ctx, struct list *list1, struct list *list2, + enum hlsl_ir_expr_op op, const struct vkd3d_shader_location *loc) +{ + struct hlsl_ir_node *arg1 = node_from_list(list1), *arg2 = node_from_list(list2); + + list_move_tail(list1, list2); + vkd3d_free(list2); + add_binary_logical_expr(ctx, list1, op, arg1, arg2, loc); + + return list1; +} + static enum hlsl_ir_expr_op op_from_assignment(enum parse_assign_op op) { static const enum hlsl_ir_expr_op ops[] = @@ -3664,7 +3699,7 @@ logicand_expr: bitor_expr | logicand_expr OP_AND bitor_expr { - hlsl_fixme(ctx, &@$, "Logical AND."); + $$ = add_binary_logical_expr_merge(ctx, $1, $3, HLSL_OP2_LOGIC_AND, &@2); }
logicor_expr: -- 2.35.1
Signed-off-by: Matteo Bruni <mbruni(a)codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet(a)codeweavers.com>
From: Giovanni Mascellani <gmascellani(a)codeweavers.com> Signed-off-by: Giovanni Mascellani <gmascellani(a)codeweavers.com> Signed-off-by: Zebediah Figura <zfigura(a)codeweavers.com> --- v2: No changes. libs/vkd3d-shader/hlsl.y | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index bb24e39de..4cdb471e8 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -3706,7 +3706,7 @@ logicor_expr: logicand_expr | logicor_expr OP_OR logicand_expr { - hlsl_fixme(ctx, &@$, "Logical OR."); + $$ = add_binary_logical_expr_merge(ctx, $1, $3, HLSL_OP2_LOGIC_OR, &@2); } conditional_expr: -- 2.35.1
Signed-off-by: Francisco Casas <fcasas(a)codeweavers.com> February 24, 2022 3:45 PM, "Zebediah Figura" <zfigura(a)codeweavers.com> wrote:
From: Giovanni Mascellani <gmascellani(a)codeweavers.com>
Signed-off-by: Giovanni Mascellani <gmascellani(a)codeweavers.com> Signed-off-by: Zebediah Figura <zfigura(a)codeweavers.com> --- v2: No changes.
libs/vkd3d-shader/hlsl.y | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index bb24e39de..4cdb471e8 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -3706,7 +3706,7 @@ logicor_expr: logicand_expr | logicor_expr OP_OR logicand_expr { - hlsl_fixme(ctx, &@$, "Logical OR."); + $$ = add_binary_logical_expr_merge(ctx, $1, $3, HLSL_OP2_LOGIC_OR, &@2); }
conditional_expr: -- 2.35.1
Signed-off-by: Matteo Bruni <mbruni(a)codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet(a)codeweavers.com>
From: Giovanni Mascellani <gmascellani(a)codeweavers.com> Signed-off-by: Giovanni Mascellani <gmascellani(a)codeweavers.com> Signed-off-by: Zebediah Figura <zfigura(a)codeweavers.com> --- v2: Use check_integer_type(); constify the "loc" parameter. libs/vkd3d-shader/hlsl.y | 45 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 4cdb471e8..7c7c89efb 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1171,6 +1171,49 @@ static struct list *add_binary_logical_expr_merge(struct hlsl_ctx *ctx, struct l return list1; } +static struct hlsl_ir_expr *add_binary_shift_expr(struct hlsl_ctx *ctx, struct list *instrs, + enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg1, struct hlsl_ir_node *arg2, + const struct vkd3d_shader_location *loc) +{ + enum hlsl_base_type base = arg1->data_type->base_type; + struct hlsl_ir_node *args[HLSL_MAX_OPERANDS] = {0}; + struct hlsl_type *return_type, *integer_type; + enum hlsl_type_class type; + unsigned int dimx, dimy; + + check_integer_type(ctx, arg1); + check_integer_type(ctx, arg2); + + if (base == HLSL_TYPE_BOOL) + base = HLSL_TYPE_INT; + + if (!expr_common_shape(ctx, arg1->data_type, arg2->data_type, loc, &type, &dimx, &dimy)) + return NULL; + + return_type = hlsl_get_numeric_type(ctx, type, base, dimx, dimy); + integer_type = hlsl_get_numeric_type(ctx, type, HLSL_TYPE_INT, dimx, dimy); + + if (!(args[0] = add_implicit_conversion(ctx, instrs, arg1, return_type, loc))) + return NULL; + + if (!(args[1] = add_implicit_conversion(ctx, instrs, arg2, integer_type, loc))) + return NULL; + + return add_expr(ctx, instrs, op, args, return_type, loc); +} + +static struct list *add_binary_shift_expr_merge(struct hlsl_ctx *ctx, struct list *list1, struct list *list2, + enum hlsl_ir_expr_op op, const struct vkd3d_shader_location *loc) +{ + struct hlsl_ir_node *arg1 = node_from_list(list1), *arg2 = node_from_list(list2); + + list_move_tail(list1, list2); + vkd3d_free(list2); + add_binary_shift_expr(ctx, list1, op, arg1, arg2, loc); + + return list1; +} + static enum hlsl_ir_expr_op op_from_assignment(enum parse_assign_op op) { static const enum hlsl_ir_expr_op ops[] = @@ -3637,7 +3680,7 @@ shift_expr: add_expr | shift_expr OP_LEFTSHIFT add_expr { - hlsl_fixme(ctx, &@$, "Left shift."); + $$ = add_binary_shift_expr_merge(ctx, $1, $3, HLSL_OP2_LSHIFT, &@2); } | shift_expr OP_RIGHTSHIFT add_expr { -- 2.35.1
Signed-off-by: Francisco Casas <fcasas(a)codeweavers.com> Note to self: We have to remember to apply (ยท & x11111) to the 2nd operand if we add this op to constant folding. February 24, 2022 3:45 PM, "Zebediah Figura" <zfigura(a)codeweavers.com> wrote:
From: Giovanni Mascellani <gmascellani(a)codeweavers.com>
Signed-off-by: Giovanni Mascellani <gmascellani(a)codeweavers.com> Signed-off-by: Zebediah Figura <zfigura(a)codeweavers.com> --- v2: Use check_integer_type(); constify the "loc" parameter.
libs/vkd3d-shader/hlsl.y | 45 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 4cdb471e8..7c7c89efb 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1171,6 +1171,49 @@ static struct list *add_binary_logical_expr_merge(struct hlsl_ctx *ctx, struct l return list1; }
+static struct hlsl_ir_expr *add_binary_shift_expr(struct hlsl_ctx *ctx, struct list *instrs, + enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg1, struct hlsl_ir_node *arg2, + const struct vkd3d_shader_location *loc) +{ + enum hlsl_base_type base = arg1->data_type->base_type; + struct hlsl_ir_node *args[HLSL_MAX_OPERANDS] = {0}; + struct hlsl_type *return_type, *integer_type; + enum hlsl_type_class type; + unsigned int dimx, dimy; + + check_integer_type(ctx, arg1); + check_integer_type(ctx, arg2); + + if (base == HLSL_TYPE_BOOL) + base = HLSL_TYPE_INT; + + if (!expr_common_shape(ctx, arg1->data_type, arg2->data_type, loc, &type, &dimx, &dimy)) + return NULL; + + return_type = hlsl_get_numeric_type(ctx, type, base, dimx, dimy); + integer_type = hlsl_get_numeric_type(ctx, type, HLSL_TYPE_INT, dimx, dimy); + + if (!(args[0] = add_implicit_conversion(ctx, instrs, arg1, return_type, loc))) + return NULL; + + if (!(args[1] = add_implicit_conversion(ctx, instrs, arg2, integer_type, loc))) + return NULL; + + return add_expr(ctx, instrs, op, args, return_type, loc); +} + +static struct list *add_binary_shift_expr_merge(struct hlsl_ctx *ctx, struct list *list1, struct list *list2, + enum hlsl_ir_expr_op op, const struct vkd3d_shader_location *loc) +{ + struct hlsl_ir_node *arg1 = node_from_list(list1), *arg2 = node_from_list(list2); + + list_move_tail(list1, list2); + vkd3d_free(list2); + add_binary_shift_expr(ctx, list1, op, arg1, arg2, loc); + + return list1; +} + static enum hlsl_ir_expr_op op_from_assignment(enum parse_assign_op op) { static const enum hlsl_ir_expr_op ops[] = @@ -3637,7 +3680,7 @@ shift_expr: add_expr | shift_expr OP_LEFTSHIFT add_expr { - hlsl_fixme(ctx, &@$, "Left shift."); + $$ = add_binary_shift_expr_merge(ctx, $1, $3, HLSL_OP2_LSHIFT, &@2); } | shift_expr OP_RIGHTSHIFT add_expr { -- 2.35.1
February 28, 2022 1:45 PM, "Francisco Casas" <fcasas(a)codeweavers.com> wrote:
Signed-off-by: Francisco Casas <fcasas(a)codeweavers.com>
Note to self: We have to remember to apply (ยท & x11111) to the 2nd operand if we add this op to constant folding.
Silly me, I meant 0x1f (5 bits).
Signed-off-by: Matteo Bruni <mbruni(a)codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet(a)codeweavers.com>
From: Giovanni Mascellani <gmascellani(a)codeweavers.com> Signed-off-by: Giovanni Mascellani <gmascellani(a)codeweavers.com> Signed-off-by: Zebediah Figura <zfigura(a)codeweavers.com> --- v2: No changes. libs/vkd3d-shader/hlsl.y | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 7c7c89efb..c1c229a6f 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -3684,7 +3684,7 @@ shift_expr: } | shift_expr OP_RIGHTSHIFT add_expr { - hlsl_fixme(ctx, &@$, "Right shift."); + $$ = add_binary_shift_expr_merge(ctx, $1, $3, HLSL_OP2_RSHIFT, &@2); } relational_expr: -- 2.35.1
Signed-off-by: Francisco Casas <fcasas(a)codeweavers.com> February 24, 2022 3:45 PM, "Zebediah Figura" <zfigura(a)codeweavers.com> wrote:
From: Giovanni Mascellani <gmascellani(a)codeweavers.com>
Signed-off-by: Giovanni Mascellani <gmascellani(a)codeweavers.com> Signed-off-by: Zebediah Figura <zfigura(a)codeweavers.com> --- v2: No changes.
libs/vkd3d-shader/hlsl.y | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 7c7c89efb..c1c229a6f 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -3684,7 +3684,7 @@ shift_expr: } | shift_expr OP_RIGHTSHIFT add_expr { - hlsl_fixme(ctx, &@$, "Right shift."); + $$ = add_binary_shift_expr_merge(ctx, $1, $3, HLSL_OP2_RSHIFT, &@2); }
relational_expr: -- 2.35.1
Signed-off-by: Matteo Bruni <mbruni(a)codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet(a)codeweavers.com>
From: Giovanni Mascellani <gmascellani(a)codeweavers.com> Signed-off-by: Giovanni Mascellani <gmascellani(a)codeweavers.com> Signed-off-by: Zebediah Figura <zfigura(a)codeweavers.com> --- v2: Use check_integer_type(); constify the "loc" parameter. libs/vkd3d-shader/hlsl.y | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index c1c229a6f..328f1bbb1 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1043,6 +1043,14 @@ static struct hlsl_ir_expr *add_unary_arithmetic_expr(struct hlsl_ctx *ctx, stru return add_expr(ctx, instrs, op, args, arg->data_type, loc); } +static struct hlsl_ir_expr *add_unary_bitwise_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) +{ + check_integer_type(ctx, arg); + + return add_unary_arithmetic_expr(ctx, instrs, op, arg, loc); +} + static struct hlsl_ir_expr *add_binary_arithmetic_expr(struct hlsl_ctx *ctx, struct list *instrs, enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg1, struct hlsl_ir_node *arg2, const struct vkd3d_shader_location *loc) @@ -3595,7 +3603,7 @@ unary_expr: } | '~' unary_expr { - add_unary_arithmetic_expr(ctx, $2, HLSL_OP1_BIT_NOT, node_from_list($2), &@1); + add_unary_bitwise_expr(ctx, $2, HLSL_OP1_BIT_NOT, node_from_list($2), &@1); $$ = $2; } | '!' unary_expr -- 2.35.1
Signed-off-by: Francisco Casas <fcasas(a)codeweavers.com> February 24, 2022 3:45 PM, "Zebediah Figura" <zfigura(a)codeweavers.com> wrote:
From: Giovanni Mascellani <gmascellani(a)codeweavers.com>
Signed-off-by: Giovanni Mascellani <gmascellani(a)codeweavers.com> Signed-off-by: Zebediah Figura <zfigura(a)codeweavers.com> --- v2: Use check_integer_type(); constify the "loc" parameter.
libs/vkd3d-shader/hlsl.y | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index c1c229a6f..328f1bbb1 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1043,6 +1043,14 @@ static struct hlsl_ir_expr *add_unary_arithmetic_expr(struct hlsl_ctx *ctx, stru return add_expr(ctx, instrs, op, args, arg->data_type, loc); }
+static struct hlsl_ir_expr *add_unary_bitwise_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) +{ + check_integer_type(ctx, arg); + + return add_unary_arithmetic_expr(ctx, instrs, op, arg, loc); +} + static struct hlsl_ir_expr *add_binary_arithmetic_expr(struct hlsl_ctx *ctx, struct list *instrs, enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg1, struct hlsl_ir_node *arg2, const struct vkd3d_shader_location *loc) @@ -3595,7 +3603,7 @@ unary_expr: } | '~' unary_expr { - add_unary_arithmetic_expr(ctx, $2, HLSL_OP1_BIT_NOT, node_from_list($2), &@1); + add_unary_bitwise_expr(ctx, $2, HLSL_OP1_BIT_NOT, node_from_list($2), &@1); $$ = $2; } | '!' unary_expr -- 2.35.1
Signed-off-by: Matteo Bruni <mbruni(a)codeweavers.com> --- Not a big deal but I'd prefer something like "vkd3d-shader/hlsl: Check argument type for bitwise NOT." as the patch subject.
Signed-off-by: Henri Verbeet <hverbeet(a)codeweavers.com>
From: Giovanni Mascellani <gmascellani(a)codeweavers.com> Signed-off-by: Giovanni Mascellani <gmascellani(a)codeweavers.com> Signed-off-by: Zebediah Figura <zfigura(a)codeweavers.com> --- v2: Constify the "loc" parameter. libs/vkd3d-shader/hlsl.y | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 328f1bbb1..92dcb3f2a 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1051,6 +1051,21 @@ static struct hlsl_ir_expr *add_unary_bitwise_expr(struct hlsl_ctx *ctx, struct return add_unary_arithmetic_expr(ctx, instrs, op, arg, loc); } +static struct hlsl_ir_expr *add_unary_logical_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) +{ + struct hlsl_ir_node *args[HLSL_MAX_OPERANDS] = {0}; + struct hlsl_type *bool_type; + + bool_type = hlsl_get_numeric_type(ctx, arg->data_type->type, HLSL_TYPE_BOOL, + arg->data_type->dimx, arg->data_type->dimy); + + if (!(args[0] = add_implicit_conversion(ctx, instrs, arg, bool_type, loc))) + return NULL; + + return add_expr(ctx, instrs, op, args, bool_type, loc); +} + static struct hlsl_ir_expr *add_binary_arithmetic_expr(struct hlsl_ctx *ctx, struct list *instrs, enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg1, struct hlsl_ir_node *arg2, const struct vkd3d_shader_location *loc) @@ -3608,7 +3623,7 @@ unary_expr: } | '!' unary_expr { - add_unary_arithmetic_expr(ctx, $2, HLSL_OP1_LOGIC_NOT, node_from_list($2), &@1); + add_unary_logical_expr(ctx, $2, HLSL_OP1_LOGIC_NOT, node_from_list($2), &@1); $$ = $2; } /* var_modifiers is necessary to avoid shift/reduce conflicts. */ -- 2.35.1
Signed-off-by: Francisco Casas <fcasas(a)codeweavers.com> February 24, 2022 3:45 PM, "Zebediah Figura" <zfigura(a)codeweavers.com> wrote:
From: Giovanni Mascellani <gmascellani(a)codeweavers.com>
Signed-off-by: Giovanni Mascellani <gmascellani(a)codeweavers.com> Signed-off-by: Zebediah Figura <zfigura(a)codeweavers.com> --- v2: Constify the "loc" parameter.
libs/vkd3d-shader/hlsl.y | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 328f1bbb1..92dcb3f2a 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1051,6 +1051,21 @@ static struct hlsl_ir_expr *add_unary_bitwise_expr(struct hlsl_ctx *ctx, struct return add_unary_arithmetic_expr(ctx, instrs, op, arg, loc); }
+static struct hlsl_ir_expr *add_unary_logical_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) +{ + struct hlsl_ir_node *args[HLSL_MAX_OPERANDS] = {0}; + struct hlsl_type *bool_type; + + bool_type = hlsl_get_numeric_type(ctx, arg->data_type->type, HLSL_TYPE_BOOL, + arg->data_type->dimx, arg->data_type->dimy); + + if (!(args[0] = add_implicit_conversion(ctx, instrs, arg, bool_type, loc))) + return NULL; + + return add_expr(ctx, instrs, op, args, bool_type, loc); +} + static struct hlsl_ir_expr *add_binary_arithmetic_expr(struct hlsl_ctx *ctx, struct list *instrs, enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg1, struct hlsl_ir_node *arg2, const struct vkd3d_shader_location *loc) @@ -3608,7 +3623,7 @@ unary_expr: } | '!' unary_expr { - add_unary_arithmetic_expr(ctx, $2, HLSL_OP1_LOGIC_NOT, node_from_list($2), &@1); + add_unary_logical_expr(ctx, $2, HLSL_OP1_LOGIC_NOT, node_from_list($2), &@1); $$ = $2; } /* var_modifiers is necessary to avoid shift/reduce conflicts. */ -- 2.35.1
Signed-off-by: Matteo Bruni <mbruni(a)codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet(a)codeweavers.com>
Signed-off-by: Giovanni Mascellani <gmascellani(a)codeweavers.com> Il 24/02/22 19:45, Zebediah Figura ha scritto:
Signed-off-by: Zebediah Figura <zfigura(a)codeweavers.com> --- libs/vkd3d-shader/hlsl.y | 46 ++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 23 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 459ad03bf..01e6b3dfb 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1014,6 +1014,27 @@ static struct hlsl_ir_expr *add_expr(struct hlsl_ctx *ctx, struct list *instrs, 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, 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, const struct vkd3d_shader_location *loc) { - if (arg1->data_type->base_type != HLSL_TYPE_INT && arg1->data_type->base_type != HLSL_TYPE_UINT - && arg1->data_type->base_type != HLSL_TYPE_BOOL) - { - 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; - } + check_integer_type(ctx, arg1); + check_integer_type(ctx, arg2);
return add_binary_arithmetic_expr(ctx, instrs, op, arg1, arg2, loc); }
Signed-off-by: Francisco Casas <fcasas(a)codeweavers.com> February 24, 2022 3:45 PM, "Zebediah Figura" <zfigura(a)codeweavers.com> wrote:
Signed-off-by: Zebediah Figura <zfigura(a)codeweavers.com> --- libs/vkd3d-shader/hlsl.y | 46 ++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 23 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 459ad03bf..01e6b3dfb 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1014,6 +1014,27 @@ static struct hlsl_ir_expr *add_expr(struct hlsl_ctx *ctx, struct list *instrs, 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, 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, const struct vkd3d_shader_location *loc) { - if (arg1->data_type->base_type != HLSL_TYPE_INT && arg1->data_type->base_type != HLSL_TYPE_UINT - && arg1->data_type->base_type != HLSL_TYPE_BOOL) - { - 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; - } + check_integer_type(ctx, arg1); + check_integer_type(ctx, arg2);
return add_binary_arithmetic_expr(ctx, instrs, op, arg1, arg2, loc); } -- 2.35.1
participants (5)
-
Francisco Casas -
Giovanni Mascellani -
Henri Verbeet -
Matteo Bruni -
Zebediah Figura