summaryrefslogtreecommitdiff
path: root/external
diff options
context:
space:
mode:
authorDejan Mircevski <deki@google.com>2016-02-11 12:19:56 -0500
committerDejan Mircevski <deki@google.com>2016-02-29 13:56:02 -0500
commit7e99a1155b6b262ff0728fe72ddb24898b7a7b6e (patch)
tree3d6ff7db2fd6a381760a62788946459008187130 /external
parent446bb6de17ac9595148d885b986dc6bed7fc5e70 (diff)
downloadVK-GL-CTS-7e99a1155b6b262ff0728fe72ddb24898b7a7b6e.tar.gz
VK-GL-CTS-7e99a1155b6b262ff0728fe72ddb24898b7a7b6e.tar.bz2
VK-GL-CTS-7e99a1155b6b262ff0728fe72ddb24898b7a7b6e.zip
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.
Diffstat (limited to 'external')
-rw-r--r--external/fetch_sources.py2
-rw-r--r--external/vulkancts/framework/vulkan/vkPrograms.cpp7
-rw-r--r--external/vulkancts/framework/vulkan/vkSpirVAsm.cpp24
-rw-r--r--external/vulkancts/framework/vulkan/vkSpirVAsm.hpp3
4 files changed, 33 insertions, 3 deletions
diff --git a/external/fetch_sources.py b/external/fetch_sources.py
index efa530d22..7c9e83e30 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 1e3e7b87c..e900cd965 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<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]);
}
diff --git a/external/vulkancts/framework/vulkan/vkSpirVAsm.cpp b/external/vulkancts/framework/vulkan/vkSpirVAsm.cpp
index 62a3eb8a5..9d292efe2 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<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
diff --git a/external/vulkancts/framework/vulkan/vkSpirVAsm.hpp b/external/vulkancts/framework/vulkan/vkSpirVAsm.hpp
index 577739a87..43348d98c 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<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