Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Vulkan][Codegen] Added spvValidate check after vulkan shader generation #8098

Merged
merged 1 commit into from
May 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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