From e59516fa8c3a16eb7b99a928c5b85b97bf44fd72 Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 31 Jan 2022 16:26:03 -0800 Subject: 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 --- source/slang/slang.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) (limited to 'source/slang/slang.cpp') diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 1333e3660..3880d1114 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -3160,6 +3160,15 @@ SLANG_NO_THROW SlangResult SLANG_MCALL ComponentType::specialize( return SLANG_OK; } +SLANG_NO_THROW SlangResult SLANG_MCALL + ComponentType::renameEntryPoint(const char* newName, IComponentType** outEntryPoint) +{ + RefPtr result = + new RenamedEntryPointComponentType(this, newName); + *outEntryPoint = result.detach(); + return SLANG_OK; +} + RefPtr fillRequirements( ComponentType* inComponentType); @@ -3195,6 +3204,13 @@ struct EnumerateModulesVisitor : ComponentTypeVisitor void visitEntryPoint(EntryPoint*, EntryPoint::EntryPointSpecializationInfo*) SLANG_OVERRIDE {} + void visitRenamedEntryPoint( + RenamedEntryPointComponentType* entryPoint, + EntryPoint::EntryPointSpecializationInfo* specializationInfo) SLANG_OVERRIDE + { + entryPoint->getBase()->acceptVisitor(this, specializationInfo); + } + void visitModule(Module* module, Module::ModuleSpecializationInfo*) SLANG_OVERRIDE { m_callback(module, m_userData); @@ -3236,6 +3252,13 @@ struct EnumerateIRModulesVisitor : ComponentTypeVisitor void visitEntryPoint(EntryPoint*, EntryPoint::EntryPointSpecializationInfo*) SLANG_OVERRIDE {} + void visitRenamedEntryPoint( + RenamedEntryPointComponentType* entryPoint, + EntryPoint::EntryPointSpecializationInfo* specializationInfo) SLANG_OVERRIDE + { + entryPoint->getBase()->acceptVisitor(this, specializationInfo); + } + void visitModule(Module* module, Module::ModuleSpecializationInfo*) SLANG_OVERRIDE { m_callback(module->getIRModule(), m_userData); @@ -3427,7 +3450,6 @@ void CompositeComponentType::acceptVisitor(ComponentTypeVisitor* visitor, Specia visitor->visitComposite(this, as(specializationInfo)); } - RefPtr CompositeComponentType::_validateSpecializationArgsImpl( SpecializationArg const* args, Index argCount, @@ -3562,6 +3584,13 @@ struct SpecializationArgModuleCollector : ComponentTypeVisitor collectReferencedModules(specializationInfo->existentialSpecializationArgs); } + void visitRenamedEntryPoint( + RenamedEntryPointComponentType* entryPoint, + EntryPoint::EntryPointSpecializationInfo* specializationInfo) SLANG_OVERRIDE + { + entryPoint->getBase()->acceptVisitor(this, specializationInfo); + } + void visitModule(Module* module, Module::ModuleSpecializationInfo* specializationInfo) SLANG_OVERRIDE { SLANG_UNUSED(module); @@ -3801,6 +3830,14 @@ SpecializedComponentType::SpecializedComponentType( (*entryPointNameOverrides).add(entryPoint->getEntryPointNameOverride(0)); } + void visitRenamedEntryPoint( + RenamedEntryPointComponentType* entryPoint, + EntryPoint::EntryPointSpecializationInfo* specializationInfo) SLANG_OVERRIDE + { + entryPoint->getBase()->acceptVisitor(this, specializationInfo); + (*entryPointNameOverrides).getLast() = entryPoint->getEntryPointNameOverride(0); + } + void visitModule(Module*, Module::ModuleSpecializationInfo*) SLANG_OVERRIDE {} void visitComposite(CompositeComponentType* composite, CompositeComponentType::CompositeSpecializationInfo* specializationInfo) SLANG_OVERRIDE @@ -3854,6 +3891,23 @@ String SpecializedComponentType::getEntryPointNameOverride(Index index) return m_entryPointNameOverrides[index]; } +// RenamedEntryPointComponentType + +RenamedEntryPointComponentType::RenamedEntryPointComponentType( + ComponentType* base, String newName) + : ComponentType(base->getLinkage()) + , m_base(base) + , m_entryPointNameOverride(newName) +{ +} + +void RenamedEntryPointComponentType::acceptVisitor( + ComponentTypeVisitor* visitor, SpecializationInfo* specializationInfo) +{ + visitor->visitRenamedEntryPoint( + this, as(specializationInfo)); +} + void ComponentTypeVisitor::visitChildren(CompositeComponentType* composite, CompositeComponentType::CompositeSpecializationInfo* specializationInfo) { auto childCount = composite->getChildComponentCount(); -- cgit v1.2.3