Generate errors from the SPIR-V builder.

This Cl adds error messages into the SPIR-V generator.

Bug: tint:5
Change-Id: I45c0d286dd8ec251773ff5e036322090647d780c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/17521
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
dan sinclair 2020-03-23 20:07:34 +00:00 committed by dan sinclair
parent 248170ae44
commit 781a4acb6f
5 changed files with 11 additions and 2 deletions

View File

@ -399,7 +399,7 @@ if(${TINT_BUILD_SPV_WRITER})
list(APPEND TINT_TEST_SRCS
writer/spirv/binary_writer_test.cc
writer/spirv/builder_test.cc
writer/spirv/builder_test_entry_point_test.cc
writer/spirv/builder_entry_point_test.cc
writer/spirv/instruction_test.cc
writer/spirv/operand_test.cc
)

View File

@ -120,11 +120,13 @@ bool Builder::GenerateEntryPoint(ast::EntryPoint* ep) {
auto id = id_for_func_name(ep->function_name());
if (id == 0) {
error_ = "unable to find ID for function: " + ep->function_name();
return false;
}
auto stage = pipeline_stage_to_execution_model(ep->stage());
if (stage == SpvExecutionModelMax) {
error_ = "Unknown pipeline stage provided";
return false;
}

View File

@ -39,6 +39,9 @@ class Builder {
/// @returns true if the SPIR-V was successfully built
bool Build(const ast::Module& module);
/// @returns the error string or blank if no error was reported.
const std::string& error() const { return error_; }
/// @returns the number of uint32_t's needed to make up the results
uint32_t total_size() const;
@ -125,6 +128,7 @@ class Builder {
private:
Operand result_op();
std::string error_;
uint32_t next_id_ = 1;
std::vector<Instruction> preamble_;
std::vector<Instruction> debug_;

View File

@ -66,6 +66,7 @@ TEST_F(BuilderTest, EntryPoint_BadFunction) {
Builder b;
EXPECT_FALSE(b.GenerateEntryPoint(&ep));
EXPECT_EQ(b.error(), "unable to find ID for function: frag_main");
}
struct EntryPointStageData {

View File

@ -25,8 +25,10 @@ Generator::Generator(ast::Module module) : writer::Writer(std::move(module)) {}
Generator::~Generator() = default;
bool Generator::Generate() {
if (!builder_.Build(module_))
if (!builder_.Build(module_)) {
set_error(builder_.error());
return false;
}
return writer_.Write(builder_);
}