diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2019-12-12 14:53:44 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-12-12 14:53:44 -0500 |
| commit | 15335549340c54fd7b89b28104ddc907e9c64638 (patch) | |
| tree | 02c4705fc7784c3003d14fc661894b5f88c05875 /source/slang | |
| parent | 6e6a876a6b5ad3d2ef402757d2e20641f5a2b49b (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')
| -rw-r--r-- | source/slang/slang-check.cpp | 199 | ||||
| -rw-r--r-- | source/slang/slang-compiler.cpp | 76 | ||||
| -rw-r--r-- | source/slang/slang-compiler.h | 37 | ||||
| -rw-r--r-- | source/slang/slang-diagnostic-defs.h | 2 | ||||
| -rw-r--r-- | source/slang/slang-dxc-support.cpp | 11 | ||||
| -rw-r--r-- | source/slang/slang-emit.cpp | 2 | ||||
| -rw-r--r-- | source/slang/slang.cpp | 90 |
7 files changed, 172 insertions, 245 deletions
diff --git a/source/slang/slang-check.cpp b/source/slang/slang-check.cpp index db69a3155..50de73f07 100644 --- a/source/slang/slang-check.cpp +++ b/source/slang/slang-check.cpp @@ -13,86 +13,151 @@ namespace Slang struct FunctionInfo { const char* name; - SharedLibraryType libraryType; + PassThroughMode compilerType; }; + + const Guid IID_ISlangSharedLibraryLoader = SLANG_UUID_ISlangSharedLibraryLoader; + const Guid IID_ISlangUnknown = SLANG_UUID_ISlangUnknown; + + class SinkSharedLibraryLoader : public RefObject, public ISlangSharedLibraryLoader + { + public: + SLANG_REF_OBJECT_IUNKNOWN_ALL + + virtual SLANG_NO_THROW SlangResult SLANG_MCALL loadSharedLibrary( + const char* path, + ISlangSharedLibrary** outSharedLibrary) SLANG_OVERRIDE + { + SlangResult res = m_loader->loadSharedLibrary(path, outSharedLibrary); + + // Special handling for failure... + if (SLANG_FAILED(res) && m_sink) + { + String filename = Path::getFileNameWithoutExt(path); + if (filename == "dxil") + { + m_sink->diagnose(SourceLoc(), Diagnostics::dxilNotFound); + } + else + { + m_sink->diagnose(SourceLoc(), Diagnostics::failedToLoadDynamicLibrary, path); + } + } + return res; + } + + SinkSharedLibraryLoader(ISlangSharedLibraryLoader* loader, DiagnosticSink* sink) : + m_loader(loader), + m_sink(sink) + { + } + + protected: + ISlangUnknown* getInterface(const Guid& guid) + { + return (guid == IID_ISlangUnknown || guid == IID_ISlangSharedLibraryLoader) ? static_cast<ISlangSharedLibraryLoader*>(this) : nullptr; + } + ISlangSharedLibraryLoader* m_loader; + DiagnosticSink* m_sink; + }; + } // anonymous static FunctionInfo _getFunctionInfo(Session::SharedLibraryFuncType funcType) { typedef Session::SharedLibraryFuncType FuncType; - typedef SharedLibraryType LibType; - + switch (funcType) { - case FuncType::Glslang_Compile: return { "glslang_compile", LibType::Glslang } ; - case FuncType::Fxc_D3DCompile: return { "D3DCompile", LibType::Fxc }; - case FuncType::Fxc_D3DDisassemble: return { "D3DDisassemble", LibType::Fxc }; - case FuncType::Dxc_DxcCreateInstance: return { "DxcCreateInstance", LibType::Dxc }; - default: return { nullptr, LibType::Unknown }; + case FuncType::Glslang_Compile: return { "glslang_compile", PassThroughMode::Glslang} ; + case FuncType::Fxc_D3DCompile: return { "D3DCompile", PassThroughMode::Fxc}; + case FuncType::Fxc_D3DDisassemble: return { "D3DDisassemble", PassThroughMode::Fxc }; + case FuncType::Dxc_DxcCreateInstance: return { "DxcCreateInstance", PassThroughMode::Dxc }; + default: return { nullptr, PassThroughMode::None }; } } - static PassThroughMode _toPassThroughMode(SharedLibraryType type) + void Session::setSharedLibraryLoader(ISlangSharedLibraryLoader* loader) { - switch (type) + if (m_sharedLibraryLoader != loader) { - case SharedLibraryType::Dxil: - case SharedLibraryType::Dxc: + // Need to clear all of the libraries + m_downstreamCompilerSet->clear(); + m_downstreamCompilerInitialized = 0; + + for (Index i = 0; i < Index(SLANG_PASS_THROUGH_COUNT_OF); ++i) { - return PassThroughMode::Dxc; + m_downstreamCompilers[i].setNull(); } - case SharedLibraryType::Fxc: return PassThroughMode::Fxc; - case SharedLibraryType::Glslang: return PassThroughMode::Glslang; - default: break; - } - return PassThroughMode::None; + // Clear all of the functions + ::memset(m_sharedLibraryFunctions, 0, sizeof(m_sharedLibraryFunctions)); + + // Set the loader + m_sharedLibraryLoader = loader; + } } - void Session::setSharedLibrary(SharedLibraryType type, ISlangSharedLibrary* library) + void Session::resetDownstreamCompiler(PassThroughMode type) { - sharedLibraries[int(type)] = library; + // Mark as initialized + m_downstreamCompilerInitialized &= ~(1 << int(type)); + m_downstreamCompilers[int(type)].setNull(); } - ISlangSharedLibrary* Session::getOrLoadSharedLibrary(SharedLibraryType type, DiagnosticSink* sink) + DownstreamCompiler* Session::getOrLoadDownstreamCompiler(PassThroughMode type, DiagnosticSink* sink) { - // If not loaded, try loading it - if (!sharedLibraries[int(type)]) + if (m_downstreamCompilerInitialized & (1 << int(type))) { - // Try to preload dxil first, if loading dxc - if (type == SharedLibraryType::Dxc) - { - // Pass nullptr as the sink, because if it fails we don't want to report as error - getOrLoadSharedLibrary(SharedLibraryType::Dxil, nullptr); - } + return m_downstreamCompilers[int(type)]; + } + + if (type == PassThroughMode::GenericCCpp) + { + // try loading all C/C++ compilers + getOrLoadDownstreamCompiler(PassThroughMode::Clang, sink); + getOrLoadDownstreamCompiler(PassThroughMode::Gcc, sink); + getOrLoadDownstreamCompiler(PassThroughMode::VisualStudio, sink); + } - const char* libName = DefaultSharedLibraryLoader::getSharedLibraryNameFromType(type); + // Mark that we have tried to load it + m_downstreamCompilerInitialized |= (1 << int(type)); + m_downstreamCompilers[int(type)].setNull(); - StringBuilder builder; - PassThroughMode passThrough = _toPassThroughMode(type); - if (passThrough != PassThroughMode::None && m_downstreamCompilerPaths[int(passThrough)].getLength() > 0) - { - Path::combineIntoBuilder(m_downstreamCompilerPaths[int(passThrough)].getUnownedSlice(), UnownedStringSlice(libName), builder); - libName = builder.getBuffer(); - } + // Do we have a locator + auto locator = m_downstreamCompilerLocators[int(type)]; + if (!locator) + { + return nullptr; + } - if (SLANG_FAILED(sharedLibraryLoader->loadSharedLibrary(libName, sharedLibraries[int(type)].writeRef()))) - { - if (sink) - { - sink->diagnose(SourceLoc(), Diagnostics::failedToLoadDynamicLibrary, libName); - } - return nullptr; - } + m_downstreamCompilerSet->remove(SlangPassThrough(type)); + + SinkSharedLibraryLoader loader(m_sharedLibraryLoader, sink); + locator(m_downstreamCompilerPaths[int(type)], &loader, m_downstreamCompilerSet); + + DownstreamCompilerUtil::updateDefaults(m_downstreamCompilerSet); + + if (type == PassThroughMode::GenericCCpp) + { + m_downstreamCompilers[int(type)] = m_downstreamCompilerSet->getDefaultCompiler(DownstreamCompiler::SourceType::CPP); } - return sharedLibraries[int(type)]; + else + { + DownstreamCompiler::Desc desc; + desc.type = SlangPassThrough(type); + + m_downstreamCompilers[int(type)] = DownstreamCompilerUtil::findCompiler(m_downstreamCompilerSet, DownstreamCompilerUtil::MatchType::Newest, desc); + } + + return m_downstreamCompilers[int(type)]; } SlangFuncPtr Session::getSharedLibraryFunc(SharedLibraryFuncType type, DiagnosticSink* sink) { - if (sharedLibraryFunctions[int(type)]) + if (m_sharedLibraryFunctions[int(type)]) { - return sharedLibraryFunctions[int(type)]; + return m_sharedLibraryFunctions[int(type)]; } // do we have the library FunctionInfo info = _getFunctionInfo(type); @@ -101,47 +166,31 @@ namespace Slang return nullptr; } // Try loading the library - ISlangSharedLibrary* sharedLib = getOrLoadSharedLibrary(info.libraryType, sink); - if (!sharedLib) + DownstreamCompiler* compiler = getOrLoadDownstreamCompiler(info.compilerType, sink); + if (!compiler) + { + return nullptr; + } + ISlangSharedLibrary* sharedLibrary = compiler->getSharedLibrary(); + if (!sharedLibrary) { return nullptr; } // Okay now access the func - SlangFuncPtr func = sharedLib->findFuncByName(info.name); + SlangFuncPtr func = sharedLibrary->findFuncByName(info.name); if (!func) { - const char* libName = DefaultSharedLibraryLoader::getSharedLibraryNameFromType(info.libraryType); - sink->diagnose(SourceLoc(), Diagnostics::failedToFindFunctionInSharedLibrary, info.name, libName); + UnownedStringSlice compilerName = DownstreamCompiler::getCompilerTypeAsText(SlangPassThrough(info.compilerType)); + sink->diagnose(SourceLoc(), Diagnostics::failedToFindFunctionForCompiler, info.name, compilerName); return nullptr; } // Store in the function cache - sharedLibraryFunctions[int(type)] = func; + m_sharedLibraryFunctions[int(type)] = func; return func; } - DownstreamCompilerSet* Session::requireDownstreamCompilerSet() - { - if (downstreamCompilerSet == nullptr) - { - downstreamCompilerSet = new DownstreamCompilerSet; - - typedef DownstreamCompiler::CompilerType CompilerType; - DownstreamCompilerUtil::InitializeSetDesc desc; - - desc.paths[int(CompilerType::GCC)] = m_downstreamCompilerPaths[int(PassThroughMode::Gcc)]; - desc.paths[int(CompilerType::Clang)] = m_downstreamCompilerPaths[int(PassThroughMode::Clang)]; - desc.paths[int(CompilerType::VisualStudio)] = m_downstreamCompilerPaths[int(PassThroughMode::VisualStudio)]; - - desc.sharedLibraries[int(CompilerType::NVRTC)] = getOrLoadSharedLibrary(SharedLibraryType::NVRTC, nullptr); - - DownstreamCompilerUtil::initializeSet(desc, downstreamCompilerSet); - } - SLANG_ASSERT(downstreamCompilerSet); - return downstreamCompilerSet; - } - TypeCheckingCache* Session::getTypeCheckingCache() { if (!typeCheckingCache) diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp index cba25d7df..16d9a5546 100644 --- a/source/slang/slang-compiler.cpp +++ b/source/slang/slang-compiler.cpp @@ -427,6 +427,7 @@ namespace Slang { "glsl", SourceLanguage::GLSL }, { "c", SourceLanguage::C }, { "cxx", SourceLanguage::CPP }, + { "cuda", SourceLanguage::CUDA }, }; SourceLanguage findSourceLanguageByName(String const& name) @@ -444,6 +445,7 @@ namespace Slang SlangResult checkExternalCompilerSupport(Session* session, PassThroughMode passThrough) { + // Check if the type is supported on this compile switch (passThrough) { case PassThroughMode::None: @@ -451,54 +453,20 @@ namespace Slang // If no pass through -> that will always work! return SLANG_OK; } - case PassThroughMode::Dxc: - { -#if SLANG_ENABLE_DXIL_SUPPORT - // Must have dxc - return session->getOrLoadSharedLibrary(SharedLibraryType::Dxc, nullptr) ? SLANG_OK : SLANG_E_NOT_FOUND; +#if !SLANG_ENABLE_DXIL_SUPPORT + case PassThroughMode::Dxc: return SLANG_E_NOT_IMPLEMENTED; #endif - break; - } - case PassThroughMode::Fxc: - { -#if SLANG_ENABLE_DXBC_SUPPORT - // Must have fxc - return session->getOrLoadSharedLibrary(SharedLibraryType::Fxc, nullptr) ? SLANG_OK : SLANG_E_NOT_FOUND; +#if !SLANG_ENABLE_DXBC_SUPPORT + case PassThroughMode::Fxc: return SLANG_E_NOT_IMPLEMENTED; #endif - break; - } - case PassThroughMode::Glslang: - { -#if SLANG_ENABLE_GLSLANG_SUPPORT - return session->getOrLoadSharedLibrary(Slang::SharedLibraryType::Glslang, nullptr) ? SLANG_OK : SLANG_E_NOT_FOUND; +#if !SLANG_ENABLE_GLSLANG_SUPPORT + case PassThroughMode::Glslang: return SLANG_E_NOT_IMPLEMENTED; #endif - break; - } - case PassThroughMode::Clang: - { - return session->requireDownstreamCompilerSet()->hasCompiler(DownstreamCompiler::CompilerType::Clang) ? SLANG_OK: SLANG_E_NOT_FOUND; - } - case PassThroughMode::VisualStudio: - { - return session->requireDownstreamCompilerSet()->hasCompiler(DownstreamCompiler::CompilerType::VisualStudio) ? SLANG_OK: SLANG_E_NOT_FOUND; - } - case PassThroughMode::Gcc: - { - return session->requireDownstreamCompilerSet()->hasCompiler(DownstreamCompiler::CompilerType::GCC) ? SLANG_OK: SLANG_E_NOT_FOUND; - } - case PassThroughMode::GenericCCpp: - { - List<DownstreamCompiler::Desc> descs; - session->requireDownstreamCompilerSet()->getCompilerDescs(descs); - return descs.getCount() ? SLANG_OK: SLANG_E_NOT_FOUND; - } - case PassThroughMode::NVRTC: - { - return session->requireDownstreamCompilerSet()->hasCompiler(DownstreamCompiler::CompilerType::NVRTC) ? SLANG_OK: SLANG_E_NOT_FOUND; - } + default: break; } - return SLANG_E_NOT_IMPLEMENTED; + + return session->getOrLoadDownstreamCompiler(passThrough, nullptr) ? SLANG_OK: SLANG_E_NOT_FOUND; } PassThroughMode getDownstreamCompilerRequiredForTarget(CodeGenTarget target) @@ -561,20 +529,6 @@ namespace Slang return PassThroughMode::None; } - PassThroughMode getPassThroughModeForDownstreamCompiler(DownstreamCompiler::CompilerType type) - { - typedef DownstreamCompiler::CompilerType CompilerType; - - switch (type) - { - case CompilerType::VisualStudio: return PassThroughMode::VisualStudio; - case CompilerType::GCC: return PassThroughMode::Gcc; - case CompilerType::Clang: return PassThroughMode::Clang; - case CompilerType::NVRTC: return PassThroughMode::NVRTC; - default: return PassThroughMode::None; - } - } - SlangResult checkCompileTargetSupport(Session* session, CodeGenTarget target) { const PassThroughMode mode = getDownstreamCompilerRequiredForTarget(target); @@ -1290,7 +1244,7 @@ SlangResult dissassembleDXILUsingDXC( return SLANG_OK; } - SlangResult emitDownstreamForEntryPoint( + SlangResult emitWithDownstreamForEntryPoint( BackEndCompileRequest* slangRequest, Int entryPointIndex, TargetRequest* targetReq, @@ -1330,8 +1284,8 @@ SlangResult dissassembleDXILUsingDXC( } } - // Get the required downstream CPP compiler - DownstreamCompiler* compiler = session->getDownstreamCompiler(downstreamCompiler); + // Get the required downstream compiler + DownstreamCompiler* compiler = session->getOrLoadDownstreamCompiler(downstreamCompiler, sink); if (!compiler) { @@ -1714,7 +1668,7 @@ SlangResult dissassembleDXILUsingDXC( { RefPtr<DownstreamCompileResult> downstreamResult; - if (SLANG_SUCCEEDED(emitDownstreamForEntryPoint( + if (SLANG_SUCCEEDED(emitWithDownstreamForEntryPoint( compileRequest, entryPointIndex, targetReq, diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h index be5251d14..884c1acbc 100644 --- a/source/slang/slang-compiler.h +++ b/source/slang/slang-compiler.h @@ -769,7 +769,7 @@ namespace Slang Profile m_profile; }; - enum class PassThroughMode : SlangPassThrough + enum class PassThroughMode : SlangPassThroughIntegral { None = SLANG_PASS_THROUGH_NONE, ///< don't pass through: use Slang compiler Fxc = SLANG_PASS_THROUGH_FXC, ///< pass through HLSL to `D3DCompile` API @@ -1077,9 +1077,7 @@ namespace Slang /// Given a target returns the required downstream compiler PassThroughMode getDownstreamCompilerRequiredForTarget(CodeGenTarget target); - PassThroughMode getPassThroughModeForDownstreamCompiler(DownstreamCompiler::CompilerType type); - - + /// A context for loading and re-using code modules. class Linkage : public RefObject, public slang::ISession { @@ -1836,8 +1834,6 @@ namespace Slang SLANG_NO_THROW SlangPassThrough SLANG_MCALL getDefaultDownstreamCompiler(SlangSourceLanguage sourceLanguage) override; - /// Get the specified compiler - DownstreamCompiler* getDownstreamCompiler(PassThroughMode downstreamCompiler); /// Get the default cpp compiler for a language DownstreamCompiler* getDefaultDownstreamCompiler(SourceLanguage sourceLanguage); @@ -1895,12 +1891,7 @@ namespace Slang RefPtr<Type> stringType; RefPtr<Type> enumTypeType; - RefPtr<DownstreamCompilerSet> downstreamCompilerSet; ///< Information about available C/C++ compilers. null unless information is requested (because slow) - - ComPtr<ISlangSharedLibraryLoader> sharedLibraryLoader; ///< The shared library loader (never null) - ComPtr<ISlangSharedLibrary> sharedLibraries[int(SharedLibraryType::CountOf)]; ///< The loaded shared libraries - SlangFuncPtr sharedLibraryFunctions[int(SharedLibraryFuncType::CountOf)]; - + Dictionary<int, RefPtr<Type>> builtinTypes; Dictionary<String, Decl*> magicDecls; @@ -1963,22 +1954,18 @@ namespace Slang void destroyTypeCheckingCache(); // + void setSharedLibraryLoader(ISlangSharedLibraryLoader* loader); + /// Will try to load the library by specified name (using the set loader), if not one already available. - ISlangSharedLibrary* getOrLoadSharedLibrary(SharedLibraryType type, DiagnosticSink* sink); + DownstreamCompiler* getOrLoadDownstreamCompiler(PassThroughMode type, DiagnosticSink* sink); /// Will unload the specified shared library if it's currently loaded - void setSharedLibrary(SharedLibraryType type, ISlangSharedLibrary* library); - - /// Gets a shared library by type, or null if not loaded - ISlangSharedLibrary* getSharedLibrary(SharedLibraryType type) const { return sharedLibraries[int(type)]; } + void resetDownstreamCompiler(PassThroughMode type); SlangFuncPtr getSharedLibraryFunc(SharedLibraryFuncType type, DiagnosticSink* sink); /// Get the downstream compiler prelude const String& getDownstreamCompilerPrelude(PassThroughMode mode) { return m_downstreamCompilerPreludes[int(mode)]; } - /// Finds out what compilers are present and caches the result - DownstreamCompilerSet* requireDownstreamCompilerSet(); - Session(); void addBuiltinSource( @@ -1987,10 +1974,20 @@ namespace Slang String const& source); ~Session(); + ComPtr<ISlangSharedLibraryLoader> m_sharedLibraryLoader; ///< The shared library loader (never null) + SlangFuncPtr m_sharedLibraryFunctions[int(SharedLibraryFuncType::CountOf)]; ///< Functions from shared libraries + + int m_downstreamCompilerInitialized = 0; + + RefPtr<DownstreamCompilerSet> m_downstreamCompilerSet; ///< Information about all available downstream compilers. + RefPtr<DownstreamCompiler> m_downstreamCompilers[int(PassThroughMode::CountOf)]; ///< A downstream compiler for a pass through + DownstreamCompilerLocatorFunc m_downstreamCompilerLocators[int(PassThroughMode::CountOf)]; + private: SlangResult _loadRequest(EndToEndCompileRequest* request, const void* data, size_t size); + /// Linkage used for all built-in (stdlib) code. RefPtr<Linkage> m_builtinLinkage; diff --git a/source/slang/slang-diagnostic-defs.h b/source/slang/slang-diagnostic-defs.h index d7a45335e..8beb246e7 100644 --- a/source/slang/slang-diagnostic-defs.h +++ b/source/slang/slang-diagnostic-defs.h @@ -103,7 +103,7 @@ DIAGNOSTIC( 50, Error, duplicateTargets, "the target '$0' has been specified DIAGNOSTIC( 60, Error, cannotDeduceOutputFormatFromPath, "cannot infer an output format from the output path '$0'") DIAGNOSTIC( 61, Error, cannotMatchOutputFileToTarget, "no specified '-target' option matches the output path '$0', which implies the '$1' format") -DIAGNOSTIC( 62, Error, failedToFindFunctionInSharedLibrary, "failed to find function '$0' in shared/dynamic library '$1'") +DIAGNOSTIC( 62, Error, failedToFindFunctionForCompiler, "failed to find function '$0' for downstream compiler '$1'") DIAGNOSTIC( 70, Error, cannotMatchOutputFileToEntryPoint, "the output path '$0' is not associated with any entry point; a '-o' option for a compiled kernel must follow the '-entry' option for its corresponding entry point") diff --git a/source/slang/slang-dxc-support.cpp b/source/slang/slang-dxc-support.cpp index 816de5960..e0ca4df82 100644 --- a/source/slang/slang-dxc-support.cpp +++ b/source/slang/slang-dxc-support.cpp @@ -35,6 +35,8 @@ namespace Slang TargetRequest* targetReq, EndToEndCompileRequest* endToEndReq); + SlangResult locateDXCCompilers(const String& path, ISlangSharedLibraryLoader* loader, DownstreamCompilerSet* set); + static UnownedStringSlice _getSlice(IDxcBlob* blob) { if (blob) @@ -69,15 +71,6 @@ namespace Slang return SLANG_FAIL; } - { - if (!session->getSharedLibrary(SharedLibraryType::Dxil)) - { - // If can't load dxil - dxc will not be able to sign output - // Output a suitable warning to the user - sink->diagnose(SourceLoc(), Diagnostics::dxilNotFound); - } - } - ComPtr<IDxcCompiler> dxcCompiler; SLANG_RETURN_ON_FAIL(dxcCreateInstance( CLSID_DxcCompiler, diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp index 45eef5148..9aa7b1203 100644 --- a/source/slang/slang-emit.cpp +++ b/source/slang/slang-emit.cpp @@ -586,7 +586,7 @@ String emitEntryPointSource( DownstreamCompiler* compiler = session->getDefaultDownstreamCompiler(sourceLanguage); if (compiler) { - passThru = getPassThroughModeForDownstreamCompiler(compiler->getDesc().type); + passThru = PassThroughMode(compiler->getDesc().type); } } 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( |
