diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2022-08-22 17:39:56 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-22 14:39:56 -0700 |
| commit | 6ab0baf910dea838dca2d29557c3361297180a34 (patch) | |
| tree | 4f2a3418f0662c8a61fd1ba9bf1c1d24b77c276b /source/compiler-core/slang-glslang-compiler.cpp | |
| parent | 4bd3e6e02324f913e8927fe69d32c0aafe9fc831 (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-glslang-compiler.cpp')
| -rw-r--r-- | source/compiler-core/slang-glslang-compiler.cpp | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/source/compiler-core/slang-glslang-compiler.cpp b/source/compiler-core/slang-glslang-compiler.cpp index 5ae9419fd..3a96ed69d 100644 --- a/source/compiler-core/slang-glslang-compiler.cpp +++ b/source/compiler-core/slang-glslang-compiler.cpp @@ -15,6 +15,7 @@ #include "../core/slang-char-util.h" #include "slang-artifact-associated-impl.h" +#include "slang-artifact-desc-util.h" #include "slang-include-system.h" #include "slang-source-loc.h" @@ -43,7 +44,8 @@ public: // IDownstreamCompiler virtual SLANG_NO_THROW SlangResult SLANG_MCALL compile(const CompileOptions& options, IArtifact** outResult) SLANG_OVERRIDE; - virtual SLANG_NO_THROW SlangResult SLANG_MCALL disassemble(SlangCompileTarget sourceBlobTarget, const void* blob, size_t blobSize, ISlangBlob** out) SLANG_OVERRIDE; + virtual SLANG_NO_THROW bool SLANG_MCALL canConvert(const ArtifactDesc& from, const ArtifactDesc& to) SLANG_OVERRIDE; + virtual SLANG_NO_THROW SlangResult SLANG_MCALL convert(IArtifact* from, const ArtifactDesc& to, IArtifact** outArtifact) SLANG_OVERRIDE; virtual SLANG_NO_THROW bool SLANG_MCALL isFileBased() SLANG_OVERRIDE { return false; } /// Must be called before use @@ -217,14 +219,22 @@ SlangResult GlslangDownstreamCompiler::compile(const CompileOptions& options, IA return SLANG_OK; } -SlangResult GlslangDownstreamCompiler::disassemble(SlangCompileTarget sourceBlobTarget, const void* blob, size_t blobSize, ISlangBlob** out) +bool GlslangDownstreamCompiler::canConvert(const ArtifactDesc& from, const ArtifactDesc& to) { - // Can only disassemble blobs that are DXBC - if (sourceBlobTarget != SLANG_SPIRV) + // Can only disassemble blobs that are SPIR-V + return ArtifactDescUtil::isDissassembly(from, to) && from.payload == ArtifactPayload::SPIRV; +} + +SlangResult GlslangDownstreamCompiler::convert(IArtifact* from, const ArtifactDesc& to, IArtifact** outArtifact) +{ + if (!canConvert(from->getDesc(), to)) { return SLANG_FAIL; } + ComPtr<ISlangBlob> blob; + SLANG_RETURN_ON_FAIL(from->loadBlob(ArtifactKeep::No, blob.writeRef())); + StringBuilder builder; auto outputFunc = [](void const* data, size_t size, void* userData) @@ -240,16 +250,22 @@ SlangResult GlslangDownstreamCompiler::disassemble(SlangCompileTarget sourceBlob request.sourcePath = nullptr; - request.inputBegin = blob; - request.inputEnd = (char*)blob + blobSize; + char* blobData = (char*)blob->getBufferPointer(); + + request.inputBegin = blobData; + request.inputEnd = blobData + blob->getBufferSize(); request.outputFunc = outputFunc; request.outputUserData = &builder; SLANG_RETURN_ON_FAIL(_invoke(request)); - ComPtr<ISlangBlob> disassemblyBlob = StringUtil::createStringBlob(builder); - *out = disassemblyBlob.detach(); + auto disassemblyBlob = StringBlob::moveCreate(builder); + + auto artifact = ArtifactUtil::createArtifact(to); + artifact->addRepresentationUnknown(disassemblyBlob); + + *outArtifact = artifact.detach(); return SLANG_OK; } |
