From 7e99a1155b6b262ff0728fe72ddb24898b7a7b6e Mon Sep 17 00:00:00 2001 From: Dejan Mircevski Date: Thu, 11 Feb 2016 12:19:56 -0500 Subject: [PATCH] Enable SPIR-V validator in the module-building chain. 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 | 2 +- external/vulkancts/framework/vulkan/vkPrograms.cpp | 7 +++++++ external/vulkancts/framework/vulkan/vkSpirVAsm.cpp | 24 ++++++++++++++++++++-- external/vulkancts/framework/vulkan/vkSpirVAsm.hpp | 3 +++ 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/external/fetch_sources.py b/external/fetch_sources.py index efa530d..7c9e83e 100644 --- a/external/fetch_sources.py +++ b/external/fetch_sources.py @@ -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", diff --git a/external/vulkancts/framework/vulkan/vkPrograms.cpp b/external/vulkancts/framework/vulkan/vkPrograms.cpp index 1e3e7b8..e900cd9 100644 --- a/external/vulkancts/framework/vulkan/vkPrograms.cpp +++ b/external/vulkancts/framework/vulkan/vkPrograms.cpp @@ -61,6 +61,8 @@ ProgramBinary* buildProgram (const glu::ProgramSources& program, ProgramFormat b { vector 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 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]); } diff --git a/external/vulkancts/framework/vulkan/vkSpirVAsm.cpp b/external/vulkancts/framework/vulkan/vkSpirVAsm.cpp index 62a3eb8..9d292ef 100644 --- a/external/vulkancts/framework/vulkan/vkSpirVAsm.cpp +++ b/external/vulkancts/framework/vulkan/vkSpirVAsm.cpp @@ -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* dst, Sp return; } +bool validateSpirV (const std::vector& spirv, std::string* infoLog) +{ + const size_t bytesPerWord = sizeof(uint32_t) / sizeof(deUint8); + DE_ASSERT(spirv.size() % bytesPerWord == 0); + std::vector 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*, SpirVProgramInfo*) @@ -89,6 +104,11 @@ void assembleSpirV (const SpirVAsmSource*, std::vector*, SpirVProgramIn TCU_THROW(NotSupportedError, "SPIR-V assembly not supported (DEQP_HAVE_SPIRV_TOOLS not defined)"); } +bool validateSpirV (std::vector*, std::string*) +{ + TCU_THROW(NotSupportedError, "SPIR-V validation not supported (DEQP_HAVE_SPIRV_TOOLS not defined)"); +} + #endif } // vk diff --git a/external/vulkancts/framework/vulkan/vkSpirVAsm.hpp b/external/vulkancts/framework/vulkan/vkSpirVAsm.hpp index 577739a..43348d9 100644 --- a/external/vulkancts/framework/vulkan/vkSpirVAsm.hpp +++ b/external/vulkancts/framework/vulkan/vkSpirVAsm.hpp @@ -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* 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& spirv, std::string* infoLog); + } // vk #endif // _VKSPIRVASM_HPP -- 2.7.4