From 142be506298368dc820d0f51ab163fa071fa4cd2 Mon Sep 17 00:00:00 2001 From: Zebediah Figura Date: Thu, 18 Jun 2020 10:46:20 -0500 Subject: [PATCH] d3dcompiler: Prepend static initializers to the function body. Signed-off-by: Zebediah Figura Signed-off-by: Matteo Bruni Signed-off-by: Alexandre Julliard --- dlls/d3dcompiler_43/d3dcompiler_private.h | 2 ++ dlls/d3dcompiler_43/hlsl.y | 20 +++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/dlls/d3dcompiler_43/d3dcompiler_private.h b/dlls/d3dcompiler_43/d3dcompiler_private.h index 9feaee0d8ac..a2d9c04d3bc 100644 --- a/dlls/d3dcompiler_43/d3dcompiler_private.h +++ b/dlls/d3dcompiler_43/d3dcompiler_private.h @@ -979,6 +979,8 @@ struct hlsl_parse_ctx struct hlsl_type *sampler[HLSL_SAMPLER_DIM_MAX + 1]; struct hlsl_type *Void; } builtin_types; + + struct list static_initializers; }; extern struct hlsl_parse_ctx hlsl_ctx DECLSPEC_HIDDEN; diff --git a/dlls/d3dcompiler_43/hlsl.y b/dlls/d3dcompiler_43/hlsl.y index 393f8d52fbd..c9dbdeb8c18 100644 --- a/dlls/d3dcompiler_43/hlsl.y +++ b/dlls/d3dcompiler_43/hlsl.y @@ -888,14 +888,17 @@ static struct list *declare_vars(struct hlsl_type *basic_type, DWORD modifiers, continue; } - list_move_tail(statements_list, v->initializer.instrs); - d3dcompiler_free(v->initializer.instrs); - load = new_var_load(var, var->loc); - list_add_tail(statements_list, &load->node.entry); + list_add_tail(v->initializer.instrs, &load->node.entry); assignment = make_assignment(&load->node, ASSIGN_OP_ASSIGN, v->initializer.args[0]); d3dcompiler_free(v->initializer.args); - list_add_tail(statements_list, &assignment->entry); + list_add_tail(v->initializer.instrs, &assignment->entry); + + if (modifiers & HLSL_STORAGE_STATIC) + list_move_tail(&hlsl_ctx.static_initializers, v->initializer.instrs); + else + list_move_tail(statements_list, v->initializer.instrs); + d3dcompiler_free(v->initializer.instrs); } d3dcompiler_free(v); } @@ -1514,6 +1517,10 @@ hlsl_prog: /* empty */ | hlsl_prog declaration_statement { TRACE("Declaration statement parsed.\n"); + + if (!list_empty($2)) + FIXME("Uniform initializer.\n"); + free_instr_list($2); } | hlsl_prog preproc_directive { @@ -2961,6 +2968,7 @@ HRESULT parse_hlsl(enum shader_type type, DWORD major, DWORD minor, list_init(&hlsl_ctx.scopes); list_init(&hlsl_ctx.types); init_functions_tree(&hlsl_ctx.functions); + list_init(&hlsl_ctx.static_initializers); push_scope(&hlsl_ctx); hlsl_ctx.globals = hlsl_ctx.cur_scope; @@ -2984,6 +2992,8 @@ HRESULT parse_hlsl(enum shader_type type, DWORD major, DWORD minor, "entry point \"%s\" is missing a return value semantic", entry_func->func->name); } + list_move_head(entry_func->body, &hlsl_ctx.static_initializers); + /* Index 0 means unused; index 1 means function entry, so start at 2. */ index_instructions(entry_func->body, 2);