mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-10 05:57:51 +00:00
Move entry point validation from Validator to Resolver
Move logic and relevant tests. Remove validator/validator_decoration_test.cc. Bug: tint:642 Change-Id: Ie89118a11233931605f18e762274bb2afcaaa460 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46941 Commit-Queue: Antonio Maiorano <amaiorano@google.com> Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: James Price <jrprice@google.com> Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
committed by
Commit Bot service account
parent
bbbb0edec2
commit
bfc97945f3
@@ -272,5 +272,39 @@ INSTANTIATE_TEST_SUITE_P(
|
||||
TestParams{DecorationKind::kStructBlock, false},
|
||||
TestParams{DecorationKind::kWorkgroup, false}));
|
||||
|
||||
using FunctionDecorationTest = TestWithParams;
|
||||
TEST_P(FunctionDecorationTest, IsValid) {
|
||||
auto params = GetParam();
|
||||
|
||||
Func("foo", ast::VariableList{}, ty.void_(), ast::StatementList{},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
|
||||
createDecoration(Source{{12, 34}}, *this, params.kind)});
|
||||
|
||||
if (params.should_pass) {
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
} else {
|
||||
EXPECT_FALSE(r()->Resolve()) << r()->error();
|
||||
EXPECT_EQ(r()->error(),
|
||||
"12:34 error: decoration is not valid for functions");
|
||||
}
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
ValidatorTest,
|
||||
FunctionDecorationTest,
|
||||
testing::Values(TestParams{DecorationKind::kAccess, false},
|
||||
TestParams{DecorationKind::kAlign, false},
|
||||
TestParams{DecorationKind::kBinding, false},
|
||||
TestParams{DecorationKind::kBuiltin, false},
|
||||
TestParams{DecorationKind::kConstantId, false},
|
||||
TestParams{DecorationKind::kGroup, false},
|
||||
TestParams{DecorationKind::kLocation, false},
|
||||
TestParams{DecorationKind::kOffset, false},
|
||||
TestParams{DecorationKind::kSize, false},
|
||||
// Skip kStage as we always apply it in this test
|
||||
TestParams{DecorationKind::kStride, false},
|
||||
TestParams{DecorationKind::kStructBlock, false},
|
||||
TestParams{DecorationKind::kWorkgroup, true}));
|
||||
|
||||
} // namespace
|
||||
} // namespace tint
|
||||
|
||||
@@ -181,5 +181,25 @@ TEST_F(ResolverFunctionValidationTest,
|
||||
"return type, returned 'u32', expected 'myf32'");
|
||||
}
|
||||
|
||||
TEST_F(ResolverFunctionValidationTest, PipelineStage_MustBeUnique_Fail) {
|
||||
// [[stage(fragment)]]
|
||||
// [[stage(vertex)]]
|
||||
// fn main() -> void { return; }
|
||||
Func(Source{Source::Location{12, 34}}, "main", ast::VariableList{},
|
||||
ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::ReturnStatement>(),
|
||||
},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
||||
});
|
||||
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
EXPECT_EQ(r()->error(),
|
||||
"12:34 error v-0020: only one stage decoration permitted per entry "
|
||||
"point");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace tint
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include "src/ast/switch_statement.h"
|
||||
#include "src/ast/unary_op_expression.h"
|
||||
#include "src/ast/variable_decl_statement.h"
|
||||
#include "src/ast/workgroup_decoration.h"
|
||||
#include "src/semantic/array.h"
|
||||
#include "src/semantic/call.h"
|
||||
#include "src/semantic/function.h"
|
||||
@@ -328,6 +329,23 @@ bool Resolver::ValidateFunction(const ast::Function* func) {
|
||||
}
|
||||
|
||||
bool Resolver::ValidateEntryPoint(const ast::Function* func) {
|
||||
auto stage_deco_count = 0;
|
||||
for (auto* deco : func->decorations()) {
|
||||
if (deco->Is<ast::StageDecoration>()) {
|
||||
stage_deco_count++;
|
||||
} else if (!deco->Is<ast::WorkgroupDecoration>()) {
|
||||
diagnostics_.add_error("decoration is not valid for functions",
|
||||
deco->source());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (stage_deco_count > 1) {
|
||||
diagnostics_.add_error(
|
||||
"v-0020", "only one stage decoration permitted per entry point",
|
||||
func->source());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Use a lambda to validate the entry point decorations for a type.
|
||||
// Persistent state is used to track which builtins and locations have already
|
||||
// been seen, in order to catch conflicts.
|
||||
|
||||
Reference in New Issue
Block a user