Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- libs/vkd3d-shader/hlsl.c | 44 +++++++++++++++++++++++++++++++++++-- libs/vkd3d-shader/hlsl.h | 4 ++-- libs/vkd3d-shader/hlsl.l | 4 ++-- libs/vkd3d-shader/hlsl.y | 47 +--------------------------------------- 4 files changed, 47 insertions(+), 52 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 0486c952..02fa4843 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -188,6 +188,22 @@ bool hlsl_get_function(struct hlsl_ctx *ctx, const char *name) return rb_get(&ctx->functions, name) != NULL; }
+struct hlsl_ir_function_decl *hlsl_get_func_decl(struct hlsl_ctx *ctx, const char *name) +{ + struct hlsl_ir_function_decl *decl; + struct hlsl_ir_function *func; + struct rb_entry *entry; + + if ((entry = rb_get(&ctx->functions, name))) + { + func = RB_ENTRY_VALUE(entry, struct hlsl_ir_function, entry); + RB_FOR_EACH_ENTRY(decl, &func->overloads, struct hlsl_ir_function_decl, entry) + return decl; + } + + return NULL; +} + unsigned int hlsl_type_component_count(struct hlsl_type *type) { struct hlsl_struct_field *field; @@ -1606,7 +1622,9 @@ int hlsl_compile_shader(const char *text, const struct vkd3d_shader_compile_info struct vkd3d_shader_code *dxbc, struct vkd3d_shader_message_context *message_context) { const struct vkd3d_shader_hlsl_source_info *hlsl_source_info; + struct hlsl_ir_function_decl *entry_func; const struct hlsl_profile_info *profile; + const char *entry_point; struct hlsl_ctx ctx; int ret;
@@ -1615,6 +1633,7 @@ int hlsl_compile_shader(const char *text, const struct vkd3d_shader_compile_info ERR("No HLSL source info given.\n"); return VKD3D_ERROR_INVALID_ARGUMENT; } + entry_point = hlsl_source_info->entry_point ? hlsl_source_info->entry_point : "main";
if (!(profile = get_target_info(hlsl_source_info->profile))) { @@ -1627,9 +1646,30 @@ int hlsl_compile_shader(const char *text, const struct vkd3d_shader_compile_info if (!hlsl_ctx_init(&ctx, message_context)) return VKD3D_ERROR_OUT_OF_MEMORY;
- ret = hlsl_lexer_compile(&ctx, text, hlsl_source_info->entry_point ? hlsl_source_info->entry_point : "main"); + hlsl_lexer_compile(&ctx, text);
- hlsl_ctx_cleanup(&ctx); + if (ctx.failed) + { + hlsl_ctx_cleanup(&ctx); + return VKD3D_ERROR_INVALID_SHADER; + } + + if (!(entry_func = hlsl_get_func_decl(&ctx, entry_point))) + { + const struct vkd3d_shader_location loc = {.source_name = compile_info->source_name};
+ hlsl_error(&ctx, loc, VKD3D_SHADER_ERROR_HLSL_NOT_DEFINED, + "Entry point "%s" is not defined.", entry_point); + return VKD3D_ERROR_INVALID_SHADER; + } + + if (!hlsl_type_is_void(entry_func->return_type) + && entry_func->return_type->type != HLSL_CLASS_STRUCT && !entry_func->semantic) + hlsl_error(&ctx, entry_func->loc, VKD3D_SHADER_ERROR_HLSL_MISSING_SEMANTIC, + "Entry point "%s" is missing a return value semantic.", entry_point); + + ret = hlsl_emit_dxbc(&ctx, entry_func); + + hlsl_ctx_cleanup(&ctx); return ret; } diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 73ba2bec..4af021ec 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -518,6 +518,7 @@ void hlsl_free_type(struct hlsl_type *type) DECLSPEC_HIDDEN; void hlsl_free_var(struct hlsl_ir_var *decl) DECLSPEC_HIDDEN;
bool hlsl_get_function(struct hlsl_ctx *ctx, const char *name) DECLSPEC_HIDDEN; +struct hlsl_ir_function_decl *hlsl_get_func_decl(struct hlsl_ctx *ctx, const char *name) DECLSPEC_HIDDEN; struct hlsl_type *hlsl_get_type(struct hlsl_scope *scope, const char *name, bool recursive) DECLSPEC_HIDDEN; struct hlsl_ir_var *hlsl_get_var(struct hlsl_scope *scope, const char *name) DECLSPEC_HIDDEN;
@@ -571,7 +572,6 @@ unsigned int hlsl_type_component_count(struct hlsl_type *type) DECLSPEC_HIDDEN; bool hlsl_type_is_row_major(const struct hlsl_type *type) DECLSPEC_HIDDEN; bool hlsl_type_is_void(const struct hlsl_type *type) DECLSPEC_HIDDEN;
-int hlsl_lexer_compile(struct hlsl_ctx *ctx, const char *text, const char *entrypoint) DECLSPEC_HIDDEN; -int hlsl_parser_compile(struct hlsl_ctx *ctx, const char *entrypoint) DECLSPEC_HIDDEN; +int hlsl_lexer_compile(struct hlsl_ctx *ctx, const char *text) DECLSPEC_HIDDEN;
#endif diff --git a/libs/vkd3d-shader/hlsl.l b/libs/vkd3d-shader/hlsl.l index 4cc0a3ea..da54d57b 100644 --- a/libs/vkd3d-shader/hlsl.l +++ b/libs/vkd3d-shader/hlsl.l @@ -282,7 +282,7 @@ static void update_location(struct hlsl_ctx *ctx, YYLTYPE *lloc) ctx->location.column += yyget_leng(ctx->scanner); }
-int hlsl_lexer_compile(struct hlsl_ctx *ctx, const char *text, const char *entrypoint) +int hlsl_lexer_compile(struct hlsl_ctx *ctx, const char *text) { YY_BUFFER_STATE buffer; int ret; @@ -291,7 +291,7 @@ int hlsl_lexer_compile(struct hlsl_ctx *ctx, const char *text, const char *entry buffer = yy_scan_string(text, ctx->scanner); yy_switch_to_buffer(buffer, ctx->scanner);
- ret = hlsl_parser_compile(ctx, entrypoint); + ret = hlsl_yyparse(ctx->scanner, ctx);
yy_delete_buffer(buffer, ctx->scanner); yylex_destroy(ctx->scanner); diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index ae151181..66747740 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -286,22 +286,6 @@ static struct hlsl_ir_node *add_implicit_conversion(struct hlsl_ctx *ctx, struct return &cast->node; }
-static struct hlsl_ir_function_decl *get_func_entry(struct hlsl_ctx *ctx, const char *name) -{ - struct hlsl_ir_function_decl *decl; - struct hlsl_ir_function *func; - struct rb_entry *entry; - - if ((entry = rb_get(&ctx->functions, name))) - { - func = RB_ENTRY_VALUE(entry, struct hlsl_ir_function, entry); - RB_FOR_EACH_ENTRY(decl, &func->overloads, struct hlsl_ir_function_decl, entry) - return decl; - } - - return NULL; -} - static bool declare_variable(struct hlsl_ctx *ctx, struct hlsl_ir_var *decl, bool local) { struct hlsl_ir_function_decl *func; @@ -334,7 +318,7 @@ static bool declare_variable(struct hlsl_ctx *ctx, struct hlsl_ir_var *decl, boo } else { - if ((func = get_func_entry(ctx, decl->name))) + if ((func = hlsl_get_func_decl(ctx, decl->name))) { hlsl_error(ctx, decl->loc, VKD3D_SHADER_ERROR_HLSL_REDEFINED, "Variable '%s' is already defined as a function.", decl->name); @@ -3012,32 +2996,3 @@ expr: list_move_tail($$, $3); vkd3d_free($3); } - -%% - -int hlsl_parser_compile(struct hlsl_ctx *ctx, const char *entrypoint) -{ - struct hlsl_ir_function_decl *entry_func; - - yyparse(ctx->scanner, ctx); - - if (ctx->failed) - return VKD3D_ERROR_INVALID_SHADER; - - if (!(entry_func = get_func_entry(ctx, entrypoint))) - { - const struct vkd3d_shader_location loc = {.source_name = ctx->location.source_name}; - - hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_NOT_DEFINED, "Entry point "%s" is not defined.", entrypoint); - return VKD3D_ERROR_INVALID_SHADER; - } - - if (!hlsl_type_is_void(entry_func->return_type) - && entry_func->return_type->type != HLSL_CLASS_STRUCT && !entry_func->semantic) - { - hlsl_error(ctx, entry_func->loc, VKD3D_SHADER_ERROR_HLSL_MISSING_SEMANTIC, - "Entry point "%s" is missing a return value semantic.", entry_func->func->name); - } - - return hlsl_emit_dxbc(ctx, entry_func); -}
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- libs/vkd3d-shader/hlsl.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 02fa4843..19bfc93a 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -1646,7 +1646,11 @@ int hlsl_compile_shader(const char *text, const struct vkd3d_shader_compile_info if (!hlsl_ctx_init(&ctx, message_context)) return VKD3D_ERROR_OUT_OF_MEMORY;
- hlsl_lexer_compile(&ctx, text); + if (hlsl_lexer_compile(&ctx, text) == 2) + { + hlsl_ctx_cleanup(&ctx); + return VKD3D_ERROR_OUT_OF_MEMORY; + }
if (ctx.failed) {
On Fri, Mar 5, 2021 at 12:33 AM Zebediah Figura zfigura@codeweavers.com wrote:
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
libs/vkd3d-shader/hlsl.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 02fa4843..19bfc93a 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -1646,7 +1646,11 @@ int hlsl_compile_shader(const char *text, const struct vkd3d_shader_compile_info if (!hlsl_ctx_init(&ctx, message_context)) return VKD3D_ERROR_OUT_OF_MEMORY;
- hlsl_lexer_compile(&ctx, text);
if (hlsl_lexer_compile(&ctx, text) == 2)
{
hlsl_ctx_cleanup(&ctx);
return VKD3D_ERROR_OUT_OF_MEMORY;
}
if (ctx.failed) {
Is this intended to catch memory allocation failures from the bison-generated parser proper? It looks like for me that returns YYENOMEM which is defined as -2.
On 3/5/21 7:20 AM, Matteo Bruni wrote:
On Fri, Mar 5, 2021 at 12:33 AM Zebediah Figura zfigura@codeweavers.com wrote:
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
libs/vkd3d-shader/hlsl.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 02fa4843..19bfc93a 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -1646,7 +1646,11 @@ int hlsl_compile_shader(const char *text, const struct vkd3d_shader_compile_info if (!hlsl_ctx_init(&ctx, message_context)) return VKD3D_ERROR_OUT_OF_MEMORY;
- hlsl_lexer_compile(&ctx, text);
if (hlsl_lexer_compile(&ctx, text) == 2)
{
hlsl_ctx_cleanup(&ctx);
return VKD3D_ERROR_OUT_OF_MEMORY;
}
if (ctx.failed) {
Is this intended to catch memory allocation failures from the bison-generated parser proper? It looks like for me that returns YYENOMEM which is defined as -2.
YYENOMEM is intended to be returned by user callbacks [1]. yyparse() itself returns 2, not -2, for which there is not yet a symbolic constant [2].
[1] https://www.gnu.org/software/bison/manual/html_node/Syntax-Error-Reporting-F...
[2] https://www.gnu.org/software/bison/manual/html_node/Parser-Function.html
On Fri, Mar 5, 2021 at 5:30 PM Zebediah Figura (she/her) zfigura@codeweavers.com wrote:
On 3/5/21 7:20 AM, Matteo Bruni wrote:
On Fri, Mar 5, 2021 at 12:33 AM Zebediah Figura zfigura@codeweavers.com wrote:
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
libs/vkd3d-shader/hlsl.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 02fa4843..19bfc93a 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -1646,7 +1646,11 @@ int hlsl_compile_shader(const char *text, const struct vkd3d_shader_compile_info if (!hlsl_ctx_init(&ctx, message_context)) return VKD3D_ERROR_OUT_OF_MEMORY;
- hlsl_lexer_compile(&ctx, text);
if (hlsl_lexer_compile(&ctx, text) == 2)
{
hlsl_ctx_cleanup(&ctx);
return VKD3D_ERROR_OUT_OF_MEMORY;
}
if (ctx.failed) {
Is this intended to catch memory allocation failures from the bison-generated parser proper? It looks like for me that returns YYENOMEM which is defined as -2.
YYENOMEM is intended to be returned by user callbacks [1]. yyparse() itself returns 2, not -2, for which there is not yet a symbolic constant [2].
[1] https://www.gnu.org/software/bison/manual/html_node/Syntax-Error-Reporting-F...
[2] https://www.gnu.org/software/bison/manual/html_node/Parser-Function.html
Indeed, the generated code is pretty clear if one looks in the correct place...
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- Makefile.am | 2 ++ tests/hlsl-nested-arrays.shader_test | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 tests/hlsl-nested-arrays.shader_test
diff --git a/Makefile.am b/Makefile.am index 3b09dc7f..a4121944 100644 --- a/Makefile.am +++ b/Makefile.am @@ -57,6 +57,7 @@ vkd3d_shader_tests = \ tests/hlsl-invalid.shader_test \ tests/hlsl-majority-pragma.shader_test \ tests/hlsl-majority-typedef.shader_test \ + tests/hlsl-nested-arrays.shader_test \ tests/hlsl-return-implicit-conversion.shader_test \ tests/hlsl-return-void.shader_test \ tests/hlsl-static-initializer.shader_test \ @@ -249,6 +250,7 @@ XFAIL_TESTS = \ tests/hlsl-comma.shader_test \ tests/hlsl-majority-pragma.shader_test \ tests/hlsl-majority-typedef.shader_test \ + tests/hlsl-nested-arrays.shader_test \ tests/hlsl-return-implicit-conversion.shader_test \ tests/hlsl-return-void.shader_test \ tests/hlsl-static-initializer.shader_test \ diff --git a/tests/hlsl-nested-arrays.shader_test b/tests/hlsl-nested-arrays.shader_test new file mode 100644 index 00000000..66ae93e1 --- /dev/null +++ b/tests/hlsl-nested-arrays.shader_test @@ -0,0 +1,25 @@ +[pixel shader fail] +uniform float4 color[2][3]; + +float4 main() : sv_target +{ + return color[2][1]; +} + +[pixel shader] +uniform float color[2][3]; + +float4 main() : sv_target +{ + return float4(color[1][0], color[0][0], color[1][2], color[0][2]); +} + +[test] +uniform 0 float4 0.1 0.0 0.0 0.0 +uniform 4 float4 0.2 0.0 0.0 0.0 +uniform 8 float4 0.3 0.0 0.0 0.0 +uniform 12 float4 0.4 0.0 0.0 0.0 +uniform 16 float4 0.5 0.0 0.0 0.0 +uniform 20 float4 0.6 0.0 0.0 0.0 +draw quad +probe all rgba (0.4, 0.1, 0.6, 0.3)
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- libs/vkd3d-shader/hlsl.y | 109 +++++++++++++++++++++++++++------------ 1 file changed, 76 insertions(+), 33 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 66747740..ce4bd626 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -50,13 +50,19 @@ struct parse_initializer struct list *instrs; };
+struct parse_array_sizes +{ + uint32_t *sizes; /* innermost first */ + unsigned int count; +}; + struct parse_variable_def { struct list entry; struct vkd3d_shader_location loc;
char *name; - uint32_t array_size; + struct parse_array_sizes arrays; const char *semantic; struct hlsl_reg_reservation *reg_reservation; struct parse_initializer initializer; @@ -732,15 +738,17 @@ static struct list *gen_struct_fields(struct hlsl_ctx *ctx, struct hlsl_type *ty return NULL; LIST_FOR_EACH_ENTRY_SAFE(v, v_next, fields, struct parse_variable_def, entry) { + unsigned int i; + if (!(field = vkd3d_calloc(1, sizeof(*field)))) { vkd3d_free(v); return list; } - if (v->array_size) - field->type = hlsl_new_array_type(ctx, type, v->array_size); - else - field->type = type; + + field->type = type; + for (i = 0; i < v->arrays.count; ++i) + field->type = hlsl_new_array_type(ctx, field->type, v->arrays.sizes[i]); field->loc = v->loc; field->name = v->name; field->modifiers = modifiers; @@ -761,16 +769,27 @@ static bool add_typedef(struct hlsl_ctx *ctx, DWORD modifiers, struct hlsl_type { struct parse_variable_def *v, *v_next; struct hlsl_type *type; + unsigned int i; bool ret;
LIST_FOR_EACH_ENTRY_SAFE(v, v_next, list, struct parse_variable_def, entry) { - if (v->array_size) - type = hlsl_new_array_type(ctx, orig_type, v->array_size); + if (!v->arrays.count) + { + if (!(type = hlsl_type_clone(ctx, orig_type, 0))) + return false; + } else - type = hlsl_type_clone(ctx, orig_type, 0); - if (!type) - return false; + { + type = orig_type; + } + + for (i = 0; i < v->arrays.count; ++i) + { + if (!(type = hlsl_new_array_type(ctx, type, v->arrays.sizes[i]))) + return false; + } + vkd3d_free((void *)type->name); type->name = v->name; type->modifiers |= modifiers; @@ -1369,6 +1388,7 @@ static void struct_var_initializer(struct hlsl_ctx *ctx, struct list *list, stru 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); vkd3d_free(v->reg_reservation); @@ -1400,10 +1420,11 @@ static struct list *declare_vars(struct hlsl_ctx *ctx, struct hlsl_type *basic_t
LIST_FOR_EACH_ENTRY_SAFE(v, v_next, var_list, struct parse_variable_def, entry) { - if (v->array_size) - type = hlsl_new_array_type(ctx, basic_type, v->array_size); - else - type = basic_type; + unsigned int i; + + type = basic_type; + for (i = 0; i < v->arrays.count; ++i) + type = hlsl_new_array_type(ctx, type, v->arrays.sizes[i]);
if (!(var = hlsl_new_var(v->name, type, v->loc, v->semantic, modifiers, v->reg_reservation))) { @@ -1475,7 +1496,7 @@ static struct list *declare_vars(struct hlsl_ctx *ctx, struct hlsl_type *basic_t vkd3d_free(v); continue; } - if (v->array_size > 0) + if (v->arrays.count) { FIXME("Initializing arrays is not supported yet.\n"); free_parse_initializer(&v->initializer); @@ -1531,6 +1552,7 @@ static struct list *declare_vars(struct hlsl_ctx *ctx, struct hlsl_type *basic_t struct parse_function function; struct parse_parameter parameter; struct parse_initializer initializer; + struct parse_array_sizes arrays; struct parse_variable_def *variable_def; struct parse_if_body if_body; enum parse_unary_op unary_op; @@ -1681,6 +1703,8 @@ static struct list *declare_vars(struct hlsl_ctx *ctx, struct hlsl_type *basic_t %token <name> STRING %token <name> TYPE_IDENTIFIER
+%type <arrays> arrays + %type <assign_op> assign_op
%type <boolval> boolean @@ -1695,8 +1719,6 @@ static struct list *declare_vars(struct hlsl_ctx *ctx, struct hlsl_type *basic_t
%type <if_body> if_body
-%type <intval> array - %type <modifiers> input_mod %type <modifiers> input_mods %type <modifiers> var_modifiers @@ -2217,12 +2239,12 @@ type_specs: }
type_spec: - any_identifier array + any_identifier arrays { $$ = vkd3d_calloc(1, sizeof(*$$)); $$->loc = @1; $$->name = $1; - $$->array_size = $2; + $$->arrays = $2; }
declaration: @@ -2257,41 +2279,46 @@ variables_def: }
variable_def: - any_identifier array colon_attribute + any_identifier arrays colon_attribute { $$ = vkd3d_calloc(1, sizeof(*$$)); $$->loc = @1; $$->name = $1; - $$->array_size = $2; + $$->arrays = $2; $$->semantic = $3.semantic; $$->reg_reservation = $3.reg_reservation; } - | any_identifier array colon_attribute '=' complex_initializer + | any_identifier arrays colon_attribute '=' complex_initializer { $$ = vkd3d_calloc(1, sizeof(*$$)); $$->loc = @1; $$->name = $1; - $$->array_size = $2; + $$->arrays = $2; $$->semantic = $3.semantic; $$->reg_reservation = $3.reg_reservation; $$->initializer = $5; }
-array: +arrays: %empty { - $$ = 0; + $$.sizes = NULL; + $$.count = 0; } - | '[' expr ']' + | '[' expr ']' arrays { unsigned int size = evaluate_array_dimension(node_from_list($2)); + uint32_t *new_array;
hlsl_free_instr_list($2);
+ $$ = $4; + if (!size) { hlsl_error(ctx, @2, VKD3D_SHADER_ERROR_HLSL_INVALID_SIZE, "Array size is not a positive integer constant."); + vkd3d_free($$.sizes); YYABORT; }
@@ -2299,9 +2326,17 @@ array: { hlsl_error(ctx, @2, VKD3D_SHADER_ERROR_HLSL_INVALID_SIZE, "Array size %u is not between 1 and 65536.", size); + vkd3d_free($$.sizes); YYABORT; } - $$ = size; + + if (!(new_array = vkd3d_realloc($$.sizes, ($$.count + 1) * sizeof(*new_array)))) + { + vkd3d_free($$.sizes); + YYABORT; + } + $$.sizes = new_array; + $$.sizes[$$.count++] = size; }
var_modifiers: @@ -2632,6 +2667,7 @@ postfix_expr: | postfix_expr '[' expr ']' { struct hlsl_ir_node *array = node_from_list($1), *index = node_from_list($3); + struct hlsl_ir_expr *cast;
list_move_tail($1, $3); vkd3d_free($3); @@ -2643,7 +2679,14 @@ postfix_expr: YYABORT; }
- if (!add_array_load(ctx, $1, array, index, @2)) + if (!(cast = hlsl_new_cast(index, ctx->builtin_types.scalar[HLSL_TYPE_UINT], &index->loc))) + { + hlsl_free_instr_list($1); + YYABORT; + } + list_add_tail($1, &cast->node.entry); + + if (!add_array_load(ctx, $1, array, &cast->node, @2)) { hlsl_free_instr_list($1); YYABORT; @@ -2762,10 +2805,11 @@ unary_expr: }
/* var_modifiers is necessary to avoid shift/reduce conflicts. */ - | '(' var_modifiers type array ')' unary_expr + | '(' var_modifiers type arrays ')' unary_expr { struct hlsl_type *src_type = node_from_list($6)->data_type; struct hlsl_type *dst_type; + unsigned int i;
if ($2) { @@ -2774,10 +2818,9 @@ unary_expr: YYABORT; }
- if ($4) - dst_type = hlsl_new_array_type(ctx, $3, $4); - else - dst_type = $3; + dst_type = $3; + for (i = 0; i < $4.count; ++i) + dst_type = hlsl_new_array_type(ctx, dst_type, $4.sizes[i]);
if (!compatible_data_types(src_type, dst_type)) {
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- libs/vkd3d-shader/hlsl.c | 4 ++-- libs/vkd3d-shader/hlsl.h | 2 +- libs/vkd3d-shader/hlsl.l | 4 ++-- libs/vkd3d-shader/vkd3d_shader_main.c | 2 +- libs/vkd3d-shader/vkd3d_shader_private.h | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 19bfc93a..e78f05c3 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -1618,7 +1618,7 @@ static void hlsl_ctx_cleanup(struct hlsl_ctx *ctx) hlsl_free_type(type); }
-int hlsl_compile_shader(const char *text, const struct vkd3d_shader_compile_info *compile_info, +int hlsl_compile_shader(const struct vkd3d_shader_code *hlsl, const struct vkd3d_shader_compile_info *compile_info, struct vkd3d_shader_code *dxbc, struct vkd3d_shader_message_context *message_context) { const struct vkd3d_shader_hlsl_source_info *hlsl_source_info; @@ -1646,7 +1646,7 @@ int hlsl_compile_shader(const char *text, const struct vkd3d_shader_compile_info if (!hlsl_ctx_init(&ctx, message_context)) return VKD3D_ERROR_OUT_OF_MEMORY;
- if (hlsl_lexer_compile(&ctx, text) == 2) + if (hlsl_lexer_compile(&ctx, hlsl) == 2) { hlsl_ctx_cleanup(&ctx); return VKD3D_ERROR_OUT_OF_MEMORY; diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 4af021ec..76734401 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -572,6 +572,6 @@ unsigned int hlsl_type_component_count(struct hlsl_type *type) DECLSPEC_HIDDEN; bool hlsl_type_is_row_major(const struct hlsl_type *type) DECLSPEC_HIDDEN; bool hlsl_type_is_void(const struct hlsl_type *type) DECLSPEC_HIDDEN;
-int hlsl_lexer_compile(struct hlsl_ctx *ctx, const char *text) DECLSPEC_HIDDEN; +int hlsl_lexer_compile(struct hlsl_ctx *ctx, const struct vkd3d_shader_code *hlsl) DECLSPEC_HIDDEN;
#endif diff --git a/libs/vkd3d-shader/hlsl.l b/libs/vkd3d-shader/hlsl.l index da54d57b..cee98ea5 100644 --- a/libs/vkd3d-shader/hlsl.l +++ b/libs/vkd3d-shader/hlsl.l @@ -282,13 +282,13 @@ static void update_location(struct hlsl_ctx *ctx, YYLTYPE *lloc) ctx->location.column += yyget_leng(ctx->scanner); }
-int hlsl_lexer_compile(struct hlsl_ctx *ctx, const char *text) +int hlsl_lexer_compile(struct hlsl_ctx *ctx, const struct vkd3d_shader_code *hlsl) { YY_BUFFER_STATE buffer; int ret;
yylex_init_extra(ctx, &ctx->scanner); - buffer = yy_scan_string(text, ctx->scanner); + buffer = yy_scan_bytes(hlsl->code, hlsl->size, ctx->scanner); yy_switch_to_buffer(buffer, ctx->scanner);
ret = hlsl_yyparse(ctx->scanner, ctx); diff --git a/libs/vkd3d-shader/vkd3d_shader_main.c b/libs/vkd3d-shader/vkd3d_shader_main.c index 51136243..2308b894 100644 --- a/libs/vkd3d-shader/vkd3d_shader_main.c +++ b/libs/vkd3d-shader/vkd3d_shader_main.c @@ -1047,7 +1047,7 @@ static int compile_hlsl(const struct vkd3d_shader_compile_info *compile_info, if ((ret = preproc_lexer_parse(compile_info, &preprocessed, message_context))) return ret;
- ret = hlsl_compile_shader(preprocessed.code, compile_info, out, message_context); + ret = hlsl_compile_shader(&preprocessed, compile_info, out, message_context);
vkd3d_shader_free_shader_code(&preprocessed); return ret; diff --git a/libs/vkd3d-shader/vkd3d_shader_private.h b/libs/vkd3d-shader/vkd3d_shader_private.h index cf66c67a..6d756e40 100644 --- a/libs/vkd3d-shader/vkd3d_shader_private.h +++ b/libs/vkd3d-shader/vkd3d_shader_private.h @@ -949,7 +949,7 @@ void vkd3d_compute_dxbc_checksum(const void *dxbc, size_t size, uint32_t checksu int preproc_lexer_parse(const struct vkd3d_shader_compile_info *compile_info, struct vkd3d_shader_code *out, struct vkd3d_shader_message_context *message_context) DECLSPEC_HIDDEN;
-int hlsl_compile_shader(const char *text, const struct vkd3d_shader_compile_info *compile_info, +int hlsl_compile_shader(const struct vkd3d_shader_code *hlsl, const struct vkd3d_shader_compile_info *compile_info, struct vkd3d_shader_code *dxbc, struct vkd3d_shader_message_context *message_context) DECLSPEC_HIDDEN;
static inline enum vkd3d_shader_component_type vkd3d_component_type_from_data_type(
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com