From 996d4dc537272e36dde1d9c1110064d597fa212f Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Tue, 27 Jun 2017 09:13:19 -0700 Subject: Emit global-scope parameters from imported files. This fixes up a bug in the earlier change that provided reflection for imported parameters; I'd failed to confirm that the code generation logic can handle imported parameters correctly. The main fix was to have an `import` declaration automatically use the global-scope layout already determined, sine imported parameters will in general appear there. --- source/slang/emit.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'source/slang/emit.cpp') diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp index 699294d84..77b0c2fe9 100644 --- a/source/slang/emit.cpp +++ b/source/slang/emit.cpp @@ -35,7 +35,16 @@ struct EmitContext Dictionary mapGLSLSourcePathToID; int glslSourceIDCount = 0; + // We only want to emit each `import`ed module one time, so + // we maintain a set of already-emitted modules. HashSet modulesAlreadyEmitted; + + // We track the original global-scope layout so that we can + // find layout information for `import`ed parameters. + // + // TODO: This will probably change if we represent imports + // explicitly in the layout data. + StructTypeLayout* globalStructLayout; }; // @@ -2628,6 +2637,8 @@ static void EmitProgram( auto globalScopeLayout = programLayout->globalScopeLayout; if( auto globalStructLayout = globalScopeLayout.As() ) { + context->globalStructLayout = globalStructLayout.Ptr(); + // The `struct` case is easy enough to handle: we just // emit all the declarations directly, using their layout // information as a guideline. @@ -2657,6 +2668,8 @@ static void EmitProgram( // We expect all constant buffers to contain `struct` types for now assert(elementTypeStructLayout); + context->globalStructLayout = elementTypeStructLayout.Ptr(); + EmitDeclsInContainerUsingLayout( context, program, @@ -2732,7 +2745,7 @@ static void EmitDeclImpl(EmitContext* context, RefPtr decl, RefPtrglobalStructLayout); } return; -- cgit v1.2.3