summaryrefslogtreecommitdiff
path: root/source/slang/slang.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2019-12-12 14:53:44 -0500
committerGitHub <noreply@github.com>2019-12-12 14:53:44 -0500
commit15335549340c54fd7b89b28104ddc907e9c64638 (patch)
tree02c4705fc7784c3003d14fc661894b5f88c05875 /source/slang/slang.cpp
parent6e6a876a6b5ad3d2ef402757d2e20641f5a2b49b (diff)
Use DownstreamCompiler for all downstream compilers (#1152)
* CPPCompiler -> DownstreamCompiler * Added DownstreamCompileResult to start abstraction such that we don't need files. * * Split out slang-blob.cpp * Made CompileResult hold a DownstreamCompileResult - for access to binary or ISlangSharedLibrary * Keep temporary files in scope. * Add a hash to the hex dump stream. * Move all file tracking into DownstreamCompiler. * WIP support for nvrtc. * WIP: Adding support for nvrtc compiler. Adding enum types, wiring up the nvrtc into slang. * Fix remaining CPPCompiler references. * Fix order issue on target string matching. * Use ISlangSharedLibrary for nvrtc. * Use DownstreamCompiler for nvrtc. * WIP first pass at compilation win nvrtc. * Added testing if file is on file system into CommandLineDownstreamCompiler. Added sourceContentsPath. * Make test cuda-compile.cu work by just compiling not comparing output. * Genearlize DownstreamCompiler usage. * Fix warning on clang. * Remove CompilerType from DownstreamCompiler. * Use DownstreamCompiler interface for all compilers. NOTE for FXC, DXC and GLSLANG this doesn't mean using 'compile' - it's still extracting functions from shared library. * Fix compiling on gcc/clang for DownstreamCompiler. * Fix problem on non-vc builds with not having return on locateCompilers for VS. * Change so no warning for code not reachable on locateCompilers for vs.
Diffstat (limited to 'source/slang/slang.cpp')
-rw-r--r--source/slang/slang.cpp90
1 files changed, 12 insertions, 78 deletions
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index 0319d1f7d..de3c6b0a6 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -46,12 +46,16 @@ static const Guid IID_IModule = SLANG_UUID_IModule;
Session::Session()
{
+ ::memset(m_downstreamCompilerLocators, 0, sizeof(m_downstreamCompilerLocators));
+ DownstreamCompilerUtil::setDefaultLocators(m_downstreamCompilerLocators);
+ m_downstreamCompilerSet = new DownstreamCompilerSet;
+
// Initialize name pool
getNamePool()->setRootNamePool(getRootNamePool());
- sharedLibraryLoader = DefaultSharedLibraryLoader::getSingleton();
+ m_sharedLibraryLoader = DefaultSharedLibraryLoader::getSingleton();
// Set all the shared library function pointers to nullptr
- ::memset(sharedLibraryFunctions, 0, sizeof(sharedLibraryFunctions));
+ ::memset(m_sharedLibraryFunctions, 0, sizeof(m_sharedLibraryFunctions));
// Initialize the lookup table of syntax classes:
@@ -169,44 +173,8 @@ SLANG_NO_THROW void SLANG_MCALL Session::setDownstreamCompilerPath(
if (m_downstreamCompilerPaths[int(passThrough)] != path)
{
- // If it's changed we should unload any shared libraries that use it
- switch (passThrough)
- {
- case PassThroughMode::Dxc:
- {
- setSharedLibrary(SharedLibraryType::Dxc, nullptr);
- setSharedLibrary(SharedLibraryType::Dxil, nullptr);
- break;
- }
- case PassThroughMode::Fxc:
- {
- setSharedLibrary(SharedLibraryType::Fxc, nullptr);
- break;
- }
- case PassThroughMode::Glslang:
- {
- setSharedLibrary(SharedLibraryType::Glslang, nullptr);
- break;
- }
- case PassThroughMode::VisualStudio:
- case PassThroughMode::Gcc:
- case PassThroughMode::Clang:
- case PassThroughMode::GenericCCpp:
- {
- // If any compiler path set changed, require all to be refreshed
- downstreamCompilerSet.setNull();
- break;
- }
- case PassThroughMode::NVRTC:
- {
- // TODO(JS): We need a way to set the NVRTC path.
- // We want to unload... and try again...
- downstreamCompilerSet.setNull();
- break;
- }
- default: break;
- }
-
+ // Make access redetermine compiler
+ resetDownstreamCompiler(passThrough);
// Set the path
m_downstreamCompilerPaths[int(passThrough)] = path;
}
@@ -287,24 +255,9 @@ SlangPassThrough SLANG_MCALL Session::getDefaultDownstreamCompiler(SlangSourceLa
return SlangPassThrough(m_defaultDownstreamCompilers[int(sourceLanguage)]);
}
-DownstreamCompiler* Session::getDownstreamCompiler(PassThroughMode compiler)
-{
- DownstreamCompilerSet* compilerSet = requireDownstreamCompilerSet();
- switch (compiler)
- {
- case PassThroughMode::GenericCCpp: return compilerSet->getDefaultCompiler(DownstreamCompiler::SourceType::CPP);
- case PassThroughMode::Clang: return DownstreamCompilerUtil::findCompiler(compilerSet, DownstreamCompilerUtil::MatchType::Newest, DownstreamCompiler::Desc(DownstreamCompiler::CompilerType::Clang));
- case PassThroughMode::VisualStudio: return DownstreamCompilerUtil::findCompiler(compilerSet, DownstreamCompilerUtil::MatchType::Newest, DownstreamCompiler::Desc(DownstreamCompiler::CompilerType::VisualStudio));
- case PassThroughMode::Gcc: return DownstreamCompilerUtil::findCompiler(compilerSet, DownstreamCompilerUtil::MatchType::Newest, DownstreamCompiler::Desc(DownstreamCompiler::CompilerType::GCC));
- case PassThroughMode::NVRTC: return compilerSet->getDefaultCompiler(DownstreamCompiler::SourceType::CUDA);
- default: break;
- }
- return nullptr;
-}
-
DownstreamCompiler* Session::getDefaultDownstreamCompiler(SourceLanguage sourceLanguage)
{
- return getDownstreamCompiler(m_defaultDownstreamCompilers[int(sourceLanguage)]);
+ return getOrLoadDownstreamCompiler(m_defaultDownstreamCompilers[int(sourceLanguage)], nullptr);
}
ISlangFileSystemExt* IncludeHandlerImpl::_getFileSystemExt()
@@ -2618,34 +2571,15 @@ SLANG_API void spSessionSetSharedLibraryLoader(
ISlangSharedLibraryLoader* loader)
{
auto s = Slang::asInternal(session);
-
- if (!loader)
- {
- // If null set the default
- loader = Slang::DefaultSharedLibraryLoader::getSingleton();
- }
-
- if (s->sharedLibraryLoader != loader)
- {
- // Need to clear all of the libraries
- for (int i = 0; i < SLANG_COUNT_OF(s->sharedLibraries); ++i)
- {
- s->sharedLibraries[i].setNull();
- }
-
- // Clear all of the functions
- ::memset(s->sharedLibraryFunctions, 0, sizeof(s->sharedLibraryFunctions));
-
- // Set the loader
- s->sharedLibraryLoader = loader;
- }
+ loader = loader ? loader : Slang::DefaultSharedLibraryLoader::getSingleton();
+ s->setSharedLibraryLoader(loader);
}
SLANG_API ISlangSharedLibraryLoader* spSessionGetSharedLibraryLoader(
SlangSession* session)
{
auto s = Slang::asInternal(session);
- return (s->sharedLibraryLoader == Slang::DefaultSharedLibraryLoader::getSingleton()) ? nullptr : s->sharedLibraryLoader.get();
+ return (s->m_sharedLibraryLoader == Slang::DefaultSharedLibraryLoader::getSingleton()) ? nullptr : s->m_sharedLibraryLoader.get();
}
SLANG_API SlangResult spSessionCheckCompileTargetSupport(