diff options
Diffstat (limited to 'source/slang')
| -rw-r--r-- | source/slang/slang-check.cpp | 44 | ||||
| -rw-r--r-- | source/slang/slang-compiler.h | 10 | ||||
| -rw-r--r-- | source/slang/slang.cpp | 61 |
3 files changed, 109 insertions, 6 deletions
diff --git a/source/slang/slang-check.cpp b/source/slang/slang-check.cpp index b7c1ccdc2..9a4a01045 100644 --- a/source/slang/slang-check.cpp +++ b/source/slang/slang-check.cpp @@ -5,6 +5,9 @@ #include "slang-visitor.h" #include "../core/slang-secure-crt.h" + +#include "../core/slang-io.h" + #include <assert.h> namespace Slang @@ -323,6 +326,28 @@ namespace Slang } } + static PassThroughMode _toPassThroughMode(SharedLibraryType type) + { + switch (type) + { + case SharedLibraryType::Dxil: + case SharedLibraryType::Dxc: + { + return PassThroughMode::Dxc; + } + case SharedLibraryType::Fxc: return PassThroughMode::Fxc; + case SharedLibraryType::Glslang: return PassThroughMode::Glslang; + default: break; + } + + return PassThroughMode::None; + } + + void Session::setSharedLibrary(SharedLibraryType type, ISlangSharedLibrary* library) + { + sharedLibraries[int(type)] = library; + } + ISlangSharedLibrary* Session::getOrLoadSharedLibrary(SharedLibraryType type, DiagnosticSink* sink) { // If not loaded, try loading it @@ -336,6 +361,15 @@ namespace Slang } const char* libName = DefaultSharedLibraryLoader::getSharedLibraryNameFromType(type); + + StringBuilder builder; + PassThroughMode passThrough = _toPassThroughMode(type); + if (passThrough != PassThroughMode::None && m_passThroughPaths[int(passThrough)].getLength() > 0) + { + Path::combineIntoBuilder(m_passThroughPaths[int(passThrough)].getUnownedSlice(), UnownedStringSlice(libName), builder); + libName = builder.getBuffer(); + } + if (SLANG_FAILED(sharedLibraryLoader->loadSharedLibrary(libName, sharedLibraries[int(type)].writeRef()))) { if (sink) @@ -386,7 +420,15 @@ namespace Slang if (cppCompilerSet == nullptr) { cppCompilerSet = new CPPCompilerSet; - CPPCompilerUtil::initializeSet(cppCompilerSet); + + typedef CPPCompiler::CompilerType CompilerType; + CPPCompilerUtil::InitializeSetDesc desc; + + desc.paths[int(CompilerType::GCC)] = m_passThroughPaths[int(PassThroughMode::Gcc)]; + desc.paths[int(CompilerType::Clang)] = m_passThroughPaths[int(PassThroughMode::Clang)]; + desc.paths[int(CompilerType::VisualStudio)] = m_passThroughPaths[int(PassThroughMode::VisualStudio)]; + + CPPCompilerUtil::initializeSet(desc, cppCompilerSet); } SLANG_ASSERT(cppCompilerSet); return cppCompilerSet; diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h index bbc6505b0..ce01e5ea3 100644 --- a/source/slang/slang-compiler.h +++ b/source/slang/slang-compiler.h @@ -762,9 +762,10 @@ namespace Slang Dxc = SLANG_PASS_THROUGH_DXC, ///< pass through HLSL to `IDxcCompiler` API Glslang = SLANG_PASS_THROUGH_GLSLANG, ///< pass through GLSL to `glslang` library Clang = SLANG_PASS_THROUGH_CLANG, ///< Pass through clang compiler - Gcc = SLANG_PASS_THROUGH_GCC, ///< Gcc compiler VisualStudio = SLANG_PASS_THROUGH_VISUAL_STUDIO, ///< Visual studio compiler + Gcc = SLANG_PASS_THROUGH_GCC, ///< Gcc compiler GenericCCpp = SLANG_PASS_THROUGH_GENERIC_C_CPP, ///< Generic C/C++ compiler + CountOf = SLANG_PASS_THROUGH_COUNT_OF, }; class SourceFile; @@ -1790,6 +1791,9 @@ namespace Slang SLANG_NO_THROW SlangProfileID SLANG_MCALL findProfile( char const* name) override; + SLANG_NO_THROW void SLANG_MCALL setPassThroughPath( + SlangPassThrough passThrough, + char const* path) override; enum class SharedLibraryFuncType @@ -1916,6 +1920,8 @@ namespace Slang /// Will try to load the library by specified name (using the set loader), if not one already available. ISlangSharedLibrary* getOrLoadSharedLibrary(SharedLibraryType 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)]; } @@ -1936,6 +1942,8 @@ namespace Slang private: /// Linkage used for all built-in (stdlib) code. RefPtr<Linkage> m_builtinLinkage; + + String m_passThroughPaths[int(PassThroughMode::CountOf)]; ///< Paths for each pass through }; diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index bb7e705e6..f0570132f 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -146,6 +146,51 @@ SLANG_NO_THROW SlangProfileID SLANG_MCALL Session::findProfile( return Slang::Profile::LookUp(name).raw; } +SLANG_NO_THROW void SLANG_MCALL Session::setPassThroughPath( + SlangPassThrough inPassThrough, + char const* path) +{ + PassThroughMode passThrough = PassThroughMode(inPassThrough); + SLANG_ASSERT(int(passThrough) > int(PassThroughMode::None) && int(passThrough) < int(PassThroughMode::CountOf)); + + if (m_passThroughPaths[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 + cppCompilerSet.setNull(); + break; + } + default: break; + } + + // Set the path + m_passThroughPaths[int(passThrough)] = path; + } +} + struct IncludeHandlerImpl : IncludeHandler { Linkage* linkage; @@ -2446,7 +2491,9 @@ Session::~Session() SLANG_API SlangSession* spCreateSession(const char*) { - return asExternal(new Slang::Session()); + Slang::RefPtr<Slang::Session> session(new Slang::Session()); + // Will be returned with a refcount of 1 + return asExternal(session.detach()); } SLANG_API SlangResult slang_createGlobalSession( @@ -2463,10 +2510,16 @@ SLANG_API SlangResult slang_createGlobalSession( } SLANG_API void spDestroySession( - SlangSession* session) + SlangSession* inSession) { - if(!session) return; - delete Slang::asInternal(session); + if(!inSession) return; + + Slang::Session* session = Slang::asInternal(inSession); + // It is assumed there is only a single reference on the session (the one placed + // with spCreateSession) if this function is called + SLANG_ASSERT(session->debugGetReferenceCount() == 1); + // Release + session->release(); } SLANG_API void spAddBuiltins( |
