Enable SPIR-V validator in the module-building chain.
authorDejan Mircevski <deki@google.com>
Thu, 11 Feb 2016 17:19:56 +0000 (12:19 -0500)
committerDejan Mircevski <deki@google.com>
Mon, 29 Feb 2016 18:56:02 +0000 (13:56 -0500)
Update fetched spirv-tools revision to get the latest validator.

Only validate hand-assembled SPIR-V for now, as many GLSL tests
currently fail validation.

external/fetch_sources.py
external/vulkancts/framework/vulkan/vkPrograms.cpp
external/vulkancts/framework/vulkan/vkSpirVAsm.cpp
external/vulkancts/framework/vulkan/vkSpirVAsm.hpp

index efa530d..7c9e83e 100644 (file)
@@ -170,7 +170,7 @@ PACKAGES = [
                postExtract = postExtractLibpng),
        GitRepo(
                "https://github.com/KhronosGroup/SPIRV-Tools.git",
-               "3e6b2dfa699b13987657298ab2a7652a0a577ca9",
+               "7ef6da7b7f9175da509b4d71a881c0a04e0b701b",
                "spirv-tools"),
        GitRepo(
                "https://github.com/KhronosGroup/glslang.git",
index 1e3e7b8..e900cd9 100644 (file)
@@ -61,6 +61,8 @@ ProgramBinary* buildProgram (const glu::ProgramSources& program, ProgramFormat b
        {
                vector<deUint8> binary;
                glslToSpirV(program, &binary, buildInfo);
+               // \todo[2016-02-10 dekimir]: Enable this when all glsl tests can pass it.
+               //validateSpirV(binary, &buildInfo->program.infoLog);
                return new ProgramBinary(binaryFormat, binary.size(), &binary[0]);
        }
        else
@@ -71,6 +73,11 @@ ProgramBinary* assembleProgram (const SpirVAsmSource& program, SpirVProgramInfo*
 {
        vector<deUint8> binary;
        assembleSpirV(&program, &binary, buildInfo);
+#if defined(DE_DEBUG)
+       buildInfo->compileOk &= validateSpirV(binary, &buildInfo->infoLog);
+       if (!buildInfo->compileOk)
+               TCU_FAIL("Failed to validate shader");
+#endif
        return new ProgramBinary(PROGRAM_FORMAT_SPIRV, binary.size(), &binary[0]);
 }
 
index 62a3eb8..9d292ef 100644 (file)
@@ -36,8 +36,6 @@
 #include "qpDebugOut.h"
 
 #if defined(DEQP_HAVE_SPIRV_TOOLS)
-#      include "deSingleton.h"
-
 #      include "libspirv/libspirv.h"
 #endif
 
@@ -82,6 +80,23 @@ void assembleSpirV (const SpirVAsmSource* program, std::vector<deUint8>* dst, Sp
        return;
 }
 
+bool validateSpirV (const std::vector<deUint8>& spirv, std::string* infoLog)
+{
+       const size_t bytesPerWord = sizeof(uint32_t) / sizeof(deUint8);
+       DE_ASSERT(spirv.size() % bytesPerWord == 0);
+       std::vector<uint32_t> words(spirv.size() / bytesPerWord);
+       deMemcpy(words.data(), spirv.data(), spirv.size());
+       spv_const_binary_t      cbinary         = { words.data(), words.size() };
+       spv_diagnostic          diagnostic      = DE_NULL;
+       spv_context                     context         = spvContextCreate();
+       const spv_result_t      valid           = spvValidate(context, &cbinary, SPV_VALIDATE_ALL, &diagnostic);
+       if (diagnostic)
+               *infoLog += diagnostic->error;
+       spvContextDestroy(context);
+       spvDiagnosticDestroy(diagnostic);
+       return valid == SPV_SUCCESS;
+}
+
 #else // defined(DEQP_HAVE_SPIRV_TOOLS)
 
 void assembleSpirV (const SpirVAsmSource*, std::vector<deUint8>*, SpirVProgramInfo*)
@@ -89,6 +104,11 @@ void assembleSpirV (const SpirVAsmSource*, std::vector<deUint8>*, SpirVProgramIn
        TCU_THROW(NotSupportedError, "SPIR-V assembly not supported (DEQP_HAVE_SPIRV_TOOLS not defined)");
 }
 
+bool validateSpirV (std::vector<deUint8>*, std::string*)
+{
+       TCU_THROW(NotSupportedError, "SPIR-V validation not supported (DEQP_HAVE_SPIRV_TOOLS not defined)");
+}
+
 #endif
 
 } // vk
index 577739a..43348d9 100644 (file)
@@ -39,6 +39,9 @@ namespace vk
 //! Assemble SPIR-V program. Will fail with NotSupportedError if compiler is not available.
 void assembleSpirV (const SpirVAsmSource* program, std::vector<deUint8>* dst, SpirVProgramInfo* buildInfo);
 
+//! Validate SPIR-V binary, returning true if validation succeeds. Will fail with NotSupportedError if compiler is not available.
+bool validateSpirV (const std::vector<deUint8>& spirv, std::string* infoLog);
+
 } // vk
 
 #endif // _VKSPIRVASM_HPP