blob: 9a334ad2ca2649afe3a3d412022969a469815c5f [file] [log] [blame]
Ben Claytonfaca02d2021-02-10 21:34:25 +00001// 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 Claytonfaca02d2021-02-10 21:34:25 +000018#include "src/program_builder.h"
Ben Claytonfd35aa82021-07-26 22:19:48 +000019#include "src/sem/depth_multisampled_texture_type.h"
Antonio Maioranoaea9c682021-04-19 22:54:43 +000020#include "src/sem/depth_texture_type.h"
Brandon Jones145f8652021-04-22 22:47:03 +000021#include "src/sem/external_texture_type.h"
Antonio Maioranoaea9c682021-04-19 22:54:43 +000022#include "src/sem/multisampled_texture_type.h"
Ben Clayton9b54a2e2021-05-18 10:28:48 +000023#include "src/sem/reference_type.h"
Antonio Maioranoaea9c682021-04-19 22:54:43 +000024#include "src/sem/sampled_texture_type.h"
25#include "src/sem/storage_texture_type.h"
Ben Claytonfaca02d2021-02-10 21:34:25 +000026
27namespace tint {
28namespace {
29
30using ::testing::ElementsAre;
31using ::testing::HasSubstr;
32
Antonio Maiorano5cd71b82021-04-16 19:07:51 +000033using IntrinsicType = sem::IntrinsicType;
34using Parameter = sem::Parameter;
Ben Clayton1934f592021-06-01 10:00:10 +000035using ParameterUsage = sem::ParameterUsage;
Ben Claytonfaca02d2021-02-10 21:34:25 +000036
37class IntrinsicTableTest : public testing::Test, public ProgramBuilder {
38 public:
Ben Claytonb29a59d2021-06-01 19:06:31 +000039 std::unique_ptr<IntrinsicTable> table = IntrinsicTable::Create(*this);
Ben Claytonfaca02d2021-02-10 21:34:25 +000040};
41
42TEST_F(IntrinsicTableTest, MatchF32) {
Ben Clayton512d60c2021-05-19 19:51:22 +000043 auto* f32 = create<sem::F32>();
Ben Claytonb29a59d2021-06-01 19:06:31 +000044 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 Clayton0f2d95d2021-07-22 13:24:59 +000049 ASSERT_THAT(result->Parameters().size(), 1);
50 EXPECT_EQ(result->Parameters()[0]->Type(), f32);
Ben Claytonfaca02d2021-02-10 21:34:25 +000051}
52
53TEST_F(IntrinsicTableTest, MismatchF32) {
Ben Claytoncf421bb2021-05-19 17:47:11 +000054 auto* i32 = create<sem::I32>();
Ben Claytonb29a59d2021-06-01 19:06:31 +000055 auto* result = table->Lookup(IntrinsicType::kCos, {i32}, Source{});
56 ASSERT_EQ(result, nullptr);
57 ASSERT_THAT(Diagnostics().str(), HasSubstr("no matching call"));
Ben Claytonfaca02d2021-02-10 21:34:25 +000058}
59
60TEST_F(IntrinsicTableTest, MatchU32) {
Ben Clayton512d60c2021-05-19 19:51:22 +000061 auto* f32 = create<sem::F32>();
Ben Clayton58dec172021-05-19 17:47:11 +000062 auto* u32 = create<sem::U32>();
Ben Clayton512d60c2021-05-19 19:51:22 +000063 auto* vec2_f32 = create<sem::Vector>(f32, 2);
Ben Claytonb29a59d2021-06-01 19:06:31 +000064 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 Clayton0f2d95d2021-07-22 13:24:59 +000070 ASSERT_EQ(result->Parameters().size(), 1u);
71 EXPECT_EQ(result->Parameters()[0]->Type(), u32);
Ben Claytonfaca02d2021-02-10 21:34:25 +000072}
73
74TEST_F(IntrinsicTableTest, MismatchU32) {
Ben Clayton512d60c2021-05-19 19:51:22 +000075 auto* f32 = create<sem::F32>();
Ben Claytonb29a59d2021-06-01 19:06:31 +000076 auto* result =
77 table->Lookup(IntrinsicType::kUnpack2x16float, {f32}, Source{});
78 ASSERT_EQ(result, nullptr);
79 ASSERT_THAT(Diagnostics().str(), HasSubstr("no matching call"));
Ben Claytonfaca02d2021-02-10 21:34:25 +000080}
81
82TEST_F(IntrinsicTableTest, MatchI32) {
Ben Clayton512d60c2021-05-19 19:51:22 +000083 auto* f32 = create<sem::F32>();
Ben Claytoncf421bb2021-05-19 17:47:11 +000084 auto* i32 = create<sem::I32>();
Ben Clayton512d60c2021-05-19 19:51:22 +000085 auto* vec4_f32 = create<sem::Vector>(f32, 4);
Ben Clayton55ecfc42021-05-20 14:42:28 +000086 auto* tex = create<sem::SampledTexture>(ast::TextureDimension::k1d, f32);
Ben Claytonb29a59d2021-06-01 19:06:31 +000087 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 Clayton0f2d95d2021-07-22 13:24:59 +000093 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 Claytonfaca02d2021-02-10 21:34:25 +0000100}
101
102TEST_F(IntrinsicTableTest, MismatchI32) {
Ben Clayton512d60c2021-05-19 19:51:22 +0000103 auto* f32 = create<sem::F32>();
Ben Clayton55ecfc42021-05-20 14:42:28 +0000104 auto* tex = create<sem::SampledTexture>(ast::TextureDimension::k1d, f32);
Ben Claytonb29a59d2021-06-01 19:06:31 +0000105 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 Claytonfaca02d2021-02-10 21:34:25 +0000109}
110
111TEST_F(IntrinsicTableTest, MatchIU32AsI32) {
Ben Claytoncf421bb2021-05-19 17:47:11 +0000112 auto* i32 = create<sem::I32>();
Ben Claytonb29a59d2021-06-01 19:06:31 +0000113 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 Clayton0f2d95d2021-07-22 13:24:59 +0000118 ASSERT_EQ(result->Parameters().size(), 1u);
119 EXPECT_EQ(result->Parameters()[0]->Type(), i32);
Ben Claytonfaca02d2021-02-10 21:34:25 +0000120}
121
122TEST_F(IntrinsicTableTest, MatchIU32AsU32) {
Ben Clayton58dec172021-05-19 17:47:11 +0000123 auto* u32 = create<sem::U32>();
Ben Claytonb29a59d2021-06-01 19:06:31 +0000124 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 Clayton0f2d95d2021-07-22 13:24:59 +0000129 ASSERT_EQ(result->Parameters().size(), 1u);
130 EXPECT_EQ(result->Parameters()[0]->Type(), u32);
Ben Claytonfaca02d2021-02-10 21:34:25 +0000131}
132
133TEST_F(IntrinsicTableTest, MismatchIU32) {
Ben Clayton512d60c2021-05-19 19:51:22 +0000134 auto* f32 = create<sem::F32>();
Ben Claytonb29a59d2021-06-01 19:06:31 +0000135 auto* result = table->Lookup(IntrinsicType::kCountOneBits, {f32}, Source{});
136 ASSERT_EQ(result, nullptr);
137 ASSERT_THAT(Diagnostics().str(), HasSubstr("no matching call"));
Ben Claytonfaca02d2021-02-10 21:34:25 +0000138}
139
140TEST_F(IntrinsicTableTest, MatchFIU32AsI32) {
Ben Claytoncf421bb2021-05-19 17:47:11 +0000141 auto* i32 = create<sem::I32>();
Ben Claytonb29a59d2021-06-01 19:06:31 +0000142 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 Clayton0f2d95d2021-07-22 13:24:59 +0000148 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 Claytonfaca02d2021-02-10 21:34:25 +0000152}
153
154TEST_F(IntrinsicTableTest, MatchFIU32AsU32) {
Ben Clayton58dec172021-05-19 17:47:11 +0000155 auto* u32 = create<sem::U32>();
Ben Claytonb29a59d2021-06-01 19:06:31 +0000156 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 Clayton0f2d95d2021-07-22 13:24:59 +0000162 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 Claytonfaca02d2021-02-10 21:34:25 +0000166}
167
168TEST_F(IntrinsicTableTest, MatchFIU32AsF32) {
Ben Clayton512d60c2021-05-19 19:51:22 +0000169 auto* f32 = create<sem::F32>();
Ben Claytonb29a59d2021-06-01 19:06:31 +0000170 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 Clayton0f2d95d2021-07-22 13:24:59 +0000176 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 Claytonfaca02d2021-02-10 21:34:25 +0000180}
181
182TEST_F(IntrinsicTableTest, MismatchFIU32) {
Ben Claytonc03d3bd2021-05-20 14:22:28 +0000183 auto* bool_ = create<sem::Bool>();
Ben Claytonb29a59d2021-06-01 19:06:31 +0000184 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 Claytonfaca02d2021-02-10 21:34:25 +0000188}
189
190TEST_F(IntrinsicTableTest, MatchBool) {
Ben Clayton512d60c2021-05-19 19:51:22 +0000191 auto* f32 = create<sem::F32>();
Ben Claytonc03d3bd2021-05-20 14:22:28 +0000192 auto* bool_ = create<sem::Bool>();
Ben Claytonb29a59d2021-06-01 19:06:31 +0000193 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 Clayton0f2d95d2021-07-22 13:24:59 +0000199 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 Claytonfaca02d2021-02-10 21:34:25 +0000203}
204
205TEST_F(IntrinsicTableTest, MismatchBool) {
Ben Clayton512d60c2021-05-19 19:51:22 +0000206 auto* f32 = create<sem::F32>();
Ben Claytonb29a59d2021-06-01 19:06:31 +0000207 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 Claytonfaca02d2021-02-10 21:34:25 +0000211}
212
213TEST_F(IntrinsicTableTest, MatchPointer) {
Ben Clayton512d60c2021-05-19 19:51:22 +0000214 auto* f32 = create<sem::F32>();
Ben Clayton18588542021-06-04 22:17:37 +0000215 auto* ptr = create<sem::Pointer>(f32, ast::StorageClass::kFunction,
216 ast::Access::kReadWrite);
Ben Claytonb29a59d2021-06-01 19:06:31 +0000217 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 Clayton0f2d95d2021-07-22 13:24:59 +0000222 ASSERT_EQ(result->Parameters().size(), 2u);
223 EXPECT_EQ(result->Parameters()[0]->Type(), f32);
224 EXPECT_EQ(result->Parameters()[1]->Type(), ptr);
Ben Claytonfaca02d2021-02-10 21:34:25 +0000225}
226
227TEST_F(IntrinsicTableTest, MismatchPointer) {
Ben Clayton512d60c2021-05-19 19:51:22 +0000228 auto* f32 = create<sem::F32>();
Ben Claytonb29a59d2021-06-01 19:06:31 +0000229 auto* result = table->Lookup(IntrinsicType::kModf, {f32, f32}, Source{});
230 ASSERT_EQ(result, nullptr);
231 ASSERT_THAT(Diagnostics().str(), HasSubstr("no matching call"));
Ben Claytonfaca02d2021-02-10 21:34:25 +0000232}
233
234TEST_F(IntrinsicTableTest, MatchArray) {
Antonio Maiorano68a6dd02021-07-20 18:28:31 +0000235 auto* arr = create<sem::Array>(create<sem::U32>(), 0, 4, 4, 4, 4);
Ben Clayton09493042021-06-18 22:44:31 +0000236 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 Claytonb29a59d2021-06-01 19:06:31 +0000240 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 Clayton0f2d95d2021-07-22 13:24:59 +0000245 auto* param_type = result->Parameters()[0]->Type();
Ben Clayton09493042021-06-18 22:44:31 +0000246 ASSERT_TRUE(param_type->Is<sem::Pointer>());
247 EXPECT_TRUE(param_type->As<sem::Pointer>()->StoreType()->Is<sem::Array>());
Ben Claytonfaca02d2021-02-10 21:34:25 +0000248}
249
250TEST_F(IntrinsicTableTest, MismatchArray) {
Ben Clayton512d60c2021-05-19 19:51:22 +0000251 auto* f32 = create<sem::F32>();
Ben Claytonb29a59d2021-06-01 19:06:31 +0000252 auto* result = table->Lookup(IntrinsicType::kArrayLength, {f32}, Source{});
253 ASSERT_EQ(result, nullptr);
254 ASSERT_THAT(Diagnostics().str(), HasSubstr("no matching call"));
Ben Claytonfaca02d2021-02-10 21:34:25 +0000255}
256
257TEST_F(IntrinsicTableTest, MatchSampler) {
Ben Clayton512d60c2021-05-19 19:51:22 +0000258 auto* f32 = create<sem::F32>();
259 auto* vec2_f32 = create<sem::Vector>(f32, 2);
260 auto* vec4_f32 = create<sem::Vector>(f32, 4);
Ben Clayton55ecfc42021-05-20 14:42:28 +0000261 auto* tex = create<sem::SampledTexture>(ast::TextureDimension::k2d, f32);
Ben Claytonb9662652021-05-20 14:54:28 +0000262 auto* sampler = create<sem::Sampler>(ast::SamplerKind::kSampler);
Ben Claytonb29a59d2021-06-01 19:06:31 +0000263 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 Clayton0f2d95d2021-07-22 13:24:59 +0000269 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 Claytonfaca02d2021-02-10 21:34:25 +0000276}
277
278TEST_F(IntrinsicTableTest, MismatchSampler) {
Ben Clayton512d60c2021-05-19 19:51:22 +0000279 auto* f32 = create<sem::F32>();
280 auto* vec2_f32 = create<sem::Vector>(f32, 2);
Ben Clayton55ecfc42021-05-20 14:42:28 +0000281 auto* tex = create<sem::SampledTexture>(ast::TextureDimension::k2d, f32);
Ben Claytonb29a59d2021-06-01 19:06:31 +0000282 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 Claytonfaca02d2021-02-10 21:34:25 +0000286}
287
288TEST_F(IntrinsicTableTest, MatchSampledTexture) {
Ben Claytoncf421bb2021-05-19 17:47:11 +0000289 auto* i32 = create<sem::I32>();
Ben Clayton512d60c2021-05-19 19:51:22 +0000290 auto* f32 = create<sem::F32>();
Ben Claytoncf421bb2021-05-19 17:47:11 +0000291 auto* vec2_i32 = create<sem::Vector>(i32, 2);
Ben Clayton512d60c2021-05-19 19:51:22 +0000292 auto* vec4_f32 = create<sem::Vector>(f32, 4);
Ben Clayton55ecfc42021-05-20 14:42:28 +0000293 auto* tex = create<sem::SampledTexture>(ast::TextureDimension::k2d, f32);
Ben Claytonb29a59d2021-06-01 19:06:31 +0000294 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 Clayton0f2d95d2021-07-22 13:24:59 +0000300 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 Claytonfaca02d2021-02-10 21:34:25 +0000307}
308
309TEST_F(IntrinsicTableTest, MatchMultisampledTexture) {
Ben Claytoncf421bb2021-05-19 17:47:11 +0000310 auto* i32 = create<sem::I32>();
Ben Clayton512d60c2021-05-19 19:51:22 +0000311 auto* f32 = create<sem::F32>();
Ben Claytoncf421bb2021-05-19 17:47:11 +0000312 auto* vec2_i32 = create<sem::Vector>(i32, 2);
Ben Clayton512d60c2021-05-19 19:51:22 +0000313 auto* vec4_f32 = create<sem::Vector>(f32, 4);
314 auto* tex = create<sem::MultisampledTexture>(ast::TextureDimension::k2d, f32);
Ben Claytonb29a59d2021-06-01 19:06:31 +0000315 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 Clayton0f2d95d2021-07-22 13:24:59 +0000321 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 Claytonfaca02d2021-02-10 21:34:25 +0000328}
329
330TEST_F(IntrinsicTableTest, MatchDepthTexture) {
Ben Clayton512d60c2021-05-19 19:51:22 +0000331 auto* f32 = create<sem::F32>();
Ben Claytoncf421bb2021-05-19 17:47:11 +0000332 auto* i32 = create<sem::I32>();
333 auto* vec2_i32 = create<sem::Vector>(i32, 2);
Ben Clayton55ecfc42021-05-20 14:42:28 +0000334 auto* tex = create<sem::DepthTexture>(ast::TextureDimension::k2d);
Ben Claytonb29a59d2021-06-01 19:06:31 +0000335 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 Clayton0f2d95d2021-07-22 13:24:59 +0000341 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 Claytonfaca02d2021-02-10 21:34:25 +0000348}
349
Ben Claytonfd35aa82021-07-26 22:19:48 +0000350TEST_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 Jones145f8652021-04-22 22:47:03 +0000370TEST_F(IntrinsicTableTest, MatchExternalTexture) {
Ben Clayton512d60c2021-05-19 19:51:22 +0000371 auto* f32 = create<sem::F32>();
Ben Claytoncf421bb2021-05-19 17:47:11 +0000372 auto* i32 = create<sem::I32>();
373 auto* vec2_i32 = create<sem::Vector>(i32, 2);
Ben Clayton512d60c2021-05-19 19:51:22 +0000374 auto* vec4_f32 = create<sem::Vector>(f32, 4);
Brandon Jones145f8652021-04-22 22:47:03 +0000375 auto* tex = create<sem::ExternalTexture>();
Ben Claytonb29a59d2021-06-01 19:06:31 +0000376 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 Clayton0f2d95d2021-07-22 13:24:59 +0000382 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 Jones145f8652021-04-22 22:47:03 +0000387}
388
Ben Claytonfaca02d2021-02-10 21:34:25 +0000389TEST_F(IntrinsicTableTest, MatchROStorageTexture) {
Ben Clayton512d60c2021-05-19 19:51:22 +0000390 auto* f32 = create<sem::F32>();
Ben Claytoncf421bb2021-05-19 17:47:11 +0000391 auto* i32 = create<sem::I32>();
392 auto* vec2_i32 = create<sem::Vector>(i32, 2);
Ben Clayton512d60c2021-05-19 19:51:22 +0000393 auto* vec4_f32 = create<sem::Vector>(f32, 4);
Antonio Maioranodc4e6c12021-05-14 17:51:13 +0000394 auto* subtype =
Ben Claytonb29a59d2021-06-01 19:06:31 +0000395 sem::StorageTexture::SubtypeFor(ast::ImageFormat::kR32Float, Types());
Ben Clayton646f4a92021-05-31 19:40:30 +0000396 auto* tex = create<sem::StorageTexture>(ast::TextureDimension::k2d,
Ben Claytonb29a59d2021-06-01 19:06:31 +0000397 ast::ImageFormat::kR32Float,
Ben Clayton93e8f522021-06-04 20:41:47 +0000398 ast::Access::kRead, subtype);
Antonio Maioranodc4e6c12021-05-14 17:51:13 +0000399
Ben Claytonb29a59d2021-06-01 19:06:31 +0000400 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 Clayton0f2d95d2021-07-22 13:24:59 +0000406 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 Claytonfaca02d2021-02-10 21:34:25 +0000411}
412
413TEST_F(IntrinsicTableTest, MatchWOStorageTexture) {
Ben Clayton512d60c2021-05-19 19:51:22 +0000414 auto* f32 = create<sem::F32>();
Ben Claytoncf421bb2021-05-19 17:47:11 +0000415 auto* i32 = create<sem::I32>();
416 auto* vec2_i32 = create<sem::Vector>(i32, 2);
Ben Clayton512d60c2021-05-19 19:51:22 +0000417 auto* vec4_f32 = create<sem::Vector>(f32, 4);
Antonio Maioranodc4e6c12021-05-14 17:51:13 +0000418 auto* subtype =
Ben Claytonb29a59d2021-06-01 19:06:31 +0000419 sem::StorageTexture::SubtypeFor(ast::ImageFormat::kR32Float, Types());
Ben Clayton646f4a92021-05-31 19:40:30 +0000420 auto* tex = create<sem::StorageTexture>(ast::TextureDimension::k2d,
Ben Claytonb29a59d2021-06-01 19:06:31 +0000421 ast::ImageFormat::kR32Float,
Ben Clayton93e8f522021-06-04 20:41:47 +0000422 ast::Access::kWrite, subtype);
Antonio Maioranodc4e6c12021-05-14 17:51:13 +0000423
Ben Claytonb29a59d2021-06-01 19:06:31 +0000424 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 Clayton0f2d95d2021-07-22 13:24:59 +0000430 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 Claytonfaca02d2021-02-10 21:34:25 +0000437}
438
439TEST_F(IntrinsicTableTest, MismatchTexture) {
Ben Clayton512d60c2021-05-19 19:51:22 +0000440 auto* f32 = create<sem::F32>();
Ben Claytoncf421bb2021-05-19 17:47:11 +0000441 auto* i32 = create<sem::I32>();
442 auto* vec2_i32 = create<sem::Vector>(i32, 2);
Ben Claytonb29a59d2021-06-01 19:06:31 +0000443 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 Claytonfaca02d2021-02-10 21:34:25 +0000447}
448
Ben Clayton9b54a2e2021-05-18 10:28:48 +0000449TEST_F(IntrinsicTableTest, ImplicitLoadOnReference) {
Ben Clayton512d60c2021-05-19 19:51:22 +0000450 auto* f32 = create<sem::F32>();
Ben Clayton18588542021-06-04 22:17:37 +0000451 auto* result =
452 table->Lookup(IntrinsicType::kCos,
453 {create<sem::Reference>(f32, ast::StorageClass::kFunction,
454 ast::Access::kReadWrite)},
455 Source{});
Ben Claytonb29a59d2021-06-01 19:06:31 +0000456 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 Clayton0f2d95d2021-07-22 13:24:59 +0000460 ASSERT_EQ(result->Parameters().size(), 1u);
461 EXPECT_EQ(result->Parameters()[0]->Type(), f32);
Ben Claytonfaca02d2021-02-10 21:34:25 +0000462}
463
Ben Claytonfaca02d2021-02-10 21:34:25 +0000464TEST_F(IntrinsicTableTest, MatchOpenType) {
Ben Clayton512d60c2021-05-19 19:51:22 +0000465 auto* f32 = create<sem::F32>();
Ben Claytonb29a59d2021-06-01 19:06:31 +0000466 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 Clayton0f2d95d2021-07-22 13:24:59 +0000472 EXPECT_EQ(result->Parameters()[0]->Type(), f32);
473 EXPECT_EQ(result->Parameters()[1]->Type(), f32);
474 EXPECT_EQ(result->Parameters()[2]->Type(), f32);
Ben Claytonfaca02d2021-02-10 21:34:25 +0000475}
476
477TEST_F(IntrinsicTableTest, MismatchOpenType) {
Ben Clayton512d60c2021-05-19 19:51:22 +0000478 auto* f32 = create<sem::F32>();
Ben Clayton58dec172021-05-19 17:47:11 +0000479 auto* u32 = create<sem::U32>();
Ben Claytonb29a59d2021-06-01 19:06:31 +0000480 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 Claytonfaca02d2021-02-10 21:34:25 +0000484}
485
486TEST_F(IntrinsicTableTest, MatchOpenSizeVector) {
Ben Clayton512d60c2021-05-19 19:51:22 +0000487 auto* f32 = create<sem::F32>();
488 auto* vec2_f32 = create<sem::Vector>(f32, 2);
Ben Claytonb29a59d2021-06-01 19:06:31 +0000489 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 Clayton0f2d95d2021-07-22 13:24:59 +0000495 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 Claytonfaca02d2021-02-10 21:34:25 +0000499}
500
501TEST_F(IntrinsicTableTest, MismatchOpenSizeVector) {
Ben Clayton512d60c2021-05-19 19:51:22 +0000502 auto* f32 = create<sem::F32>();
Ben Clayton58dec172021-05-19 17:47:11 +0000503 auto* u32 = create<sem::U32>();
Ben Clayton512d60c2021-05-19 19:51:22 +0000504 auto* vec2_f32 = create<sem::Vector>(f32, 2);
Ben Claytonb29a59d2021-06-01 19:06:31 +0000505 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 Claytonfaca02d2021-02-10 21:34:25 +0000509}
510
511TEST_F(IntrinsicTableTest, MatchOpenSizeMatrix) {
Ben Clayton512d60c2021-05-19 19:51:22 +0000512 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 Claytonb29a59d2021-06-01 19:06:31 +0000515 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 Clayton0f2d95d2021-07-22 13:24:59 +0000521 ASSERT_EQ(result->Parameters().size(), 1u);
522 EXPECT_EQ(result->Parameters()[0]->Type(), mat3_f32);
Ben Claytonfaca02d2021-02-10 21:34:25 +0000523}
524
525TEST_F(IntrinsicTableTest, MismatchOpenSizeMatrix) {
Ben Clayton512d60c2021-05-19 19:51:22 +0000526 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 Claytonb29a59d2021-06-01 19:06:31 +0000529 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 Claytonfaca02d2021-02-10 21:34:25 +0000533}
534
535TEST_F(IntrinsicTableTest, OverloadOrderByNumberOfParameters) {
536 // None of the arguments match, so expect the overloads with 2 parameters to
537 // come first
Ben Claytonc03d3bd2021-05-20 14:22:28 +0000538 auto* bool_ = create<sem::Bool>();
Ben Claytonb29a59d2021-06-01 19:06:31 +0000539 table->Lookup(IntrinsicType::kTextureDimensions, {bool_, bool_}, Source{});
540 ASSERT_EQ(Diagnostics().str(),
Ben Clayton6b4924f2021-02-17 20:13:34 +0000541 R"(error: no matching call to textureDimensions(bool, bool)
Ben Claytonfaca02d2021-02-10 21:34:25 +0000542
Ben Claytonfd35aa82021-07-26 22:19:48 +000054327 candidate functions:
Ben Clayton9e0b3cc2021-07-15 16:14:34 +0000544 textureDimensions(texture: texture_1d<T>, level: i32) -> i32 where: T is f32, i32 or u32
Ben Clayton57d6bd22021-06-03 08:32:44 +0000545 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 Claytonb96ed7b2021-06-21 16:44:26 +0000548 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 Claytonb29a59d2021-06-01 19:06:31 +0000550 textureDimensions(texture: texture_depth_2d, level: i32) -> vec2<i32>
551 textureDimensions(texture: texture_depth_2d_array, level: i32) -> vec2<i32>
Ben Claytonb96ed7b2021-06-21 16:44:26 +0000552 textureDimensions(texture: texture_depth_cube, level: i32) -> vec2<i32>
553 textureDimensions(texture: texture_depth_cube_array, level: i32) -> vec2<i32>
Ben Clayton57d6bd22021-06-03 08:32:44 +0000554 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 Claytonb96ed7b2021-06-21 16:44:26 +0000558 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 Clayton57d6bd22021-06-03 08:32:44 +0000560 textureDimensions(texture: texture_multisampled_2d<T>) -> vec2<i32> where: T is f32, i32 or u32
Ben Claytonb29a59d2021-06-01 19:06:31 +0000561 textureDimensions(texture: texture_depth_2d) -> vec2<i32>
562 textureDimensions(texture: texture_depth_2d_array) -> vec2<i32>
Ben Claytonb96ed7b2021-06-21 16:44:26 +0000563 textureDimensions(texture: texture_depth_cube) -> vec2<i32>
564 textureDimensions(texture: texture_depth_cube_array) -> vec2<i32>
Ben Claytonfd35aa82021-07-26 22:19:48 +0000565 textureDimensions(texture: texture_depth_multisampled_2d) -> vec2<i32>
Ben Clayton57d6bd22021-06-03 08:32:44 +0000566 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 Claytonb29a59d2021-06-01 19:06:31 +0000570 textureDimensions(texture: texture_external) -> vec2<i32>
Ben Claytonfaca02d2021-02-10 21:34:25 +0000571)");
572}
573
574TEST_F(IntrinsicTableTest, OverloadOrderByMatchingParameter) {
Ben Clayton55ecfc42021-05-20 14:42:28 +0000575 auto* tex = create<sem::DepthTexture>(ast::TextureDimension::k2d);
Ben Claytonc03d3bd2021-05-20 14:22:28 +0000576 auto* bool_ = create<sem::Bool>();
Ben Claytonb29a59d2021-06-01 19:06:31 +0000577 table->Lookup(IntrinsicType::kTextureDimensions, {tex, bool_}, Source{});
Ben Clayton6b4924f2021-02-17 20:13:34 +0000578 ASSERT_EQ(
Ben Claytonb29a59d2021-06-01 19:06:31 +0000579 Diagnostics().str(),
Ben Clayton6b4924f2021-02-17 20:13:34 +0000580 R"(error: no matching call to textureDimensions(texture_depth_2d, bool)
Ben Claytonfaca02d2021-02-10 21:34:25 +0000581
Ben Claytonfd35aa82021-07-26 22:19:48 +000058227 candidate functions:
Ben Claytonb29a59d2021-06-01 19:06:31 +0000583 textureDimensions(texture: texture_depth_2d, level: i32) -> vec2<i32>
584 textureDimensions(texture: texture_depth_2d) -> vec2<i32>
Ben Clayton9e0b3cc2021-07-15 16:14:34 +0000585 textureDimensions(texture: texture_1d<T>, level: i32) -> i32 where: T is f32, i32 or u32
Ben Clayton57d6bd22021-06-03 08:32:44 +0000586 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 Claytonb96ed7b2021-06-21 16:44:26 +0000589 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 Claytonb29a59d2021-06-01 19:06:31 +0000591 textureDimensions(texture: texture_depth_2d_array, level: i32) -> vec2<i32>
Ben Claytonb96ed7b2021-06-21 16:44:26 +0000592 textureDimensions(texture: texture_depth_cube, level: i32) -> vec2<i32>
593 textureDimensions(texture: texture_depth_cube_array, level: i32) -> vec2<i32>
Ben Clayton57d6bd22021-06-03 08:32:44 +0000594 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 Claytonb96ed7b2021-06-21 16:44:26 +0000598 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 Clayton57d6bd22021-06-03 08:32:44 +0000600 textureDimensions(texture: texture_multisampled_2d<T>) -> vec2<i32> where: T is f32, i32 or u32
Ben Claytonb29a59d2021-06-01 19:06:31 +0000601 textureDimensions(texture: texture_depth_2d_array) -> vec2<i32>
Ben Claytonb96ed7b2021-06-21 16:44:26 +0000602 textureDimensions(texture: texture_depth_cube) -> vec2<i32>
603 textureDimensions(texture: texture_depth_cube_array) -> vec2<i32>
Ben Claytonfd35aa82021-07-26 22:19:48 +0000604 textureDimensions(texture: texture_depth_multisampled_2d) -> vec2<i32>
Ben Clayton57d6bd22021-06-03 08:32:44 +0000605 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 Claytonb29a59d2021-06-01 19:06:31 +0000609 textureDimensions(texture: texture_external) -> vec2<i32>
Ben Claytonfaca02d2021-02-10 21:34:25 +0000610)");
611}
612
Ben Claytonb478f972021-07-15 20:34:21 +0000613TEST_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 Claytonfaca02d2021-02-10 21:34:25 +0000634} // namespace
635} // namespace tint