summaryrefslogtreecommitdiffstats
path: root/source/slang/ir-link.cpp
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2019-02-28 07:59:17 -0800
committerGitHub <noreply@github.com>2019-02-28 07:59:17 -0800
commit852c88cc9d7e720af66275bf7fdf58341f5f6e7c (patch)
tree2ffc048a68060bde53ccf5f9fcd5363869f65acf /source/slang/ir-link.cpp
parent15bab62e69286a835b68e3c3aab6ba6c946f3715 (diff)
Eliminate the specializeProgramLayout() function (#869)
The `specializeProgramLayout()` primarily existed to support global generic parameters. The guiding idea of the design had been that plugging in concrete types for global generic parameters should only affect the layout/binding of shader parameters that depend on the global generic type parameters. All other shader parameters should keep the same layout/location across all specializations. This idea was implemented by conceptually having two phases of layout: * A generic-argument-independent phase would do layout on all the shader parameters that *don't* depend on global generic type parameters. * A second phase would then pick up where the other one left off (re-using existing parameter layouts to guarantee a match), and just layout out the shader parameters that *do* depend on global generic type parameters. Because the other parameters were already laid out, these new parameters would only ever fill in the gaps in layout (or come after all the other parameters, if explicit bindings aren't used). This implementation strategy proved to be a bit of a mess, since we had to duplicate most of the code between the two passes anyway. This commit eliminates `specializeProgramLayout()` entirely, and instead threads through global generic type arguments as part of the main layout pass. It is almost strictly a cleanup pass, now that the refactored logic for `Program` means the same layout algorithm can apply to specialized and unspecialized programs. This change has one important semantic consequence (which is technically a break in backwards compatiblity for anybody using global generic parameters). Parameters that depend on global generic type parameters now get laid out in declaration order, just like all other shader parameters. This simplifies the rules, and in my experience actually makes application code *easier* to write in a systematic way (whereas the original design was motivated by the idea that giving more things stable locations would be beneficial). A future improvement could be made so that we don't thread through the global generic substitution as part of layout. Instead, we could just attach a list of the global generic type arguments directly to the `TypeLayoutContext` and look those up on-demand when we encounter a global generic parameter type during layout. This would actually eliminate the need for global generics to appear as a `Substitution` entirely.
Diffstat (limited to 'source/slang/ir-link.cpp')
-rw-r--r--source/slang/ir-link.cpp32
1 files changed, 2 insertions, 30 deletions
diff --git a/source/slang/ir-link.cpp b/source/slang/ir-link.cpp
index fd9f1222e..60bafb9d1 100644
--- a/source/slang/ir-link.cpp
+++ b/source/slang/ir-link.cpp
@@ -1180,13 +1180,6 @@ void initializeSharedSpecContext(
sharedContext->target = target;
}
-// implementation provided in parameter-binding.cpp
-RefPtr<ProgramLayout> specializeProgramLayout(
- TargetRequest * targetReq,
- ProgramLayout* programLayout,
- SubstitutionSet typeSubst,
- DiagnosticSink* sink);
-
struct IRSpecializationState
{
ProgramLayout* programLayout;
@@ -1194,7 +1187,6 @@ struct IRSpecializationState
TargetRequest* targetReq;
IRModule* irModule = nullptr;
- RefPtr<ProgramLayout> newProgramLayout;
IRSharedSpecContext sharedContextStorage;
IRSpecContext contextStorage;
@@ -1211,7 +1203,6 @@ struct IRSpecializationState
~IRSpecializationState()
{
- newProgramLayout = nullptr;
contextStorage = IRSpecContext();
sharedContextStorage = IRSharedSpecContext();
}
@@ -1260,25 +1251,6 @@ LinkedIR linkIR(
context->shared = sharedContext;
context->builder = &sharedContext->builderStorage;
- // Now specialize the program layout using the substitution
- //
- // TODO: The specialization of the layout is conceptually an AST-level operations,
- // and shouldn't be done here in the IR at all.
- //
- RefPtr<ProgramLayout> newProgramLayout = specializeProgramLayout(
- targetReq,
- programLayout,
- SubstitutionSet(program->getGlobalGenericSubstitution()),
- compileRequest->getSink());
-
- // TODO: we need to register the (IR-level) arguments of the global generic parameters as the
- // substitutions for the generic parameters in the original IR.
-
- // applyGlobalGenericParamSubsitution(...);
-
-
- state->newProgramLayout = newProgramLayout;
-
// Next, we want to optimize lookup for layout information
// associated with global declarations, so that we can
// look things up based on the IR values (using mangled names)
@@ -1290,7 +1262,7 @@ LinkedIR linkIR(
// multiple mangled names (when the unique translation
// unit name gets involved).
//
- auto globalStructLayout = getScopeStructLayout(newProgramLayout);
+ auto globalStructLayout = getScopeStructLayout(programLayout);
for(auto entry : globalStructLayout->mapVarToLayout)
{
auto mangledName = getMangledName(entry.Key);
@@ -1311,7 +1283,7 @@ LinkedIR linkIR(
cloneGlobalValue(context, (IRWitnessTable*)sym.Value->irGlobalValue);
}
- auto entryPointLayout = findEntryPointLayout(newProgramLayout, entryPoint);
+ auto entryPointLayout = findEntryPointLayout(programLayout, entryPoint);
// Next, we make sure to clone the global value for
// the entry point function itself, and rely on