summaryrefslogtreecommitdiffstats
path: root/source/compiler-core/slang-dxc-compiler.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2022-04-26 12:43:28 -0400
committerGitHub <noreply@github.com>2022-04-26 12:43:28 -0400
commitf9432467cac85eae6f7120cd94208f3a3dd9aa19 (patch)
tree1370c70a0159a1f8dd89cc8c86db930f556bdc5d /source/compiler-core/slang-dxc-compiler.cpp
parent79dd12c21e8f5c5ce01051a280679cf6ac8ffe97 (diff)
Improvements around Artifacts (#2192)
* #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. * Improvements around Artifact handling.
Diffstat (limited to 'source/compiler-core/slang-dxc-compiler.cpp')
-rw-r--r--source/compiler-core/slang-dxc-compiler.cpp92
1 files changed, 38 insertions, 54 deletions
diff --git a/source/compiler-core/slang-dxc-compiler.cpp b/source/compiler-core/slang-dxc-compiler.cpp
index eb26dd3cc..0d05bf724 100644
--- a/source/compiler-core/slang-dxc-compiler.cpp
+++ b/source/compiler-core/slang-dxc-compiler.cpp
@@ -50,51 +50,39 @@ static UnownedStringSlice _getSlice(IDxcBlob* blob) { return StringUtil::getSlic
// 7f61fc7d-950d-467f-b3e3-3c02fb49187c
static const Guid IID_IDxcIncludeHandler = { 0x7f61fc7d, 0x950d, 0x467f, { 0x3c, 0x02, 0xfb, 0x49, 0x18, 0x7c } };
-namespace { // anonymous
-
-class LibraryNameList
+static UnownedStringSlice _addName(const UnownedStringSlice& inSlice, StringSlicePool& pool)
{
-public:
- void addName(Artifact* library)
+ UnownedStringSlice slice = inSlice;
+ if (slice.getLength() == 0)
{
- String name;
- if (library->getPathType() == Artifact::Existing)
- {
- name = Path::getFileNameWithoutExt(library->getPath());
- }
- addName(name);
+ slice = UnownedStringSlice::fromLiteral("unnamed");
}
- void addName(const String& inName)
+
+ StringBuilder buf;
+ const Index length = slice.getLength();
+ buf << slice;
+
+ for (Index i = 0; ; ++i)
{
- String name(inName);
- if (name.getLength() == 0)
+ buf.reduceLength(length);
+
+ if (i > 0)
{
- name = "unnamed";
+ buf << "_" << i;
}
- if (m_names.indexOf(name) >= 0)
+ StringSlicePool::Handle handle;
+ if (!pool.findOrAdd(buf.getUnownedSlice(), handle))
{
- StringBuilder buf;
- for (Index i = 1; ; ++i)
- {
- buf.Clear();
- buf << name << "_" << i;
-
- if (m_names.indexOf(buf) < 0)
- {
- name = buf;
- break;
- }
- }
+ return pool.getSlice(handle);
}
-
- m_names.add(name);
}
+}
- List<String> m_names;
-};
-
-} // anonymous
+static UnownedStringSlice _addName(Artifact* artifact, StringSlicePool& pool)
+{
+ return _addName(artifact->getBaseName().getUnownedSlice(), pool);
+}
class DxcIncludeHandler : public IDxcIncludeHandler
{
@@ -469,9 +457,10 @@ SlangResult DXCDownstreamCompiler::compile(const CompileOptions& options, RefPtr
ComPtr<IDxcLinker> linker;
SLANG_RETURN_ON_FAIL(m_createInstance(CLSID_DxcLinker, __uuidof(linker), (void**)linker.writeRef()));
- List<ComPtr<ISlangBlob>> libraryBlobs;
+ StringSlicePool pool(StringSlicePool::Style::Default);
- LibraryNameList libraryNames;
+ List<ComPtr<ISlangBlob>> libraryBlobs;
+ List<OSString> libraryNames;
for (Artifact* library : libraries)
{
@@ -479,42 +468,37 @@ SlangResult DXCDownstreamCompiler::compile(const CompileOptions& options, RefPtr
SLANG_RETURN_ON_FAIL(library->loadBlob(ArtifactKeep::Yes, blob));
libraryBlobs.add(blob);
- libraryNames.addName(library);
+ libraryNames.add(String(_addName(library, pool)).toWString());
}
// Add the compiled blob name
-
- {
- auto blob = (ISlangBlob*)dxcResultBlob.get();
- libraryBlobs.add(ComPtr<ISlangBlob>(blob));
- }
-
+ String name;
if (options.modulePath.getLength())
{
- libraryNames.addName(Path::getFileNameWithoutExt(options.modulePath));
+ name = Path::getFileNameWithoutExt(options.modulePath);
}
else if (options.sourceContentsPath.getLength())
{
- libraryNames.addName(Path::getFileNameWithoutExt(options.sourceContentsPath));
+ name = Path::getFileNameWithoutExt(options.sourceContentsPath);
}
- else
+
+ // Add the blob with name
{
- libraryNames.addName("");
+ auto blob = (ISlangBlob*)dxcResultBlob.get();
+ libraryBlobs.add(ComPtr<ISlangBlob>(blob));
+ libraryNames.add(String(_addName(name.getUnownedSlice(), pool)).toWString());
}
- const Index librariesCount = libraryNames.m_names.getCount();
+ const Index librariesCount = libraryNames.getCount();
SLANG_ASSERT(libraryBlobs.getCount() == librariesCount);
List<const wchar_t*> linkLibraryNames;
- List<OSString> wideLibraryNames;
-
+
linkLibraryNames.setCount(librariesCount);
- wideLibraryNames.setCount(librariesCount);
-
+
for (Index i = 0; i < librariesCount; ++i)
{
- wideLibraryNames[i] = libraryNames.m_names[i].toWString();
- linkLibraryNames[i] = wideLibraryNames[i].begin();
+ linkLibraryNames[i] = libraryNames[i].begin();
// Register the library
SLANG_RETURN_ON_FAIL(linker->RegisterLibrary(linkLibraryNames[i], (IDxcBlob*)libraryBlobs[i].get()));