[validation] check if at least one of vertex, fragment or compute shader is peresent

Bug: tint: 6
Change-Id: I826d951c374409699082f38fb65225f5b4a83f2d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/27483
Commit-Queue: Sarah Mashayekhi <sarahmashay@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Sarah Mashayekhi 2020-08-27 18:05:00 +00:00 committed by Commit Bot service account
parent 4bc38c3f63
commit 5f915f1f92
3 changed files with 48 additions and 1 deletions

View File

@ -402,5 +402,45 @@ TEST_F(ValidateFunctionTest,
EXPECT_TRUE(v()->Validate(mod())) << v()->error(); EXPECT_TRUE(v()->Validate(mod())) << v()->error();
} }
TEST_F(ValidateFunctionTest,
AtLeastOneOfVertexFragmentComputeShaderMustBePeresent_Pass) {
// entry_point vertex as "main" = vtx_func
// fn vtx_func() -> void { return; }
ast::type::VoidType void_type;
ast::VariableList params;
auto func = std::make_unique<ast::Function>("vtx_func", std::move(params),
&void_type);
auto body = std::make_unique<ast::BlockStatement>();
body->append(std::make_unique<ast::ReturnStatement>());
func->set_body(std::move(body));
auto entry_point = std::make_unique<ast::EntryPoint>(
ast::PipelineStage::kVertex, "main", "vtx_func");
mod()->AddFunction(std::move(func));
mod()->AddEntryPoint(std::move(entry_point));
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_TRUE(v()->Validate(mod())) << v()->error();
}
TEST_F(ValidateFunctionTest,
AtLeastOneOfVertexFragmentComputeShaderMustBePeresent_Fail) {
// fn vtx_func() -> void { return; }
ast::type::VoidType void_type;
ast::VariableList params;
auto func = std::make_unique<ast::Function>("vtx_func", std::move(params),
&void_type);
auto body = std::make_unique<ast::BlockStatement>();
body->append(std::make_unique<ast::ReturnStatement>());
func->set_body(std::move(body));
mod()->AddFunction(std::move(func));
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_FALSE(v()->Validate(mod()));
EXPECT_EQ(v()->error(),
"0:0: v-0003: At least one of vertex, fragment or compute shader "
"must be present");
}
} // namespace } // namespace
} // namespace tint } // namespace tint

View File

@ -112,6 +112,12 @@ bool ValidatorImpl::ValidateEntryPoints(const ast::EntryPointList& eps) {
entry_point_map.set(ep_ptr->name(), ep_ptr->stage()); entry_point_map.set(ep_ptr->name(), ep_ptr->stage());
} }
if (eps.empty()) {
set_error(Source{0, 0},
"v-0003: At least one of vertex, fragment or compute shader must "
"be present");
return false;
}
entry_point_map.pop_scope(); entry_point_map.pop_scope();
return true; return true;
} }

View File

@ -37,7 +37,7 @@ class ValidatorTestHelper {
/// A handle to the created module /// A handle to the created module
/// @return a pointer to the test module /// @return a pointer to the test module
ast::Module* mod() { return &mod_; } ast::Module* mod() { return &mod_; }
/// Create a function and add an entry point to it /// Creates a function and add an entry point to it
void AddFakeEntryPoint(); void AddFakeEntryPoint();
private: private:
@ -45,6 +45,7 @@ class ValidatorTestHelper {
Context ctx_; Context ctx_;
ast::Module mod_; ast::Module mod_;
std::unique_ptr<TypeDeterminer> td_; std::unique_ptr<TypeDeterminer> td_;
ast::type::VoidType void_type_;
}; };
} // namespace tint } // namespace tint