summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorTim Foley <tfoley@nvidia.com>2017-06-27 09:13:19 -0700
committerTim Foley <tfoley@nvidia.com>2017-06-27 09:13:19 -0700
commit996d4dc537272e36dde1d9c1110064d597fa212f (patch)
tree8958b8c8848d2b7760a5b71ecef69574e4d9d6ab /source
parent8824b102a5dd5ac1f08daedd897b5994b1bf8b6d (diff)
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.
Diffstat (limited to 'source')
-rw-r--r--source/slang/emit.cpp15
1 files changed, 14 insertions, 1 deletions
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<String, int> 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<ProgramSyntaxNode*> 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<StructTypeLayout>() )
{
+ 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> decl, RefPtr<VarLayo
// TODO: do we need to modify the code generation environment at
// all when doing this recursive emit?
- EmitDeclsInContainer(context, moduleDecl);
+ EmitDeclsInContainerUsingLayout(context, moduleDecl, context->globalStructLayout);
}
return;