summaryrefslogtreecommitdiffstats
path: root/source/compiler-core
diff options
context:
space:
mode:
authorJay Kwak <82421531+jkwak-work@users.noreply.github.com>2024-07-17 17:00:05 -0700
committerGitHub <noreply@github.com>2024-07-17 17:00:05 -0700
commit32b1e25e359f8daf5254301dca8be308e8e1e2ab (patch)
tree2dd2bf7324b771c4a0aa989194a9b1d3b219af18 /source/compiler-core
parent2db15080085856ed9b5f20642dbb354aac59a888 (diff)
Use slang-glslang.dll for spirv-validation (#4642)
* Use slang-glslang.dll for spirv-validation This change replaces the use of "spirv-val.exe" with an API call to "spvtools::SpirvTools::Validate()". Closes #4610
Diffstat (limited to 'source/compiler-core')
-rw-r--r--source/compiler-core/slang-downstream-compiler.h3
-rw-r--r--source/compiler-core/slang-glslang-compiler.cpp17
2 files changed, 20 insertions, 0 deletions
diff --git a/source/compiler-core/slang-downstream-compiler.h b/source/compiler-core/slang-downstream-compiler.h
index 14e924f8b..95793eaa3 100644
--- a/source/compiler-core/slang-downstream-compiler.h
+++ b/source/compiler-core/slang-downstream-compiler.h
@@ -309,6 +309,8 @@ public:
virtual SLANG_NO_THROW SlangResult SLANG_MCALL convert(IArtifact* from, const ArtifactDesc& to, IArtifact** outArtifact) = 0;
/// Get the version of this compiler
virtual SLANG_NO_THROW SlangResult SLANG_MCALL getVersionString(slang::IBlob** outVersionString) = 0;
+ /// Validate and return the result
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL validate(const uint32_t* contents, int contentsSize) = 0;
/// True if underlying compiler uses file system to communicate source
virtual SLANG_NO_THROW bool SLANG_MCALL isFileBased() = 0;
@@ -327,6 +329,7 @@ public:
virtual SLANG_NO_THROW bool SLANG_MCALL canConvert(const ArtifactDesc& from, const ArtifactDesc& to) SLANG_OVERRIDE { SLANG_UNUSED(from); SLANG_UNUSED(to); return false; }
virtual SLANG_NO_THROW SlangResult SLANG_MCALL convert(IArtifact* from, const ArtifactDesc& to, IArtifact** outArtifact) SLANG_OVERRIDE;
virtual SLANG_NO_THROW SlangResult SLANG_MCALL getVersionString(slang::IBlob** outVersionString) SLANG_OVERRIDE { *outVersionString = nullptr; return SLANG_FAIL; }
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL validate(const uint32_t* contents, int contentsSize) SLANG_OVERRIDE { SLANG_UNUSED(contents); SLANG_UNUSED(contentsSize); 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 e0a537757..9ef8e7fb4 100644
--- a/source/compiler-core/slang-glslang-compiler.cpp
+++ b/source/compiler-core/slang-glslang-compiler.cpp
@@ -48,6 +48,7 @@ public:
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; }
virtual SLANG_NO_THROW SlangResult SLANG_MCALL getVersionString(slang::IBlob** outVersionString) SLANG_OVERRIDE;
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL validate(const uint32_t* contents, int contentsSize) SLANG_OVERRIDE;
/// Must be called before use
SlangResult init(ISlangSharedLibrary* library);
@@ -61,6 +62,7 @@ protected:
glslang_CompileFunc_1_0 m_compile_1_0 = nullptr;
glslang_CompileFunc_1_1 m_compile_1_1 = nullptr;
glslang_CompileFunc_1_2 m_compile_1_2 = nullptr;
+ glslang_ValidateSPIRVFunc m_validate = nullptr;
ComPtr<ISlangSharedLibrary> m_sharedLibrary;
@@ -72,6 +74,7 @@ SlangResult GlslangDownstreamCompiler::init(ISlangSharedLibrary* library)
m_compile_1_0 = (glslang_CompileFunc_1_0)library->findFuncByName("glslang_compile");
m_compile_1_1 = (glslang_CompileFunc_1_1)library->findFuncByName("glslang_compile_1_1");
m_compile_1_2 = (glslang_CompileFunc_1_2)library->findFuncByName("glslang_compile_1_2");
+ m_validate = (glslang_ValidateSPIRVFunc)library->findFuncByName("glslang_validateSPIRV");
if (m_compile_1_0 == nullptr && m_compile_1_1 == nullptr && m_compile_1_2 == nullptr)
@@ -281,6 +284,20 @@ SlangResult GlslangDownstreamCompiler::compile(const CompileOptions& inOptions,
return SLANG_OK;
}
+SlangResult GlslangDownstreamCompiler::validate(const uint32_t* contents, int contentsSize)
+{
+ if (m_validate == nullptr)
+ {
+ return SLANG_FAIL;
+ }
+
+ if (m_validate(contents, contentsSize))
+ {
+ return SLANG_OK;
+ }
+ return SLANG_FAIL;
+}
+
bool GlslangDownstreamCompiler::canConvert(const ArtifactDesc& from, const ArtifactDesc& to)
{
// Can only disassemble blobs that are SPIR-V