summaryrefslogtreecommitdiff
path: root/source/core/slang-shared-library.h
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2018-11-06 14:28:25 -0500
committerGitHub <noreply@github.com>2018-11-06 14:28:25 -0500
commit1185bd464092f372430cbfaa15a7be4dcaa90752 (patch)
treeb3b68f2d9de00c0845f4912a797f10b27741031f /source/core/slang-shared-library.h
parent453331951b0df2a612f9bc0d68eab2ad786ec5bf (diff)
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.
Diffstat (limited to 'source/core/slang-shared-library.h')
-rw-r--r--source/core/slang-shared-library.h122
1 files changed, 122 insertions, 0 deletions
diff --git a/source/core/slang-shared-library.h b/source/core/slang-shared-library.h
new file mode 100644
index 000000000..62d15b6b4
--- /dev/null
+++ b/source/core/slang-shared-library.h
@@ -0,0 +1,122 @@
+#ifndef SLANG_SHARED_LIBRARY_H_INCLUDED
+#define SLANG_SHARED_LIBRARY_H_INCLUDED
+
+#include "../../slang.h"
+#include "../../slang-com-helper.h"
+#include "../../slang-com-ptr.h"
+
+#include "../core/platform.h"
+#include "../core/common.h"
+#include "../core/dictionary.h"
+
+namespace Slang
+{
+
+/* NOTE! Do not change this enum without making the appropriate changes to DefaultSharedLibraryLoader::s_libraryNames */
+enum class SharedLibraryType
+{
+ Unknown, ///< Unknown compiler
+ Dxc, ///< Dxc compiler
+ Fxc, ///< Fxc compiler
+ Glslang, ///< Slang specific glslang compiler
+ Dxil, ///< Dxil is used with dxc
+ CountOf,
+};
+
+class DefaultSharedLibraryLoader : public ISlangSharedLibraryLoader
+{
+public:
+
+ // ISlangUnknown
+ // override ref counting, as DefaultSharedLibraryLoader is singleton
+ SLANG_IUNKNOWN_QUERY_INTERFACE
+ SLANG_NO_THROW uint32_t SLANG_MCALL addRef() SLANG_OVERRIDE { return 1; }
+ SLANG_NO_THROW uint32_t SLANG_MCALL release() SLANG_OVERRIDE { return 1; }
+
+ // ISlangSharedLibraryLoader
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL loadSharedLibrary(const char* path,
+ ISlangSharedLibrary** sharedLibraryOut) SLANG_OVERRIDE;
+
+ /// Get the singleton
+ static DefaultSharedLibraryLoader* getSingleton() { return &s_singleton; }
+
+ /// Get the type from the name
+ static SharedLibraryType getSharedLibraryTypeFromName(const UnownedStringSlice& name);
+
+ /// Get the name from the type, or nullptr if not known
+ static const char* getSharedLibraryNameFromType(SharedLibraryType type) { return s_libraryNames[int(type)]; }
+
+ /// Make a shared library to it's name
+ static const char* s_libraryNames[int(SharedLibraryType::CountOf)];
+
+private:
+ /// Make so not constructible
+ DefaultSharedLibraryLoader() {}
+ virtual ~DefaultSharedLibraryLoader() {}
+
+ ISlangUnknown* getInterface(const Guid& guid);
+
+ static DefaultSharedLibraryLoader s_singleton;
+};
+
+class DefaultSharedLibrary : public ISlangSharedLibrary, public RefObject
+{
+ public:
+ // ISlangUnknown
+ SLANG_REF_OBJECT_IUNKNOWN_ALL
+
+ // ISlangSharedLibrary
+ virtual SLANG_NO_THROW SlangFuncPtr SLANG_MCALL findFuncByName(char const* name) SLANG_OVERRIDE;
+
+ /// Ctor.
+ DefaultSharedLibrary(const SharedLibrary::Handle sharedLibraryHandle):
+ m_sharedLibraryHandle(sharedLibraryHandle)
+ {
+ SLANG_ASSERT(sharedLibraryHandle);
+ }
+
+ /// Need virtual dtor to keep delete this happy
+ virtual ~DefaultSharedLibrary();
+
+ protected:
+ ISlangUnknown* getInterface(const Guid& guid);
+
+ SharedLibrary::Handle m_sharedLibraryHandle = nullptr;
+};
+
+class ConfigurableSharedLibraryLoader: public ISlangSharedLibraryLoader, public RefObject
+{
+public:
+ typedef Result (*Func)(const char* pathIn, const String& entryString, SharedLibrary::Handle& handleOut);
+
+ // IUnknown
+ SLANG_REF_OBJECT_IUNKNOWN_ALL
+
+ // ISlangSharedLibraryLoader
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL loadSharedLibrary(const char* path, ISlangSharedLibrary** sharedLibraryOut) SLANG_OVERRIDE;
+
+ /// Function to replace the the path with entryString
+ static Result replace(const char* pathIn, const String& entryString, SharedLibrary::Handle& handleOut);
+ /// Function to change the path using the entryStrinct
+ static Result changePath(const char* pathIn, const String& entryString, SharedLibrary::Handle& handleOut);
+
+ void addEntry(const String& libName, Func func, const String& entryString) { m_entryMap.Add(libName, Entry{ func, entryString} ); }
+ void addEntry(SharedLibraryType libType, Func func, const String& entryString) { m_entryMap.Add(DefaultSharedLibraryLoader::getSharedLibraryNameFromType(libType), Entry { func, entryString} ); }
+
+ virtual ~ConfigurableSharedLibraryLoader() {}
+ protected:
+
+ struct Entry
+ {
+ Func func;
+ String entryString;
+ };
+
+ ISlangUnknown* getInterface(const Guid& guid);
+
+ Dictionary<String, Entry> m_entryMap;
+};
+
+}
+
+#endif // SLANG_SHARED_LIBRARY_H_INCLUDED \ No newline at end of file