postExtract = postExtractLibpng),
GitRepo(
"https://github.com/KhronosGroup/SPIRV-Tools.git",
- "3e6b2dfa699b13987657298ab2a7652a0a577ca9",
+ "7ef6da7b7f9175da509b4d71a881c0a04e0b701b",
"spirv-tools"),
GitRepo(
"https://github.com/KhronosGroup/glslang.git",
{
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
{
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]);
}
#include "qpDebugOut.h"
#if defined(DEQP_HAVE_SPIRV_TOOLS)
-# include "deSingleton.h"
-
# include "libspirv/libspirv.h"
#endif
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*)
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
//! 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