Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 1 | // Copyright 2021 The Tint Authors. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | #include "src/intrinsic_table.h" |
| 16 | |
| 17 | #include "gmock/gmock.h" |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 18 | #include "src/program_builder.h" |
Ben Clayton | fd35aa8 | 2021-07-26 22:19:48 +0000 | [diff] [blame] | 19 | #include "src/sem/depth_multisampled_texture_type.h" |
Antonio Maiorano | aea9c68 | 2021-04-19 22:54:43 +0000 | [diff] [blame] | 20 | #include "src/sem/depth_texture_type.h" |
Brandon Jones | 145f865 | 2021-04-22 22:47:03 +0000 | [diff] [blame] | 21 | #include "src/sem/external_texture_type.h" |
Antonio Maiorano | aea9c68 | 2021-04-19 22:54:43 +0000 | [diff] [blame] | 22 | #include "src/sem/multisampled_texture_type.h" |
Ben Clayton | 9b54a2e | 2021-05-18 10:28:48 +0000 | [diff] [blame] | 23 | #include "src/sem/reference_type.h" |
Antonio Maiorano | aea9c68 | 2021-04-19 22:54:43 +0000 | [diff] [blame] | 24 | #include "src/sem/sampled_texture_type.h" |
| 25 | #include "src/sem/storage_texture_type.h" |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 26 | |
| 27 | namespace tint { |
| 28 | namespace { |
| 29 | |
| 30 | using ::testing::ElementsAre; |
| 31 | using ::testing::HasSubstr; |
| 32 | |
Antonio Maiorano | 5cd71b8 | 2021-04-16 19:07:51 +0000 | [diff] [blame] | 33 | using IntrinsicType = sem::IntrinsicType; |
| 34 | using Parameter = sem::Parameter; |
Ben Clayton | 1934f59 | 2021-06-01 10:00:10 +0000 | [diff] [blame] | 35 | using ParameterUsage = sem::ParameterUsage; |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 36 | |
| 37 | class IntrinsicTableTest : public testing::Test, public ProgramBuilder { |
| 38 | public: |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 39 | std::unique_ptr<IntrinsicTable> table = IntrinsicTable::Create(*this); |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | TEST_F(IntrinsicTableTest, MatchF32) { |
Ben Clayton | 512d60c | 2021-05-19 19:51:22 +0000 | [diff] [blame] | 43 | auto* f32 = create<sem::F32>(); |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 44 | auto* result = table->Lookup(IntrinsicType::kCos, {f32}, Source{}); |
| 45 | ASSERT_NE(result, nullptr) << Diagnostics().str(); |
| 46 | ASSERT_EQ(Diagnostics().str(), ""); |
| 47 | EXPECT_THAT(result->Type(), IntrinsicType::kCos); |
| 48 | EXPECT_THAT(result->ReturnType(), f32); |
Ben Clayton | 0f2d95d | 2021-07-22 13:24:59 +0000 | [diff] [blame] | 49 | ASSERT_THAT(result->Parameters().size(), 1); |
| 50 | EXPECT_EQ(result->Parameters()[0]->Type(), f32); |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | TEST_F(IntrinsicTableTest, MismatchF32) { |
Ben Clayton | cf421bb | 2021-05-19 17:47:11 +0000 | [diff] [blame] | 54 | auto* i32 = create<sem::I32>(); |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 55 | auto* result = table->Lookup(IntrinsicType::kCos, {i32}, Source{}); |
| 56 | ASSERT_EQ(result, nullptr); |
| 57 | ASSERT_THAT(Diagnostics().str(), HasSubstr("no matching call")); |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | TEST_F(IntrinsicTableTest, MatchU32) { |
Ben Clayton | 512d60c | 2021-05-19 19:51:22 +0000 | [diff] [blame] | 61 | auto* f32 = create<sem::F32>(); |
Ben Clayton | 58dec17 | 2021-05-19 17:47:11 +0000 | [diff] [blame] | 62 | auto* u32 = create<sem::U32>(); |
Ben Clayton | 512d60c | 2021-05-19 19:51:22 +0000 | [diff] [blame] | 63 | auto* vec2_f32 = create<sem::Vector>(f32, 2); |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 64 | auto* result = |
| 65 | table->Lookup(IntrinsicType::kUnpack2x16float, {u32}, Source{}); |
| 66 | ASSERT_NE(result, nullptr) << Diagnostics().str(); |
| 67 | ASSERT_EQ(Diagnostics().str(), ""); |
| 68 | EXPECT_THAT(result->Type(), IntrinsicType::kUnpack2x16float); |
| 69 | EXPECT_THAT(result->ReturnType(), vec2_f32); |
Ben Clayton | 0f2d95d | 2021-07-22 13:24:59 +0000 | [diff] [blame] | 70 | ASSERT_EQ(result->Parameters().size(), 1u); |
| 71 | EXPECT_EQ(result->Parameters()[0]->Type(), u32); |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | TEST_F(IntrinsicTableTest, MismatchU32) { |
Ben Clayton | 512d60c | 2021-05-19 19:51:22 +0000 | [diff] [blame] | 75 | auto* f32 = create<sem::F32>(); |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 76 | auto* result = |
| 77 | table->Lookup(IntrinsicType::kUnpack2x16float, {f32}, Source{}); |
| 78 | ASSERT_EQ(result, nullptr); |
| 79 | ASSERT_THAT(Diagnostics().str(), HasSubstr("no matching call")); |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | TEST_F(IntrinsicTableTest, MatchI32) { |
Ben Clayton | 512d60c | 2021-05-19 19:51:22 +0000 | [diff] [blame] | 83 | auto* f32 = create<sem::F32>(); |
Ben Clayton | cf421bb | 2021-05-19 17:47:11 +0000 | [diff] [blame] | 84 | auto* i32 = create<sem::I32>(); |
Ben Clayton | 512d60c | 2021-05-19 19:51:22 +0000 | [diff] [blame] | 85 | auto* vec4_f32 = create<sem::Vector>(f32, 4); |
Ben Clayton | 55ecfc4 | 2021-05-20 14:42:28 +0000 | [diff] [blame] | 86 | auto* tex = create<sem::SampledTexture>(ast::TextureDimension::k1d, f32); |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 87 | auto* result = |
| 88 | table->Lookup(IntrinsicType::kTextureLoad, {tex, i32, i32}, Source{}); |
| 89 | ASSERT_NE(result, nullptr) << Diagnostics().str(); |
| 90 | ASSERT_EQ(Diagnostics().str(), ""); |
| 91 | EXPECT_THAT(result->Type(), IntrinsicType::kTextureLoad); |
| 92 | EXPECT_THAT(result->ReturnType(), vec4_f32); |
Ben Clayton | 0f2d95d | 2021-07-22 13:24:59 +0000 | [diff] [blame] | 93 | ASSERT_EQ(result->Parameters().size(), 3u); |
| 94 | EXPECT_EQ(result->Parameters()[0]->Type(), tex); |
| 95 | EXPECT_EQ(result->Parameters()[0]->Usage(), ParameterUsage::kTexture); |
| 96 | EXPECT_EQ(result->Parameters()[1]->Type(), i32); |
| 97 | EXPECT_EQ(result->Parameters()[1]->Usage(), ParameterUsage::kCoords); |
| 98 | EXPECT_EQ(result->Parameters()[2]->Type(), i32); |
| 99 | EXPECT_EQ(result->Parameters()[2]->Usage(), ParameterUsage::kLevel); |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | TEST_F(IntrinsicTableTest, MismatchI32) { |
Ben Clayton | 512d60c | 2021-05-19 19:51:22 +0000 | [diff] [blame] | 103 | auto* f32 = create<sem::F32>(); |
Ben Clayton | 55ecfc4 | 2021-05-20 14:42:28 +0000 | [diff] [blame] | 104 | auto* tex = create<sem::SampledTexture>(ast::TextureDimension::k1d, f32); |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 105 | auto* result = |
| 106 | table->Lookup(IntrinsicType::kTextureLoad, {tex, f32}, Source{}); |
| 107 | ASSERT_EQ(result, nullptr); |
| 108 | ASSERT_THAT(Diagnostics().str(), HasSubstr("no matching call")); |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | TEST_F(IntrinsicTableTest, MatchIU32AsI32) { |
Ben Clayton | cf421bb | 2021-05-19 17:47:11 +0000 | [diff] [blame] | 112 | auto* i32 = create<sem::I32>(); |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 113 | auto* result = table->Lookup(IntrinsicType::kCountOneBits, {i32}, Source{}); |
| 114 | ASSERT_NE(result, nullptr) << Diagnostics().str(); |
| 115 | ASSERT_EQ(Diagnostics().str(), ""); |
| 116 | EXPECT_THAT(result->Type(), IntrinsicType::kCountOneBits); |
| 117 | EXPECT_THAT(result->ReturnType(), i32); |
Ben Clayton | 0f2d95d | 2021-07-22 13:24:59 +0000 | [diff] [blame] | 118 | ASSERT_EQ(result->Parameters().size(), 1u); |
| 119 | EXPECT_EQ(result->Parameters()[0]->Type(), i32); |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | TEST_F(IntrinsicTableTest, MatchIU32AsU32) { |
Ben Clayton | 58dec17 | 2021-05-19 17:47:11 +0000 | [diff] [blame] | 123 | auto* u32 = create<sem::U32>(); |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 124 | auto* result = table->Lookup(IntrinsicType::kCountOneBits, {u32}, Source{}); |
| 125 | ASSERT_NE(result, nullptr) << Diagnostics().str(); |
| 126 | ASSERT_EQ(Diagnostics().str(), ""); |
| 127 | EXPECT_THAT(result->Type(), IntrinsicType::kCountOneBits); |
| 128 | EXPECT_THAT(result->ReturnType(), u32); |
Ben Clayton | 0f2d95d | 2021-07-22 13:24:59 +0000 | [diff] [blame] | 129 | ASSERT_EQ(result->Parameters().size(), 1u); |
| 130 | EXPECT_EQ(result->Parameters()[0]->Type(), u32); |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | TEST_F(IntrinsicTableTest, MismatchIU32) { |
Ben Clayton | 512d60c | 2021-05-19 19:51:22 +0000 | [diff] [blame] | 134 | auto* f32 = create<sem::F32>(); |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 135 | auto* result = table->Lookup(IntrinsicType::kCountOneBits, {f32}, Source{}); |
| 136 | ASSERT_EQ(result, nullptr); |
| 137 | ASSERT_THAT(Diagnostics().str(), HasSubstr("no matching call")); |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | TEST_F(IntrinsicTableTest, MatchFIU32AsI32) { |
Ben Clayton | cf421bb | 2021-05-19 17:47:11 +0000 | [diff] [blame] | 141 | auto* i32 = create<sem::I32>(); |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 142 | auto* result = |
| 143 | table->Lookup(IntrinsicType::kClamp, {i32, i32, i32}, Source{}); |
| 144 | ASSERT_NE(result, nullptr) << Diagnostics().str(); |
| 145 | ASSERT_EQ(Diagnostics().str(), ""); |
| 146 | EXPECT_THAT(result->Type(), IntrinsicType::kClamp); |
| 147 | EXPECT_THAT(result->ReturnType(), i32); |
Ben Clayton | 0f2d95d | 2021-07-22 13:24:59 +0000 | [diff] [blame] | 148 | ASSERT_EQ(result->Parameters().size(), 3u); |
| 149 | EXPECT_EQ(result->Parameters()[0]->Type(), i32); |
| 150 | EXPECT_EQ(result->Parameters()[1]->Type(), i32); |
| 151 | EXPECT_EQ(result->Parameters()[2]->Type(), i32); |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | TEST_F(IntrinsicTableTest, MatchFIU32AsU32) { |
Ben Clayton | 58dec17 | 2021-05-19 17:47:11 +0000 | [diff] [blame] | 155 | auto* u32 = create<sem::U32>(); |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 156 | auto* result = |
| 157 | table->Lookup(IntrinsicType::kClamp, {u32, u32, u32}, Source{}); |
| 158 | ASSERT_NE(result, nullptr) << Diagnostics().str(); |
| 159 | ASSERT_EQ(Diagnostics().str(), ""); |
| 160 | EXPECT_THAT(result->Type(), IntrinsicType::kClamp); |
| 161 | EXPECT_THAT(result->ReturnType(), u32); |
Ben Clayton | 0f2d95d | 2021-07-22 13:24:59 +0000 | [diff] [blame] | 162 | ASSERT_EQ(result->Parameters().size(), 3u); |
| 163 | EXPECT_EQ(result->Parameters()[0]->Type(), u32); |
| 164 | EXPECT_EQ(result->Parameters()[1]->Type(), u32); |
| 165 | EXPECT_EQ(result->Parameters()[2]->Type(), u32); |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | TEST_F(IntrinsicTableTest, MatchFIU32AsF32) { |
Ben Clayton | 512d60c | 2021-05-19 19:51:22 +0000 | [diff] [blame] | 169 | auto* f32 = create<sem::F32>(); |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 170 | auto* result = |
| 171 | table->Lookup(IntrinsicType::kClamp, {f32, f32, f32}, Source{}); |
| 172 | ASSERT_NE(result, nullptr) << Diagnostics().str(); |
| 173 | ASSERT_EQ(Diagnostics().str(), ""); |
| 174 | EXPECT_THAT(result->Type(), IntrinsicType::kClamp); |
| 175 | EXPECT_THAT(result->ReturnType(), f32); |
Ben Clayton | 0f2d95d | 2021-07-22 13:24:59 +0000 | [diff] [blame] | 176 | ASSERT_EQ(result->Parameters().size(), 3u); |
| 177 | EXPECT_EQ(result->Parameters()[0]->Type(), f32); |
| 178 | EXPECT_EQ(result->Parameters()[1]->Type(), f32); |
| 179 | EXPECT_EQ(result->Parameters()[2]->Type(), f32); |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | TEST_F(IntrinsicTableTest, MismatchFIU32) { |
Ben Clayton | c03d3bd | 2021-05-20 14:22:28 +0000 | [diff] [blame] | 183 | auto* bool_ = create<sem::Bool>(); |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 184 | auto* result = |
| 185 | table->Lookup(IntrinsicType::kClamp, {bool_, bool_, bool_}, Source{}); |
| 186 | ASSERT_EQ(result, nullptr); |
| 187 | ASSERT_THAT(Diagnostics().str(), HasSubstr("no matching call")); |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | TEST_F(IntrinsicTableTest, MatchBool) { |
Ben Clayton | 512d60c | 2021-05-19 19:51:22 +0000 | [diff] [blame] | 191 | auto* f32 = create<sem::F32>(); |
Ben Clayton | c03d3bd | 2021-05-20 14:22:28 +0000 | [diff] [blame] | 192 | auto* bool_ = create<sem::Bool>(); |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 193 | auto* result = |
| 194 | table->Lookup(IntrinsicType::kSelect, {f32, f32, bool_}, Source{}); |
| 195 | ASSERT_NE(result, nullptr) << Diagnostics().str(); |
| 196 | ASSERT_EQ(Diagnostics().str(), ""); |
| 197 | EXPECT_THAT(result->Type(), IntrinsicType::kSelect); |
| 198 | EXPECT_THAT(result->ReturnType(), f32); |
Ben Clayton | 0f2d95d | 2021-07-22 13:24:59 +0000 | [diff] [blame] | 199 | ASSERT_EQ(result->Parameters().size(), 3u); |
| 200 | EXPECT_EQ(result->Parameters()[0]->Type(), f32); |
| 201 | EXPECT_EQ(result->Parameters()[1]->Type(), f32); |
| 202 | EXPECT_EQ(result->Parameters()[2]->Type(), bool_); |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | TEST_F(IntrinsicTableTest, MismatchBool) { |
Ben Clayton | 512d60c | 2021-05-19 19:51:22 +0000 | [diff] [blame] | 206 | auto* f32 = create<sem::F32>(); |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 207 | auto* result = |
| 208 | table->Lookup(IntrinsicType::kSelect, {f32, f32, f32}, Source{}); |
| 209 | ASSERT_EQ(result, nullptr); |
| 210 | ASSERT_THAT(Diagnostics().str(), HasSubstr("no matching call")); |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | TEST_F(IntrinsicTableTest, MatchPointer) { |
Ben Clayton | 512d60c | 2021-05-19 19:51:22 +0000 | [diff] [blame] | 214 | auto* f32 = create<sem::F32>(); |
Ben Clayton | 1858854 | 2021-06-04 22:17:37 +0000 | [diff] [blame] | 215 | auto* ptr = create<sem::Pointer>(f32, ast::StorageClass::kFunction, |
| 216 | ast::Access::kReadWrite); |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 217 | auto* result = table->Lookup(IntrinsicType::kModf, {f32, ptr}, Source{}); |
| 218 | ASSERT_NE(result, nullptr) << Diagnostics().str(); |
| 219 | ASSERT_EQ(Diagnostics().str(), ""); |
| 220 | EXPECT_THAT(result->Type(), IntrinsicType::kModf); |
| 221 | EXPECT_THAT(result->ReturnType(), f32); |
Ben Clayton | 0f2d95d | 2021-07-22 13:24:59 +0000 | [diff] [blame] | 222 | ASSERT_EQ(result->Parameters().size(), 2u); |
| 223 | EXPECT_EQ(result->Parameters()[0]->Type(), f32); |
| 224 | EXPECT_EQ(result->Parameters()[1]->Type(), ptr); |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | TEST_F(IntrinsicTableTest, MismatchPointer) { |
Ben Clayton | 512d60c | 2021-05-19 19:51:22 +0000 | [diff] [blame] | 228 | auto* f32 = create<sem::F32>(); |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 229 | auto* result = table->Lookup(IntrinsicType::kModf, {f32, f32}, Source{}); |
| 230 | ASSERT_EQ(result, nullptr); |
| 231 | ASSERT_THAT(Diagnostics().str(), HasSubstr("no matching call")); |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | TEST_F(IntrinsicTableTest, MatchArray) { |
Antonio Maiorano | 68a6dd0 | 2021-07-20 18:28:31 +0000 | [diff] [blame] | 235 | auto* arr = create<sem::Array>(create<sem::U32>(), 0, 4, 4, 4, 4); |
Ben Clayton | 0949304 | 2021-06-18 22:44:31 +0000 | [diff] [blame] | 236 | auto* arr_ptr = create<sem::Pointer>(arr, ast::StorageClass::kStorage, |
| 237 | ast::Access::kReadWrite); |
| 238 | auto* result = |
| 239 | table->Lookup(IntrinsicType::kArrayLength, {arr_ptr}, Source{}); |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 240 | ASSERT_NE(result, nullptr) << Diagnostics().str(); |
| 241 | ASSERT_EQ(Diagnostics().str(), ""); |
| 242 | EXPECT_THAT(result->Type(), IntrinsicType::kArrayLength); |
| 243 | EXPECT_TRUE(result->ReturnType()->Is<sem::U32>()); |
| 244 | ASSERT_EQ(result->Parameters().size(), 1u); |
Ben Clayton | 0f2d95d | 2021-07-22 13:24:59 +0000 | [diff] [blame] | 245 | auto* param_type = result->Parameters()[0]->Type(); |
Ben Clayton | 0949304 | 2021-06-18 22:44:31 +0000 | [diff] [blame] | 246 | ASSERT_TRUE(param_type->Is<sem::Pointer>()); |
| 247 | EXPECT_TRUE(param_type->As<sem::Pointer>()->StoreType()->Is<sem::Array>()); |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | TEST_F(IntrinsicTableTest, MismatchArray) { |
Ben Clayton | 512d60c | 2021-05-19 19:51:22 +0000 | [diff] [blame] | 251 | auto* f32 = create<sem::F32>(); |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 252 | auto* result = table->Lookup(IntrinsicType::kArrayLength, {f32}, Source{}); |
| 253 | ASSERT_EQ(result, nullptr); |
| 254 | ASSERT_THAT(Diagnostics().str(), HasSubstr("no matching call")); |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | TEST_F(IntrinsicTableTest, MatchSampler) { |
Ben Clayton | 512d60c | 2021-05-19 19:51:22 +0000 | [diff] [blame] | 258 | auto* f32 = create<sem::F32>(); |
| 259 | auto* vec2_f32 = create<sem::Vector>(f32, 2); |
| 260 | auto* vec4_f32 = create<sem::Vector>(f32, 4); |
Ben Clayton | 55ecfc4 | 2021-05-20 14:42:28 +0000 | [diff] [blame] | 261 | auto* tex = create<sem::SampledTexture>(ast::TextureDimension::k2d, f32); |
Ben Clayton | b966265 | 2021-05-20 14:54:28 +0000 | [diff] [blame] | 262 | auto* sampler = create<sem::Sampler>(ast::SamplerKind::kSampler); |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 263 | auto* result = table->Lookup(IntrinsicType::kTextureSample, |
| 264 | {tex, sampler, vec2_f32}, Source{}); |
| 265 | ASSERT_NE(result, nullptr) << Diagnostics().str(); |
| 266 | ASSERT_EQ(Diagnostics().str(), ""); |
| 267 | EXPECT_THAT(result->Type(), IntrinsicType::kTextureSample); |
| 268 | EXPECT_THAT(result->ReturnType(), vec4_f32); |
Ben Clayton | 0f2d95d | 2021-07-22 13:24:59 +0000 | [diff] [blame] | 269 | ASSERT_EQ(result->Parameters().size(), 3u); |
| 270 | EXPECT_EQ(result->Parameters()[0]->Type(), tex); |
| 271 | EXPECT_EQ(result->Parameters()[0]->Usage(), ParameterUsage::kTexture); |
| 272 | EXPECT_EQ(result->Parameters()[1]->Type(), sampler); |
| 273 | EXPECT_EQ(result->Parameters()[1]->Usage(), ParameterUsage::kSampler); |
| 274 | EXPECT_EQ(result->Parameters()[2]->Type(), vec2_f32); |
| 275 | EXPECT_EQ(result->Parameters()[2]->Usage(), ParameterUsage::kCoords); |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | TEST_F(IntrinsicTableTest, MismatchSampler) { |
Ben Clayton | 512d60c | 2021-05-19 19:51:22 +0000 | [diff] [blame] | 279 | auto* f32 = create<sem::F32>(); |
| 280 | auto* vec2_f32 = create<sem::Vector>(f32, 2); |
Ben Clayton | 55ecfc4 | 2021-05-20 14:42:28 +0000 | [diff] [blame] | 281 | auto* tex = create<sem::SampledTexture>(ast::TextureDimension::k2d, f32); |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 282 | auto* result = table->Lookup(IntrinsicType::kTextureSample, |
| 283 | {tex, f32, vec2_f32}, Source{}); |
| 284 | ASSERT_EQ(result, nullptr); |
| 285 | ASSERT_THAT(Diagnostics().str(), HasSubstr("no matching call")); |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | TEST_F(IntrinsicTableTest, MatchSampledTexture) { |
Ben Clayton | cf421bb | 2021-05-19 17:47:11 +0000 | [diff] [blame] | 289 | auto* i32 = create<sem::I32>(); |
Ben Clayton | 512d60c | 2021-05-19 19:51:22 +0000 | [diff] [blame] | 290 | auto* f32 = create<sem::F32>(); |
Ben Clayton | cf421bb | 2021-05-19 17:47:11 +0000 | [diff] [blame] | 291 | auto* vec2_i32 = create<sem::Vector>(i32, 2); |
Ben Clayton | 512d60c | 2021-05-19 19:51:22 +0000 | [diff] [blame] | 292 | auto* vec4_f32 = create<sem::Vector>(f32, 4); |
Ben Clayton | 55ecfc4 | 2021-05-20 14:42:28 +0000 | [diff] [blame] | 293 | auto* tex = create<sem::SampledTexture>(ast::TextureDimension::k2d, f32); |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 294 | auto* result = table->Lookup(IntrinsicType::kTextureLoad, |
| 295 | {tex, vec2_i32, i32}, Source{}); |
| 296 | ASSERT_NE(result, nullptr) << Diagnostics().str(); |
| 297 | ASSERT_EQ(Diagnostics().str(), ""); |
| 298 | EXPECT_THAT(result->Type(), IntrinsicType::kTextureLoad); |
| 299 | EXPECT_THAT(result->ReturnType(), vec4_f32); |
Ben Clayton | 0f2d95d | 2021-07-22 13:24:59 +0000 | [diff] [blame] | 300 | ASSERT_EQ(result->Parameters().size(), 3u); |
| 301 | EXPECT_EQ(result->Parameters()[0]->Type(), tex); |
| 302 | EXPECT_EQ(result->Parameters()[0]->Usage(), ParameterUsage::kTexture); |
| 303 | EXPECT_EQ(result->Parameters()[1]->Type(), vec2_i32); |
| 304 | EXPECT_EQ(result->Parameters()[1]->Usage(), ParameterUsage::kCoords); |
| 305 | EXPECT_EQ(result->Parameters()[2]->Type(), i32); |
| 306 | EXPECT_EQ(result->Parameters()[2]->Usage(), ParameterUsage::kLevel); |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | TEST_F(IntrinsicTableTest, MatchMultisampledTexture) { |
Ben Clayton | cf421bb | 2021-05-19 17:47:11 +0000 | [diff] [blame] | 310 | auto* i32 = create<sem::I32>(); |
Ben Clayton | 512d60c | 2021-05-19 19:51:22 +0000 | [diff] [blame] | 311 | auto* f32 = create<sem::F32>(); |
Ben Clayton | cf421bb | 2021-05-19 17:47:11 +0000 | [diff] [blame] | 312 | auto* vec2_i32 = create<sem::Vector>(i32, 2); |
Ben Clayton | 512d60c | 2021-05-19 19:51:22 +0000 | [diff] [blame] | 313 | auto* vec4_f32 = create<sem::Vector>(f32, 4); |
| 314 | auto* tex = create<sem::MultisampledTexture>(ast::TextureDimension::k2d, f32); |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 315 | auto* result = table->Lookup(IntrinsicType::kTextureLoad, |
| 316 | {tex, vec2_i32, i32}, Source{}); |
| 317 | ASSERT_NE(result, nullptr) << Diagnostics().str(); |
| 318 | ASSERT_EQ(Diagnostics().str(), ""); |
| 319 | EXPECT_THAT(result->Type(), IntrinsicType::kTextureLoad); |
| 320 | EXPECT_THAT(result->ReturnType(), vec4_f32); |
Ben Clayton | 0f2d95d | 2021-07-22 13:24:59 +0000 | [diff] [blame] | 321 | ASSERT_EQ(result->Parameters().size(), 3u); |
| 322 | EXPECT_EQ(result->Parameters()[0]->Type(), tex); |
| 323 | EXPECT_EQ(result->Parameters()[0]->Usage(), ParameterUsage::kTexture); |
| 324 | EXPECT_EQ(result->Parameters()[1]->Type(), vec2_i32); |
| 325 | EXPECT_EQ(result->Parameters()[1]->Usage(), ParameterUsage::kCoords); |
| 326 | EXPECT_EQ(result->Parameters()[2]->Type(), i32); |
| 327 | EXPECT_EQ(result->Parameters()[2]->Usage(), ParameterUsage::kSampleIndex); |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | TEST_F(IntrinsicTableTest, MatchDepthTexture) { |
Ben Clayton | 512d60c | 2021-05-19 19:51:22 +0000 | [diff] [blame] | 331 | auto* f32 = create<sem::F32>(); |
Ben Clayton | cf421bb | 2021-05-19 17:47:11 +0000 | [diff] [blame] | 332 | auto* i32 = create<sem::I32>(); |
| 333 | auto* vec2_i32 = create<sem::Vector>(i32, 2); |
Ben Clayton | 55ecfc4 | 2021-05-20 14:42:28 +0000 | [diff] [blame] | 334 | auto* tex = create<sem::DepthTexture>(ast::TextureDimension::k2d); |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 335 | auto* result = table->Lookup(IntrinsicType::kTextureLoad, |
| 336 | {tex, vec2_i32, i32}, Source{}); |
| 337 | ASSERT_NE(result, nullptr) << Diagnostics().str(); |
| 338 | ASSERT_EQ(Diagnostics().str(), ""); |
| 339 | EXPECT_THAT(result->Type(), IntrinsicType::kTextureLoad); |
| 340 | EXPECT_THAT(result->ReturnType(), f32); |
Ben Clayton | 0f2d95d | 2021-07-22 13:24:59 +0000 | [diff] [blame] | 341 | ASSERT_EQ(result->Parameters().size(), 3u); |
| 342 | EXPECT_EQ(result->Parameters()[0]->Type(), tex); |
| 343 | EXPECT_EQ(result->Parameters()[0]->Usage(), ParameterUsage::kTexture); |
| 344 | EXPECT_EQ(result->Parameters()[1]->Type(), vec2_i32); |
| 345 | EXPECT_EQ(result->Parameters()[1]->Usage(), ParameterUsage::kCoords); |
| 346 | EXPECT_EQ(result->Parameters()[2]->Type(), i32); |
| 347 | EXPECT_EQ(result->Parameters()[2]->Usage(), ParameterUsage::kLevel); |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 348 | } |
| 349 | |
Ben Clayton | fd35aa8 | 2021-07-26 22:19:48 +0000 | [diff] [blame] | 350 | TEST_F(IntrinsicTableTest, MatchDepthMultisampledTexture) { |
| 351 | auto* f32 = create<sem::F32>(); |
| 352 | auto* i32 = create<sem::I32>(); |
| 353 | auto* vec2_i32 = create<sem::Vector>(i32, 2); |
| 354 | auto* tex = create<sem::DepthMultisampledTexture>(ast::TextureDimension::k2d); |
| 355 | auto* result = table->Lookup(IntrinsicType::kTextureLoad, |
| 356 | {tex, vec2_i32, i32}, Source{}); |
| 357 | ASSERT_NE(result, nullptr) << Diagnostics().str(); |
| 358 | ASSERT_EQ(Diagnostics().str(), ""); |
| 359 | EXPECT_THAT(result->Type(), IntrinsicType::kTextureLoad); |
| 360 | EXPECT_THAT(result->ReturnType(), f32); |
| 361 | ASSERT_EQ(result->Parameters().size(), 3u); |
| 362 | EXPECT_EQ(result->Parameters()[0]->Type(), tex); |
| 363 | EXPECT_EQ(result->Parameters()[0]->Usage(), ParameterUsage::kTexture); |
| 364 | EXPECT_EQ(result->Parameters()[1]->Type(), vec2_i32); |
| 365 | EXPECT_EQ(result->Parameters()[1]->Usage(), ParameterUsage::kCoords); |
| 366 | EXPECT_EQ(result->Parameters()[2]->Type(), i32); |
| 367 | EXPECT_EQ(result->Parameters()[2]->Usage(), ParameterUsage::kSampleIndex); |
| 368 | } |
| 369 | |
Brandon Jones | 145f865 | 2021-04-22 22:47:03 +0000 | [diff] [blame] | 370 | TEST_F(IntrinsicTableTest, MatchExternalTexture) { |
Ben Clayton | 512d60c | 2021-05-19 19:51:22 +0000 | [diff] [blame] | 371 | auto* f32 = create<sem::F32>(); |
Ben Clayton | cf421bb | 2021-05-19 17:47:11 +0000 | [diff] [blame] | 372 | auto* i32 = create<sem::I32>(); |
| 373 | auto* vec2_i32 = create<sem::Vector>(i32, 2); |
Ben Clayton | 512d60c | 2021-05-19 19:51:22 +0000 | [diff] [blame] | 374 | auto* vec4_f32 = create<sem::Vector>(f32, 4); |
Brandon Jones | 145f865 | 2021-04-22 22:47:03 +0000 | [diff] [blame] | 375 | auto* tex = create<sem::ExternalTexture>(); |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 376 | auto* result = |
| 377 | table->Lookup(IntrinsicType::kTextureLoad, {tex, vec2_i32}, Source{}); |
| 378 | ASSERT_NE(result, nullptr) << Diagnostics().str(); |
| 379 | ASSERT_EQ(Diagnostics().str(), ""); |
| 380 | EXPECT_THAT(result->Type(), IntrinsicType::kTextureLoad); |
| 381 | EXPECT_THAT(result->ReturnType(), vec4_f32); |
Ben Clayton | 0f2d95d | 2021-07-22 13:24:59 +0000 | [diff] [blame] | 382 | ASSERT_EQ(result->Parameters().size(), 2u); |
| 383 | EXPECT_EQ(result->Parameters()[0]->Type(), tex); |
| 384 | EXPECT_EQ(result->Parameters()[0]->Usage(), ParameterUsage::kTexture); |
| 385 | EXPECT_EQ(result->Parameters()[1]->Type(), vec2_i32); |
| 386 | EXPECT_EQ(result->Parameters()[1]->Usage(), ParameterUsage::kCoords); |
Brandon Jones | 145f865 | 2021-04-22 22:47:03 +0000 | [diff] [blame] | 387 | } |
| 388 | |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 389 | TEST_F(IntrinsicTableTest, MatchROStorageTexture) { |
Ben Clayton | 512d60c | 2021-05-19 19:51:22 +0000 | [diff] [blame] | 390 | auto* f32 = create<sem::F32>(); |
Ben Clayton | cf421bb | 2021-05-19 17:47:11 +0000 | [diff] [blame] | 391 | auto* i32 = create<sem::I32>(); |
| 392 | auto* vec2_i32 = create<sem::Vector>(i32, 2); |
Ben Clayton | 512d60c | 2021-05-19 19:51:22 +0000 | [diff] [blame] | 393 | auto* vec4_f32 = create<sem::Vector>(f32, 4); |
Antonio Maiorano | dc4e6c1 | 2021-05-14 17:51:13 +0000 | [diff] [blame] | 394 | auto* subtype = |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 395 | sem::StorageTexture::SubtypeFor(ast::ImageFormat::kR32Float, Types()); |
Ben Clayton | 646f4a9 | 2021-05-31 19:40:30 +0000 | [diff] [blame] | 396 | auto* tex = create<sem::StorageTexture>(ast::TextureDimension::k2d, |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 397 | ast::ImageFormat::kR32Float, |
Ben Clayton | 93e8f52 | 2021-06-04 20:41:47 +0000 | [diff] [blame] | 398 | ast::Access::kRead, subtype); |
Antonio Maiorano | dc4e6c1 | 2021-05-14 17:51:13 +0000 | [diff] [blame] | 399 | |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 400 | auto* result = |
| 401 | table->Lookup(IntrinsicType::kTextureLoad, {tex, vec2_i32}, Source{}); |
| 402 | ASSERT_NE(result, nullptr) << Diagnostics().str(); |
| 403 | ASSERT_EQ(Diagnostics().str(), ""); |
| 404 | EXPECT_THAT(result->Type(), IntrinsicType::kTextureLoad); |
| 405 | EXPECT_THAT(result->ReturnType(), vec4_f32); |
Ben Clayton | 0f2d95d | 2021-07-22 13:24:59 +0000 | [diff] [blame] | 406 | ASSERT_EQ(result->Parameters().size(), 2u); |
| 407 | EXPECT_EQ(result->Parameters()[0]->Type(), tex); |
| 408 | EXPECT_EQ(result->Parameters()[0]->Usage(), ParameterUsage::kTexture); |
| 409 | EXPECT_EQ(result->Parameters()[1]->Type(), vec2_i32); |
| 410 | EXPECT_EQ(result->Parameters()[1]->Usage(), ParameterUsage::kCoords); |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | TEST_F(IntrinsicTableTest, MatchWOStorageTexture) { |
Ben Clayton | 512d60c | 2021-05-19 19:51:22 +0000 | [diff] [blame] | 414 | auto* f32 = create<sem::F32>(); |
Ben Clayton | cf421bb | 2021-05-19 17:47:11 +0000 | [diff] [blame] | 415 | auto* i32 = create<sem::I32>(); |
| 416 | auto* vec2_i32 = create<sem::Vector>(i32, 2); |
Ben Clayton | 512d60c | 2021-05-19 19:51:22 +0000 | [diff] [blame] | 417 | auto* vec4_f32 = create<sem::Vector>(f32, 4); |
Antonio Maiorano | dc4e6c1 | 2021-05-14 17:51:13 +0000 | [diff] [blame] | 418 | auto* subtype = |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 419 | sem::StorageTexture::SubtypeFor(ast::ImageFormat::kR32Float, Types()); |
Ben Clayton | 646f4a9 | 2021-05-31 19:40:30 +0000 | [diff] [blame] | 420 | auto* tex = create<sem::StorageTexture>(ast::TextureDimension::k2d, |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 421 | ast::ImageFormat::kR32Float, |
Ben Clayton | 93e8f52 | 2021-06-04 20:41:47 +0000 | [diff] [blame] | 422 | ast::Access::kWrite, subtype); |
Antonio Maiorano | dc4e6c1 | 2021-05-14 17:51:13 +0000 | [diff] [blame] | 423 | |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 424 | auto* result = table->Lookup(IntrinsicType::kTextureStore, |
| 425 | {tex, vec2_i32, vec4_f32}, Source{}); |
| 426 | ASSERT_NE(result, nullptr) << Diagnostics().str(); |
| 427 | ASSERT_EQ(Diagnostics().str(), ""); |
| 428 | EXPECT_THAT(result->Type(), IntrinsicType::kTextureStore); |
| 429 | EXPECT_TRUE(result->ReturnType()->Is<sem::Void>()); |
Ben Clayton | 0f2d95d | 2021-07-22 13:24:59 +0000 | [diff] [blame] | 430 | ASSERT_EQ(result->Parameters().size(), 3u); |
| 431 | EXPECT_EQ(result->Parameters()[0]->Type(), tex); |
| 432 | EXPECT_EQ(result->Parameters()[0]->Usage(), ParameterUsage::kTexture); |
| 433 | EXPECT_EQ(result->Parameters()[1]->Type(), vec2_i32); |
| 434 | EXPECT_EQ(result->Parameters()[1]->Usage(), ParameterUsage::kCoords); |
| 435 | EXPECT_EQ(result->Parameters()[2]->Type(), vec4_f32); |
| 436 | EXPECT_EQ(result->Parameters()[2]->Usage(), ParameterUsage::kValue); |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | TEST_F(IntrinsicTableTest, MismatchTexture) { |
Ben Clayton | 512d60c | 2021-05-19 19:51:22 +0000 | [diff] [blame] | 440 | auto* f32 = create<sem::F32>(); |
Ben Clayton | cf421bb | 2021-05-19 17:47:11 +0000 | [diff] [blame] | 441 | auto* i32 = create<sem::I32>(); |
| 442 | auto* vec2_i32 = create<sem::Vector>(i32, 2); |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 443 | auto* result = |
| 444 | table->Lookup(IntrinsicType::kTextureLoad, {f32, vec2_i32}, Source{}); |
| 445 | ASSERT_EQ(result, nullptr); |
| 446 | ASSERT_THAT(Diagnostics().str(), HasSubstr("no matching call")); |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 447 | } |
| 448 | |
Ben Clayton | 9b54a2e | 2021-05-18 10:28:48 +0000 | [diff] [blame] | 449 | TEST_F(IntrinsicTableTest, ImplicitLoadOnReference) { |
Ben Clayton | 512d60c | 2021-05-19 19:51:22 +0000 | [diff] [blame] | 450 | auto* f32 = create<sem::F32>(); |
Ben Clayton | 1858854 | 2021-06-04 22:17:37 +0000 | [diff] [blame] | 451 | auto* result = |
| 452 | table->Lookup(IntrinsicType::kCos, |
| 453 | {create<sem::Reference>(f32, ast::StorageClass::kFunction, |
| 454 | ast::Access::kReadWrite)}, |
| 455 | Source{}); |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 456 | ASSERT_NE(result, nullptr) << Diagnostics().str(); |
| 457 | ASSERT_EQ(Diagnostics().str(), ""); |
| 458 | EXPECT_THAT(result->Type(), IntrinsicType::kCos); |
| 459 | EXPECT_THAT(result->ReturnType(), f32); |
Ben Clayton | 0f2d95d | 2021-07-22 13:24:59 +0000 | [diff] [blame] | 460 | ASSERT_EQ(result->Parameters().size(), 1u); |
| 461 | EXPECT_EQ(result->Parameters()[0]->Type(), f32); |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 462 | } |
| 463 | |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 464 | TEST_F(IntrinsicTableTest, MatchOpenType) { |
Ben Clayton | 512d60c | 2021-05-19 19:51:22 +0000 | [diff] [blame] | 465 | auto* f32 = create<sem::F32>(); |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 466 | auto* result = |
| 467 | table->Lookup(IntrinsicType::kClamp, {f32, f32, f32}, Source{}); |
| 468 | ASSERT_NE(result, nullptr) << Diagnostics().str(); |
| 469 | ASSERT_EQ(Diagnostics().str(), ""); |
| 470 | EXPECT_THAT(result->Type(), IntrinsicType::kClamp); |
| 471 | EXPECT_THAT(result->ReturnType(), f32); |
Ben Clayton | 0f2d95d | 2021-07-22 13:24:59 +0000 | [diff] [blame] | 472 | EXPECT_EQ(result->Parameters()[0]->Type(), f32); |
| 473 | EXPECT_EQ(result->Parameters()[1]->Type(), f32); |
| 474 | EXPECT_EQ(result->Parameters()[2]->Type(), f32); |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | TEST_F(IntrinsicTableTest, MismatchOpenType) { |
Ben Clayton | 512d60c | 2021-05-19 19:51:22 +0000 | [diff] [blame] | 478 | auto* f32 = create<sem::F32>(); |
Ben Clayton | 58dec17 | 2021-05-19 17:47:11 +0000 | [diff] [blame] | 479 | auto* u32 = create<sem::U32>(); |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 480 | auto* result = |
| 481 | table->Lookup(IntrinsicType::kClamp, {f32, u32, f32}, Source{}); |
| 482 | ASSERT_EQ(result, nullptr); |
| 483 | ASSERT_THAT(Diagnostics().str(), HasSubstr("no matching call")); |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | TEST_F(IntrinsicTableTest, MatchOpenSizeVector) { |
Ben Clayton | 512d60c | 2021-05-19 19:51:22 +0000 | [diff] [blame] | 487 | auto* f32 = create<sem::F32>(); |
| 488 | auto* vec2_f32 = create<sem::Vector>(f32, 2); |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 489 | auto* result = table->Lookup(IntrinsicType::kClamp, |
| 490 | {vec2_f32, vec2_f32, vec2_f32}, Source{}); |
| 491 | ASSERT_NE(result, nullptr) << Diagnostics().str(); |
| 492 | ASSERT_EQ(Diagnostics().str(), ""); |
| 493 | EXPECT_THAT(result->Type(), IntrinsicType::kClamp); |
| 494 | EXPECT_THAT(result->ReturnType(), vec2_f32); |
Ben Clayton | 0f2d95d | 2021-07-22 13:24:59 +0000 | [diff] [blame] | 495 | ASSERT_EQ(result->Parameters().size(), 3u); |
| 496 | EXPECT_EQ(result->Parameters()[0]->Type(), vec2_f32); |
| 497 | EXPECT_EQ(result->Parameters()[1]->Type(), vec2_f32); |
| 498 | EXPECT_EQ(result->Parameters()[2]->Type(), vec2_f32); |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | TEST_F(IntrinsicTableTest, MismatchOpenSizeVector) { |
Ben Clayton | 512d60c | 2021-05-19 19:51:22 +0000 | [diff] [blame] | 502 | auto* f32 = create<sem::F32>(); |
Ben Clayton | 58dec17 | 2021-05-19 17:47:11 +0000 | [diff] [blame] | 503 | auto* u32 = create<sem::U32>(); |
Ben Clayton | 512d60c | 2021-05-19 19:51:22 +0000 | [diff] [blame] | 504 | auto* vec2_f32 = create<sem::Vector>(f32, 2); |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 505 | auto* result = |
| 506 | table->Lookup(IntrinsicType::kClamp, {vec2_f32, u32, vec2_f32}, Source{}); |
| 507 | ASSERT_EQ(result, nullptr); |
| 508 | ASSERT_THAT(Diagnostics().str(), HasSubstr("no matching call")); |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | TEST_F(IntrinsicTableTest, MatchOpenSizeMatrix) { |
Ben Clayton | 512d60c | 2021-05-19 19:51:22 +0000 | [diff] [blame] | 512 | auto* f32 = create<sem::F32>(); |
| 513 | auto* vec3_f32 = create<sem::Vector>(f32, 3); |
| 514 | auto* mat3_f32 = create<sem::Matrix>(vec3_f32, 3); |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 515 | auto* result = |
| 516 | table->Lookup(IntrinsicType::kDeterminant, {mat3_f32}, Source{}); |
| 517 | ASSERT_NE(result, nullptr) << Diagnostics().str(); |
| 518 | ASSERT_EQ(Diagnostics().str(), ""); |
| 519 | EXPECT_THAT(result->Type(), IntrinsicType::kDeterminant); |
| 520 | EXPECT_THAT(result->ReturnType(), f32); |
Ben Clayton | 0f2d95d | 2021-07-22 13:24:59 +0000 | [diff] [blame] | 521 | ASSERT_EQ(result->Parameters().size(), 1u); |
| 522 | EXPECT_EQ(result->Parameters()[0]->Type(), mat3_f32); |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | TEST_F(IntrinsicTableTest, MismatchOpenSizeMatrix) { |
Ben Clayton | 512d60c | 2021-05-19 19:51:22 +0000 | [diff] [blame] | 526 | auto* f32 = create<sem::F32>(); |
| 527 | auto* vec2_f32 = create<sem::Vector>(f32, 2); |
| 528 | auto* mat3x2_f32 = create<sem::Matrix>(vec2_f32, 3); |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 529 | auto* result = |
| 530 | table->Lookup(IntrinsicType::kDeterminant, {mat3x2_f32}, Source{}); |
| 531 | ASSERT_EQ(result, nullptr); |
| 532 | ASSERT_THAT(Diagnostics().str(), HasSubstr("no matching call")); |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | TEST_F(IntrinsicTableTest, OverloadOrderByNumberOfParameters) { |
| 536 | // None of the arguments match, so expect the overloads with 2 parameters to |
| 537 | // come first |
Ben Clayton | c03d3bd | 2021-05-20 14:22:28 +0000 | [diff] [blame] | 538 | auto* bool_ = create<sem::Bool>(); |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 539 | table->Lookup(IntrinsicType::kTextureDimensions, {bool_, bool_}, Source{}); |
| 540 | ASSERT_EQ(Diagnostics().str(), |
Ben Clayton | 6b4924f | 2021-02-17 20:13:34 +0000 | [diff] [blame] | 541 | R"(error: no matching call to textureDimensions(bool, bool) |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 542 | |
Ben Clayton | fd35aa8 | 2021-07-26 22:19:48 +0000 | [diff] [blame] | 543 | 27 candidate functions: |
Ben Clayton | 9e0b3cc | 2021-07-15 16:14:34 +0000 | [diff] [blame] | 544 | textureDimensions(texture: texture_1d<T>, level: i32) -> i32 where: T is f32, i32 or u32 |
Ben Clayton | 57d6bd2 | 2021-06-03 08:32:44 +0000 | [diff] [blame] | 545 | textureDimensions(texture: texture_2d<T>, level: i32) -> vec2<i32> where: T is f32, i32 or u32 |
| 546 | textureDimensions(texture: texture_2d_array<T>, level: i32) -> vec2<i32> where: T is f32, i32 or u32 |
| 547 | textureDimensions(texture: texture_3d<T>, level: i32) -> vec3<i32> where: T is f32, i32 or u32 |
Ben Clayton | b96ed7b | 2021-06-21 16:44:26 +0000 | [diff] [blame] | 548 | textureDimensions(texture: texture_cube<T>, level: i32) -> vec2<i32> where: T is f32, i32 or u32 |
| 549 | textureDimensions(texture: texture_cube_array<T>, level: i32) -> vec2<i32> where: T is f32, i32 or u32 |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 550 | textureDimensions(texture: texture_depth_2d, level: i32) -> vec2<i32> |
| 551 | textureDimensions(texture: texture_depth_2d_array, level: i32) -> vec2<i32> |
Ben Clayton | b96ed7b | 2021-06-21 16:44:26 +0000 | [diff] [blame] | 552 | textureDimensions(texture: texture_depth_cube, level: i32) -> vec2<i32> |
| 553 | textureDimensions(texture: texture_depth_cube_array, level: i32) -> vec2<i32> |
Ben Clayton | 57d6bd2 | 2021-06-03 08:32:44 +0000 | [diff] [blame] | 554 | textureDimensions(texture: texture_1d<T>) -> i32 where: T is f32, i32 or u32 |
| 555 | textureDimensions(texture: texture_2d<T>) -> vec2<i32> where: T is f32, i32 or u32 |
| 556 | textureDimensions(texture: texture_2d_array<T>) -> vec2<i32> where: T is f32, i32 or u32 |
| 557 | textureDimensions(texture: texture_3d<T>) -> vec3<i32> where: T is f32, i32 or u32 |
Ben Clayton | b96ed7b | 2021-06-21 16:44:26 +0000 | [diff] [blame] | 558 | textureDimensions(texture: texture_cube<T>) -> vec2<i32> where: T is f32, i32 or u32 |
| 559 | textureDimensions(texture: texture_cube_array<T>) -> vec2<i32> where: T is f32, i32 or u32 |
Ben Clayton | 57d6bd2 | 2021-06-03 08:32:44 +0000 | [diff] [blame] | 560 | textureDimensions(texture: texture_multisampled_2d<T>) -> vec2<i32> where: T is f32, i32 or u32 |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 561 | textureDimensions(texture: texture_depth_2d) -> vec2<i32> |
| 562 | textureDimensions(texture: texture_depth_2d_array) -> vec2<i32> |
Ben Clayton | b96ed7b | 2021-06-21 16:44:26 +0000 | [diff] [blame] | 563 | textureDimensions(texture: texture_depth_cube) -> vec2<i32> |
| 564 | textureDimensions(texture: texture_depth_cube_array) -> vec2<i32> |
Ben Clayton | fd35aa8 | 2021-07-26 22:19:48 +0000 | [diff] [blame] | 565 | textureDimensions(texture: texture_depth_multisampled_2d) -> vec2<i32> |
Ben Clayton | 57d6bd2 | 2021-06-03 08:32:44 +0000 | [diff] [blame] | 566 | textureDimensions(texture: texture_storage_1d<F, A>) -> i32 where: A is read or write |
| 567 | textureDimensions(texture: texture_storage_2d<F, A>) -> vec2<i32> where: A is read or write |
| 568 | textureDimensions(texture: texture_storage_2d_array<F, A>) -> vec2<i32> where: A is read or write |
| 569 | textureDimensions(texture: texture_storage_3d<F, A>) -> vec3<i32> where: A is read or write |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 570 | textureDimensions(texture: texture_external) -> vec2<i32> |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 571 | )"); |
| 572 | } |
| 573 | |
| 574 | TEST_F(IntrinsicTableTest, OverloadOrderByMatchingParameter) { |
Ben Clayton | 55ecfc4 | 2021-05-20 14:42:28 +0000 | [diff] [blame] | 575 | auto* tex = create<sem::DepthTexture>(ast::TextureDimension::k2d); |
Ben Clayton | c03d3bd | 2021-05-20 14:22:28 +0000 | [diff] [blame] | 576 | auto* bool_ = create<sem::Bool>(); |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 577 | table->Lookup(IntrinsicType::kTextureDimensions, {tex, bool_}, Source{}); |
Ben Clayton | 6b4924f | 2021-02-17 20:13:34 +0000 | [diff] [blame] | 578 | ASSERT_EQ( |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 579 | Diagnostics().str(), |
Ben Clayton | 6b4924f | 2021-02-17 20:13:34 +0000 | [diff] [blame] | 580 | R"(error: no matching call to textureDimensions(texture_depth_2d, bool) |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 581 | |
Ben Clayton | fd35aa8 | 2021-07-26 22:19:48 +0000 | [diff] [blame] | 582 | 27 candidate functions: |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 583 | textureDimensions(texture: texture_depth_2d, level: i32) -> vec2<i32> |
| 584 | textureDimensions(texture: texture_depth_2d) -> vec2<i32> |
Ben Clayton | 9e0b3cc | 2021-07-15 16:14:34 +0000 | [diff] [blame] | 585 | textureDimensions(texture: texture_1d<T>, level: i32) -> i32 where: T is f32, i32 or u32 |
Ben Clayton | 57d6bd2 | 2021-06-03 08:32:44 +0000 | [diff] [blame] | 586 | textureDimensions(texture: texture_2d<T>, level: i32) -> vec2<i32> where: T is f32, i32 or u32 |
| 587 | textureDimensions(texture: texture_2d_array<T>, level: i32) -> vec2<i32> where: T is f32, i32 or u32 |
| 588 | textureDimensions(texture: texture_3d<T>, level: i32) -> vec3<i32> where: T is f32, i32 or u32 |
Ben Clayton | b96ed7b | 2021-06-21 16:44:26 +0000 | [diff] [blame] | 589 | textureDimensions(texture: texture_cube<T>, level: i32) -> vec2<i32> where: T is f32, i32 or u32 |
| 590 | textureDimensions(texture: texture_cube_array<T>, level: i32) -> vec2<i32> where: T is f32, i32 or u32 |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 591 | textureDimensions(texture: texture_depth_2d_array, level: i32) -> vec2<i32> |
Ben Clayton | b96ed7b | 2021-06-21 16:44:26 +0000 | [diff] [blame] | 592 | textureDimensions(texture: texture_depth_cube, level: i32) -> vec2<i32> |
| 593 | textureDimensions(texture: texture_depth_cube_array, level: i32) -> vec2<i32> |
Ben Clayton | 57d6bd2 | 2021-06-03 08:32:44 +0000 | [diff] [blame] | 594 | textureDimensions(texture: texture_1d<T>) -> i32 where: T is f32, i32 or u32 |
| 595 | textureDimensions(texture: texture_2d<T>) -> vec2<i32> where: T is f32, i32 or u32 |
| 596 | textureDimensions(texture: texture_2d_array<T>) -> vec2<i32> where: T is f32, i32 or u32 |
| 597 | textureDimensions(texture: texture_3d<T>) -> vec3<i32> where: T is f32, i32 or u32 |
Ben Clayton | b96ed7b | 2021-06-21 16:44:26 +0000 | [diff] [blame] | 598 | textureDimensions(texture: texture_cube<T>) -> vec2<i32> where: T is f32, i32 or u32 |
| 599 | textureDimensions(texture: texture_cube_array<T>) -> vec2<i32> where: T is f32, i32 or u32 |
Ben Clayton | 57d6bd2 | 2021-06-03 08:32:44 +0000 | [diff] [blame] | 600 | textureDimensions(texture: texture_multisampled_2d<T>) -> vec2<i32> where: T is f32, i32 or u32 |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 601 | textureDimensions(texture: texture_depth_2d_array) -> vec2<i32> |
Ben Clayton | b96ed7b | 2021-06-21 16:44:26 +0000 | [diff] [blame] | 602 | textureDimensions(texture: texture_depth_cube) -> vec2<i32> |
| 603 | textureDimensions(texture: texture_depth_cube_array) -> vec2<i32> |
Ben Clayton | fd35aa8 | 2021-07-26 22:19:48 +0000 | [diff] [blame] | 604 | textureDimensions(texture: texture_depth_multisampled_2d) -> vec2<i32> |
Ben Clayton | 57d6bd2 | 2021-06-03 08:32:44 +0000 | [diff] [blame] | 605 | textureDimensions(texture: texture_storage_1d<F, A>) -> i32 where: A is read or write |
| 606 | textureDimensions(texture: texture_storage_2d<F, A>) -> vec2<i32> where: A is read or write |
| 607 | textureDimensions(texture: texture_storage_2d_array<F, A>) -> vec2<i32> where: A is read or write |
| 608 | textureDimensions(texture: texture_storage_3d<F, A>) -> vec3<i32> where: A is read or write |
Ben Clayton | b29a59d | 2021-06-01 19:06:31 +0000 | [diff] [blame] | 609 | textureDimensions(texture: texture_external) -> vec2<i32> |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 610 | )"); |
| 611 | } |
| 612 | |
Ben Clayton | b478f97 | 2021-07-15 20:34:21 +0000 | [diff] [blame] | 613 | TEST_F(IntrinsicTableTest, SameOverloadReturnsSameIntrinsicPointer) { |
| 614 | auto* f32 = create<sem::F32>(); |
| 615 | auto* vec2_f32 = create<sem::Vector>(create<sem::F32>(), 2); |
| 616 | auto* bool_ = create<sem::Bool>(); |
| 617 | auto* a = table->Lookup(IntrinsicType::kSelect, {f32, f32, bool_}, Source{}); |
| 618 | ASSERT_NE(a, nullptr) << Diagnostics().str(); |
| 619 | |
| 620 | auto* b = table->Lookup(IntrinsicType::kSelect, {f32, f32, bool_}, Source{}); |
| 621 | ASSERT_NE(b, nullptr) << Diagnostics().str(); |
| 622 | ASSERT_EQ(Diagnostics().str(), ""); |
| 623 | |
| 624 | auto* c = table->Lookup(IntrinsicType::kSelect, {vec2_f32, vec2_f32, bool_}, |
| 625 | Source{}); |
| 626 | ASSERT_NE(c, nullptr) << Diagnostics().str(); |
| 627 | ASSERT_EQ(Diagnostics().str(), ""); |
| 628 | |
| 629 | EXPECT_EQ(a, b); |
| 630 | EXPECT_NE(a, c); |
| 631 | EXPECT_NE(b, c); |
| 632 | } |
| 633 | |
Ben Clayton | faca02d | 2021-02-10 21:34:25 +0000 | [diff] [blame] | 634 | } // namespace |
| 635 | } // namespace tint |