summaryrefslogtreecommitdiff
path: root/source/compiler-core/slang-artifact-desc-util.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2022-08-22 17:39:56 -0400
committerGitHub <noreply@github.com>2022-08-22 14:39:56 -0700
commit6ab0baf910dea838dca2d29557c3361297180a34 (patch)
tree4f2a3418f0662c8a61fd1ba9bf1c1d24b77c276b /source/compiler-core/slang-artifact-desc-util.cpp
parent4bd3e6e02324f913e8927fe69d32c0aafe9fc831 (diff)
Improve binary compatibility for DownstreamCompiler types (#2371)
* #include an absolute path didn't work - because paths were taken to always be relative. * WIP replacing DownstreamCompileResult. * First attempt at replacing DownstreamCompileResult with IArtifact and associated types. * Small renaming around CharSlice. * ICastable -> ISlangCastable Added IClonable Fix issue with cloning in ArtifactDiagnostics. * Only add the blob if one is defined in DXC. * Guard adding blob representation. * Make cloneInterface available across code base. Set enums backing type for ArtifactDiagnostic. * Added ::create for ArtifactDiagnostics. * Use SemanticVersion for DownstreamCompilerDesc. Set sizes for enum types. * Depreciate old incompatible CompileOptions. Change SemanticVersion use 32 bits for the patch. * Split out CastableUtil. * Change IDownstreamCompiler to use canConvert and convert to use artifact types. * Fix typos. * Fix typo bug. Allow trafficing in PTX assembly/binaries * struct DownstreamCompilerBaseUtil -> struct DownstreamCompilerUtilBase Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'source/compiler-core/slang-artifact-desc-util.cpp')
-rw-r--r--source/compiler-core/slang-artifact-desc-util.cpp111
1 files changed, 111 insertions, 0 deletions
diff --git a/source/compiler-core/slang-artifact-desc-util.cpp b/source/compiler-core/slang-artifact-desc-util.cpp
index 490020a27..4681b60f4 100644
--- a/source/compiler-core/slang-artifact-desc-util.cpp
+++ b/source/compiler-core/slang-artifact-desc-util.cpp
@@ -279,6 +279,68 @@ SLANG_HIERARCHICAL_ENUM(ArtifactStyle, SLANG_ARTIFACT_STYLE, SLANG_ARTIFACT_STYL
SLANG_UNEXPECTED("Unhandled type");
}
+/* static */SlangCompileTarget ArtifactDescUtil::getCompileTargetFromDesc(const ArtifactDesc& desc)
+{
+ switch (desc.kind)
+ {
+ case ArtifactKind::None: return SLANG_TARGET_NONE;
+ case ArtifactKind::Source:
+ {
+ switch (desc.payload)
+ {
+ case Payload::HLSL: return SLANG_HLSL;
+ case Payload::GLSL: return SLANG_GLSL;
+ case Payload::C: return SLANG_C_SOURCE;
+ case Payload::Cpp: return (desc.style == Style::Host) ? SLANG_HOST_CPP_SOURCE : SLANG_CPP_SOURCE;
+ case Payload::CUDA: return SLANG_CUDA_SOURCE;
+ default: break;
+ }
+ break;
+ }
+ case ArtifactKind::Assembly:
+ {
+ switch (desc.payload)
+ {
+ case Payload::SPIRV: return SLANG_SPIRV_ASM;
+ case Payload::DXIL: return SLANG_DXIL_ASM;
+ case Payload::DXBC: return SLANG_DXBC_ASM;
+ case Payload::PTX: return SLANG_PTX;
+ default: break;
+ }
+ }
+ default: break;
+ }
+
+ if (isDerivedFrom(desc.kind, ArtifactKind::BinaryLike))
+ {
+ if (isDerivedFrom(desc.payload, ArtifactPayload::CPULike))
+ {
+ switch (desc.kind)
+ {
+ case Kind::Executable: return SLANG_HOST_EXECUTABLE;
+ case Kind::SharedLibrary: return SLANG_SHADER_SHARED_LIBRARY;
+ case Kind::HostCallable: return desc.style == ArtifactStyle::Host ? SLANG_HOST_HOST_CALLABLE : SLANG_SHADER_HOST_CALLABLE;
+ case Kind::ObjectCode: return SLANG_OBJECT_CODE;
+ default: break;
+ }
+ }
+ else
+ {
+ switch (desc.payload)
+ {
+ case Payload::SPIRV: return SLANG_SPIRV;
+ case Payload::DXIL: return SLANG_DXIL;
+ case Payload::DXBC: return SLANG_DXBC;
+ case Payload::PTX: return SLANG_PTX;
+ default: break;
+ }
+ }
+ }
+
+ return SLANG_TARGET_UNKNOWN;
+}
+
+
namespace { // anonymous
struct KindExtension
{
@@ -699,4 +761,53 @@ SlangResult ArtifactDescUtil::appendDefaultExtension(const ArtifactDesc& desc, S
}
}
+/* static */bool ArtifactDescUtil::isDissassembly(const ArtifactDesc& from, const ArtifactDesc& to)
+{
+ // From must be a binary like type
+ if (!isDerivedFrom(from.kind, ArtifactKind::BinaryLike))
+ {
+ return false;
+ }
+
+
+ // Target must be assembly, and the payload be the same type
+ if (!(to.kind == ArtifactKind::Assembly &&
+ to.payload == from.payload))
+ {
+ return false;
+ }
+
+ const auto payload = from.payload;
+
+ // Check the payload seems like something plausible to 'disassemble'
+ if (!(isDerivedFrom(payload, ArtifactPayload::KernelLike) ||
+ isDerivedFrom(payload, ArtifactPayload::CPULike) ||
+ isDerivedFrom(payload, ArtifactPayload::GeneralIR)))
+ {
+ return false;
+ }
+
+ // If the flags or style are different, then it's something more than just disassembly
+ if (!(from.style == to.style &&
+ from.flags == to.flags))
+ {
+ return false;
+ }
+
+ return true;
+}
+
+/* static */void ArtifactDescUtil::appendText(const ArtifactDesc& desc, StringBuilder& out)
+{
+ out << getName(desc.kind) << "/" << getName(desc.payload) << "/" << getName(desc.style);
+ // TODO(JS): Output flags? None currently used
+}
+
+/* static */String ArtifactDescUtil::getText(const ArtifactDesc& desc)
+{
+ StringBuilder buf;
+ appendText(desc, buf);
+ return buf;
+}
+
} // namespace Slang