diff options
author | Ethan Nicholas <ethannicholas@google.com> | 2017-03-16 09:56:54 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-03-16 14:42:20 +0000 |
commit | a6ae1f7cda072ff814a838e2d9013a017552cc35 (patch) | |
tree | b8fd601aade94a114e36b13ca07f56a6a3d15920 /src/sksl | |
parent | 3338914bc786cb47cf5c75a4d8dadb0950ef2471 (diff) |
wired up SPIR-V validator
Change-Id: I33dfd5e7ea3ea048b88c6db2f14389b16a0af7c8
Reviewed-on: https://skia-review.googlesource.com/9688
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
Reviewed-by: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'src/sksl')
-rw-r--r-- | src/sksl/SkSLCompiler.cpp | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/sksl/SkSLCompiler.cpp b/src/sksl/SkSLCompiler.cpp index d5742390a9..1cbc4410b5 100644 --- a/src/sksl/SkSLCompiler.cpp +++ b/src/sksl/SkSLCompiler.cpp @@ -21,6 +21,10 @@ #include "ir/SkSLVarDeclarations.h" #include "SkMutex.h" +#ifdef SK_ENABLE_SPIRV_VALIDATION +#include "spirv-tools/libspirv.hpp" +#endif + #define STRINGIFY(x) #x // include the built-in shader symbols as static strings @@ -486,10 +490,28 @@ std::unique_ptr<Program> Compiler::convertProgram(Program::Kind kind, SkString t return result; } - bool Compiler::toSPIRV(const Program& program, SkWStream& out) { +#ifdef SK_ENABLE_SPIRV_VALIDATION + SkDynamicMemoryWStream buffer; + SPIRVCodeGenerator cg(&fContext, &program, this, &buffer); + bool result = cg.generateCode(); + if (result) { + sk_sp<SkData> data(buffer.detachAsData()); + spvtools::SpirvTools tools(SPV_ENV_VULKAN_1_0); + SkASSERT(0 == data->size() % 4); + auto dumpmsg = [](spv_message_level_t, const char*, const spv_position_t&, const char* m) { + SkDebugf("SPIR-V validation error: %s\n", m); + }; + tools.SetMessageConsumer(dumpmsg); + // Verify that the SPIR-V we produced is valid. If this assert fails, check the logs prior + // to the failure to see the validation errors. + SkAssertResult(tools.Validate((const uint32_t*) data->data(), data->size() / 4)); + out.write(data->data(), data->size()); + } +#else SPIRVCodeGenerator cg(&fContext, &program, this, &out); bool result = cg.generateCode(); +#endif this->writeErrorCount(); return result; } |