summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-module-library.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2022-04-26 12:09:32 -0400
committerGitHub <noreply@github.com>2022-04-26 12:09:32 -0400
commit79dd12c21e8f5c5ce01051a280679cf6ac8ffe97 (patch)
tree705df0ab9047e4418a6218993cd0ddb2a46dffbc /source/slang/slang-module-library.cpp
parent66ad0072821b58318c6dc5d2d64c966e312951dd (diff)
Linking in DXC (#2190)
* #include an absolute path didn't work - because paths were taken to always be relative. * Compile to a dxil library. * Added CompileProduct. * Support handling of ModuleLibrary. * CacheBehavior -> Cache * Use CompileProduct for -r references. * CompileProduct -> Artifact. * Determining an artifact type on binding. * Determine binary linkability. * Added Artifact::exists. * Added ArtifactKeep. * Small fixes. * Small improvements to Artifact. * Add zip extension. * Fix some comments. * Fix multiple adding of PublicDecoration. Make public output export for DXIL/lib. Add checking for simpleDecorations such that only added once. * Use 'whole program' to identify library build. * Move slang-artifact into compiler-core. * Split out Keep free functions. * Artifact::Keep -> ArtifactKeep. * Handle libraries as artifacts. * Add -target dxil so test infrastructure knows it needs DXC. * Linking working in DXC. * Improve handling around emit for 'export'. * Add comment around Artifact name. * Render test working with linking. Co-authored-by: Theresa Foley <10618364+tangent-vector@users.noreply.github.com>
Diffstat (limited to 'source/slang/slang-module-library.cpp')
-rw-r--r--source/slang/slang-module-library.cpp95
1 files changed, 95 insertions, 0 deletions
diff --git a/source/slang/slang-module-library.cpp b/source/slang/slang-module-library.cpp
new file mode 100644
index 000000000..76bb85ebb
--- /dev/null
+++ b/source/slang/slang-module-library.cpp
@@ -0,0 +1,95 @@
+// slang-module-library.cpp
+#include "slang-module-library.h"
+#include <assert.h>
+
+#include "../core/slang-blob.h"
+#include "../core/slang-riff.h"
+
+#include "../core/slang-type-text-util.h"
+
+// Serialization
+#include "slang-serialize-ir.h"
+#include "slang-serialize-container.h"
+
+namespace Slang {
+
+
+SlangResult loadModuleLibrary(const Byte* inBytes, size_t bytesCount, EndToEndCompileRequest* req, RefPtr<ModuleLibrary>& outLibrary)
+{
+ RefPtr<ModuleLibrary> library = new ModuleLibrary;
+
+ // Load up the module
+ MemoryStreamBase memoryStream(FileAccess::Read, inBytes, bytesCount);
+
+ RiffContainer riffContainer;
+ SLANG_RETURN_ON_FAIL(RiffUtil::read(&memoryStream, riffContainer));
+
+ auto linkage = req->getLinkage();
+
+ // TODO(JS): May be better to have a ITypeComponent that encapsulates a collection of modules
+ // For now just add to the linkage
+
+ {
+ SerialContainerData containerData;
+
+ SerialContainerUtil::ReadOptions options;
+ options.namePool = req->getNamePool();
+ options.session = req->getSession();
+ options.sharedASTBuilder = linkage->getASTBuilder()->getSharedASTBuilder();
+ options.sourceManager = linkage->getSourceManager();
+ options.linkage = req->getLinkage();
+ options.sink = req->getSink();
+
+ SLANG_RETURN_ON_FAIL(SerialContainerUtil::read(&riffContainer, options, containerData));
+
+ for (const auto& module : containerData.modules)
+ {
+ // If the irModule is set, add it
+ if (module.irModule)
+ {
+ library->m_modules.add(module.irModule);
+ }
+ }
+
+ for (const auto& entryPoint : containerData.entryPoints)
+ {
+ FrontEndCompileRequest::ExtraEntryPointInfo dst;
+ dst.mangledName = entryPoint.mangledName;
+ dst.name = entryPoint.name;
+ dst.profile = entryPoint.profile;
+
+ // Add entry point
+ library->m_entryPoints.add(dst);
+ }
+ }
+
+ outLibrary = library;
+ return SLANG_OK;
+}
+
+SlangResult loadModuleLibrary(ArtifactKeep keep, Artifact* product, EndToEndCompileRequest* req, RefPtr<ModuleLibrary>& outLibrary)
+{
+ if (auto foundLibrary = product->findObjectInstance<ModuleLibrary>())
+ {
+ outLibrary = foundLibrary;
+ return SLANG_OK;
+ }
+
+ // Load the blob
+ ComPtr<ISlangBlob> blob;
+ SLANG_RETURN_ON_FAIL(product->loadBlob(getIntermediateKeep(keep), blob));
+
+ // Load the module
+ RefPtr<ModuleLibrary> library;
+ SLANG_RETURN_ON_FAIL(loadModuleLibrary((const Byte*)blob->getBufferPointer(), blob->getBufferSize(), req, library));
+
+ if (canKeep(keep))
+ {
+ product->add(Artifact::Entry::Style::Artifact, library);
+ }
+
+ outLibrary = library;
+ return SLANG_OK;
+}
+
+} // namespace Slang