From c16fc84a0071892ea0f4e3c5c70aa101e6400aec Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Mon, 26 Jun 2017 09:07:07 -0700 Subject: Include imported code when generating reflection data - The basic idea is simple: be sure to enumerate code in `__import`ed modules when generating reflection info - Note that we don't currently allow an entry point to appear in an imported module, so we only consider globlal-scope parameters - Although there isn't currently a real implementation of namespacing, I went ahead and ensured that parameters in imported modules are treated as distinct from parameters in the user's code, even if they have the same name. --- source/slang/parameter-binding.cpp | 40 +++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) (limited to 'source/slang/parameter-binding.cpp') diff --git a/source/slang/parameter-binding.cpp b/source/slang/parameter-binding.cpp index 70cb4e7ba..939380659 100644 --- a/source/slang/parameter-binding.cpp +++ b/source/slang/parameter-binding.cpp @@ -134,9 +134,6 @@ struct SharedParameterBindingContext // All shader parameters we've discovered so far, and started to lay out... List> parameters; - // A dictionary to accellerate looking up parameters by name - Dictionary mapNameToParameterInfo; - // The program layout we are trying to construct RefPtr programLayout; @@ -158,6 +155,9 @@ struct ParameterBindingContext // The layout rules to use while computing usage... LayoutRulesFamilyImpl* layoutRules; + // A dictionary to accellerate looking up parameters by name + Dictionary mapNameToParameterInfo; + // What stage (if any) are we compiling for? Stage stage; }; @@ -448,7 +448,7 @@ static void collectGlobalScopeParameter( // of this parameter: auto parameterName = varDecl->Name.Content; ParameterInfo* parameterInfo = nullptr; - if( context->shared->mapNameToParameterInfo.TryGetValue(parameterName, parameterInfo) ) + if( context->mapNameToParameterInfo.TryGetValue(parameterName, parameterInfo) ) { // If the parameters have the same name, but don't "match" according to some reasonable rules, // then we need to bail out. @@ -463,7 +463,7 @@ static void collectGlobalScopeParameter( { parameterInfo = new ParameterInfo(); context->shared->parameters.Add(parameterInfo); - context->shared->mapNameToParameterInfo.Add(parameterName, parameterInfo); + context->mapNameToParameterInfo.Add(parameterName, parameterInfo); } else { @@ -1061,10 +1061,34 @@ inferStageForTranslationUnit( return Stage::Unknown; } +static void collectModuleParameters( + ParameterBindingContext* inContext, + ProgramSyntaxNode* module) +{ + // Each loaded module provides a separate (logical) namespace for + // parameters, so that two parameters with the same name, in + // distinct modules, should yield different bindings. + // + ParameterBindingContext contextData = *inContext; + auto context = &contextData; + + context->stage = Stage::Unknown; + + // A loaded module cannot define entry points that + // we'll expose (for now), so we just need to + // consider global-scope parameters. + collectGlobalScopeParameters(context, module); +} + static void collectParameters( ParameterBindingContext* inContext, CompileRequest* request) { + // All of the parameters in translation units directly + // referenced in the compile request are part of one + // logical namespace/"linkage" so that two parameters + // with the same name should represent the same + // parameter, and get the same binding(s) ParameterBindingContext contextData = *inContext; auto context = &contextData; @@ -1082,6 +1106,12 @@ static void collectParameters( collectEntryPointParameters(context, entryPoint.Ptr(), translationUnit->SyntaxNode.Ptr()); } } + + // Now collect parameters from loaded modules + for (auto& module : request->loadedModulesList) + { + collectModuleParameters(context, module.Ptr()); + } } void generateParameterBindings( -- cgit v1.2.3