summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2019-09-13 10:41:11 -0700
committerGitHub <noreply@github.com>2019-09-13 10:41:11 -0700
commit0b6321b3f08c48e37e6b8256d420f05d9727fb5a (patch)
tree9bb880dd91fd01839df504741923b8d0d019b0b9 /source
parent33f95e0e3d41262a6ebe023b2b2624d735539c6d (diff)
Revisions to "new" Slang API based on use in Falcor (#1052)
* Revisions to "new" Slang API based on use in Falcor As I've been integrating the new/revised Slang API (using the "COM-lite" interfaces) I've run into some cases where the API was either missing features or didn't really work as originally implemented. This change fixes the gaps/problems that came up. There are two main things here: 1. Some of the routines that returned an `IComponentType*` as a function result weren't actually doing anythign to retain the object they returned (e.g., putting it into a cache). Leaving aside the question of whether we need to add that caching layer, it made sense to instead have the return be through an output argument. Discussion after the initial iteration of the COM-lite API came around to the point that properly reference-counting objects that get returned would be useful if we ever decide we don't like having ever-expanding memory usage for caches of specialized/composed component types. 2. There was no way with the existing API to get at an `IComponentType` that represents an entry point produced during compilation, so that a user could include it in their own composition. This change alters `spCompileRequest_getProgram` to return the global program *without* the entry points, and adds a separate `spCompileRequest_getEntryPoint`. This design lets an application compose whatever combination/layout they want, rather than being stuck with a pre-designed composition baked into the compiler. * fixup: review feedback
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-check.cpp10
-rw-r--r--source/slang/slang-compiler.h31
-rw-r--r--source/slang/slang-reflection.cpp1
-rw-r--r--source/slang/slang.cpp69
4 files changed, 86 insertions, 25 deletions
diff --git a/source/slang/slang-check.cpp b/source/slang/slang-check.cpp
index 33fc10e45..cec6b02a2 100644
--- a/source/slang/slang-check.cpp
+++ b/source/slang/slang-check.cpp
@@ -10840,7 +10840,8 @@ static bool doesParameterMatch(
/// account any specialization arguments the user might have supplied.
///
RefPtr<ComponentType> createUnspecializedGlobalAndEntryPointsComponentType(
- FrontEndCompileRequest* compileRequest)
+ FrontEndCompileRequest* compileRequest,
+ List<RefPtr<ComponentType>>& outUnspecializedEntryPoints)
{
auto linkage = compileRequest->getLinkage();
auto sink = compileRequest->getSink();
@@ -10880,6 +10881,7 @@ static bool doesParameterMatch(
//
entryPointReq->getTranslationUnit()->entryPoints.add(entryPoint);
+ outUnspecializedEntryPoints.add(entryPoint);
allComponentTypes.add(entryPoint);
}
}
@@ -10958,6 +10960,7 @@ static bool doesParameterMatch(
//
translationUnit->entryPoints.add(entryPoint);
+ outUnspecializedEntryPoints.add(entryPoint);
allComponentTypes.add(entryPoint);
}
}
@@ -11570,7 +11573,8 @@ static bool doesParameterMatch(
/// compilation (e.g., from the command line).
///
RefPtr<ComponentType> createSpecializedGlobalAndEntryPointsComponentType(
- EndToEndCompileRequest* endToEndReq)
+ EndToEndCompileRequest* endToEndReq,
+ List<RefPtr<ComponentType>>& outSpecializedEntryPoints)
{
auto specializedGlobalComponentType = endToEndReq->getSpecializedGlobalComponentType();
@@ -11587,6 +11591,8 @@ static bool doesParameterMatch(
auto specializedEntryPoint = createSpecializedEntryPoint(endToEndReq, unspecializedEntryPoint, entryPointInfo);
allComponentTypes.add(specializedEntryPoint);
+
+ outSpecializedEntryPoints.add(specializedEntryPoint);
}
RefPtr<ComponentType> composed = CompositeComponentType::create(endToEndReq->getLinkage(), allComponentTypes);
diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h
index 0b97e2af7..c43af9506 100644
--- a/source/slang/slang-compiler.h
+++ b/source/slang/slang-compiler.h
@@ -287,9 +287,10 @@ namespace Slang
SlangInt targetIndex,
slang::IBlob** outCode,
slang::IBlob** outDiagnostics) SLANG_OVERRIDE;
- SLANG_NO_THROW IComponentType* SLANG_MCALL specialize(
+ SLANG_NO_THROW SlangResult SLANG_MCALL specialize(
slang::SpecializationArg const* specializationArgs,
SlangInt specializationArgCount,
+ slang::IComponentType** outSpecializedComponentType,
ISlangBlob** outDiagnostics) SLANG_OVERRIDE;
/// Get the linkage (aka "session" in the public API) for this component type.
@@ -810,12 +811,17 @@ namespace Slang
return Super::getEntryPointCode(entryPointIndex, targetIndex, outCode, outDiagnostics);
}
- SLANG_NO_THROW IComponentType* SLANG_MCALL specialize(
+ SLANG_NO_THROW SlangResult SLANG_MCALL specialize(
slang::SpecializationArg const* specializationArgs,
SlangInt specializationArgCount,
+ slang::IComponentType** outSpecializedComponentType,
ISlangBlob** outDiagnostics) SLANG_OVERRIDE
{
- return Super::specialize(specializationArgs, specializationArgCount, outDiagnostics);
+ return Super::specialize(
+ specializationArgs,
+ specializationArgCount,
+ outSpecializedComponentType,
+ outDiagnostics);
}
//
@@ -1077,10 +1083,11 @@ namespace Slang
SLANG_NO_THROW slang::IModule* SLANG_MCALL loadModule(
const char* moduleName,
slang::IBlob** outDiagnostics = nullptr) override;
- SLANG_NO_THROW slang::IComponentType* SLANG_MCALL createCompositeComponentType(
- slang::IComponentType* const* componentTypes,
- SlangInt componentTypeCount,
- ISlangBlob** outDiagnostics = nullptr) override;
+ SLANG_NO_THROW SlangResult SLANG_MCALL createCompositeComponentType(
+ slang::IComponentType* const* componentTypes,
+ SlangInt componentTypeCount,
+ slang::IComponentType** outCompositeComponentType,
+ ISlangBlob** outDiagnostics = nullptr) override;
SLANG_NO_THROW slang::TypeReflection* SLANG_MCALL specializeType(
slang::TypeReflection* type,
slang::SpecializationArg const* specializationArgs,
@@ -1408,12 +1415,16 @@ namespace Slang
/// Get a component type that represents the global scope of the compile request, plus the requested entry points.
ComponentType* getGlobalAndEntryPointsComponentType() { return m_globalAndEntryPointsComponentType; }
+ List<RefPtr<ComponentType>> const& getUnspecializedEntryPoints() { return m_unspecializedEntryPoints; }
+
private:
/// A component type that includes only the global scopes of the translation unit(s) that were compiled.
RefPtr<ComponentType> m_globalComponentType;
/// A component type that extends the global scopes with all of the entry points that were specified.
RefPtr<ComponentType> m_globalAndEntryPointsComponentType;
+
+ List<RefPtr<ComponentType>> m_unspecializedEntryPoints;
};
/// A "legacy" program composes multiple translation units from a single compile request,
@@ -1727,6 +1738,11 @@ namespace Slang
ComponentType* getSpecializedGlobalComponentType() { return m_specializedGlobalComponentType; }
ComponentType* getSpecializedGlobalAndEntryPointsComponentType() { return m_specializedGlobalAndEntryPointsComponentType; }
+ ComponentType* getSpecializedEntryPointComponentType(Index index)
+ {
+ return m_specializedEntryPoints[index];
+ }
+
private:
void init();
@@ -1736,6 +1752,7 @@ namespace Slang
RefPtr<FrontEndCompileRequest> m_frontEndReq;
RefPtr<ComponentType> m_specializedGlobalComponentType;
RefPtr<ComponentType> m_specializedGlobalAndEntryPointsComponentType;
+ List<RefPtr<ComponentType>> m_specializedEntryPoints;
RefPtr<BackEndCompileRequest> m_backEndReq;
// For output
diff --git a/source/slang/slang-reflection.cpp b/source/slang/slang-reflection.cpp
index 5e6fd10cd..a6015b31c 100644
--- a/source/slang/slang-reflection.cpp
+++ b/source/slang/slang-reflection.cpp
@@ -1522,4 +1522,3 @@ SLANG_API SlangReflectionType* spReflection_specializeType(
return convert(specializedType);
}
-
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index da04587fd..d5adae722 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -497,16 +497,22 @@ SLANG_NO_THROW slang::IModule* SLANG_MCALL Linkage::loadModule(
return asExternal(module);
}
-SLANG_NO_THROW slang::IComponentType* SLANG_MCALL Linkage::createCompositeComponentType(
- slang::IComponentType* const* componentTypes,
- SlangInt componentTypeCount,
- ISlangBlob** outDiagnostics)
+SLANG_NO_THROW SlangResult SLANG_MCALL Linkage::createCompositeComponentType(
+ slang::IComponentType* const* componentTypes,
+ SlangInt componentTypeCount,
+ slang::IComponentType** outCompositeComponentType,
+ ISlangBlob** outDiagnostics)
{
// Attempting to create a "composite" of just one component type should
// just return the component type itself, to avoid redundant work.
//
if( componentTypeCount == 1)
- return componentTypes[0];
+ {
+ auto componentType = componentTypes[0];
+ componentType->addRef();
+ *outCompositeComponentType = componentType;
+ return SLANG_OK;
+ }
DiagnosticSink sink(getSourceManager());
@@ -521,7 +527,9 @@ SLANG_NO_THROW slang::IComponentType* SLANG_MCALL Linkage::createCompositeCompon
childComponents);
sink.getBlobIfNeeded(outDiagnostics);
- return asExternal(composite.detach());
+
+ *outCompositeComponentType = asExternal(composite.detach());
+ return SLANG_OK;
}
SLANG_NO_THROW slang::TypeReflection* SLANG_MCALL Linkage::specializeType(
@@ -953,13 +961,15 @@ RefPtr<ComponentType> createUnspecializedGlobalComponentType(
FrontEndCompileRequest* compileRequest);
RefPtr<ComponentType> createUnspecializedGlobalAndEntryPointsComponentType(
- FrontEndCompileRequest* compileRequest);
+ FrontEndCompileRequest* compileRequest,
+ List<RefPtr<ComponentType>>& outUnspecializedEntryPoints);
RefPtr<ComponentType> createSpecializedGlobalComponentType(
EndToEndCompileRequest* endToEndReq);
RefPtr<ComponentType> createSpecializedGlobalAndEntryPointsComponentType(
- EndToEndCompileRequest* endToEndReq);
+ EndToEndCompileRequest* endToEndReq,
+ List<RefPtr<ComponentType>>& outSpecializedEntryPoints);
void FrontEndCompileRequest::checkAllTranslationUnits()
{
@@ -1092,7 +1102,9 @@ SlangResult FrontEndCompileRequest::executeActionsInner()
if (getSink()->GetErrorCount() != 0)
return SLANG_FAIL;
- m_globalAndEntryPointsComponentType = createUnspecializedGlobalAndEntryPointsComponentType(this);
+ m_globalAndEntryPointsComponentType = createUnspecializedGlobalAndEntryPointsComponentType(
+ this,
+ m_unspecializedEntryPoints);
if (getSink()->GetErrorCount() != 0)
return SLANG_FAIL;
@@ -1208,6 +1220,7 @@ SlangResult EndToEndCompileRequest::executeActionsInner()
//
m_specializedGlobalComponentType = getUnspecializedGlobalComponentType();
m_specializedGlobalAndEntryPointsComponentType = getUnspecializedGlobalAndEntryPointsComponentType();
+ m_specializedEntryPoints = getFrontEndReq()->getUnspecializedEntryPoints();
return SLANG_OK;
}
@@ -1221,7 +1234,9 @@ SlangResult EndToEndCompileRequest::executeActionsInner()
if (getSink()->GetErrorCount() != 0)
return SLANG_FAIL;
- m_specializedGlobalAndEntryPointsComponentType = createSpecializedGlobalAndEntryPointsComponentType(this);
+ m_specializedGlobalAndEntryPointsComponentType = createSpecializedGlobalAndEntryPointsComponentType(
+ this,
+ m_specializedEntryPoints);
if (getSink()->GetErrorCount() != 0)
return SLANG_FAIL;
@@ -1260,6 +1275,7 @@ SlangResult EndToEndCompileRequest::executeActionsInner()
m_specializedGlobalComponentType = getUnspecializedGlobalComponentType();
m_specializedGlobalAndEntryPointsComponentType = composedProgram;
+ m_specializedEntryPoints = getFrontEndReq()->getUnspecializedEntryPoints();
}
// Generate output code, in whatever format was requested
@@ -1788,6 +1804,11 @@ RefPtr<ComponentType> ComponentType::specialize(
SlangInt specializationArgCount,
DiagnosticSink* sink)
{
+ if(specializationArgCount == 0)
+ {
+ return this;
+ }
+
List<SpecializationArg> specializationArgs;
specializationArgs.addRange(
inSpecializationArgs,
@@ -1810,9 +1831,10 @@ RefPtr<ComponentType> ComponentType::specialize(
sink);
}
-SLANG_NO_THROW slang::IComponentType* SLANG_MCALL ComponentType::specialize(
+SLANG_NO_THROW SlangResult SLANG_MCALL ComponentType::specialize(
slang::SpecializationArg const* specializationArgs,
SlangInt specializationArgCount,
+ slang::IComponentType** outSpecializedComponentType,
ISlangBlob** outDiagnostics)
{
DiagnosticSink sink(getLinkage()->getSourceManager());
@@ -1825,7 +1847,7 @@ SLANG_NO_THROW slang::IComponentType* SLANG_MCALL ComponentType::specialize(
{
// TODO: diagnose
sink.getBlobIfNeeded(outDiagnostics);
- return nullptr;
+ return SLANG_FAIL;
}
List<SpecializationArg> expandedArgs;
@@ -1842,7 +1864,7 @@ SLANG_NO_THROW slang::IComponentType* SLANG_MCALL ComponentType::specialize(
default:
sink.getBlobIfNeeded(outDiagnostics);
- return nullptr;
+ return SLANG_FAIL;
}
expandedArgs.add(expandedArg);
}
@@ -1854,7 +1876,9 @@ SLANG_NO_THROW slang::IComponentType* SLANG_MCALL ComponentType::specialize(
sink.getBlobIfNeeded(outDiagnostics);
- return specializedComponentType;
+ *outSpecializedComponentType = specializedComponentType.detach();
+
+ return SLANG_OK;
}
/// Visitor used by `ComponentType::enumerateModules`
@@ -3305,12 +3329,27 @@ SLANG_API SlangResult spCompileRequest_getProgram(
{
if( !request ) return SLANG_ERROR_INVALID_PARAMETER;
auto req = Slang::asInternal(request);
- auto program = req->getSpecializedGlobalAndEntryPointsComponentType();
+ auto program = req->getSpecializedGlobalComponentType();
*outProgram = Slang::ComPtr<slang::IComponentType>(program).detach();
return SLANG_OK;
}
+SLANG_API SlangResult spCompileRequest_getEntryPoint(
+ SlangCompileRequest* request,
+ SlangInt entryPointIndex,
+ slang::IComponentType** outEntryPoint)
+{
+ if( !request ) return SLANG_ERROR_INVALID_PARAMETER;
+ auto req = Slang::asInternal(request);
+
+ auto entryPoint = req->getSpecializedEntryPointComponentType(entryPointIndex);
+
+ *outEntryPoint = Slang::ComPtr<slang::IComponentType>(entryPoint).detach();
+ return SLANG_OK;
+}
+
+
SLANG_API SlangReflection* spGetReflection(
SlangCompileRequest* request)
{