From 51ad07d1fbffd41c758eba172aa77ebba3204924 Mon Sep 17 00:00:00 2001 From: Yong He Date: Sun, 23 Feb 2025 10:31:05 -0800 Subject: Improve performance when compiling small shaders. (#6396) Improve performance when compiling small shaders. Avoid copying witness table entries that are not getting used during linking. Avoid copying auto-diff related decorations and derivative functions during linking, if the user modules doesn't use autodiff. Cache operator overload resolution results on global session, so each new Session doesn't need to repetitively run through overload resolution from scratch. --- source/slang/slang.cpp | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'source/slang/slang.cpp') diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index c316974f1..ec90ee418 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -410,6 +410,11 @@ const char* getBuiltinModuleNameStr(slang::BuiltinModuleName name) return result; } +TypeCheckingCache* Session::getTypeCheckingCache() +{ + return static_cast(m_typeCheckingCache.get()); +} + Session::BuiltinModuleInfo Session::getBuiltinModuleInfo(slang::BuiltinModuleName name) { Session::BuiltinModuleInfo result; @@ -700,6 +705,7 @@ SlangResult Session::_readBuiltinModule( module->setModuleDecl(moduleDecl); } + srcModule.irModule->setName(module->getNameObj()); module->setIRModule(srcModule.irModule); // Put in the loaded module map @@ -803,6 +809,10 @@ Session::createSession(slang::SessionDesc const& inDesc, slang::ISession** outSe RefPtr linkage = new Linkage(this, astBuilder, getBuiltinLinkage()); + if (m_typeCheckingCache) + linkage->m_typeCheckingCache = + new TypeCheckingCache(*static_cast(m_typeCheckingCache.get())); + linkage->setMatrixLayoutMode(desc.defaultMatrixLayoutMode); Int searchPathCount = desc.searchPathCount; @@ -1263,9 +1273,6 @@ Linkage::Linkage(Session* session, ASTBuilder* astBuilder, Linkage* builtinLinka , m_astBuilder(astBuilder) , m_cmdLineContext(new CommandLineContext()) { - if (builtinLinkage) - m_astBuilder->m_cachedNodes = builtinLinkage->getASTBuilder()->m_cachedNodes; - getNamePool()->setRootNamePool(session->getRootNamePool()); m_defaultSourceManager.initialize(session->getBuiltinSourceManager(), nullptr); @@ -1297,6 +1304,17 @@ ISlangUnknown* Linkage::getInterface(const Guid& guid) Linkage::~Linkage() { + // Upstream type checking cache. + if (m_typeCheckingCache) + { + auto globalSession = getSessionImpl(); + if (!globalSession->m_typeCheckingCache || + globalSession->getTypeCheckingCache()->resolvedOperatorOverloadCache.getCount() < + getTypeCheckingCache()->resolvedOperatorOverloadCache.getCount()) + { + globalSession->m_typeCheckingCache = m_typeCheckingCache; + } + } destroyTypeCheckingCache(); } @@ -1318,12 +1336,11 @@ TypeCheckingCache* Linkage::getTypeCheckingCache() { m_typeCheckingCache = new TypeCheckingCache(); } - return m_typeCheckingCache; + return static_cast(m_typeCheckingCache.get()); } void Linkage::destroyTypeCheckingCache() { - delete m_typeCheckingCache; m_typeCheckingCache = nullptr; } @@ -4080,6 +4097,8 @@ RefPtr Linkage::loadModuleFromIRBlobImpl( loadedModulesList.add(resultModule); resultModule->setPathInfo(filePathInfo); + resultModule->getIRModule()->setName(resultModule->getNameObj()); + return resultModule; } -- cgit v1.2.3