From: Francisco Casas fcasas@codeweavers.com
Signed-off-by: Francisco Casas fcasas@codeweavers.com Signed-off-by: Zebediah Figura zfigura@codeweavers.com Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- v7: Catch another case.
libs/vkd3d-shader/hlsl.y | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 1ab56fba..0fc8fa29 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -3208,7 +3208,10 @@ complex_initializer: { $$.args_count = 1; if (!($$.args = hlsl_alloc(ctx, sizeof(*$$.args)))) + { + destroy_instr_list($1); YYABORT; + } $$.args[0] = node_from_list($1); $$.instrs = $1; } @@ -3229,15 +3232,25 @@ initializer_expr_list: { $$.args_count = 1; if (!($$.args = hlsl_alloc(ctx, sizeof(*$$.args)))) + { + destroy_instr_list($1); YYABORT; + } $$.args[0] = node_from_list($1); $$.instrs = $1; } | initializer_expr_list ',' initializer_expr { + struct hlsl_ir_node **new_args; + $$ = $1; - if (!($$.args = hlsl_realloc(ctx, $$.args, ($$.args_count + 1) * sizeof(*$$.args)))) + if (!(new_args = hlsl_realloc(ctx, $$.args, ($$.args_count + 1) * sizeof(*$$.args)))) + { + free_parse_initializer(&$$); + destroy_instr_list($3); YYABORT; + } + $$.args = new_args; $$.args[$$.args_count++] = node_from_list($3); list_move_tail($$.instrs, $3); vkd3d_free($3);
From: Francisco Casas fcasas@codeweavers.com
Signed-off-by: Francisco Casas fcasas@codeweavers.com Signed-off-by: Zebediah Figura zfigura@codeweavers.com Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- v7: Tiny stylistical tweak.
libs/vkd3d-shader/hlsl.y | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 0fc8fa29..8f8b3c35 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -2408,6 +2408,7 @@ static bool add_method_call(struct hlsl_ctx *ctx, struct list *instrs, struct hl %type <function> func_prototype
%type <initializer> complex_initializer +%type <initializer> complex_initializer_list %type <initializer> func_arguments %type <initializer> initializer_expr_list
@@ -3215,15 +3216,36 @@ complex_initializer: $$.args[0] = node_from_list($1); $$.instrs = $1; } - | '{' initializer_expr_list '}' + | '{' complex_initializer_list '}' { $$ = $2; } - | '{' initializer_expr_list ',' '}' + | '{' complex_initializer_list ',' '}' { $$ = $2; }
+complex_initializer_list: + complex_initializer + | complex_initializer_list ',' complex_initializer + { + struct hlsl_ir_node **new_args; + unsigned int i; + + $$ = $1; + if (!(new_args = hlsl_realloc(ctx, $$.args, ($$.args_count + $3.args_count) * sizeof(*$$.args)))) + { + free_parse_initializer(&$$); + free_parse_initializer(&$3); + YYABORT; + } + $$.args = new_args; + for (i = 0; i < $3.args_count; ++i) + $$.args[$$.args_count++] = $3.args[i]; + list_move_tail($$.instrs, $3.instrs); + free_parse_initializer(&$3); + } + initializer_expr: assignment_expr
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
From: Francisco Casas fcasas@codeweavers.com
Signed-off-by: Francisco Casas fcasas@codeweavers.com Signed-off-by: Zebediah Figura zfigura@codeweavers.com Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- libs/vkd3d-shader/hlsl.y | 6 ++++++ 1 file changed, 6 insertions(+)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 8f8b3c35..6fcacc67 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -48,6 +48,7 @@ struct parse_initializer struct hlsl_ir_node **args; unsigned int args_count; struct list *instrs; + bool braces; };
struct parse_array_sizes @@ -3215,14 +3216,17 @@ complex_initializer: } $$.args[0] = node_from_list($1); $$.instrs = $1; + $$.braces = false; } | '{' complex_initializer_list '}' { $$ = $2; + $$.braces = true; } | '{' complex_initializer_list ',' '}' { $$ = $2; + $$.braces = true; }
complex_initializer_list: @@ -3260,6 +3264,7 @@ initializer_expr_list: } $$.args[0] = node_from_list($1); $$.instrs = $1; + $$.braces = false; } | initializer_expr_list ',' initializer_expr { @@ -3396,6 +3401,7 @@ func_arguments: $$.args_count = 0; if (!($$.instrs = make_empty_list(ctx))) YYABORT; + $$.braces = false; } | initializer_expr_list
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
From: Francisco Casas fcasas@codeweavers.com
Signed-off-by: Francisco Casas fcasas@codeweavers.com Signed-off-by: Zebediah Figura zfigura@codeweavers.com Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- libs/vkd3d-shader/hlsl.y | 42 +++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 6fcacc67..a5a45640 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -668,6 +668,15 @@ static struct hlsl_type *apply_type_modifiers(struct hlsl_ctx *ctx, struct hlsl_ return new_type; }
+static void free_parse_variable_def(struct parse_variable_def *v) +{ + free_parse_initializer(&v->initializer); + vkd3d_free(v->arrays.sizes); + vkd3d_free(v->name); + vkd3d_free((void *)v->semantic.name); + vkd3d_free(v); +} + static struct list *gen_struct_fields(struct hlsl_ctx *ctx, struct hlsl_type *type, struct list *fields) { struct parse_variable_def *v, *v_next; @@ -685,13 +694,14 @@ static struct list *gen_struct_fields(struct hlsl_ctx *ctx, struct hlsl_type *ty
if (!(field = hlsl_alloc(ctx, sizeof(*field)))) { - vkd3d_free(v); - return list; + free_parse_variable_def(v); + continue; }
field->type = type; for (i = 0; i < v->arrays.count; ++i) field->type = hlsl_new_array_type(ctx, field->type, v->arrays.sizes[i]); + vkd3d_free(v->arrays.sizes); field->loc = v->loc; field->name = v->name; field->semantic = v->semantic; @@ -719,18 +729,29 @@ static bool add_typedef(struct hlsl_ctx *ctx, DWORD modifiers, struct hlsl_type if (!v->arrays.count) { if (!(type = hlsl_type_clone(ctx, orig_type, 0, modifiers))) - return false; + { + free_parse_variable_def(v); + continue; + } } else { type = orig_type; }
+ ret = true; for (i = 0; i < v->arrays.count; ++i) { if (!(type = hlsl_new_array_type(ctx, type, v->arrays.sizes[i]))) - return false; + { + free_parse_variable_def(v); + ret = false; + break; + } } + if (!ret) + continue; + vkd3d_free(v->arrays.sizes);
vkd3d_free((void *)type->name); type->name = v->name; @@ -747,6 +768,7 @@ static bool add_typedef(struct hlsl_ctx *ctx, DWORD modifiers, struct hlsl_type if (!ret) hlsl_error(ctx, &v->loc, VKD3D_SHADER_ERROR_HLSL_REDEFINED, "Type '%s' is already defined.", v->name); + free_parse_initializer(&v->initializer); vkd3d_free(v); } vkd3d_free(list); @@ -1470,15 +1492,6 @@ static void struct_var_initializer(struct hlsl_ctx *ctx, struct list *list, stru vkd3d_free(initializer->args); }
-static void free_parse_variable_def(struct parse_variable_def *v) -{ - free_parse_initializer(&v->initializer); - vkd3d_free(v->arrays.sizes); - vkd3d_free(v->name); - vkd3d_free((void *)v->semantic.name); - vkd3d_free(v); -} - static struct list *declare_vars(struct hlsl_ctx *ctx, struct hlsl_type *basic_type, DWORD modifiers, struct list *var_list) { @@ -1510,6 +1523,7 @@ static struct list *declare_vars(struct hlsl_ctx *ctx, struct hlsl_type *basic_t type = basic_type; for (i = 0; i < v->arrays.count; ++i) type = hlsl_new_array_type(ctx, type, v->arrays.sizes[i]); + vkd3d_free(v->arrays.sizes);
if (type->type != HLSL_CLASS_MATRIX) check_invalid_matrix_modifiers(ctx, modifiers, v->loc); @@ -1569,6 +1583,7 @@ static struct list *declare_vars(struct hlsl_ctx *ctx, struct hlsl_type *basic_t hlsl_error(ctx, &v->loc, VKD3D_SHADER_ERROR_HLSL_MISSING_INITIALIZER, "Const variable "%s" is missing an initializer.", var->name); hlsl_free_var(var); + free_parse_initializer(&v->initializer); vkd3d_free(v); continue; } @@ -1581,6 +1596,7 @@ static struct list *declare_vars(struct hlsl_ctx *ctx, struct hlsl_type *basic_t "Variable "%s" was already declared in this scope.", var->name); hlsl_note(ctx, &old->loc, VKD3D_SHADER_LOG_ERROR, ""%s" was previously declared here.", old->name); hlsl_free_var(var); + free_parse_initializer(&v->initializer); vkd3d_free(v); continue; }
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
From: Francisco Casas fcasas@codeweavers.com
The implicit conversion in add_assignment() takes responsability now.
Signed-off-by: Francisco Casas fcasas@codeweavers.com Signed-off-by: Zebediah Figura zfigura@codeweavers.com Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- libs/vkd3d-shader/hlsl.y | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index a5a45640..7b7c26a3 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1606,19 +1606,17 @@ static struct list *declare_vars(struct hlsl_ctx *ctx, struct hlsl_type *basic_t unsigned int size = initializer_size(&v->initializer); struct hlsl_ir_load *load;
- if (type->type <= HLSL_CLASS_LAST_NUMERIC - && type->dimx * type->dimy != size && size != 1) + if (type->type <= HLSL_CLASS_LAST_NUMERIC && v->initializer.braces + && type->dimx * type->dimy != size) { - if (size < type->dimx * type->dimy) - { - hlsl_error(ctx, &v->loc, VKD3D_SHADER_ERROR_HLSL_WRONG_PARAMETER_COUNT, - "Expected %u components in numeric initializer, but got %u.", - type->dimx * type->dimy, size); - free_parse_initializer(&v->initializer); - vkd3d_free(v); - continue; - } + hlsl_error(ctx, &v->loc, VKD3D_SHADER_ERROR_HLSL_WRONG_PARAMETER_COUNT, + "Expected %u components in numeric initializer, but got %u.", + type->dimx * type->dimy, v->initializer.args_count); + free_parse_initializer(&v->initializer); + vkd3d_free(v); + continue; } + if ((type->type == HLSL_CLASS_STRUCT || type->type == HLSL_CLASS_ARRAY) && hlsl_type_component_count(type) != size) {
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
From: Francisco Casas fcasas@codeweavers.com
Signed-off-by: Francisco Casas fcasas@codeweavers.com Signed-off-by: Zebediah Figura zfigura@codeweavers.com Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- libs/vkd3d-shader/hlsl.y | 91 +++++++++++++++++++++------------------- 1 file changed, 48 insertions(+), 43 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 7b7c26a3..2fbebf01 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1603,61 +1603,66 @@ static struct list *declare_vars(struct hlsl_ctx *ctx, struct hlsl_type *basic_t
if (v->initializer.args_count) { - unsigned int size = initializer_size(&v->initializer); - struct hlsl_ir_load *load; - - if (type->type <= HLSL_CLASS_LAST_NUMERIC && v->initializer.braces - && type->dimx * type->dimy != size) + if (v->initializer.braces) { - hlsl_error(ctx, &v->loc, VKD3D_SHADER_ERROR_HLSL_WRONG_PARAMETER_COUNT, - "Expected %u components in numeric initializer, but got %u.", - type->dimx * type->dimy, v->initializer.args_count); - free_parse_initializer(&v->initializer); - vkd3d_free(v); - continue; - } + unsigned int size = initializer_size(&v->initializer);
- if ((type->type == HLSL_CLASS_STRUCT || type->type == HLSL_CLASS_ARRAY) - && hlsl_type_component_count(type) != size) - { - hlsl_error(ctx, &v->loc, VKD3D_SHADER_ERROR_HLSL_WRONG_PARAMETER_COUNT, - "Expected %u components in initializer, but got %u.", hlsl_type_component_count(type), size); - free_parse_initializer(&v->initializer); - vkd3d_free(v); - continue; - } + if (type->type <= HLSL_CLASS_LAST_NUMERIC && type->dimx * type->dimy != size) + { + hlsl_error(ctx, &v->loc, VKD3D_SHADER_ERROR_HLSL_WRONG_PARAMETER_COUNT, + "Expected %u components in numeric initializer, but got %u.", + type->dimx * type->dimy, v->initializer.args_count); + free_parse_initializer(&v->initializer); + vkd3d_free(v); + continue; + }
- if (type->type > HLSL_CLASS_LAST_NUMERIC && type->type != HLSL_CLASS_STRUCT) - { - FIXME("Initializers for non scalar/struct variables not supported yet.\n"); - free_parse_initializer(&v->initializer); - vkd3d_free(v); - continue; - } + if ((type->type == HLSL_CLASS_STRUCT || type->type == HLSL_CLASS_ARRAY) + && hlsl_type_component_count(type) != size) + { + hlsl_error(ctx, &v->loc, VKD3D_SHADER_ERROR_HLSL_WRONG_PARAMETER_COUNT, + "Expected %u components in initializer, but got %u.", hlsl_type_component_count(type), size); + free_parse_initializer(&v->initializer); + vkd3d_free(v); + continue; + }
- if (type->type == HLSL_CLASS_STRUCT) - { - struct_var_initializer(ctx, statements_list, var, &v->initializer); - vkd3d_free(v); - continue; + if (type->type > HLSL_CLASS_LAST_NUMERIC && type->type != HLSL_CLASS_STRUCT) + { + FIXME("Initializers for non scalar/struct variables not supported yet.\n"); + free_parse_initializer(&v->initializer); + vkd3d_free(v); + continue; + } + + if (type->type == HLSL_CLASS_STRUCT) + { + struct_var_initializer(ctx, statements_list, var, &v->initializer); + vkd3d_free(v); + continue; + } + else + { + hlsl_fixme(ctx, &v->loc, "Complex initializer."); + free_parse_initializer(&v->initializer); + vkd3d_free(v); + continue; + } } - if (v->initializer.args_count > 1) + else { - hlsl_fixme(ctx, &v->loc, "Complex initializer."); - free_parse_initializer(&v->initializer); - vkd3d_free(v); - continue; - } + struct hlsl_ir_load *load = hlsl_new_var_load(ctx, var, var->loc);
- load = hlsl_new_var_load(ctx, var, var->loc); - list_add_tail(v->initializer.instrs, &load->node.entry); - add_assignment(ctx, v->initializer.instrs, &load->node, ASSIGN_OP_ASSIGN, v->initializer.args[0]); - vkd3d_free(v->initializer.args); + assert(v->initializer.args_count == 1); + list_add_tail(v->initializer.instrs, &load->node.entry); + add_assignment(ctx, v->initializer.instrs, &load->node, ASSIGN_OP_ASSIGN, v->initializer.args[0]); + }
if (modifiers & HLSL_STORAGE_STATIC) list_move_tail(&ctx->static_initializers, v->initializer.instrs); else list_move_tail(statements_list, v->initializer.instrs); + vkd3d_free(v->initializer.args); vkd3d_free(v->initializer.instrs); } vkd3d_free(v);
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
This is especially a problem when e.g. it introduces a whitespace before a #pragma directive, breaking shader compilation.
Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- libs/vkd3d-shader/preproc.l | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/libs/vkd3d-shader/preproc.l b/libs/vkd3d-shader/preproc.l index 20cb0c35..7686e018 100644 --- a/libs/vkd3d-shader/preproc.l +++ b/libs/vkd3d-shader/preproc.l @@ -578,7 +578,10 @@ int yylex(YYSTYPE *lval, YYLTYPE *lloc, yyscan_t scanner) if (ctx->current_directive) return return_token(token, lval, text);
- vkd3d_string_buffer_printf(&ctx->buffer, "%s ", text); + if (isspace(text[0])) + vkd3d_string_buffer_printf(&ctx->buffer, "%s", text); + else + vkd3d_string_buffer_printf(&ctx->buffer, "%s ", text); break; }
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
---
FWIW, the native preprocessor doesn't emit spaces after newlines, but also, the native HLSL compiler is fine with spaces before "preprocessor" directives. I have patches in my tree for the latter issue as well.
On Thu, Mar 31, 2022 at 7:13 PM Zebediah Figura zfigura@codeweavers.com wrote:
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
FWIW, the native preprocessor doesn't emit spaces after newlines, but also, the native HLSL compiler is fine with spaces before "preprocessor" directives. I have patches in my tree for the latter issue as well.
Good to know, makes sense given that the preprocessor allows those. I think I mostly jumped at the opportunity to get rid of those ugly extra whitespaces :D
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Fixes regressions in Wine's d3dcompiler asm tests.
Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- libs/vkd3d-shader/preproc.l | 10 +++++----- libs/vkd3d-shader/preproc.y | 8 ++++++++ 2 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/libs/vkd3d-shader/preproc.l b/libs/vkd3d-shader/preproc.l index 7686e018..00a4458a 100644 --- a/libs/vkd3d-shader/preproc.l +++ b/libs/vkd3d-shader/preproc.l @@ -91,13 +91,13 @@ INT_SUFFIX [uUlL]{0,2}
/* We have no use for floats, but shouldn't parse them as integers. */
-<INITIAL>[0-9]*.[0-9]+([eE][+-]?[0-9]+)?[hHfF]? {return T_TEXT;} -<INITIAL>[0-9]+.([eE][+-]?[0-9]+)?[hHfF]? {return T_TEXT;} -<INITIAL>[0-9]+([eE][+-]?[0-9]+)?[hHfF] {return T_TEXT;} -<INITIAL>[0-9]+[eE][+-]?[0-9]+ {return T_TEXT;} +<INITIAL>-?[0-9]*.[0-9]+([eE][+-]?[0-9]+)?[hHfF]? {return T_TEXT;} +<INITIAL>-?[0-9]+.([eE][+-]?[0-9]+)?[hHfF]? {return T_TEXT;} +<INITIAL>-?[0-9]+([eE][+-]?[0-9]+)?[hHfF] {return T_TEXT;} +<INITIAL>-?[0-9]+[eE][+-]?[0-9]+ {return T_TEXT;} <INITIAL,LINE>0[xX][0-9a-fA-f]+{INT_SUFFIX} {return T_INTEGER;} <INITIAL,LINE>0[0-7]*{INT_SUFFIX} {return T_INTEGER;} -<INITIAL,LINE>[1-9][0-9]*{INT_SUFFIX} {return T_INTEGER;} +<INITIAL,LINE>-?[1-9][0-9]*{INT_SUFFIX} {return T_INTEGER;}
<INITIAL>## {return T_CONCAT;}
diff --git a/libs/vkd3d-shader/preproc.y b/libs/vkd3d-shader/preproc.y index 3f02ac03..5dd7929a 100644 --- a/libs/vkd3d-shader/preproc.y +++ b/libs/vkd3d-shader/preproc.y @@ -179,8 +179,14 @@ static int char_to_int(char c) static uint32_t preproc_parse_integer(const char *s) { uint32_t base = 10, ret = 0; + bool sign = false; int digit;
+ if (*s == '-') + { + sign = true; + ++s; + } if (*s == '0') { base = 8; @@ -194,6 +200,8 @@ static uint32_t preproc_parse_integer(const char *s)
while ((digit = char_to_int(*s++)) >= 0) ret = ret * base + (uint32_t)digit; + if (sign) + ret = -ret; return ret; }
On Wed, Mar 30, 2022 at 11:56 PM Matteo Bruni mbruni@codeweavers.com wrote:
Fixes regressions in Wine's d3dcompiler asm tests.
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
libs/vkd3d-shader/preproc.l | 10 +++++----- libs/vkd3d-shader/preproc.y | 8 ++++++++ 2 files changed, 13 insertions(+), 5 deletions(-)
Please ignore this patch, it should be fixed on the assembler's side. Thanks Giovanni for the hint.