From 15335549340c54fd7b89b28104ddc907e9c64638 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Thu, 12 Dec 2019 14:53:44 -0500 Subject: 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. --- source/core/slang-shared-library.cpp | 78 ++++++------------------------------ 1 file changed, 13 insertions(+), 65 deletions(-) (limited to 'source/core/slang-shared-library.cpp') diff --git a/source/core/slang-shared-library.cpp b/source/core/slang-shared-library.cpp index 2b18ad6aa..b09f345c7 100644 --- a/source/core/slang-shared-library.cpp +++ b/source/core/slang-shared-library.cpp @@ -15,31 +15,8 @@ static const Guid IID_ISlangSharedLibraryLoader = SLANG_UUID_ISlangSharedLibrary /* !!!!!!!!!!!!!!!!!!!!!!!!!! DefaultSharedLibraryLoader !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ -/* static */const char* DefaultSharedLibraryLoader::s_libraryNames[int(SharedLibraryType::CountOf)] = -{ - nullptr, // SharedLibraryType::Unknown - "dxcompiler", // SharedLibraryType::Dxc - "d3dcompiler_47", // SharedLibraryType::Fxc - "slang-glslang", // SharedLibraryType::Glslang - "dxil", // SharedLibraryType::Dxil - "nvrtc64_102_0", // SharedLibraryType::NVRTC -}; - /* static */DefaultSharedLibraryLoader DefaultSharedLibraryLoader::s_singleton; -/* static */SharedLibraryType DefaultSharedLibraryLoader::getSharedLibraryTypeFromName(const UnownedStringSlice& name) -{ - // Start from 1 to skip Unknown - for (int i = 1; i < SLANG_COUNT_OF(s_libraryNames); ++i) - { - if (name == s_libraryNames[i]) - { - return SharedLibraryType(i); - } - } - return SharedLibraryType::Unknown; -} - ISlangUnknown* DefaultSharedLibraryLoader::getInterface(const Guid& guid) { return (guid == IID_ISlangUnknown || guid == IID_ISlangSharedLibraryLoader) ? static_cast(this) : nullptr; @@ -65,6 +42,19 @@ SlangResult DefaultSharedLibraryLoader::loadPlatformSharedLibrary(const char* pa return SLANG_OK; } +/* static */SlangResult DefaultSharedLibraryLoader::load(ISlangSharedLibraryLoader* loader, const String& path, const String& name, ISlangSharedLibrary** outLibrary) +{ + if (path.getLength()) + { + String combinedPath = Path::combine(path, name); + return loader->loadSharedLibrary(combinedPath.getBuffer(), outLibrary); + } + else + { + return loader->loadSharedLibrary(name.getBuffer(), outLibrary); + } +} + /* !!!!!!!!!!!!!!!!!!!!!!!!!! DefaultSharedLibrary !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ TemporarySharedLibrary::~TemporarySharedLibrary() @@ -97,46 +87,4 @@ SlangFuncPtr DefaultSharedLibrary::findFuncByName(char const* name) return SharedLibrary::findFuncByName(m_sharedLibraryHandle, name); } -/* !!!!!!!!!!!!!!!!!!!!!!!!!! ConfigurableSharedLibraryLoader !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ - -ISlangUnknown* ConfigurableSharedLibraryLoader::getInterface(const Guid& guid) -{ - return (guid == IID_ISlangUnknown || guid == IID_ISlangSharedLibraryLoader) ? static_cast(this) : nullptr; -} - -SlangResult ConfigurableSharedLibraryLoader::loadSharedLibrary(const char* path, ISlangSharedLibrary** sharedLibraryOut) -{ - Entry* entry = m_entryMap.TryGetValue(String(path)); - if (entry) - { - SharedLibrary::Handle handle; - SLANG_RETURN_ON_FAIL(entry->func(path, entry->entryString, handle)); - SLANG_ASSERT(handle); - - ComPtr sharedLib(new DefaultSharedLibrary(handle)); - *sharedLibraryOut = sharedLib.detach(); - return SLANG_OK; - } - - return DefaultSharedLibraryLoader::getSingleton()->loadSharedLibrary(path, sharedLibraryOut); -} - -/* static */Result ConfigurableSharedLibraryLoader::replace(const char* pathIn, const String& entryString, SharedLibrary::Handle& handleOut) -{ - SLANG_UNUSED(pathIn); - // The replacement is the *whole* string - return SharedLibrary::loadWithPlatformPath(entryString.begin(), handleOut); -} - -/* static */Result ConfigurableSharedLibraryLoader::changePath(const char* pathIn, const String& entryString, SharedLibrary::Handle& handleOut ) -{ - // Okay we need to reconstruct the name and insert the path - StringBuilder builder; - SharedLibrary::appendPlatformFileName(UnownedStringSlice(pathIn), builder); - String path = Path::combine(entryString, builder); - - return SharedLibrary::loadWithPlatformPath(path.begin(), handleOut); -} - - } -- cgit v1.2.3