diff options
| -rw-r--r-- | build/visual-studio/compiler-core/compiler-core.vcxproj | 2 | ||||
| -rw-r--r-- | build/visual-studio/compiler-core/compiler-core.vcxproj.filters | 6 | ||||
| -rw-r--r-- | slang.h | 1 | ||||
| -rw-r--r-- | source/compiler-core/slang-downstream-compiler-util.cpp | 2 | ||||
| -rw-r--r-- | source/compiler-core/slang-spirv-dis-compiler.cpp | 88 | ||||
| -rw-r--r-- | source/compiler-core/slang-spirv-dis-compiler.h | 26 | ||||
| -rw-r--r-- | source/core/slang-type-text-util.cpp | 1 | ||||
| -rwxr-xr-x | source/slang/slang-compiler.h | 9 | ||||
| -rw-r--r-- | tests/diagnostics/command-line/x-arg-tool-unknown.slang.expected | 2 |
9 files changed, 132 insertions, 5 deletions
diff --git a/build/visual-studio/compiler-core/compiler-core.vcxproj b/build/visual-studio/compiler-core/compiler-core.vcxproj index 7cfa0fa16..cc3ac06da 100644 --- a/build/visual-studio/compiler-core/compiler-core.vcxproj +++ b/build/visual-studio/compiler-core/compiler-core.vcxproj @@ -310,6 +310,7 @@ <ClInclude Include="..\..\..\source\compiler-core\slang-source-embed-util.h" />
<ClInclude Include="..\..\..\source\compiler-core\slang-source-loc.h" />
<ClInclude Include="..\..\..\source\compiler-core\slang-source-map.h" />
+ <ClInclude Include="..\..\..\source\compiler-core\slang-spirv-dis-compiler.h" />
<ClInclude Include="..\..\..\source\compiler-core\slang-test-server-protocol.h" />
<ClInclude Include="..\..\..\source\compiler-core\slang-token-defs.h" />
<ClInclude Include="..\..\..\source\compiler-core\slang-token.h" />
@@ -356,6 +357,7 @@ <ClCompile Include="..\..\..\source\compiler-core\slang-source-embed-util.cpp" />
<ClCompile Include="..\..\..\source\compiler-core\slang-source-loc.cpp" />
<ClCompile Include="..\..\..\source\compiler-core\slang-source-map.cpp" />
+ <ClCompile Include="..\..\..\source\compiler-core\slang-spirv-dis-compiler.cpp" />
<ClCompile Include="..\..\..\source\compiler-core\slang-test-server-protocol.cpp" />
<ClCompile Include="..\..\..\source\compiler-core\slang-token.cpp" />
<ClCompile Include="..\..\..\source\compiler-core\slang-visual-studio-compiler-util.cpp" />
diff --git a/build/visual-studio/compiler-core/compiler-core.vcxproj.filters b/build/visual-studio/compiler-core/compiler-core.vcxproj.filters index 57fd7525f..c4d2737b2 100644 --- a/build/visual-studio/compiler-core/compiler-core.vcxproj.filters +++ b/build/visual-studio/compiler-core/compiler-core.vcxproj.filters @@ -144,6 +144,9 @@ <ClInclude Include="..\..\..\source\compiler-core\slang-source-map.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="..\..\..\source\compiler-core\slang-spirv-dis-compiler.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
<ClInclude Include="..\..\..\source\compiler-core\slang-test-server-protocol.h">
<Filter>Header Files</Filter>
</ClInclude>
@@ -278,6 +281,9 @@ <ClCompile Include="..\..\..\source\compiler-core\slang-source-map.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="..\..\..\source\compiler-core\slang-spirv-dis-compiler.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
<ClCompile Include="..\..\..\source\compiler-core\slang-test-server-protocol.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@@ -634,6 +634,7 @@ extern "C" SLANG_PASS_THROUGH_FXC, SLANG_PASS_THROUGH_DXC, SLANG_PASS_THROUGH_GLSLANG, + SLANG_PASS_THROUGH_SPIRV_DIS, SLANG_PASS_THROUGH_CLANG, ///< Clang C/C++ compiler SLANG_PASS_THROUGH_VISUAL_STUDIO, ///< Visual studio C/C++ compiler SLANG_PASS_THROUGH_GCC, ///< GCC C/C++ compiler diff --git a/source/compiler-core/slang-downstream-compiler-util.cpp b/source/compiler-core/slang-downstream-compiler-util.cpp index d00c3fecb..44d750be8 100644 --- a/source/compiler-core/slang-downstream-compiler-util.cpp +++ b/source/compiler-core/slang-downstream-compiler-util.cpp @@ -23,6 +23,7 @@ #include "slang-dxc-compiler.h" #include "slang-glslang-compiler.h" #include "slang-llvm-compiler.h" +#include "slang-spirv-dis-compiler.h" namespace Slang { @@ -327,6 +328,7 @@ DownstreamCompilerMatchVersion DownstreamCompilerUtil::getCompiledVersion() outFuncs[int(SLANG_PASS_THROUGH_FXC)] = &FXCDownstreamCompilerUtil::locateCompilers; outFuncs[int(SLANG_PASS_THROUGH_GLSLANG)] = &GlslangDownstreamCompilerUtil::locateCompilers; outFuncs[int(SLANG_PASS_THROUGH_LLVM)] = &LLVMDownstreamCompilerUtil::locateCompilers; + outFuncs[int(SLANG_PASS_THROUGH_SPIRV_DIS)] = &SPIRVDisDownstreamCompilerUtil::locateCompilers; } static String _getParentPath(const String& path) diff --git a/source/compiler-core/slang-spirv-dis-compiler.cpp b/source/compiler-core/slang-spirv-dis-compiler.cpp new file mode 100644 index 000000000..04e5c8e4a --- /dev/null +++ b/source/compiler-core/slang-spirv-dis-compiler.cpp @@ -0,0 +1,88 @@ +#include "slang-spirv-dis-compiler.h" + +#include "../core/slang-common.h" +#include "slang-artifact-representation.h" +#include "slang-artifact-util.h" + +namespace Slang +{ + +SlangResult SPIRVDisDownstreamCompilerUtil::locateCompilers( + const String&, + ISlangSharedLibraryLoader*, + DownstreamCompilerSet* set) +{ + // TODO: We could check that the compiler is actually present in PATH (or + // explicitly given) + + ComPtr<IDownstreamCompiler> com( + new SPIRVDisDownstreamCompiler(DownstreamCompilerDesc(SLANG_PASS_THROUGH_SPIRV_DIS))); + set->addCompiler(com); + + return SLANG_OK; +} + +SlangResult SLANG_MCALL SPIRVDisDownstreamCompiler::convert( + IArtifact* from, + const ArtifactDesc& to, + IArtifact** outArtifact) noexcept +{ + const auto& fromDesc = from->getDesc(); + if(to.kind != ArtifactKind::Assembly || + to.payload != ArtifactPayload::SPIRV || + to.flags != 0 || + fromDesc.kind != ArtifactKind::Executable || + fromDesc.payload != ArtifactPayload::SPIRV || + fromDesc.flags != 0) + return SLANG_E_INVALID_ARG; + + ISlangBlob* fromBlob; + SLANG_RETURN_ON_FAIL(from->loadBlob(ArtifactKeep::No, &fromBlob)); + + // Set up our process + CommandLine commandLine; + commandLine.m_executableLocation.setName("spirv-dis"); + RefPtr<Process> p; + SLANG_RETURN_ON_FAIL(Process::create(commandLine, 0, p)); + const auto in = p->getStream(StdStreamType::In); + const auto out = p->getStream(StdStreamType::Out); + const auto err = p->getStream(StdStreamType::ErrorOut); + + // Write the assembly + SLANG_RETURN_ON_FAIL(in->write(fromBlob->getBufferPointer(), fromBlob->getBufferSize())); + in->close(); + + // Wait for it to finish + if(!p->waitForTermination(1000)) + return SLANG_FAIL; + + // TODO: allow inheriting stderr in Process + List<Byte> errData; + SLANG_RETURN_ON_FAIL(StreamUtil::readAll(err, 0, errData)); + fwrite(errData.getBuffer(), errData.getCount(), 1, stderr); + + const auto ret = p->getReturnValue(); + if(ret != 0) + return SLANG_FAIL; + + // Read the disassembly + List<Byte> outData; + SLANG_RETURN_ON_FAIL(StreamUtil::readAll(out, 0, outData)); + + // Wobble it into an artifact + ComPtr<ISlangBlob> outBlob = RawBlob::create(outData.getBuffer(), outData.getCount()); + auto artifact = ArtifactUtil::createArtifact(to); + artifact->addRepresentationUnknown(outBlob.detach()); + *outArtifact = artifact.detach(); + + return SLANG_OK; +} + +SlangResult SLANG_MCALL SPIRVDisDownstreamCompiler::compile( + const CompileOptions&, + IArtifact**) noexcept +{ + SLANG_UNIMPLEMENTED_X(__func__); +} + +} diff --git a/source/compiler-core/slang-spirv-dis-compiler.h b/source/compiler-core/slang-spirv-dis-compiler.h new file mode 100644 index 000000000..fb01627cd --- /dev/null +++ b/source/compiler-core/slang-spirv-dis-compiler.h @@ -0,0 +1,26 @@ +#pragma once + +#include "slang-downstream-compiler-util.h" + +#include "../core/slang-platform.h" + +namespace Slang +{ + +struct SPIRVDisDownstreamCompilerUtil +{ + static SlangResult locateCompilers(const String& path, ISlangSharedLibraryLoader* loader, DownstreamCompilerSet* set); +}; + +class SPIRVDisDownstreamCompiler : public DownstreamCompilerBase +{ +public: + SPIRVDisDownstreamCompiler(const Desc& desc) : DownstreamCompilerBase(desc) {} + + virtual SlangResult SLANG_MCALL convert(IArtifact* from, const ArtifactDesc& to, IArtifact** outArtifact) noexcept override; + + virtual bool SLANG_MCALL isFileBased() noexcept override { return true; } + virtual SlangResult SLANG_MCALL compile(const CompileOptions& options, IArtifact** outArtifact) noexcept override; +}; + +} diff --git a/source/core/slang-type-text-util.cpp b/source/core/slang-type-text-util.cpp index 6743800b3..2196fbaa8 100644 --- a/source/core/slang-type-text-util.cpp +++ b/source/core/slang-type-text-util.cpp @@ -79,6 +79,7 @@ static const NamesDescriptionValue s_compilerInfos[] = { SLANG_PASS_THROUGH_FXC, "fxc", "FXC HLSL compiler" }, { SLANG_PASS_THROUGH_DXC, "dxc", "DXC HLSL compiler" }, { SLANG_PASS_THROUGH_GLSLANG, "glslang", "GLSLANG GLSL compiler" }, + { SLANG_PASS_THROUGH_SPIRV_DIS, "spirv-dis", "spirv-tools SPIRV disassembler" }, { SLANG_PASS_THROUGH_VISUAL_STUDIO, "visualstudio,vs", "Visual Studio C/C++ compiler" }, { SLANG_PASS_THROUGH_CLANG, "clang", "Clang C/C++ compiler" }, { SLANG_PASS_THROUGH_GCC, "gcc", "GCC C/C++ compiler" }, diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h index 79f6b6ed4..96456478d 100755 --- a/source/slang/slang-compiler.h +++ b/source/slang/slang-compiler.h @@ -1182,10 +1182,11 @@ namespace Slang enum class PassThroughMode : SlangPassThroughIntegral { - None = SLANG_PASS_THROUGH_NONE, ///< don't pass through: use Slang compiler - Fxc = SLANG_PASS_THROUGH_FXC, ///< pass through HLSL to `D3DCompile` API - Dxc = SLANG_PASS_THROUGH_DXC, ///< pass through HLSL to `IDxcCompiler` API - Glslang = SLANG_PASS_THROUGH_GLSLANG, ///< pass through GLSL to `glslang` library + None = SLANG_PASS_THROUGH_NONE, ///< don't pass through: use Slang compiler + Fxc = SLANG_PASS_THROUGH_FXC, ///< pass through HLSL to `D3DCompile` API + Dxc = SLANG_PASS_THROUGH_DXC, ///< pass through HLSL to `IDxcCompiler` API + Glslang = SLANG_PASS_THROUGH_GLSLANG, ///< pass through GLSL to `glslang` library + SpirvDis = SLANG_PASS_THROUGH_SPIRV_DIS, ///< pass through spirv-dis Clang = SLANG_PASS_THROUGH_CLANG, ///< Pass through clang compiler VisualStudio = SLANG_PASS_THROUGH_VISUAL_STUDIO, ///< Visual studio compiler Gcc = SLANG_PASS_THROUGH_GCC, ///< Gcc compiler diff --git a/tests/diagnostics/command-line/x-arg-tool-unknown.slang.expected b/tests/diagnostics/command-line/x-arg-tool-unknown.slang.expected index 599e497f5..f3353574e 100644 --- a/tests/diagnostics/command-line/x-arg-tool-unknown.slang.expected +++ b/tests/diagnostics/command-line/x-arg-tool-unknown.slang.expected @@ -1,6 +1,6 @@ result code = 1 standard error = { -(1): error 100000: downstream tool name not known, allowed names are [ fxc, dxc, glslang, clang, visualstudio, gcc, genericcpp, nvrtc, llvm, downstream, linker ] +(1): error 100000: downstream tool name not known, allowed names are [ fxc, dxc, glslang, spirv-dis, clang, visualstudio, gcc, genericcpp, nvrtc, llvm, downstream, linker ] tests/diagnostics/command-line/x-arg-tool-unknown.slang -entry main -stage compute -o myKernel.dxbc -o myKernel.dxbc -Xthingy ^ } |
