summaryrefslogtreecommitdiff
path: root/source/slang/slang-compiler.h
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2022-01-31 16:26:03 -0800
committerGitHub <noreply@github.com>2022-01-31 16:26:03 -0800
commite59516fa8c3a16eb7b99a928c5b85b97bf44fd72 (patch)
tree869c2b8df0cc0d368af928324d53079a9f7999e0 /source/slang/slang-compiler.h
parent2bb43bbe4709533e0c6e53df1c62d368132dcd73 (diff)
Revise entrypoint renaming interface. (#2113)
Changed the interface from `IEntryPoint::getRenamedEntryPoint` to `IComponentType::renameEntryPoint`. The underlying implementation creates a `RenamedEntryPointComponentType` wrapper object around the base entry-point. This new implementation allows the user to specify entry point renaming on an IComponentType that isn't just a `EntryPoint`, but also on `SpecializedComponentType` or `CompositeComponentType` as long as the component defines a single entry point. Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-compiler.h')
-rwxr-xr-xsource/slang/slang-compiler.h160
1 files changed, 148 insertions, 12 deletions
diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h
index 930210a96..9ae414424 100755
--- a/source/slang/slang-compiler.h
+++ b/source/slang/slang-compiler.h
@@ -293,6 +293,9 @@ namespace Slang
SlangInt specializationArgCount,
slang::IComponentType** outSpecializedComponentType,
ISlangBlob** outDiagnostics) SLANG_OVERRIDE;
+ SLANG_NO_THROW SlangResult SLANG_MCALL renameEntryPoint(
+ const char* newName,
+ slang::IComponentType** outEntryPoint) SLANG_OVERRIDE;
SLANG_NO_THROW SlangResult SLANG_MCALL link(
slang::IComponentType** outLinkedComponentType,
ISlangBlob** outDiagnostics) SLANG_OVERRIDE;
@@ -654,6 +657,130 @@ namespace Slang
List<RefPtr<ComponentType>> m_requirements;
};
+ class RenamedEntryPointComponentType : public ComponentType
+ {
+ public:
+ using Super = ComponentType;
+
+ RenamedEntryPointComponentType(ComponentType* base, String newName);
+
+ ComponentType* getBase() { return m_base.Ptr(); }
+
+ // Forward `IComponentType` methods
+
+ SLANG_NO_THROW slang::ISession* SLANG_MCALL getSession() SLANG_OVERRIDE
+ {
+ return Super::getSession();
+ }
+
+ SLANG_NO_THROW slang::ProgramLayout* SLANG_MCALL
+ getLayout(SlangInt targetIndex, slang::IBlob** outDiagnostics) SLANG_OVERRIDE
+ {
+ return Super::getLayout(targetIndex, outDiagnostics);
+ }
+
+ SLANG_NO_THROW SlangResult SLANG_MCALL getEntryPointCode(
+ SlangInt entryPointIndex,
+ SlangInt targetIndex,
+ slang::IBlob** outCode,
+ slang::IBlob** outDiagnostics) SLANG_OVERRIDE
+ {
+ return Super::getEntryPointCode(entryPointIndex, targetIndex, outCode, outDiagnostics);
+ }
+
+ 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,
+ outSpecializedComponentType,
+ outDiagnostics);
+ }
+
+ SLANG_NO_THROW SlangResult SLANG_MCALL renameEntryPoint(
+ const char* newName, slang::IComponentType** outEntryPoint) SLANG_OVERRIDE
+ {
+ return Super::renameEntryPoint(newName, outEntryPoint);
+ }
+
+ SLANG_NO_THROW SlangResult SLANG_MCALL link(
+ slang::IComponentType** outLinkedComponentType,
+ ISlangBlob** outDiagnostics) SLANG_OVERRIDE
+ {
+ return Super::link(outLinkedComponentType, outDiagnostics);
+ }
+
+ SLANG_NO_THROW SlangResult SLANG_MCALL getEntryPointHostCallable(
+ int entryPointIndex,
+ int targetIndex,
+ ISlangSharedLibrary** outSharedLibrary,
+ slang::IBlob** outDiagnostics) SLANG_OVERRIDE
+ {
+ return Super::getEntryPointHostCallable(
+ entryPointIndex, targetIndex, outSharedLibrary, outDiagnostics);
+ }
+
+ List<Module*> const& getModuleDependencies() SLANG_OVERRIDE
+ {
+ return m_base->getModuleDependencies();
+ }
+ List<String> const& getFilePathDependencies() SLANG_OVERRIDE
+ {
+ return m_base->getFilePathDependencies();
+ }
+
+ SLANG_NO_THROW Index SLANG_MCALL getSpecializationParamCount() SLANG_OVERRIDE
+ {
+ return m_base->getSpecializationParamCount();
+ }
+
+ SpecializationParam const& getSpecializationParam(Index index) SLANG_OVERRIDE
+ {
+ return m_base->getSpecializationParam(index);
+ }
+
+ Index getRequirementCount() SLANG_OVERRIDE { return m_base->getRequirementCount(); }
+ RefPtr<ComponentType> getRequirement(Index index) SLANG_OVERRIDE
+ {
+ return m_base->getRequirement(index);
+ }
+ Index getEntryPointCount() SLANG_OVERRIDE { return m_base->getEntryPointCount(); }
+ RefPtr<EntryPoint> getEntryPoint(Index index) SLANG_OVERRIDE
+ {
+ return m_base->getEntryPoint(index);
+ }
+ String getEntryPointMangledName(Index index) SLANG_OVERRIDE { return m_base->getEntryPointMangledName(index); }
+ String getEntryPointNameOverride(Index index) SLANG_OVERRIDE
+ {
+ SLANG_UNUSED(index);
+ SLANG_ASSERT(index == 0);
+ return m_entryPointNameOverride;
+ }
+
+ Index getShaderParamCount() SLANG_OVERRIDE { return m_base->getShaderParamCount(); }
+ ShaderParamInfo getShaderParam(Index index) SLANG_OVERRIDE
+ {
+ return m_base->getShaderParam(index);
+ }
+
+ void acceptVisitor(ComponentTypeVisitor* visitor, SpecializationInfo* specializationInfo)
+ SLANG_OVERRIDE;
+ private:
+ RefPtr<ComponentType> m_base;
+ String m_entryPointNameOverride;
+
+ protected:
+ RefPtr<SpecializationInfo> _validateSpecializationArgsImpl(
+ SpecializationArg const* args, Index argCount, DiagnosticSink* sink) SLANG_OVERRIDE
+ {
+ return m_base->_validateSpecializationArgsImpl(args, argCount, sink);
+ }
+ };
+
/// Describes an entry point for the purposes of layout and code generation.
///
/// This class also tracks any generic arguments to the entry point,
@@ -710,6 +837,12 @@ namespace Slang
outDiagnostics);
}
+ SLANG_NO_THROW SlangResult SLANG_MCALL renameEntryPoint(
+ const char* newName, slang::IComponentType** outEntryPoint) SLANG_OVERRIDE
+ {
+ return Super::renameEntryPoint(newName, outEntryPoint);
+ }
+
SLANG_NO_THROW SlangResult SLANG_MCALL link(
slang::IComponentType** outLinkedComponentType,
ISlangBlob** outDiagnostics) SLANG_OVERRIDE
@@ -728,15 +861,6 @@ namespace Slang
return Super::getEntryPointHostCallable(entryPointIndex, targetIndex, outSharedLibrary, outDiagnostics);
}
- SLANG_NO_THROW SlangResult SLANG_MCALL getRenamedEntryPoint(const char* newName, IEntryPoint** outEntryPoint)
- SLANG_OVERRIDE
- {
- RefPtr<EntryPoint> newEntryPoint = create(getLinkage(), m_funcDeclRef, m_profile);
- newEntryPoint->m_nameOverride = newName;
- *outEntryPoint = newEntryPoint.detach();
- return SLANG_OK;
- }
-
/// Create an entry point that refers to the given function.
static RefPtr<EntryPoint> create(
Linkage* linkage,
@@ -848,9 +972,6 @@ namespace Slang
/// The mangled name of the entry point function
String m_mangledName;
- /// The name of this entry point in the compiled code.
- String m_nameOverride;
-
SpecializationParams m_genericSpecializationParams;
SpecializationParams m_existentialSpecializationParams;
@@ -922,6 +1043,12 @@ namespace Slang
outDiagnostics);
}
+ SLANG_NO_THROW SlangResult SLANG_MCALL renameEntryPoint(
+ const char* newName, slang::IComponentType** outEntryPoint) SLANG_OVERRIDE
+ {
+ return Super::renameEntryPoint(newName, outEntryPoint);
+ }
+
SLANG_NO_THROW SlangResult SLANG_MCALL link(
slang::IComponentType** outLinkedComponentType,
ISlangBlob** outDiagnostics) SLANG_OVERRIDE
@@ -1060,6 +1187,12 @@ namespace Slang
outDiagnostics);
}
+ SLANG_NO_THROW SlangResult SLANG_MCALL renameEntryPoint(
+ const char* newName, slang::IComponentType** outEntryPoint) SLANG_OVERRIDE
+ {
+ return Super::renameEntryPoint(newName, outEntryPoint);
+ }
+
SLANG_NO_THROW SlangResult SLANG_MCALL link(
slang::IComponentType** outLinkedComponentType,
ISlangBlob** outDiagnostics) SLANG_OVERRIDE
@@ -1919,6 +2052,9 @@ namespace Slang
virtual void visitComposite(CompositeComponentType* composite, CompositeComponentType::CompositeSpecializationInfo* specializationInfo) = 0;
virtual void visitSpecialized(SpecializedComponentType* specialized) = 0;
virtual void visitTypeConformance(TypeConformance* conformance) = 0;
+ virtual void visitRenamedEntryPoint(
+ RenamedEntryPointComponentType* renamedEntryPoint,
+ EntryPoint::EntryPointSpecializationInfo* specializationInfo) = 0;
protected:
// These helpers can be used to recurse into the logical children of a