From 634f5414f332f904c7db968810b3d6f0ca253959 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Wed, 27 Apr 2022 17:53:21 -0400 Subject: Make artifact an interface (#2195) * #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. * Add ArtifactPayloadInfo. * Small tidy up around artifact. * Split out code to get info about Artifacts into artifact-info.cpp/.h * IArtifact interface and IArtifactInstance interface. * Fix small issues. * Fix compilation warning issue. * Fix missing SLANG_OVERRIDE. * Small fixes to make compilation work on Visual Studio 2022. * Small improvements to Artifact interface/naming. * Added Desc with each element in IArchive to allow more flexibility in usage. * Fix clang warning issue. * Add ArtifactPayload::Diagnostics * More discussion around IArtifact usage. * Re-add slang-artifact.h which was removed during merge. * Fix typo identified in review. --- source/slang/slang-compiler.cpp | 2 +- source/slang/slang-compiler.h | 2 +- source/slang/slang-emit-hlsl.cpp | 1 - source/slang/slang-ir-link.cpp | 4 ++-- source/slang/slang-module-library.cpp | 16 ++++++++++++---- source/slang/slang-module-library.h | 14 ++++++++++++-- source/slang/slang-options.cpp | 20 ++++++++++++++------ source/slang/slang-serialize-ast.cpp | 2 ++ source/slang/slang-serialize-ir.cpp | 1 + source/slang/slang-serialize.cpp | 2 ++ source/slang/slang.cpp | 6 +++--- 11 files changed, 50 insertions(+), 20 deletions(-) (limited to 'source/slang') diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp index edcb6e2d4..4445d9620 100644 --- a/source/slang/slang-compiler.cpp +++ b/source/slang/slang-compiler.cpp @@ -1286,7 +1286,7 @@ void printDiagnosticArg(StringBuilder& sb, CodeGenTarget val) { options.libraryPaths.add(Path::getParentDirectory(Path::getExecutablePath())); // Set up the library artifact - RefPtr artifact = new Artifact(ArtifactDesc::make(ArtifactKind::Library, Artifact::Payload::HostCPU), "slang-rt"); + ComPtr artifact(new Artifact(ArtifactDesc::make(ArtifactKind::Library, Artifact::Payload::HostCPU), "slang-rt")); options.libraries.add(artifact); } } diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h index 74929d7da..d534e986a 100755 --- a/source/slang/slang-compiler.h +++ b/source/slang/slang-compiler.h @@ -1808,7 +1808,7 @@ namespace Slang bool m_useFalcorCustomSharedKeywordSemantics = false; // Modules that have been read in with the -r option - List> m_libModules; + List> m_libModules; void _stopRetainingParentSession() { diff --git a/source/slang/slang-emit-hlsl.cpp b/source/slang/slang-emit-hlsl.cpp index 03566f9df..650012b9f 100644 --- a/source/slang/slang-emit-hlsl.cpp +++ b/source/slang/slang-emit-hlsl.cpp @@ -736,7 +736,6 @@ void HLSLSourceEmitter::emitFuncDecorationImpl(IRDecoration* decoration) auto profile = m_effectiveProfile; const auto family = profile.getFamily(); - const auto stage = profile.getStage(); const auto version = profile.getVersion(); // If it's whole program and it's for a late enough version of shader model diff --git a/source/slang/slang-ir-link.cpp b/source/slang/slang-ir-link.cpp index fd91d81bb..8c1edc032 100644 --- a/source/slang/slang-ir-link.cpp +++ b/source/slang/slang-ir-link.cpp @@ -1391,9 +1391,9 @@ LinkedIR linkIR( { irModules.add(irModule); }); - for (Artifact* artifact : linkage->m_libModules) + for (IArtifact* artifact : linkage->m_libModules) { - ModuleLibrary* library = artifact->findObjectInstance(); + ModuleLibrary* library = (ModuleLibrary*)artifact->findElementObject(ModuleLibrary::getTypeGuid()); if (library) { irModules.addRange(library->m_modules.getBuffer()->readRef(), library->m_modules.getCount()); diff --git a/source/slang/slang-module-library.cpp b/source/slang/slang-module-library.cpp index 76bb85ebb..140be4d64 100644 --- a/source/slang/slang-module-library.cpp +++ b/source/slang/slang-module-library.cpp @@ -13,6 +13,14 @@ namespace Slang { +void* ModuleLibrary::getInterface(const Guid& uuid) +{ + if (uuid == ISlangUnknown::getTypeGuid() || uuid == IArtifactInstance::getTypeGuid()) + { + return static_cast(this); + } + return nullptr; +} SlangResult loadModuleLibrary(const Byte* inBytes, size_t bytesCount, EndToEndCompileRequest* req, RefPtr& outLibrary) { @@ -67,9 +75,9 @@ SlangResult loadModuleLibrary(const Byte* inBytes, size_t bytesCount, EndToEndCo return SLANG_OK; } -SlangResult loadModuleLibrary(ArtifactKeep keep, Artifact* product, EndToEndCompileRequest* req, RefPtr& outLibrary) +SlangResult loadModuleLibrary(ArtifactKeep keep, IArtifact* artifact, EndToEndCompileRequest* req, RefPtr& outLibrary) { - if (auto foundLibrary = product->findObjectInstance()) + if (auto foundLibrary = (ModuleLibrary*)artifact->findElementObject(ModuleLibrary::getTypeGuid())) { outLibrary = foundLibrary; return SLANG_OK; @@ -77,7 +85,7 @@ SlangResult loadModuleLibrary(ArtifactKeep keep, Artifact* product, EndToEndComp // Load the blob ComPtr blob; - SLANG_RETURN_ON_FAIL(product->loadBlob(getIntermediateKeep(keep), blob)); + SLANG_RETURN_ON_FAIL(artifact->loadBlob(getIntermediateKeep(keep), blob.writeRef())); // Load the module RefPtr library; @@ -85,7 +93,7 @@ SlangResult loadModuleLibrary(ArtifactKeep keep, Artifact* product, EndToEndComp if (canKeep(keep)) { - product->add(Artifact::Entry::Style::Artifact, library); + artifact->addElement(artifact->getDesc(), library); } outLibrary = library; diff --git a/source/slang/slang-module-library.h b/source/slang/slang-module-library.h index dc709a684..7b65dad9e 100644 --- a/source/slang/slang-module-library.h +++ b/source/slang/slang-module-library.h @@ -10,18 +10,28 @@ namespace Slang { // Class to hold information serialized in from a -r slang-lib/slang-module -class ModuleLibrary : public RefObject +class ModuleLibrary : public ComObject, public IArtifactInstance { public: + SLANG_COM_OBJECT_IUNKNOWN_ALL + + SLANG_CLASS_GUID(0x2f7412bd, 0x6154, 0x40a9, { 0x89, 0xb3, 0x62, 0xe0, 0x24, 0x17, 0x24, 0xa1 }); + + // IArtifactInstance + virtual SLANG_NO_THROW SlangResult SLANG_MCALL writeToBlob(ISlangBlob** blob) SLANG_OVERRIDE { SLANG_UNUSED(blob); return SLANG_E_NOT_IMPLEMENTED; } + virtual SLANG_NO_THROW void* SLANG_MCALL queryObject(const Guid& classGuid) SLANG_OVERRIDE { return classGuid == getTypeGuid() ? this : nullptr; } + List m_entryPoints; List> m_modules; + + void* getInterface(const Guid& uuid); }; SlangResult loadModuleLibrary(const Byte* inBytes, size_t bytesCount, EndToEndCompileRequest* req, RefPtr& module); // Given a product make available as a module -SlangResult loadModuleLibrary(ArtifactKeep keep, Artifact* artifact, EndToEndCompileRequest* req, RefPtr& module); +SlangResult loadModuleLibrary(ArtifactKeep keep, IArtifact* artifact, EndToEndCompileRequest* req, RefPtr& module); } // namespace Slang diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp index 10980f216..c31006058 100644 --- a/source/slang/slang-options.cpp +++ b/source/slang/slang-options.cpp @@ -26,7 +26,7 @@ namespace Slang { -SlangResult _addLibraryReference(EndToEndCompileRequest* req, Artifact* artifact); +SlangResult _addLibraryReference(EndToEndCompileRequest* req, IArtifact* artifact); struct OptionsParser { @@ -1401,7 +1401,7 @@ struct OptionsParser CommandLineArg referenceModuleName; SLANG_RETURN_ON_FAIL(reader.expectArg(referenceModuleName)); - auto path = referenceModuleName.value; + const auto path = referenceModuleName.value; auto desc = ArtifactInfoUtil::getDescFromPath(path.getUnownedSlice()); @@ -1423,13 +1423,21 @@ struct OptionsParser return SLANG_FAIL; } - const String name = Artifact::getBaseNameFromPath(desc, referenceModuleName.value.getUnownedSlice()); + const String name = ArtifactInfoUtil::getBaseNameFromPath(desc, path.getUnownedSlice()); // Create the artifact - RefPtr artifact = new Artifact(desc, name); + ComPtr artifact(new Artifact(desc, name)); - // Set the path - artifact->setPath(Artifact::PathType::Existing, referenceModuleName.value); + // There is a problem here if I want to reference a library that is a 'system' library or is not directly a file + // In that case the path shouldn't be set and the name should completely define the library. + // Seeing as on all targets the baseName doesn't have an extension, and all library types do + // if the name doesn't have an extension we can assume there is no path to it. + + if (Path::getPathExt(path).getLength() > 0) + { + // Set the path + artifact->setPath(Artifact::PathType::Existing, path.getBuffer()); + } // TODO(JS): We might want to check if the artifact exists. // If the artifact is a CPU (or downstream compiler) library diff --git a/source/slang/slang-serialize-ast.cpp b/source/slang/slang-serialize-ast.cpp index bbd8237d2..31a3f6ac0 100644 --- a/source/slang/slang-serialize-ast.cpp +++ b/source/slang/slang-serialize-ast.cpp @@ -107,6 +107,8 @@ struct ASTFieldAccess const size_t writtenSize = writtenEntry->calcSize(classes); const size_t readSize = readEntry->calcSize(classes); + SLANG_UNUSED(writtenSize); + SLANG_UNUSED(readSize); SLANG_ASSERT(readSize == writtenSize); // Check the payload is the same diff --git a/source/slang/slang-serialize-ir.cpp b/source/slang/slang-serialize-ir.cpp index 0824bd68d..221a97bc8 100644 --- a/source/slang/slang-serialize-ir.cpp +++ b/source/slang/slang-serialize-ir.cpp @@ -852,6 +852,7 @@ Result IRSerialReader::read(const IRSerialData& data, Session* session, SerialSo { const Ser::Inst& srcInst = data.m_insts[i]; const IROp op((IROp)srcInst.m_op); + SLANG_UNUSED(op); IRInst* dstInst = insts[i]; diff --git a/source/slang/slang-serialize.cpp b/source/slang/slang-serialize.cpp index a7074df1c..71ef303b7 100644 --- a/source/slang/slang-serialize.cpp +++ b/source/slang/slang-serialize.cpp @@ -487,6 +487,7 @@ SlangResult SerialWriter::write(Stream* stream) const size_t nextAlignment = SerialInfo::getAlignment(next->info); const size_t alignment = SerialInfo::getAlignment(entry->info); + SLANG_UNUSED(alignment); entry->info = SerialInfo::combineWithNext(entry->info, next->info); @@ -559,6 +560,7 @@ SlangResult SerialWriter::writeIntoContainer(FourCC fourCc, RiffContainer* conta const size_t nextAlignment = SerialInfo::getAlignment(next->info); const size_t alignment = SerialInfo::getAlignment(entry->info); + SLANG_UNUSED(alignment); entry->info = SerialInfo::combineWithNext(entry->info, next->info); diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 83c52c660..985599022 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -4329,7 +4329,7 @@ void EndToEndCompileRequest::setDefaultModuleName(const char* defaultModuleName) frontEndReq->m_defaultModuleName = namePool->getName(defaultModuleName); } -SlangResult _addLibraryReference(EndToEndCompileRequest* req, Artifact* artifact) +SlangResult _addLibraryReference(EndToEndCompileRequest* req, IArtifact* artifact) { auto desc = artifact->getDesc(); @@ -4350,7 +4350,7 @@ SlangResult _addLibraryReference(EndToEndCompileRequest* req, Artifact* artifact // Add to the m_libModules auto linkage = req->getLinkage(); - linkage->m_libModules.add(artifact); + linkage->m_libModules.add(ComPtr(artifact)); return SLANG_OK; } @@ -4366,7 +4366,7 @@ SlangResult EndToEndCompileRequest::addLibraryReference(const void* libData, siz // Create an artifact without any name (as one is not provided) RefPtr artifact = new Artifact(desc, String()); - artifact->add(Artifact::Entry::Style::Artifact, library); + artifact->addElement(desc, library); return _addLibraryReference(this, artifact); } -- cgit v1.2.3