From 32b1e25e359f8daf5254301dca8be308e8e1e2ab Mon Sep 17 00:00:00 2001 From: Jay Kwak <82421531+jkwak-work@users.noreply.github.com> Date: Wed, 17 Jul 2024 17:00:05 -0700 Subject: 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 --- source/slang-glslang/slang-glslang.cpp | 20 ++++++++++++++++++++ source/slang-glslang/slang-glslang.h | 1 + 2 files changed, 21 insertions(+) (limited to 'source/slang-glslang') diff --git a/source/slang-glslang/slang-glslang.cpp b/source/slang-glslang/slang-glslang.cpp index cdbc95031..8ae85b631 100644 --- a/source/slang-glslang/slang-glslang.cpp +++ b/source/slang-glslang/slang-glslang.cpp @@ -145,6 +145,26 @@ struct SPIRVOptimizationDiagnostic std::string message; }; +// Validate the given SPIRV-ASM instructions. +extern "C" +#ifdef _MSC_VER +_declspec(dllexport) +#else +__attribute__((__visibility__("default"))) +#endif +bool glslang_validateSPIRV(const uint32_t* contents, int contentsSize) +{ + spv_target_env target_env = SPV_ENV_VULKAN_1_3; + + spvtools::ValidatorOptions options; + options.SetScalarBlockLayout(true); + + spvtools::SpirvTools tools(target_env); + //tools.SetMessageConsumer(spvtools::utils::CLIMessageConsumer); + + return tools.Validate(contents, contentsSize, options); +} + // Apply the SPIRV-Tools optimizer to generated SPIR-V based on the desired optimization level // TODO: add flag for optimizing SPIR-V size as well static void glslang_optimizeSPIRV(spv_target_env targetEnv, const glslang_CompileRequest_1_2& request, std::vector& outDiags, std::vector& ioSpirv) diff --git a/source/slang-glslang/slang-glslang.h b/source/slang-glslang/slang-glslang.h index 68c24d889..00205a114 100644 --- a/source/slang-glslang/slang-glslang.h +++ b/source/slang-glslang/slang-glslang.h @@ -147,5 +147,6 @@ inline void glslang_CompileRequest_1_2::set(const glslang_CompileRequest_1_1& in typedef int (*glslang_CompileFunc_1_0)(glslang_CompileRequest_1_0* request); typedef int (*glslang_CompileFunc_1_1)(glslang_CompileRequest_1_1* request); typedef int (*glslang_CompileFunc_1_2)(glslang_CompileRequest_1_2* request); +typedef bool (*glslang_ValidateSPIRVFunc)(const uint32_t* contents, int contentsSize); #endif -- cgit v1.2.3