2021-03-18 20:46:24 +00:00
|
|
|
// Copyright 2021 The Tint Authors.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
#include "src/resolver/resolver.h"
|
|
|
|
|
|
|
|
#include "gmock/gmock.h"
|
2021-04-19 20:20:33 +00:00
|
|
|
#include "src/ast/struct_block_decoration.h"
|
2021-03-18 20:46:24 +00:00
|
|
|
#include "src/resolver/resolver_test_helper.h"
|
2021-04-19 22:54:43 +00:00
|
|
|
#include "src/sem/access_control_type.h"
|
2021-04-16 19:07:51 +00:00
|
|
|
#include "src/sem/struct.h"
|
2021-03-18 20:46:24 +00:00
|
|
|
|
|
|
|
namespace tint {
|
|
|
|
namespace resolver {
|
|
|
|
namespace {
|
|
|
|
|
2021-03-18 21:03:24 +00:00
|
|
|
using ResolverHostShareableValidationTest = ResolverTest;
|
2021-03-18 20:46:24 +00:00
|
|
|
|
2021-03-18 21:03:24 +00:00
|
|
|
TEST_F(ResolverHostShareableValidationTest, BoolMember) {
|
2021-05-07 14:49:34 +00:00
|
|
|
auto* s = Structure("S", {Member(Source{{12, 34}}, "x", ty.bool_())},
|
|
|
|
{create<ast::StructBlockDecoration>()});
|
2021-04-22 14:40:23 +00:00
|
|
|
auto a = ty.access(ast::AccessControl::kReadOnly, s);
|
2021-05-10 19:16:46 +00:00
|
|
|
Global(Source{{56, 78}}, "g", a, ast::StorageClass::kStorage, nullptr,
|
|
|
|
{
|
|
|
|
create<ast::BindingDecoration>(0),
|
|
|
|
create<ast::GroupDecoration>(0),
|
|
|
|
});
|
2021-03-18 20:46:24 +00:00
|
|
|
|
|
|
|
ASSERT_FALSE(r()->Resolve());
|
|
|
|
|
|
|
|
EXPECT_EQ(
|
|
|
|
r()->error(),
|
2021-03-18 21:03:24 +00:00
|
|
|
R"(56:78 error: Type 'bool' cannot be used in storage class 'storage' as it is non-host-shareable
|
2021-03-18 20:46:24 +00:00
|
|
|
12:34 note: while analysing structure member S.x
|
|
|
|
56:78 note: while instantiating variable g)");
|
|
|
|
}
|
|
|
|
|
2021-03-18 21:03:24 +00:00
|
|
|
TEST_F(ResolverHostShareableValidationTest, BoolVectorMember) {
|
2021-05-07 14:49:34 +00:00
|
|
|
auto* s = Structure("S", {Member(Source{{12, 34}}, "x", ty.vec3<bool>())},
|
|
|
|
{create<ast::StructBlockDecoration>()});
|
2021-04-22 14:40:23 +00:00
|
|
|
auto a = ty.access(ast::AccessControl::kReadOnly, s);
|
2021-05-10 19:16:46 +00:00
|
|
|
Global(Source{{56, 78}}, "g", a, ast::StorageClass::kStorage, nullptr,
|
|
|
|
{
|
|
|
|
create<ast::BindingDecoration>(0),
|
|
|
|
create<ast::GroupDecoration>(0),
|
|
|
|
});
|
2021-03-18 20:46:24 +00:00
|
|
|
|
|
|
|
ASSERT_FALSE(r()->Resolve());
|
|
|
|
|
|
|
|
EXPECT_EQ(
|
|
|
|
r()->error(),
|
2021-03-18 21:03:24 +00:00
|
|
|
R"(56:78 error: Type 'vec3<bool>' cannot be used in storage class 'storage' as it is non-host-shareable
|
2021-03-18 20:46:24 +00:00
|
|
|
12:34 note: while analysing structure member S.x
|
|
|
|
56:78 note: while instantiating variable g)");
|
|
|
|
}
|
|
|
|
|
2021-03-18 21:03:24 +00:00
|
|
|
TEST_F(ResolverHostShareableValidationTest, Aliases) {
|
2021-05-10 17:38:01 +00:00
|
|
|
auto* a1 = ty.alias("a1", ty.bool_());
|
2021-05-04 19:02:01 +00:00
|
|
|
AST().AddConstructedType(a1);
|
2021-05-07 14:49:34 +00:00
|
|
|
auto* s = Structure("S", {Member(Source{{12, 34}}, "x", a1)},
|
|
|
|
{create<ast::StructBlockDecoration>()});
|
2021-04-22 14:40:23 +00:00
|
|
|
auto ac = ty.access(ast::AccessControl::kReadOnly, s);
|
2021-05-10 17:38:01 +00:00
|
|
|
auto* a2 = ty.alias("a2", ac);
|
2021-05-04 19:02:01 +00:00
|
|
|
AST().AddConstructedType(a2);
|
2021-05-10 19:16:46 +00:00
|
|
|
Global(Source{{56, 78}}, "g", a2, ast::StorageClass::kStorage, nullptr,
|
|
|
|
{
|
|
|
|
create<ast::BindingDecoration>(0),
|
|
|
|
create<ast::GroupDecoration>(0),
|
|
|
|
});
|
2021-03-18 20:46:24 +00:00
|
|
|
|
|
|
|
ASSERT_FALSE(r()->Resolve());
|
|
|
|
|
|
|
|
EXPECT_EQ(
|
|
|
|
r()->error(),
|
2021-03-18 21:03:24 +00:00
|
|
|
R"(56:78 error: Type 'bool' cannot be used in storage class 'storage' as it is non-host-shareable
|
2021-03-18 20:46:24 +00:00
|
|
|
12:34 note: while analysing structure member S.x
|
|
|
|
56:78 note: while instantiating variable g)");
|
|
|
|
}
|
|
|
|
|
2021-03-18 21:03:24 +00:00
|
|
|
TEST_F(ResolverHostShareableValidationTest, NestedStructures) {
|
2021-05-07 14:49:34 +00:00
|
|
|
auto* i1 = Structure("I1", {Member(Source{{1, 2}}, "x", ty.bool_())});
|
|
|
|
auto* i2 = Structure("I2", {Member(Source{{3, 4}}, "y", i1)});
|
|
|
|
auto* i3 = Structure("I3", {Member(Source{{5, 6}}, "z", i2)});
|
2021-03-18 20:46:24 +00:00
|
|
|
|
2021-05-07 14:49:34 +00:00
|
|
|
auto* s = Structure("S", {Member(Source{{7, 8}}, "m", i3)},
|
|
|
|
{create<ast::StructBlockDecoration>()});
|
2021-04-22 14:40:23 +00:00
|
|
|
auto a = ty.access(ast::AccessControl::kReadOnly, s);
|
2021-05-10 19:16:46 +00:00
|
|
|
Global(Source{{9, 10}}, "g", a, ast::StorageClass::kStorage, nullptr,
|
|
|
|
{
|
|
|
|
create<ast::BindingDecoration>(0),
|
|
|
|
create<ast::GroupDecoration>(0),
|
|
|
|
});
|
2021-03-18 20:46:24 +00:00
|
|
|
|
|
|
|
ASSERT_FALSE(r()->Resolve());
|
|
|
|
|
|
|
|
EXPECT_EQ(
|
|
|
|
r()->error(),
|
2021-03-18 21:03:24 +00:00
|
|
|
R"(9:10 error: Type 'bool' cannot be used in storage class 'storage' as it is non-host-shareable
|
2021-03-18 20:46:24 +00:00
|
|
|
1:2 note: while analysing structure member I1.x
|
|
|
|
3:4 note: while analysing structure member I2.y
|
|
|
|
5:6 note: while analysing structure member I3.z
|
|
|
|
7:8 note: while analysing structure member S.m
|
|
|
|
9:10 note: while instantiating variable g)");
|
|
|
|
}
|
|
|
|
|
2021-03-18 21:03:24 +00:00
|
|
|
TEST_F(ResolverHostShareableValidationTest, NoError) {
|
2021-05-07 14:49:34 +00:00
|
|
|
auto* i1 =
|
2021-03-18 20:46:24 +00:00
|
|
|
Structure("I1", {
|
|
|
|
Member(Source{{1, 1}}, "x1", ty.f32()),
|
|
|
|
Member(Source{{2, 1}}, "y1", ty.vec3<f32>()),
|
|
|
|
Member(Source{{3, 1}}, "z1", ty.array<i32, 4>()),
|
|
|
|
});
|
2021-05-10 17:38:01 +00:00
|
|
|
auto* a1 = ty.alias("a1", i1);
|
2021-05-04 19:02:01 +00:00
|
|
|
AST().AddConstructedType(a1);
|
2021-05-07 14:49:34 +00:00
|
|
|
auto* i2 = Structure("I2", {
|
|
|
|
Member(Source{{4, 1}}, "x2", ty.mat2x2<f32>()),
|
|
|
|
Member(Source{{5, 1}}, "y2", i1),
|
|
|
|
Member(Source{{6, 1}}, "z2", ty.mat3x2<i32>()),
|
|
|
|
});
|
2021-05-10 17:38:01 +00:00
|
|
|
auto* a2 = ty.alias("a2", i2);
|
2021-05-04 19:02:01 +00:00
|
|
|
AST().AddConstructedType(a2);
|
2021-05-07 14:49:34 +00:00
|
|
|
auto* i3 = Structure("I3", {
|
|
|
|
Member(Source{{4, 1}}, "x3", a1),
|
|
|
|
Member(Source{{5, 1}}, "y3", i2),
|
|
|
|
Member(Source{{6, 1}}, "z3", a2),
|
|
|
|
});
|
|
|
|
|
|
|
|
auto* s = Structure("S", {Member(Source{{7, 8}}, "m", i3)},
|
|
|
|
{create<ast::StructBlockDecoration>()});
|
2021-04-22 14:40:23 +00:00
|
|
|
auto a = ty.access(ast::AccessControl::kReadOnly, s);
|
2021-05-10 19:16:46 +00:00
|
|
|
Global(Source{{9, 10}}, "g", a, ast::StorageClass::kStorage, nullptr,
|
|
|
|
{
|
|
|
|
create<ast::BindingDecoration>(0),
|
|
|
|
create<ast::GroupDecoration>(0),
|
|
|
|
});
|
2021-03-18 20:46:24 +00:00
|
|
|
|
|
|
|
ASSERT_TRUE(r()->Resolve()) << r()->error();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
} // namespace resolver
|
|
|
|
} // namespace tint
|