// 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())); EXPECT_TRUE(r()->IsHostShareable(ty.vec3())); EXPECT_TRUE(r()->IsHostShareable(ty.vec4())); EXPECT_TRUE(r()->IsHostShareable(ty.vec2())); EXPECT_TRUE(r()->IsHostShareable(ty.vec3())); EXPECT_TRUE(r()->IsHostShareable(ty.vec4())); EXPECT_TRUE(r()->IsHostShareable(ty.vec2())); EXPECT_TRUE(r()->IsHostShareable(ty.vec3())); EXPECT_TRUE(r()->IsHostShareable(ty.vec4())); } TEST_F(ResolverIsHostShareable, BoolVector) { EXPECT_FALSE(r()->IsHostShareable(ty.vec2())); EXPECT_FALSE(r()->IsHostShareable(ty.vec3())); EXPECT_FALSE(r()->IsHostShareable(ty.vec4())); EXPECT_FALSE(r()->IsHostShareable(ty.vec2())); EXPECT_FALSE(r()->IsHostShareable(ty.vec3())); EXPECT_FALSE(r()->IsHostShareable(ty.vec4())); EXPECT_FALSE(r()->IsHostShareable(ty.vec2())); EXPECT_FALSE(r()->IsHostShareable(ty.vec3())); EXPECT_FALSE(r()->IsHostShareable(ty.vec4())); } TEST_F(ResolverIsHostShareable, Matrix) { EXPECT_TRUE(r()->IsHostShareable(ty.mat2x2())); EXPECT_TRUE(r()->IsHostShareable(ty.mat2x3())); EXPECT_TRUE(r()->IsHostShareable(ty.mat2x4())); EXPECT_TRUE(r()->IsHostShareable(ty.mat3x2())); EXPECT_TRUE(r()->IsHostShareable(ty.mat3x3())); EXPECT_TRUE(r()->IsHostShareable(ty.mat3x4())); EXPECT_TRUE(r()->IsHostShareable(ty.mat4x2())); EXPECT_TRUE(r()->IsHostShareable(ty.mat4x3())); EXPECT_TRUE(r()->IsHostShareable(ty.mat4x4())); } TEST_F(ResolverIsHostShareable, Pointer) { EXPECT_FALSE( r()->IsHostShareable(ty.pointer(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(create(), 5, 4, 20, 4, true); EXPECT_TRUE(r()->IsHostShareable(arr)); } TEST_F(ResolverIsHostShareable, ArrayUnsizedOfHostShareable) { auto* arr = create(create(), 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