diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2022-04-27 13:51:30 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-27 10:51:30 -0700 |
| commit | 50d5a1021623a89df035a1ef78557e0f1152648d (patch) | |
| tree | 46b859c764dbc6d27a679b32c025f23ee0baaa74 /source/compiler-core/slang-artifact.cpp | |
| parent | f9432467cac85eae6f7120cd94208f3a3dd9aa19 (diff) | |
Split out Artifact info (#2193)
* #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
* Re-add slang-artifact.cpp
* Readd artifact.cpp.
Diffstat (limited to 'source/compiler-core/slang-artifact.cpp')
| -rw-r--r-- | source/compiler-core/slang-artifact.cpp | 220 |
1 files changed, 6 insertions, 214 deletions
diff --git a/source/compiler-core/slang-artifact.cpp b/source/compiler-core/slang-artifact.cpp index 1f11c31df..862e7bb37 100644 --- a/source/compiler-core/slang-artifact.cpp +++ b/source/compiler-core/slang-artifact.cpp @@ -1,73 +1,13 @@ // slang-artifact.cpp #include "slang-artifact.h" +#include "slang-artifact-info.h" + #include "../core/slang-type-text-util.h" #include "../core/slang-io.h" namespace Slang { -namespace { // anonymous -struct KindExtension -{ - ArtifactKind kind; - UnownedStringSlice ext; -}; -} // anonymous - -#define SLANG_KIND_EXTENSION(kind, ext) \ - { ArtifactKind::kind, UnownedStringSlice::fromLiteral(ext) }, - -static const KindExtension g_cpuKindExts[] = -{ -#if SLANG_WINDOWS_FAMILY - SLANG_KIND_EXTENSION(Library, "lib") - SLANG_KIND_EXTENSION(ObjectCode, "obj") - SLANG_KIND_EXTENSION(Executable, "exe") - SLANG_KIND_EXTENSION(SharedLibrary, "dll") -#else - SLANG_KIND_EXTENSION(Library, "a") - SLANG_KIND_EXTENSION(ObjectCode, "o") - SLANG_KIND_EXTENSION(Executable, "") - -#if __CYGWIN__ - SLANG_KIND_EXTENSION(SharedLibrary, "dll") -#elif SLANG_APPLE_FAMILY - SLANG_KIND_EXTENSION(SharedLibrary, "dylib") -#else - SLANG_KIND_EXTENSION(SharedLibrary, "so") -#endif - -#endif -}; - -/* static */ArtifactDesc ArtifactDesc::fromPath(const UnownedStringSlice& slice) -{ - auto extension = Path::getPathExt(slice); - return fromExtension(extension); -} - -/* static */ ArtifactDesc ArtifactDesc::fromExtension(const UnownedStringSlice& slice) -{ - if (slice == "slang-module" || - slice == "slang-lib") - { - return make(ArtifactKind::Library, ArtifactPayload::SlangIR, ArtifactStyle::Unknown); - } - - for (const auto& kindExt : g_cpuKindExts) - { - if (slice == kindExt.ext) - { - // We'll assume it's for the host CPU for now.. - return make(kindExt.kind, Payload::HostCPU, Style::Unknown); - } - } - - const auto target = TypeTextUtil::findCompileTargetFromExtension(slice); - - return makeFromCompileTarget(target); -} - /* static */ArtifactDesc ArtifactDesc::makeFromCompileTarget(SlangCompileTarget target) { switch (target) @@ -104,154 +44,6 @@ static const KindExtension g_cpuKindExts[] = SLANG_UNEXPECTED("Unhandled type"); } -/* static */bool ArtifactDesc::isPayloadGpuBinary(Payload payloadType) -{ - switch (payloadType) - { - case Payload::DXIL: - case Payload::DXBC: - case Payload::SPIRV: - case Payload::PTX: - { - return true; - } - default: break; - } - return false; -} - -/* static */bool ArtifactDesc::isPayloadCpuBinary(Payload payloadType) -{ - switch (payloadType) - { - case Payload::X86: - case Payload::X86_64: - case Payload::AARCH: - case Payload::AARCH64: - case Payload::HostCPU: - { - return true; - } - default: break; - } - return false; -} - -/* static */bool ArtifactDesc::isPayloadGpuBinaryLinkable(Payload payload) -{ - switch (payload) - { - case Payload::DXBC: - { - // It seems as if DXBC is potentially linkable from - // https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-appendix-keywords#export - return true; - } - - case Payload::DXIL: - case Payload::PTX: - case Payload::SPIRV: - { - // We can't *actually* link PTX or SPIR-V currently but it is in principal possible - // so let's say we accept for now - return true; - } - default: break; - } - return false; -} - -bool ArtifactDesc::isBinaryLinkable() const -{ - if (isKindBinaryLinkable(kind)) - { - return isPayloadCpuBinary(payload) || isPayloadGpuBinaryLinkable(payload) || payload == ArtifactPayload::SlangIR; - } - - return false; -} - -/* static */bool ArtifactDesc::isKindBinaryLinkable(Kind kind) -{ - switch (kind) - { - case Kind::Library: - case Kind::ObjectCode: - { - return true; - } - default: break; - } - return false; -} - -/* static*/ UnownedStringSlice ArtifactDesc::getCpuExtensionForKind(Kind kind) -{ - for (const auto& kindExt : g_cpuKindExts) - { - if (kind == kindExt.kind) - { - return kindExt.ext; - } - } - return UnownedStringSlice(); -} - -UnownedStringSlice ArtifactDesc::getDefaultExtension() -{ - if (isPayloadCpuBinary(payload)) - { - return getCpuExtensionForKind(kind); - } - else - { - return getDefaultExtensionForPayload(payload); - } -} - -/* static */UnownedStringSlice ArtifactDesc::getDefaultExtensionForPayload(Payload payload) -{ - switch (payload) - { - case Payload::None: return UnownedStringSlice(); - case Payload::Unknown: return UnownedStringSlice::fromLiteral("unknown"); - - case Payload::DXIL: return UnownedStringSlice::fromLiteral("dxil"); - case Payload::DXBC: return UnownedStringSlice::fromLiteral("dxbc"); - case Payload::SPIRV: return UnownedStringSlice::fromLiteral("spirv"); - - case Payload::PTX: return UnownedStringSlice::fromLiteral("ptx"); - - case Payload::X86: - case Payload::X86_64: - case Payload::AARCH: - case Payload::AARCH64: - case Payload::HostCPU: - { - return UnownedStringSlice(); - } - - case Payload::SlangIR: return UnownedStringSlice::fromLiteral("slang-ir"); - case Payload::LLVMIR: return UnownedStringSlice::fromLiteral("llvm-ir"); - - case Payload::HLSL: return UnownedStringSlice::fromLiteral("hlsl"); - case Payload::GLSL: return UnownedStringSlice::fromLiteral("glsl"); - - case Payload::CPP: return UnownedStringSlice::fromLiteral("cpp"); - case Payload::C: return UnownedStringSlice::fromLiteral("c"); - - case Payload::CUDA: return UnownedStringSlice::fromLiteral("cu"); - - case Payload::Slang: return UnownedStringSlice::fromLiteral("slang"); - - case Payload::Zip: return UnownedStringSlice::fromLiteral("zip"); - - default: break; - } - - SLANG_UNEXPECTED("Unknown content type"); -} - /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Artifact !!!!!!!!!!!!!!!!!!!!!!!!!!! */ Artifact::~Artifact() @@ -372,7 +164,7 @@ ISlangUnknown* Artifact::findInterfaceInstance(const Guid& guid) if (isSharedLibraryPrefixPlatform) { // Strip lib prefix - if (desc.isCpuBinary() && + if (ArtifactInfoUtil::isCpuBinary(desc) && (desc.kind == ArtifactKind::Library || desc.kind == ArtifactKind::SharedLibrary)) { @@ -387,7 +179,7 @@ ISlangUnknown* Artifact::findInterfaceInstance(const Guid& guid) // Strip any extension { - auto descExt = desc.getDefaultExtension(); + auto descExt = ArtifactInfoUtil::getDefaultExtension(desc); // Strip the extension if it's a match if (descExt.getLength() && Path::getPathExt(name) == descExt) @@ -473,7 +265,7 @@ SlangResult Artifact::requireFile(Keep keep) String path; SLANG_RETURN_ON_FAIL(File::generateTemporary(nameBase, path)); - if (m_desc.isCpuBinary() && + if (ArtifactInfoUtil::isCpuBinary(m_desc) && (m_desc.kind == ArtifactKind::SharedLibrary || m_desc.kind == ArtifactKind::Library)) { @@ -500,7 +292,7 @@ SlangResult Artifact::requireFile(Keep keep) // If there is an extension append it - const UnownedStringSlice ext = m_desc.getDefaultExtension(); + const UnownedStringSlice ext = ArtifactInfoUtil::getDefaultExtension(m_desc); if (ext.getLength()) { |
