Skip to content

Commit

Permalink
[Vulkan][Codegen] Added spvValidate check after vulkan shader generat…
Browse files Browse the repository at this point in the history
…ion (apache#8098)

spvValidate found the bug that was fixed in apache#7966, along with a few
other issues on missing capability/extension declarations.  Now that
all unit tests pass with it enabled, would like to enable by default.

Co-authored-by: Eric Lunderberg <elunderberg@octoml.ai>
  • Loading branch information
2 people authored and Trevor Morris committed Jun 17, 2021
1 parent 84a99b3 commit 1e52b37
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/target/spirv/build_vulkan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ class SPIRVTools {
~SPIRVTools() { spvContextDestroy(ctx_); }
std::string BinaryToText(const std::vector<uint32_t>& bin) {
spv_text text = nullptr;
spv_diagnostic diagnostic;
spv_diagnostic diagnostic = nullptr;
spv_const_binary_t spv_bin{bin.data(), bin.size()};
spv_result_t res;

res =
spv_result_t res =
spvBinaryToText(ctx_, spv_bin.code, spv_bin.wordCount,
SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES | SPV_BINARY_TO_TEXT_OPTION_INDENT,
&text, &diagnostic);
Expand All @@ -53,12 +52,25 @@ class SPIRVTools {
<< " column=" << diagnostic->position.column
<< " index=" << diagnostic->position.index
<< " error:" << diagnostic->error;
spvDiagnosticDestroy(diagnostic);

std::string ret(text->str);
spvTextDestroy(text);
return ret;
}

void ValidateShader(const std::vector<uint32_t>& bin) {
spv_const_binary_t spv_bin{bin.data(), bin.size()};

spv_diagnostic diagnostic = nullptr;
spv_result_t res = spvValidate(ctx_, &spv_bin, &diagnostic);

ICHECK_EQ(res, SPV_SUCCESS) << " index=" << diagnostic->position.index
<< " error:" << diagnostic->error;

spvDiagnosticDestroy(diagnostic);
}

private:
spv_context ctx_;
};
Expand Down Expand Up @@ -92,6 +104,8 @@ runtime::Module BuildSPIRV(IRModule mod, Target target, bool webgpu_restriction)

VulkanShader shader = cg.BuildFunction(f, entry);

spirv_tools.ValidateShader(shader.data);

if (webgpu_restriction) {
for (auto param : f->params) {
ICHECK(param.dtype().is_handle()) << "WebGPU does not yet support non-buffer arguments";
Expand Down

0 comments on commit 1e52b37

Please sign in to comment.