summaryrefslogtreecommitdiffstats
path: root/source/compiler-core
diff options
context:
space:
mode:
authorMukund Keshava <mkeshava@nvidia.com>2025-03-11 21:40:05 +0530
committerGitHub <noreply@github.com>2025-03-11 16:10:05 +0000
commitf59e0ef409844f2514435a8df8ceeff3663e5db3 (patch)
tree7f8f7514ed140a49f03923d84a549fdbfdcbcc84 /source/compiler-core
parentff55a569a0bff44a6f8abb105c07cbc2484bc007 (diff)
IR: Add SPIR-V disassembly for embedded downstream IR dumps (#6529)
* IR: Add SPIR-V disassembly for embedded downstream IR dumps When dumping IR that contains embedded downstream SPIR-V code (via EmbeddedDownstreamIR instructions), display the disassembled SPIR-V instead of just showing "<binary blob>". This CL also does: - Adds a new interface for disassembly and get result. - Modify export-library-generics.slang test test to check for the disassembled SPIR-V Fixes #6513 * Add module-dual-target-verify test Fixes #6517 Adds a new test to verify that dxil and spirv targets are stored separately in the precompiled blob. * Fix review comments from cheneym2 * format code --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Diffstat (limited to 'source/compiler-core')
-rw-r--r--source/compiler-core/slang-downstream-compiler.h14
-rw-r--r--source/compiler-core/slang-glslang-compiler.cpp29
2 files changed, 43 insertions, 0 deletions
diff --git a/source/compiler-core/slang-downstream-compiler.h b/source/compiler-core/slang-downstream-compiler.h
index c96003cc4..5365b9839 100644
--- a/source/compiler-core/slang-downstream-compiler.h
+++ b/source/compiler-core/slang-downstream-compiler.h
@@ -340,6 +340,9 @@ public:
/// Disassemble and print to stdout
virtual SLANG_NO_THROW SlangResult SLANG_MCALL
disassemble(const uint32_t* contents, int contentsSize) = 0;
+ /// Disassemble and return the result as a string
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL
+ disassembleWithResult(const uint32_t* contents, int contentsSize, String& outString) = 0;
/// True if underlying compiler uses file system to communicate source
virtual SLANG_NO_THROW bool SLANG_MCALL isFileBased() = 0;
@@ -398,6 +401,17 @@ public:
return SLANG_FAIL;
}
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL disassembleWithResult(
+ const uint32_t* contents,
+ int contentsSize,
+ String& outString) SLANG_OVERRIDE
+ {
+ SLANG_UNUSED(contents);
+ SLANG_UNUSED(contentsSize);
+ SLANG_UNUSED(outString);
+ return SLANG_FAIL;
+ }
+
DownstreamCompilerBase(const Desc& desc)
: m_desc(desc)
{
diff --git a/source/compiler-core/slang-glslang-compiler.cpp b/source/compiler-core/slang-glslang-compiler.cpp
index 540b437c5..27a24512d 100644
--- a/source/compiler-core/slang-glslang-compiler.cpp
+++ b/source/compiler-core/slang-glslang-compiler.cpp
@@ -49,6 +49,10 @@ public:
validate(const uint32_t* contents, int contentsSize) SLANG_OVERRIDE;
virtual SLANG_NO_THROW SlangResult SLANG_MCALL
disassemble(const uint32_t* contents, int contentsSize) SLANG_OVERRIDE;
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL disassembleWithResult(
+ const uint32_t* contents,
+ int contentsSize,
+ String& outString) SLANG_OVERRIDE;
int link(
const uint32_t** modules,
const uint32_t* moduleSizes,
@@ -71,6 +75,7 @@ protected:
glslang_CompileFunc_1_2 m_compile_1_2 = nullptr;
glslang_ValidateSPIRVFunc m_validate = nullptr;
glslang_DisassembleSPIRVFunc m_disassemble = nullptr;
+ glslang_DisassembleSPIRVWithResultFunc m_disassembleWithResult = nullptr;
glslang_LinkSPIRVFunc m_link = nullptr;
ComPtr<ISlangSharedLibrary> m_sharedLibrary;
@@ -86,6 +91,8 @@ SlangResult GlslangDownstreamCompiler::init(ISlangSharedLibrary* library)
m_validate = (glslang_ValidateSPIRVFunc)library->findFuncByName("glslang_validateSPIRV");
m_disassemble =
(glslang_DisassembleSPIRVFunc)library->findFuncByName("glslang_disassembleSPIRV");
+ m_disassembleWithResult = (glslang_DisassembleSPIRVWithResultFunc)library->findFuncByName(
+ "glslang_disassembleSPIRVWithResult");
m_link = (glslang_LinkSPIRVFunc)library->findFuncByName("glslang_linkSPIRV");
if (m_compile_1_0 == nullptr && m_compile_1_1 == nullptr && m_compile_1_2 == nullptr)
@@ -316,6 +323,28 @@ SlangResult GlslangDownstreamCompiler::validate(const uint32_t* contents, int co
return SLANG_FAIL;
}
+SlangResult GlslangDownstreamCompiler::disassembleWithResult(
+ const uint32_t* contents,
+ int contentsSize,
+ String& outString)
+{
+ if (m_disassembleWithResult == nullptr)
+ {
+ return SLANG_FAIL;
+ }
+
+ char* resultString = nullptr;
+ if (m_disassembleWithResult(contents, contentsSize, &resultString))
+ {
+ if (resultString)
+ {
+ outString = String(resultString);
+ return SLANG_OK;
+ }
+ }
+ return SLANG_FAIL;
+}
+
SlangResult GlslangDownstreamCompiler::disassemble(const uint32_t* contents, int contentsSize)
{
if (m_disassemble == nullptr)