From 1185bd464092f372430cbfaa15a7be4dcaa90752 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Tue, 6 Nov 2018 14:28:25 -0500 Subject: Feature/shared library refactor (#712) * * Added ISlangSharedLibraryLoader and ISlangSharedLibrary * Implemented default implementations * Added slang API function to get/set the ISlangSharedLibraryLoader on the session * Put function caching onto the Session - so that if the loader is chaged, its easy to reset the shared libraries, and functions * Run premake. * Fix problem with setting null, would cause an unnecessary function/shared lib flush. * * Unload SharedLibrary when DefaultSharedLibrary is deleted. * Make SharedLibrary handle unload safely if already unloaded. * Refactor SharedLibrary, such that it becomes a utility class - simplifying it's semantics. * Simplified ISlangSharedLibrary such that doesn't have unload and isLoaded so easier to implement. Use updated SharedLibrary impl. * Disable aarch64 on windows * Premake windows files without aarch64 build. * Moved slang-shared-library to core (so can be used in code outside of main slang) Fixed problem in premake5 where on windows projects were incorrectly constructed * Allowed RefObject to base class of com types Added ConfigurableSharedLibraryLoader Added -dxc-path -fxc-path -glslang-path Fix problem with dxc-path not honoring it's path when loading dxil * Added documentation for command line control of dll loading paths. * Remove some tabbing issues. * Change name of include guard. --- source/slang/check.cpp | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) (limited to 'source/slang/check.cpp') diff --git a/source/slang/check.cpp b/source/slang/check.cpp index dbf2b294c..00c6f6dd0 100644 --- a/source/slang/check.cpp +++ b/source/slang/check.cpp @@ -274,6 +274,84 @@ namespace Slang typeCheckingCache = nullptr; } + namespace { // anonymous + struct FunctionInfo + { + const char* name; + SharedLibraryType libraryType; + }; + } // 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 }; + } + } + + ISlangSharedLibrary* Session::getOrLoadSharedLibrary(SharedLibraryType type, DiagnosticSink* sink) + { + // If not loaded, try loading it + if (!sharedLibraries[int(type)]) + { + // Try to preload dxil first, if loading dxc + if (type == SharedLibraryType::Dxc) + { + getOrLoadSharedLibrary(SharedLibraryType::Dxil, sink); + } + + const char* libName = DefaultSharedLibraryLoader::getSharedLibraryNameFromType(type); + if (SLANG_FAILED(sharedLibraryLoader->loadSharedLibrary(libName, sharedLibraries[int(type)].writeRef()))) + { + sink->diagnose(SourceLoc(), Diagnostics::failedToLoadDynamicLibrary, libName); + return nullptr; + } + } + return sharedLibraries[int(type)]; + } + + SlangFuncPtr Session::getSharedLibraryFunc(SharedLibraryFuncType type, DiagnosticSink* sink) + { + if (sharedLibraryFunctions[int(type)]) + { + return sharedLibraryFunctions[int(type)]; + } + // do we have the library + FunctionInfo info = _getFunctionInfo(type); + if (info.name == nullptr) + { + return nullptr; + } + // Try loading the library + ISlangSharedLibrary* sharedLib = getOrLoadSharedLibrary(info.libraryType, sink); + if (!sharedLib) + { + return nullptr; + } + + // Okay now access the func + SlangFuncPtr func = sharedLib->findFuncByName(info.name); + if (!func) + { + const char* libName = DefaultSharedLibraryLoader::getSharedLibraryNameFromType(info.libraryType); + sink->diagnose(SourceLoc(), Diagnostics::failedToFindFunctionInSharedLibrary, info.name, libName); + return nullptr; + } + + // Store in the function cache + sharedLibraryFunctions[int(type)] = func; + return func; + } + + enum class CheckingPhase { Header, Body -- cgit v1.2.3