dawn-cmake/src/resolver/is_host_shareable_test.cc
Ben Clayton 4cd5eea87e sem: Fold together sem::Array and sem::ArrayType
There's now no need to have both.
Removes a whole bunch of Sem().Get() smell, and simplifies the resolver.

Also fixes a long-standing issue where an array with an explicit, but equal-to-implicit-stride attribute would result in a different type to an array without the decoration.

Bug: tint:724
Fixed: tint:782
Change-Id: I0202459009cd45be427cdb621993a5a3b07ff51e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50301
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-05-07 20:58:34 +00:00

115 lines
3.9 KiB
C++

// 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"
#include "src/resolver/resolver_test_helper.h"
#include "src/sem/access_control_type.h"
namespace tint {
namespace resolver {
namespace {
using ResolverIsHostShareable = ResolverTest;
TEST_F(ResolverIsHostShareable, Void) {
EXPECT_FALSE(r()->IsHostShareable(ty.void_()));
}
TEST_F(ResolverIsHostShareable, Bool) {
EXPECT_FALSE(r()->IsHostShareable(ty.bool_()));
}
TEST_F(ResolverIsHostShareable, NumericScalar) {
EXPECT_TRUE(r()->IsHostShareable(ty.i32()));
EXPECT_TRUE(r()->IsHostShareable(ty.u32()));
EXPECT_TRUE(r()->IsHostShareable(ty.f32()));
}
TEST_F(ResolverIsHostShareable, NumericVector) {
EXPECT_TRUE(r()->IsHostShareable(ty.vec2<i32>()));
EXPECT_TRUE(r()->IsHostShareable(ty.vec3<i32>()));
EXPECT_TRUE(r()->IsHostShareable(ty.vec4<i32>()));
EXPECT_TRUE(r()->IsHostShareable(ty.vec2<u32>()));
EXPECT_TRUE(r()->IsHostShareable(ty.vec3<u32>()));
EXPECT_TRUE(r()->IsHostShareable(ty.vec4<u32>()));
EXPECT_TRUE(r()->IsHostShareable(ty.vec2<f32>()));
EXPECT_TRUE(r()->IsHostShareable(ty.vec3<f32>()));
EXPECT_TRUE(r()->IsHostShareable(ty.vec4<f32>()));
}
TEST_F(ResolverIsHostShareable, BoolVector) {
EXPECT_FALSE(r()->IsHostShareable(ty.vec2<bool>()));
EXPECT_FALSE(r()->IsHostShareable(ty.vec3<bool>()));
EXPECT_FALSE(r()->IsHostShareable(ty.vec4<bool>()));
EXPECT_FALSE(r()->IsHostShareable(ty.vec2<bool>()));
EXPECT_FALSE(r()->IsHostShareable(ty.vec3<bool>()));
EXPECT_FALSE(r()->IsHostShareable(ty.vec4<bool>()));
EXPECT_FALSE(r()->IsHostShareable(ty.vec2<bool>()));
EXPECT_FALSE(r()->IsHostShareable(ty.vec3<bool>()));
EXPECT_FALSE(r()->IsHostShareable(ty.vec4<bool>()));
}
TEST_F(ResolverIsHostShareable, Matrix) {
EXPECT_TRUE(r()->IsHostShareable(ty.mat2x2<f32>()));
EXPECT_TRUE(r()->IsHostShareable(ty.mat2x3<f32>()));
EXPECT_TRUE(r()->IsHostShareable(ty.mat2x4<f32>()));
EXPECT_TRUE(r()->IsHostShareable(ty.mat3x2<f32>()));
EXPECT_TRUE(r()->IsHostShareable(ty.mat3x3<f32>()));
EXPECT_TRUE(r()->IsHostShareable(ty.mat3x4<f32>()));
EXPECT_TRUE(r()->IsHostShareable(ty.mat4x2<f32>()));
EXPECT_TRUE(r()->IsHostShareable(ty.mat4x3<f32>()));
EXPECT_TRUE(r()->IsHostShareable(ty.mat4x4<f32>()));
}
TEST_F(ResolverIsHostShareable, Pointer) {
EXPECT_FALSE(
r()->IsHostShareable(ty.pointer<i32>(ast::StorageClass::kPrivate)));
}
TEST_F(ResolverIsHostShareable, AliasVoid) {
EXPECT_FALSE(r()->IsHostShareable(ty.alias("a", ty.void_())));
}
TEST_F(ResolverIsHostShareable, AliasI32) {
EXPECT_TRUE(r()->IsHostShareable(ty.alias("a", ty.i32())));
}
TEST_F(ResolverIsHostShareable, AccessControlVoid) {
EXPECT_FALSE(r()->IsHostShareable(
ty.access(ast::AccessControl::kReadOnly, ty.void_())));
}
TEST_F(ResolverIsHostShareable, AccessControlI32) {
EXPECT_TRUE(
r()->IsHostShareable(ty.access(ast::AccessControl::kReadOnly, ty.i32())));
}
TEST_F(ResolverIsHostShareable, ArraySizedOfHostShareable) {
auto* arr = create<sem::Array>(create<sem::I32>(), 5, 4, 20, 4, true);
EXPECT_TRUE(r()->IsHostShareable(arr));
}
TEST_F(ResolverIsHostShareable, ArrayUnsizedOfHostShareable) {
auto* arr = create<sem::Array>(create<sem::I32>(), 0, 4, 4, 4, true);
EXPECT_TRUE(r()->IsHostShareable(arr));
}
// Note: Structure tests covered in host_shareable_validation_test.cc
} // namespace
} // namespace resolver
} // namespace tint