summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-ir-link.cpp
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2019-06-19 07:23:49 -0700
committerGitHub <noreply@github.com>2019-06-19 07:23:49 -0700
commit48ae5496516878768d7de241b9b7fbba91fbaa74 (patch)
tree0579405dcca82fa4a7296efea5c5e9bc963f7495 /source/slang/slang-ir-link.cpp
parent7c9298d8b10b5f4e69e24e3eb933e93e0d92fc37 (diff)
Start exposing a new COM-lite API (#987)
* Start exposing a new COM-lite API This change is mostly about exposing a new API to the Slang compiler that allows more fine-grained control over the compilation flow. The basic concepts in the new API are: * An `IGlobalSession` is the granularity at which we load/parse the Slang stdlib, and therefore gives applications a way to amortize startup cost for the library across multiple compiles. This is a concept that might be able to go away in a future version of Slang. * An `ISession` owns all the code that gets loaded/compiled/generated. Any `import`ed modules are shared across everything in a session (we don't re-parse/-check the code when we see another `import` for the same module). Any generic- or interface-based code in the session can be specialized using types from the same session (but not necessarily across sessions). * An `IModule` is the unit of code loading and scoping. It doesn't expose any API in this change, but would be the right scope for looking up types or entry points by name. * An `IProgram` is a "linked" combination of modules and entry points from which code can be generated and reflection information queried. This change re-uses the existing reflection API types, rather than introduce a new API that duplicates that functionality. That will probably change in a future revision. There are two major pieces of functionality added here that aren't related to the new API: * We now have an API concept of "entry point groups" which are one or more entry points that are intended to be used together so that they need to have non-overlapping parameters. For now this is being used to handle "hit groups" and local root signatures for ray tracing, but I'm not sure this is a concept we will keep in the long run. * We have a very special-case (client-application-specific) flag that ascribes special meaning to the `shared` keyword, so that it can be attached to global parameters to indicate that they are actually to be part of the local root signature rather than the global one for DXR. None of the API design (including naming) here is finalized; the only reason to check in the changes at this point to avoid having a long-running branch that leads to merge pain. Clients should *not* try to depend on the new API just yet, since it is still a work in progress. * fixup: clang warning * fixup: try to detect clang C++11 support * fixup * fixup * fixup * fixup * fixup: review feedback
Diffstat (limited to 'source/slang/slang-ir-link.cpp')
-rw-r--r--source/slang/slang-ir-link.cpp40
1 files changed, 35 insertions, 5 deletions
diff --git a/source/slang/slang-ir-link.cpp b/source/slang/slang-ir-link.cpp
index 4c1f72adb..07135c148 100644
--- a/source/slang/slang-ir-link.cpp
+++ b/source/slang/slang-ir-link.cpp
@@ -13,8 +13,9 @@ namespace Slang
// TODO: maybe arrange so that codegen is driven from the layout layer
// instead of the input/request layer.
EntryPointLayout* findEntryPointLayout(
- ProgramLayout* programLayout,
- EntryPoint* EntryPoint);
+ ProgramLayout* programLayout,
+ EntryPoint* entryPoint,
+ EntryPointGroupLayout** outEntryPointGroupLayout);
struct IRSpecSymbol : RefObject
{
@@ -783,9 +784,12 @@ IRFunc* specializeIRForEntryPoint(
if( paramIndex < paramLayoutCount )
{
auto paramLayout = paramsStructLayout->fields[paramIndex];
+
+ auto offsetParamLayout = applyOffsetToVarLayout(paramLayout, entryPointLayout->parametersLayout);
+
context->builder->addLayoutDecoration(
pp,
- paramLayout);
+ offsetParamLayout);
}
else
{
@@ -1276,6 +1280,33 @@ LinkedIR linkIR(
context->globalVarLayouts.AddIfNotExists(mangledName, globalVarLayout);
}
+ EntryPointGroupLayout* entryPointGroupLayout = nullptr;
+ auto entryPointLayout = findEntryPointLayout(programLayout, entryPoint, &entryPointGroupLayout);
+
+ auto offsetEntryPointLayout = entryPointLayout->getAbsoluteLayout(entryPointGroupLayout);
+
+ // Note: when we are doing the compatibility approach for Falcor, we
+ // can have global-scope symbols that are actually part of the
+ // local root signature (entry point group), so we need to make
+ // sure to apply those layouts appropriately.
+ auto entryPointGroupStructLayout = getScopeStructLayout(entryPointGroupLayout);
+ for(auto entry : entryPointGroupStructLayout->mapVarToLayout)
+ {
+ if(!entry.Key)
+ continue;
+
+ auto mangledName = getMangledName(entry.Key);
+ auto groupVarLayout = entry.Value;
+
+ // We need to "adjust" the layout that was computed for the parameter
+ // because it will be relative to the start of the entry-point group,
+ // rather than absolute.
+ //
+ auto absoluteVarLayout = groupVarLayout->getAbsoluteLayout(entryPointGroupLayout->parametersLayout);
+
+ context->globalVarLayouts.AddIfNotExists(mangledName, absoluteVarLayout);
+ }
+
context->builder->setInsertInto(context->getModule()->getModuleInst());
// for now, clone all unreferenced witness tables
@@ -1289,13 +1320,12 @@ LinkedIR linkIR(
cloneGlobalValue(context, (IRWitnessTable*)sym.Value->irGlobalValue);
}
- auto entryPointLayout = findEntryPointLayout(programLayout, entryPoint);
// Next, we make sure to clone the global value for
// the entry point function itself, and rely on
// this step to recursively copy over anything else
// it might reference.
- auto irEntryPoint = specializeIRForEntryPoint(context, entryPoint, entryPointLayout);
+ auto irEntryPoint = specializeIRForEntryPoint(context, entryPoint, offsetEntryPointLayout);
// HACK: right now the bindings for global generic parameters are coming in
// as part of the original IR module, and we need to make sure these get