diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2017-10-16 13:12:11 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-10-16 13:12:11 -0700 |
| commit | f12c2552b3f494cbc8245edb90b32b93ca8a1539 (patch) | |
| tree | 4cd08ad6037067dc70844a4a847fb3228e0176ee /source/slang/parameter-binding.cpp | |
| parent | 3e3e2473bf85365593629bd1f6f070d11f0b8ab2 (diff) | |
Implement notion of a "container format" (#213)
The big addition here is that the Slang "bytecode" is no longer treated as just a "code generation target" (`CodeGenTarget`) akin to DX bytecode (DXBC) or SPIR-V, but instead is a `ContainerFormat` that can be used to emit all the results of a compile request (well, currently just the IR-as-BC, but the intention is there).
Getting to this goal involved some prior checkins that eliminated bogus "targets" that weren't really akin to SPIR-V or DXBC: `-target slang-ir-asm` and `-target reflection-json`. Those targets were really in place to support testing, and so they've been made more explicit testing/debug options.
This change eliminates `-target slang-ir` and instead tries to allow the user to specify `-o foo.slang-module` as an output file name, that indicates the intention to output a "container" file that will wrap up all the generated code.
I've also gone ahead and generalized the existing `-target` option so that we are actually building up a *list* of code generation targets. This is largely just a cleanup, since it forces code to be more aware of when it is doing something target-specific vs. target independent. For example, reflection layout information lives on a requested target, and not on the compile request as a whole, and similarly output code is per-target, per-entry-point.
As a cleanup, I eliminated support for per-translation-unit output. This was vestigial code from back when I used to try and do HLSL generation for a whole translation unit instead of per-entry-point (which turned out to be a lot of complexity for little gain), and it was only being used in the `hello` example and the `render-test` test fixture - in both cases fixing it up was easy enough. I've stubbed out the old `spGetTranslationUnitSource` API, but haven't removed it yet.
Diffstat (limited to 'source/slang/parameter-binding.cpp')
| -rw-r--r-- | source/slang/parameter-binding.cpp | 69 |
1 files changed, 34 insertions, 35 deletions
diff --git a/source/slang/parameter-binding.cpp b/source/slang/parameter-binding.cpp index 8cc93fdd2..4fbec5652 100644 --- a/source/slang/parameter-binding.cpp +++ b/source/slang/parameter-binding.cpp @@ -1298,30 +1298,14 @@ static RefPtr<TypeLayout> processEntryPointParameter( static void collectEntryPointParameters( ParameterBindingContext* context, - EntryPointRequest* entryPoint, - ModuleDecl* translationUnitSyntax) + EntryPointRequest* entryPoint) { - // First, look for the entry point with the specified name - - // Make sure we've got a query-able member dictionary - buildMemberDictionary(translationUnitSyntax); - - Decl* entryPointDecl; - if( !translationUnitSyntax->memberDictionary.TryGetValue(entryPoint->name, entryPointDecl) ) - { - // No such entry point! - return; - } - if( entryPointDecl->nextInContainerWithSameName ) - { - // Not the only decl of that name! - return; - } - - FuncDecl* entryPointFuncDecl = dynamic_cast<FuncDecl*>(entryPointDecl); - if( !entryPointFuncDecl ) + FuncDecl* entryPointFuncDecl = entryPoint->decl; + if (!entryPointFuncDecl) { - // Not a function! + // Something must have failed earlier, so that + // we didn't find a declaration to match this + // entry point request. return; } @@ -1504,7 +1488,7 @@ static void collectParameters( for( auto& entryPoint : translationUnit->entryPoints ) { context->stage = entryPoint->profile.GetStage(); - collectEntryPointParameters(context, entryPoint.Ptr(), translationUnit->SyntaxNode.Ptr()); + collectEntryPointParameters(context, entryPoint.Ptr()); } } @@ -1515,9 +1499,14 @@ static void collectParameters( } } -static bool isGLSLCrossCompilerNeeded(CompileRequest* request) +static bool isGLSLCrossCompilerNeeded( + TargetRequest* targetReq) { - switch (request->Target) + auto compileReq = targetReq->compileRequest; + + // We only need cross-compilation if we + // are targetting something GLSL-based. + switch (targetReq->target) { default: return false; @@ -1528,23 +1517,33 @@ static bool isGLSLCrossCompilerNeeded(CompileRequest* request) break; } - if (request->loadedModulesList.Count() != 0) + // If we `import`ed any Slang code, then the + // cross compiler is definitely needed, to + // translate that Slang over to GLSL. + if (compileReq->loadedModulesList.Count() != 0) return true; - for (auto tu : request->translationUnits) + // If there are any non-GLSL translation units, + // then we need to cross compile those... + for (auto tu : compileReq->translationUnits) { if (tu->sourceLanguage != SourceLanguage::GLSL) return true; } + // If we get to this point, then we have plain vanilla + // GLSL input, with no `import` declarations, so we + // are able to output GLSL without cross compilation. return false; } void generateParameterBindings( - CompileRequest* request) + TargetRequest* targetReq) { + CompileRequest* compileReq = targetReq->compileRequest; + // Try to find rules based on the selected code-generation target - auto rules = GetLayoutRulesFamilyImpl(request->Target); + auto rules = GetLayoutRulesFamilyImpl(targetReq->target); // If there was no target, or there are no rules for the target, // then bail out here. @@ -1556,7 +1555,7 @@ void generateParameterBindings( // Create a context to hold shared state during the process // of generating parameter bindings SharedParameterBindingContext sharedContext; - sharedContext.compileRequest = request; + sharedContext.compileRequest = compileReq; sharedContext.defaultLayoutRules = rules; sharedContext.programLayout = programLayout; @@ -1568,7 +1567,7 @@ void generateParameterBindings( context.layoutRules = sharedContext.defaultLayoutRules; // Walk through AST to discover all the parameters - collectParameters(&context, request); + collectParameters(&context, compileReq); // Now walk through the parameters to generate initial binding information for( auto& parameter : sharedContext.parameters ) @@ -1692,7 +1691,7 @@ void generateParameterBindings( // // We only want to do this if the GLSL cross-compilation support is // being invoked, so that we don't gum up other shaders. - if(isGLSLCrossCompilerNeeded(request)) + if(isGLSLCrossCompilerNeeded(targetReq)) { UInt space = 0; auto hackSamplerUsedRanges = findUsedRangeSetForSpace(&context, space); @@ -1702,8 +1701,8 @@ void generateParameterBindings( programLayout->bindingForHackSampler = (int)binding; RefPtr<Variable> var = new Variable(); - var->nameAndLoc.name = request->getNamePool()->getName("SLANG_hack_samplerForTexelFetch"); - var->type.type = getSamplerStateType(request->mSession); + var->nameAndLoc.name = compileReq->getNamePool()->getName("SLANG_hack_samplerForTexelFetch"); + var->type.type = getSamplerStateType(compileReq->mSession); auto typeLayout = new TypeLayout(); typeLayout->type = var->type.type; @@ -1724,7 +1723,7 @@ void generateParameterBindings( // We now have a bunch of layout information, which we should // record into a suitable object that represents the program programLayout->globalScopeLayout = globalScopeLayout; - request->layout = programLayout; + targetReq->layout = programLayout; } } |
