summaryrefslogtreecommitdiffstats
path: root/source/slang/slang.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2025-02-23 10:31:05 -0800
committerGitHub <noreply@github.com>2025-02-23 10:31:05 -0800
commit51ad07d1fbffd41c758eba172aa77ebba3204924 (patch)
treefadd788714c4ad37830846b0274d56b5ae1eff56 /source/slang/slang.cpp
parent0101e5ab59a1678ed7212913c3880edfaf039537 (diff)
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.
Diffstat (limited to 'source/slang/slang.cpp')
-rw-r--r--source/slang/slang.cpp29
1 files changed, 24 insertions, 5 deletions
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<TypeCheckingCache*>(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> linkage = new Linkage(this, astBuilder, getBuiltinLinkage());
+ if (m_typeCheckingCache)
+ linkage->m_typeCheckingCache =
+ new TypeCheckingCache(*static_cast<TypeCheckingCache*>(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<TypeCheckingCache*>(m_typeCheckingCache.get());
}
void Linkage::destroyTypeCheckingCache()
{
- delete m_typeCheckingCache;
m_typeCheckingCache = nullptr;
}
@@ -4080,6 +4097,8 @@ RefPtr<Module> Linkage::loadModuleFromIRBlobImpl(
loadedModulesList.add(resultModule);
resultModule->setPathInfo(filePathInfo);
+ resultModule->getIRModule()->setName(resultModule->getNameObj());
+
return resultModule;
}