summaryrefslogtreecommitdiffstats
path: root/source/slang
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/slang
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/slang')
-rw-r--r--source/slang/slang-artifact-output-util.cpp58
-rw-r--r--source/slang/slang-artifact-output-util.h2
-rw-r--r--source/slang/slang-diagnostic-defs.h1
3 files changed, 22 insertions, 39 deletions
diff --git a/source/slang/slang-artifact-output-util.cpp b/source/slang/slang-artifact-output-util.cpp
index ccf49ed30..ac4138020 100644
--- a/source/slang/slang-artifact-output-util.cpp
+++ b/source/slang/slang-artifact-output-util.cpp
@@ -17,32 +17,28 @@
namespace Slang
{
-// Given a desc returns a codegen target if it can be used for disassembly
-// Returns Unknown if cannot be used for generating disassembly
-//
-// NOTE! This returns the code gen target for the input binary, *not* the dissassembly output
-static CodeGenTarget _getDisassemblyCodeGenTarget(const ArtifactDesc& desc)
-{
- switch (desc.payload)
- {
- case ArtifactPayload::DXIL: return CodeGenTarget::DXIL;
- case ArtifactPayload::DXBC: return CodeGenTarget::DXBytecode;
- case ArtifactPayload::SPIRV: return CodeGenTarget::SPIRV;
- default: break;
- }
- return CodeGenTarget::Unknown;
-}
-
/* static */SlangResult ArtifactOutputUtil::dissassembleWithDownstream(Session* session, IArtifact* artifact, DiagnosticSink* sink, IArtifact** outArtifact)
{
auto desc = artifact->getDesc();
+ auto assemblyDesc = desc;
+ assemblyDesc.kind = ArtifactKind::Assembly;
+
+ // Check it seems like a plausbile disassembly
+ if (!ArtifactDescUtil::isDissassembly(desc, assemblyDesc))
+ {
+ if (sink)
+ {
+ sink->diagnose(SourceLoc(), Diagnostics::cannotDisassemble, ArtifactDescUtil::getText(desc));
+ }
+ return SLANG_FAIL;
+ }
// Get the downstream compiler that can be used for this target
// TODO(JS):
// This could perhaps be performed in some other manner if there was more than one way to produce
// disassembly from a binary.
- const CodeGenTarget target = _getDisassemblyCodeGenTarget(desc);
+ const CodeGenTarget target = (CodeGenTarget)ArtifactDescUtil::getCompileTargetFromDesc(desc);
if (target == CodeGenTarget::Unknown)
{
return SLANG_FAIL;
@@ -63,40 +59,26 @@ static CodeGenTarget _getDisassemblyCodeGenTarget(const ArtifactDesc& desc)
return SLANG_FAIL;
}
- ComPtr<ISlangBlob> blob;
- SLANG_RETURN_ON_FAIL(artifact->loadBlob(ArtifactKeep::No, blob.writeRef()));
-
- const auto data = blob->getBufferPointer();
- const auto dataSizeInBytes = blob->getBufferSize();
-
- ComPtr<ISlangBlob> dissassemblyBlob;
- SLANG_RETURN_ON_FAIL(compiler->disassemble(SlangCompileTarget(target), data, dataSizeInBytes, dissassemblyBlob.writeRef()));
+ SLANG_RETURN_ON_FAIL(compiler->convert(artifact, assemblyDesc, outArtifact));
- ArtifactDesc disassemblyDesc(desc);
- disassemblyDesc.kind = ArtifactKind::Assembly;
-
- auto disassemblyArtifact = ArtifactUtil::createArtifact(disassemblyDesc);
- disassemblyArtifact->addRepresentationUnknown(dissassemblyBlob);
-
- *outArtifact = disassemblyArtifact.detach();
return SLANG_OK;
}
SlangResult ArtifactOutputUtil::maybeDisassemble(Session* session, IArtifact* artifact, DiagnosticSink* sink, ComPtr<IArtifact>& outArtifact)
{
const auto desc = artifact->getDesc();
- if (ArtifactDescUtil::isText(artifact->getDesc()))
+ if (ArtifactDescUtil::isText(desc))
{
// Nothing to convert
return SLANG_OK;
}
- if (_getDisassemblyCodeGenTarget(desc) != CodeGenTarget::Unknown)
- {
- // Get the blob
- ComPtr<ISlangBlob> blob;
- SLANG_RETURN_ON_FAIL(artifact->loadBlob(ArtifactKeep::No, blob.writeRef()));
+ auto toDesc = desc;
+ toDesc.kind = ArtifactKind::Assembly;
+ // If this likes a playsible disassebly conversion
+ if (ArtifactDescUtil::isDissassembly(desc, toDesc))
+ {
ComPtr<IArtifact> disassemblyArtifact;
if (SLANG_SUCCEEDED(dissassembleWithDownstream(session, artifact, sink, disassemblyArtifact.writeRef())))
diff --git a/source/slang/slang-artifact-output-util.h b/source/slang/slang-artifact-output-util.h
index 948b3ce7a..3c8b2cfc7 100644
--- a/source/slang/slang-artifact-output-util.h
+++ b/source/slang/slang-artifact-output-util.h
@@ -18,7 +18,7 @@ struct ArtifactOutputUtil
/// Attempts to disassembly artifact into outArtifact.
/// Errors are output to sink if set. If not desired pass nullptr
static SlangResult dissassembleWithDownstream(Session* session, IArtifact* artifact, DiagnosticSink* sink, IArtifact** outArtifact);
-
+
/// Disassembles if that is plausible
/// Errors are output to sink if set. If not desired pass nullptr
static SlangResult maybeDisassemble(Session* session, IArtifact* artifact, DiagnosticSink* sink, ComPtr<IArtifact>& outArtifact);
diff --git a/source/slang/slang-diagnostic-defs.h b/source/slang/slang-diagnostic-defs.h
index 811359d71..14be426d6 100644
--- a/source/slang/slang-diagnostic-defs.h
+++ b/source/slang/slang-diagnostic-defs.h
@@ -596,6 +596,7 @@ DIAGNOSTIC(52000, Error, multiLevelBreakUnsupported, "control flow appears to re
DIAGNOSTIC(52001, Warning, dxilNotFound, "dxil shared library not found, so 'dxc' output cannot be signed! Shader code will not be runnable in non-development environments.")
DIAGNOSTIC(52002, Error, passThroughCompilerNotFound, "could not find a suitable pass-through compiler for '$0'.")
+DIAGNOSTIC(52003, Error, cannotDisassemble, "cannot disassemble '$0'.")
DIAGNOSTIC(52004, Error, unableToWriteFile, "unable to write file '$0'")
DIAGNOSTIC(52005, Error, unableToReadFile, "unable to read file '$0'")