Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +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/tint/ast/builtin_attribute.h" |
| 16 | #include "src/tint/ast/location_attribute.h" |
| 17 | #include "src/tint/ast/return_statement.h" |
| 18 | #include "src/tint/ast/stage_attribute.h" |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 19 | #include "src/tint/resolver/resolver.h" |
| 20 | #include "src/tint/resolver/resolver_test_helper.h" |
| 21 | |
| 22 | #include "gmock/gmock.h" |
| 23 | |
Ben Clayton | 0ce9ab0 | 2022-05-05 20:23:40 +0000 | [diff] [blame] | 24 | using namespace tint::number_suffixes; // NOLINT |
| 25 | |
dan sinclair | d209379 | 2022-04-07 17:45:45 +0000 | [diff] [blame] | 26 | namespace tint::resolver { |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 27 | namespace { |
| 28 | |
| 29 | // Helpers and typedefs |
| 30 | template <typename T> |
| 31 | using DataType = builder::DataType<T>; |
| 32 | template <typename T> |
| 33 | using vec2 = builder::vec2<T>; |
| 34 | template <typename T> |
| 35 | using vec3 = builder::vec3<T>; |
| 36 | template <typename T> |
| 37 | using vec4 = builder::vec4<T>; |
| 38 | template <typename T> |
| 39 | using mat2x2 = builder::mat2x2<T>; |
| 40 | template <typename T> |
| 41 | using mat3x3 = builder::mat3x3<T>; |
| 42 | template <typename T> |
| 43 | using mat4x4 = builder::mat4x4<T>; |
| 44 | template <typename T> |
| 45 | using alias = builder::alias<T>; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 46 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 47 | class ResolverEntryPointValidationTest : public TestHelper, public testing::Test {}; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 48 | |
| 49 | TEST_F(ResolverEntryPointValidationTest, ReturnTypeAttribute_Location) { |
dan sinclair | b29892b | 2022-06-07 13:55:34 +0000 | [diff] [blame] | 50 | // @fragment |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 51 | // fn main() -> @location(0) f32 { return 1.0; } |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 52 | Func(Source{{12, 34}}, "main", utils::Empty, ty.f32(), |
| 53 | utils::Vector{ |
| 54 | Return(1_f), |
| 55 | }, |
| 56 | utils::Vector{ |
| 57 | Stage(ast::PipelineStage::kFragment), |
| 58 | }, |
| 59 | utils::Vector{ |
dan sinclair | f9eeed6 | 2022-09-07 22:25:24 +0000 | [diff] [blame] | 60 | Location(0_a), |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 61 | }); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 62 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 63 | EXPECT_TRUE(r()->Resolve()) << r()->error(); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | TEST_F(ResolverEntryPointValidationTest, ReturnTypeAttribute_Builtin) { |
dan sinclair | b29892b | 2022-06-07 13:55:34 +0000 | [diff] [blame] | 67 | // @vertex |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 68 | // fn main() -> @builtin(position) vec4<f32> { return vec4<f32>(); } |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 69 | Func(Source{{12, 34}}, "main", utils::Empty, ty.vec4<f32>(), |
| 70 | utils::Vector{ |
| 71 | Return(Construct(ty.vec4<f32>())), |
| 72 | }, |
| 73 | utils::Vector{ |
| 74 | Stage(ast::PipelineStage::kVertex), |
| 75 | }, |
| 76 | utils::Vector{ |
| 77 | Builtin(ast::BuiltinValue::kPosition), |
| 78 | }); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 79 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 80 | EXPECT_TRUE(r()->Resolve()) << r()->error(); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | TEST_F(ResolverEntryPointValidationTest, ReturnTypeAttribute_Missing) { |
dan sinclair | b29892b | 2022-06-07 13:55:34 +0000 | [diff] [blame] | 84 | // @vertex |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 85 | // fn main() -> f32 { |
| 86 | // return 1.0; |
| 87 | // } |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 88 | Func(Source{{12, 34}}, "main", utils::Empty, ty.vec4<f32>(), |
| 89 | utils::Vector{ |
| 90 | Return(Construct(ty.vec4<f32>())), |
| 91 | }, |
| 92 | utils::Vector{ |
| 93 | Stage(ast::PipelineStage::kVertex), |
| 94 | }); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 95 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 96 | EXPECT_FALSE(r()->Resolve()); |
| 97 | EXPECT_EQ(r()->error(), "12:34 error: missing entry point IO attribute on return type"); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | TEST_F(ResolverEntryPointValidationTest, ReturnTypeAttribute_Multiple) { |
dan sinclair | b29892b | 2022-06-07 13:55:34 +0000 | [diff] [blame] | 101 | // @vertex |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 102 | // fn main() -> @location(0) @builtin(position) vec4<f32> { |
| 103 | // return vec4<f32>(); |
| 104 | // } |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 105 | Func(Source{{12, 34}}, "main", utils::Empty, ty.vec4<f32>(), |
| 106 | utils::Vector{ |
| 107 | Return(Construct(ty.vec4<f32>())), |
| 108 | }, |
| 109 | utils::Vector{ |
| 110 | Stage(ast::PipelineStage::kVertex), |
| 111 | }, |
| 112 | utils::Vector{ |
dan sinclair | f9eeed6 | 2022-09-07 22:25:24 +0000 | [diff] [blame] | 113 | Location(Source{{13, 43}}, 0_a), |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 114 | Builtin(Source{{14, 52}}, ast::BuiltinValue::kPosition), |
| 115 | }); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 116 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 117 | EXPECT_FALSE(r()->Resolve()); |
| 118 | EXPECT_EQ(r()->error(), R"(14:52 error: multiple entry point IO attributes |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 119 | 13:43 note: previously consumed location(0))"); |
| 120 | } |
| 121 | |
| 122 | TEST_F(ResolverEntryPointValidationTest, ReturnType_Struct_Valid) { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 123 | // struct Output { |
| 124 | // @location(0) a : f32; |
| 125 | // @builtin(frag_depth) b : f32; |
| 126 | // }; |
dan sinclair | b29892b | 2022-06-07 13:55:34 +0000 | [diff] [blame] | 127 | // @fragment |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 128 | // fn main() -> Output { |
| 129 | // return Output(); |
| 130 | // } |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 131 | auto* output = Structure( |
| 132 | "Output", utils::Vector{ |
dan sinclair | f9eeed6 | 2022-09-07 22:25:24 +0000 | [diff] [blame] | 133 | Member("a", ty.f32(), utils::Vector{Location(0_a)}), |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 134 | Member("b", ty.f32(), utils::Vector{Builtin(ast::BuiltinValue::kFragDepth)}), |
| 135 | }); |
| 136 | Func(Source{{12, 34}}, "main", utils::Empty, ty.Of(output), |
| 137 | utils::Vector{ |
| 138 | Return(Construct(ty.Of(output))), |
| 139 | }, |
| 140 | utils::Vector{ |
| 141 | Stage(ast::PipelineStage::kFragment), |
| 142 | }); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 143 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 144 | EXPECT_TRUE(r()->Resolve()) << r()->error(); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 145 | } |
| 146 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 147 | TEST_F(ResolverEntryPointValidationTest, ReturnType_Struct_MemberMultipleAttributes) { |
| 148 | // struct Output { |
| 149 | // @location(0) @builtin(frag_depth) a : f32; |
| 150 | // }; |
dan sinclair | b29892b | 2022-06-07 13:55:34 +0000 | [diff] [blame] | 151 | // @fragment |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 152 | // fn main() -> Output { |
| 153 | // return Output(); |
| 154 | // } |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 155 | auto* output = Structure( |
| 156 | "Output", |
| 157 | utils::Vector{ |
| 158 | Member("a", ty.f32(), |
dan sinclair | f9eeed6 | 2022-09-07 22:25:24 +0000 | [diff] [blame] | 159 | utils::Vector{Location(Source{{13, 43}}, 0_a), |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 160 | Builtin(Source{{14, 52}}, ast::BuiltinValue::kFragDepth)}), |
| 161 | }); |
| 162 | Func(Source{{12, 34}}, "main", utils::Empty, ty.Of(output), |
| 163 | utils::Vector{ |
| 164 | Return(Construct(ty.Of(output))), |
| 165 | }, |
| 166 | utils::Vector{ |
| 167 | Stage(ast::PipelineStage::kFragment), |
| 168 | }); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 169 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 170 | EXPECT_FALSE(r()->Resolve()); |
| 171 | EXPECT_EQ(r()->error(), R"(14:52 error: multiple entry point IO attributes |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 172 | 13:43 note: previously consumed location(0) |
Ben Clayton | 4fe330f | 2022-10-13 13:33:25 +0000 | [diff] [blame] | 173 | 12:34 note: while analyzing entry point 'main')"); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 174 | } |
| 175 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 176 | TEST_F(ResolverEntryPointValidationTest, ReturnType_Struct_MemberMissingAttribute) { |
| 177 | // struct Output { |
| 178 | // @location(0) a : f32; |
| 179 | // b : f32; |
| 180 | // }; |
dan sinclair | b29892b | 2022-06-07 13:55:34 +0000 | [diff] [blame] | 181 | // @fragment |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 182 | // fn main() -> Output { |
| 183 | // return Output(); |
| 184 | // } |
dan sinclair | f9eeed6 | 2022-09-07 22:25:24 +0000 | [diff] [blame] | 185 | auto* output = Structure( |
| 186 | "Output", utils::Vector{ |
| 187 | Member(Source{{13, 43}}, "a", ty.f32(), utils::Vector{Location(0_a)}), |
| 188 | Member(Source{{14, 52}}, "b", ty.f32(), {}), |
| 189 | }); |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 190 | Func(Source{{12, 34}}, "main", utils::Empty, ty.Of(output), |
| 191 | utils::Vector{ |
| 192 | Return(Construct(ty.Of(output))), |
| 193 | }, |
| 194 | utils::Vector{ |
| 195 | Stage(ast::PipelineStage::kFragment), |
| 196 | }); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 197 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 198 | EXPECT_FALSE(r()->Resolve()); |
| 199 | EXPECT_EQ(r()->error(), |
| 200 | R"(14:52 error: missing entry point IO attribute |
Ben Clayton | 4fe330f | 2022-10-13 13:33:25 +0000 | [diff] [blame] | 201 | 12:34 note: while analyzing entry point 'main')"); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | TEST_F(ResolverEntryPointValidationTest, ReturnType_Struct_DuplicateBuiltins) { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 205 | // struct Output { |
| 206 | // @builtin(frag_depth) a : f32; |
| 207 | // @builtin(frag_depth) b : f32; |
| 208 | // }; |
dan sinclair | b29892b | 2022-06-07 13:55:34 +0000 | [diff] [blame] | 209 | // @fragment |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 210 | // fn main() -> Output { |
| 211 | // return Output(); |
| 212 | // } |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 213 | auto* output = Structure( |
| 214 | "Output", utils::Vector{ |
| 215 | Member("a", ty.f32(), utils::Vector{Builtin(ast::BuiltinValue::kFragDepth)}), |
| 216 | Member("b", ty.f32(), utils::Vector{Builtin(ast::BuiltinValue::kFragDepth)}), |
| 217 | }); |
| 218 | Func(Source{{12, 34}}, "main", utils::Empty, ty.Of(output), |
| 219 | utils::Vector{ |
| 220 | Return(Construct(ty.Of(output))), |
| 221 | }, |
| 222 | utils::Vector{ |
| 223 | Stage(ast::PipelineStage::kFragment), |
| 224 | }); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 225 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 226 | EXPECT_FALSE(r()->Resolve()); |
| 227 | EXPECT_EQ( |
| 228 | r()->error(), |
| 229 | R"(12:34 error: builtin(frag_depth) attribute appears multiple times as pipeline output |
Ben Clayton | 4fe330f | 2022-10-13 13:33:25 +0000 | [diff] [blame] | 230 | 12:34 note: while analyzing entry point 'main')"); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | TEST_F(ResolverEntryPointValidationTest, ParameterAttribute_Location) { |
dan sinclair | b29892b | 2022-06-07 13:55:34 +0000 | [diff] [blame] | 234 | // @fragment |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 235 | // fn main(@location(0) param : f32) {} |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 236 | auto* param = Param("param", ty.f32(), |
| 237 | utils::Vector{ |
dan sinclair | f9eeed6 | 2022-09-07 22:25:24 +0000 | [diff] [blame] | 238 | Location(0_a), |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 239 | }); |
| 240 | Func(Source{{12, 34}}, "main", |
| 241 | utils::Vector{ |
| 242 | param, |
| 243 | }, |
| 244 | ty.void_(), utils::Empty, |
| 245 | utils::Vector{ |
| 246 | Stage(ast::PipelineStage::kFragment), |
| 247 | }); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 248 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 249 | EXPECT_TRUE(r()->Resolve()) << r()->error(); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | TEST_F(ResolverEntryPointValidationTest, ParameterAttribute_Missing) { |
dan sinclair | b29892b | 2022-06-07 13:55:34 +0000 | [diff] [blame] | 253 | // @fragment |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 254 | // fn main(param : f32) {} |
| 255 | auto* param = Param(Source{{13, 43}}, "param", ty.vec4<f32>()); |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 256 | Func(Source{{12, 34}}, "main", |
| 257 | utils::Vector{ |
| 258 | param, |
| 259 | }, |
| 260 | ty.void_(), utils::Empty, |
| 261 | utils::Vector{ |
| 262 | Stage(ast::PipelineStage::kFragment), |
| 263 | }); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 264 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 265 | EXPECT_FALSE(r()->Resolve()); |
| 266 | EXPECT_EQ(r()->error(), "13:43 error: missing entry point IO attribute on parameter"); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | TEST_F(ResolverEntryPointValidationTest, ParameterAttribute_Multiple) { |
dan sinclair | b29892b | 2022-06-07 13:55:34 +0000 | [diff] [blame] | 270 | // @fragment |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 271 | // fn main(@location(0) @builtin(sample_index) param : u32) {} |
Ben Clayton | f330229 | 2022-07-27 18:48:06 +0000 | [diff] [blame] | 272 | auto* param = Param("param", ty.u32(), |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 273 | utils::Vector{ |
dan sinclair | f9eeed6 | 2022-09-07 22:25:24 +0000 | [diff] [blame] | 274 | Location(Source{{13, 43}}, 0_a), |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 275 | Builtin(Source{{14, 52}}, ast::BuiltinValue::kSampleIndex), |
| 276 | }); |
| 277 | Func(Source{{12, 34}}, "main", |
| 278 | utils::Vector{ |
| 279 | param, |
| 280 | }, |
| 281 | ty.void_(), utils::Empty, |
| 282 | utils::Vector{ |
| 283 | Stage(ast::PipelineStage::kFragment), |
| 284 | }); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 285 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 286 | EXPECT_FALSE(r()->Resolve()); |
| 287 | EXPECT_EQ(r()->error(), R"(14:52 error: multiple entry point IO attributes |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 288 | 13:43 note: previously consumed location(0))"); |
| 289 | } |
| 290 | |
| 291 | TEST_F(ResolverEntryPointValidationTest, Parameter_Struct_Valid) { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 292 | // struct Input { |
| 293 | // @location(0) a : f32; |
| 294 | // @builtin(sample_index) b : u32; |
| 295 | // }; |
dan sinclair | b29892b | 2022-06-07 13:55:34 +0000 | [diff] [blame] | 296 | // @fragment |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 297 | // fn main(param : Input) {} |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 298 | auto* input = Structure( |
| 299 | "Input", utils::Vector{ |
dan sinclair | f9eeed6 | 2022-09-07 22:25:24 +0000 | [diff] [blame] | 300 | Member("a", ty.f32(), utils::Vector{Location(0_a)}), |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 301 | Member("b", ty.u32(), utils::Vector{Builtin(ast::BuiltinValue::kSampleIndex)}), |
| 302 | }); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 303 | auto* param = Param("param", ty.Of(input)); |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 304 | Func(Source{{12, 34}}, "main", |
| 305 | utils::Vector{ |
| 306 | param, |
| 307 | }, |
| 308 | ty.void_(), utils::Empty, |
| 309 | utils::Vector{ |
| 310 | Stage(ast::PipelineStage::kFragment), |
| 311 | }); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 312 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 313 | EXPECT_TRUE(r()->Resolve()) << r()->error(); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 314 | } |
| 315 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 316 | TEST_F(ResolverEntryPointValidationTest, Parameter_Struct_MemberMultipleAttributes) { |
| 317 | // struct Input { |
| 318 | // @location(0) @builtin(sample_index) a : u32; |
| 319 | // }; |
dan sinclair | b29892b | 2022-06-07 13:55:34 +0000 | [diff] [blame] | 320 | // @fragment |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 321 | // fn main(param : Input) {} |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 322 | auto* input = Structure( |
| 323 | "Input", |
| 324 | utils::Vector{ |
| 325 | Member("a", ty.u32(), |
dan sinclair | f9eeed6 | 2022-09-07 22:25:24 +0000 | [diff] [blame] | 326 | utils::Vector{Location(Source{{13, 43}}, 0_a), |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 327 | Builtin(Source{{14, 52}}, ast::BuiltinValue::kSampleIndex)}), |
| 328 | }); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 329 | auto* param = Param("param", ty.Of(input)); |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 330 | Func(Source{{12, 34}}, "main", |
| 331 | utils::Vector{ |
| 332 | param, |
| 333 | }, |
| 334 | ty.void_(), utils::Empty, |
| 335 | utils::Vector{ |
| 336 | Stage(ast::PipelineStage::kFragment), |
| 337 | }); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 338 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 339 | EXPECT_FALSE(r()->Resolve()); |
| 340 | EXPECT_EQ(r()->error(), R"(14:52 error: multiple entry point IO attributes |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 341 | 13:43 note: previously consumed location(0) |
Ben Clayton | 4fe330f | 2022-10-13 13:33:25 +0000 | [diff] [blame] | 342 | 12:34 note: while analyzing entry point 'main')"); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 343 | } |
| 344 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 345 | TEST_F(ResolverEntryPointValidationTest, Parameter_Struct_MemberMissingAttribute) { |
| 346 | // struct Input { |
| 347 | // @location(0) a : f32; |
| 348 | // b : f32; |
| 349 | // }; |
dan sinclair | b29892b | 2022-06-07 13:55:34 +0000 | [diff] [blame] | 350 | // @fragment |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 351 | // fn main(param : Input) {} |
dan sinclair | f9eeed6 | 2022-09-07 22:25:24 +0000 | [diff] [blame] | 352 | auto* input = Structure( |
| 353 | "Input", utils::Vector{ |
| 354 | Member(Source{{13, 43}}, "a", ty.f32(), utils::Vector{Location(0_a)}), |
| 355 | Member(Source{{14, 52}}, "b", ty.f32(), {}), |
| 356 | }); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 357 | auto* param = Param("param", ty.Of(input)); |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 358 | Func(Source{{12, 34}}, "main", |
| 359 | utils::Vector{ |
| 360 | param, |
| 361 | }, |
| 362 | ty.void_(), utils::Empty, |
| 363 | utils::Vector{ |
| 364 | Stage(ast::PipelineStage::kFragment), |
| 365 | }); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 366 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 367 | EXPECT_FALSE(r()->Resolve()); |
| 368 | EXPECT_EQ(r()->error(), R"(14:52 error: missing entry point IO attribute |
Ben Clayton | 4fe330f | 2022-10-13 13:33:25 +0000 | [diff] [blame] | 369 | 12:34 note: while analyzing entry point 'main')"); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | TEST_F(ResolverEntryPointValidationTest, Parameter_DuplicateBuiltins) { |
dan sinclair | b29892b | 2022-06-07 13:55:34 +0000 | [diff] [blame] | 373 | // @fragment |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 374 | // fn main(@builtin(sample_index) param_a : u32, |
| 375 | // @builtin(sample_index) param_b : u32) {} |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 376 | auto* param_a = Param("param_a", ty.u32(), |
| 377 | utils::Vector{ |
| 378 | Builtin(ast::BuiltinValue::kSampleIndex), |
| 379 | }); |
| 380 | auto* param_b = Param("param_b", ty.u32(), |
| 381 | utils::Vector{ |
| 382 | Builtin(ast::BuiltinValue::kSampleIndex), |
| 383 | }); |
| 384 | Func(Source{{12, 34}}, "main", |
| 385 | utils::Vector{ |
| 386 | param_a, |
| 387 | param_b, |
| 388 | }, |
| 389 | ty.void_(), utils::Empty, |
| 390 | utils::Vector{ |
| 391 | Stage(ast::PipelineStage::kFragment), |
| 392 | }); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 393 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 394 | EXPECT_FALSE(r()->Resolve()); |
| 395 | EXPECT_EQ(r()->error(), |
| 396 | "12:34 error: builtin(sample_index) attribute appears multiple times as " |
| 397 | "pipeline input"); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | TEST_F(ResolverEntryPointValidationTest, Parameter_Struct_DuplicateBuiltins) { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 401 | // struct InputA { |
| 402 | // @builtin(sample_index) a : u32; |
| 403 | // }; |
| 404 | // struct InputB { |
| 405 | // @builtin(sample_index) a : u32; |
| 406 | // }; |
dan sinclair | b29892b | 2022-06-07 13:55:34 +0000 | [diff] [blame] | 407 | // @fragment |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 408 | // fn main(param_a : InputA, param_b : InputB) {} |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 409 | auto* input_a = Structure( |
| 410 | "InputA", |
| 411 | utils::Vector{ |
| 412 | Member("a", ty.u32(), utils::Vector{Builtin(ast::BuiltinValue::kSampleIndex)}), |
| 413 | }); |
| 414 | auto* input_b = Structure( |
| 415 | "InputB", |
| 416 | utils::Vector{ |
| 417 | Member("a", ty.u32(), utils::Vector{Builtin(ast::BuiltinValue::kSampleIndex)}), |
| 418 | }); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 419 | auto* param_a = Param("param_a", ty.Of(input_a)); |
| 420 | auto* param_b = Param("param_b", ty.Of(input_b)); |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 421 | Func(Source{{12, 34}}, "main", |
| 422 | utils::Vector{ |
| 423 | param_a, |
| 424 | param_b, |
| 425 | }, |
| 426 | ty.void_(), utils::Empty, |
| 427 | utils::Vector{ |
| 428 | Stage(ast::PipelineStage::kFragment), |
| 429 | }); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 430 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 431 | EXPECT_FALSE(r()->Resolve()); |
| 432 | EXPECT_EQ( |
| 433 | r()->error(), |
| 434 | R"(12:34 error: builtin(sample_index) attribute appears multiple times as pipeline input |
Ben Clayton | 4fe330f | 2022-10-13 13:33:25 +0000 | [diff] [blame] | 435 | 12:34 note: while analyzing entry point 'main')"); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | TEST_F(ResolverEntryPointValidationTest, VertexShaderMustReturnPosition) { |
dan sinclair | b29892b | 2022-06-07 13:55:34 +0000 | [diff] [blame] | 439 | // @vertex |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 440 | // fn main() {} |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 441 | Func(Source{{12, 34}}, "main", utils::Empty, ty.void_(), utils::Empty, |
| 442 | utils::Vector{ |
| 443 | Stage(ast::PipelineStage::kVertex), |
| 444 | }); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 445 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 446 | EXPECT_FALSE(r()->Resolve()); |
| 447 | EXPECT_EQ(r()->error(), |
| 448 | "12:34 error: a vertex shader must include the 'position' builtin " |
| 449 | "in its return type"); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 450 | } |
| 451 | |
dan sinclair | 4abf28e | 2022-08-02 15:55:35 +0000 | [diff] [blame] | 452 | TEST_F(ResolverEntryPointValidationTest, PushConstantAllowedWithEnable) { |
| 453 | // enable chromium_experimental_push_constant; |
| 454 | // var<push_constant> a : u32; |
| 455 | Enable(ast::Extension::kChromiumExperimentalPushConstant); |
dan sinclair | ff7cf21 | 2022-10-03 14:05:23 +0000 | [diff] [blame] | 456 | GlobalVar("a", ty.u32(), ast::AddressSpace::kPushConstant); |
dan sinclair | 4abf28e | 2022-08-02 15:55:35 +0000 | [diff] [blame] | 457 | |
| 458 | EXPECT_TRUE(r()->Resolve()); |
| 459 | } |
| 460 | |
| 461 | TEST_F(ResolverEntryPointValidationTest, PushConstantDisallowedWithoutEnable) { |
| 462 | // var<push_constant> a : u32; |
dan sinclair | ff7cf21 | 2022-10-03 14:05:23 +0000 | [diff] [blame] | 463 | GlobalVar(Source{{1, 2}}, "a", ty.u32(), ast::AddressSpace::kPushConstant); |
dan sinclair | 4abf28e | 2022-08-02 15:55:35 +0000 | [diff] [blame] | 464 | |
| 465 | EXPECT_FALSE(r()->Resolve()); |
| 466 | EXPECT_EQ(r()->error(), |
dan sinclair | ff7cf21 | 2022-10-03 14:05:23 +0000 | [diff] [blame] | 467 | "1:2 error: use of variable address space 'push_constant' requires enabling " |
dan sinclair | 4abf28e | 2022-08-02 15:55:35 +0000 | [diff] [blame] | 468 | "extension 'chromium_experimental_push_constant'"); |
| 469 | } |
| 470 | |
dan sinclair | ff7cf21 | 2022-10-03 14:05:23 +0000 | [diff] [blame] | 471 | TEST_F(ResolverEntryPointValidationTest, PushConstantAllowedWithIgnoreAddressSpaceAttribute) { |
| 472 | // var<push_constant> a : u32; // With ast::DisabledValidation::kIgnoreAddressSpace |
| 473 | GlobalVar("a", ty.u32(), ast::AddressSpace::kPushConstant, |
| 474 | utils::Vector{Disable(ast::DisabledValidation::kIgnoreAddressSpace)}); |
dan sinclair | 4abf28e | 2022-08-02 15:55:35 +0000 | [diff] [blame] | 475 | |
| 476 | EXPECT_TRUE(r()->Resolve()); |
| 477 | } |
| 478 | |
| 479 | TEST_F(ResolverEntryPointValidationTest, PushConstantOneVariableUsedInEntryPoint) { |
| 480 | // enable chromium_experimental_push_constant; |
| 481 | // var<push_constant> a : u32; |
| 482 | // @compute @workgroup_size(1) fn main() { |
| 483 | // _ = a; |
| 484 | // } |
| 485 | Enable(ast::Extension::kChromiumExperimentalPushConstant); |
dan sinclair | ff7cf21 | 2022-10-03 14:05:23 +0000 | [diff] [blame] | 486 | GlobalVar("a", ty.u32(), ast::AddressSpace::kPushConstant); |
dan sinclair | 4abf28e | 2022-08-02 15:55:35 +0000 | [diff] [blame] | 487 | |
dan sinclair | ab5fc1c | 2022-08-02 19:43:14 +0000 | [diff] [blame] | 488 | Func("main", {}, ty.void_(), utils::Vector{Assign(Phony(), "a")}, |
| 489 | utils::Vector{Stage(ast::PipelineStage::kCompute), |
| 490 | create<ast::WorkgroupAttribute>(Expr(1_i))}); |
dan sinclair | 4abf28e | 2022-08-02 15:55:35 +0000 | [diff] [blame] | 491 | |
| 492 | EXPECT_TRUE(r()->Resolve()); |
| 493 | } |
| 494 | |
| 495 | TEST_F(ResolverEntryPointValidationTest, PushConstantTwoVariablesUsedInEntryPoint) { |
| 496 | // enable chromium_experimental_push_constant; |
| 497 | // var<push_constant> a : u32; |
| 498 | // var<push_constant> b : u32; |
| 499 | // @compute @workgroup_size(1) fn main() { |
| 500 | // _ = a; |
| 501 | // _ = b; |
| 502 | // } |
| 503 | Enable(ast::Extension::kChromiumExperimentalPushConstant); |
dan sinclair | ff7cf21 | 2022-10-03 14:05:23 +0000 | [diff] [blame] | 504 | GlobalVar(Source{{1, 2}}, "a", ty.u32(), ast::AddressSpace::kPushConstant); |
| 505 | GlobalVar(Source{{3, 4}}, "b", ty.u32(), ast::AddressSpace::kPushConstant); |
dan sinclair | 4abf28e | 2022-08-02 15:55:35 +0000 | [diff] [blame] | 506 | |
dan sinclair | ab5fc1c | 2022-08-02 19:43:14 +0000 | [diff] [blame] | 507 | Func(Source{{5, 6}}, "main", {}, ty.void_(), |
| 508 | utils::Vector{Assign(Phony(), "a"), Assign(Phony(), "b")}, |
| 509 | utils::Vector{Stage(ast::PipelineStage::kCompute), |
| 510 | create<ast::WorkgroupAttribute>(Expr(1_i))}); |
dan sinclair | 4abf28e | 2022-08-02 15:55:35 +0000 | [diff] [blame] | 511 | |
| 512 | EXPECT_FALSE(r()->Resolve()); |
| 513 | EXPECT_EQ(r()->error(), |
| 514 | R"(5:6 error: entry point 'main' uses two different 'push_constant' variables. |
| 515 | 3:4 note: first 'push_constant' variable declaration is here |
| 516 | 1:2 note: second 'push_constant' variable declaration is here)"); |
| 517 | } |
| 518 | |
| 519 | TEST_F(ResolverEntryPointValidationTest, |
| 520 | PushConstantTwoVariablesUsedInEntryPointWithFunctionGraph) { |
| 521 | // enable chromium_experimental_push_constant; |
| 522 | // var<push_constant> a : u32; |
| 523 | // var<push_constant> b : u32; |
| 524 | // fn uses_a() { |
| 525 | // _ = a; |
| 526 | // } |
| 527 | // fn uses_b() { |
| 528 | // _ = b; |
| 529 | // } |
| 530 | // @compute @workgroup_size(1) fn main() { |
| 531 | // uses_a(); |
| 532 | // uses_b(); |
| 533 | // } |
| 534 | Enable(ast::Extension::kChromiumExperimentalPushConstant); |
dan sinclair | ff7cf21 | 2022-10-03 14:05:23 +0000 | [diff] [blame] | 535 | GlobalVar(Source{{1, 2}}, "a", ty.u32(), ast::AddressSpace::kPushConstant); |
| 536 | GlobalVar(Source{{3, 4}}, "b", ty.u32(), ast::AddressSpace::kPushConstant); |
dan sinclair | 4abf28e | 2022-08-02 15:55:35 +0000 | [diff] [blame] | 537 | |
dan sinclair | ab5fc1c | 2022-08-02 19:43:14 +0000 | [diff] [blame] | 538 | Func(Source{{5, 6}}, "uses_a", {}, ty.void_(), utils::Vector{Assign(Phony(), "a")}); |
| 539 | Func(Source{{7, 8}}, "uses_b", {}, ty.void_(), utils::Vector{Assign(Phony(), "b")}); |
dan sinclair | 4abf28e | 2022-08-02 15:55:35 +0000 | [diff] [blame] | 540 | |
| 541 | Func(Source{{9, 10}}, "main", {}, ty.void_(), |
dan sinclair | ab5fc1c | 2022-08-02 19:43:14 +0000 | [diff] [blame] | 542 | utils::Vector{CallStmt(Call("uses_a")), CallStmt(Call("uses_b"))}, |
| 543 | utils::Vector{Stage(ast::PipelineStage::kCompute), |
| 544 | create<ast::WorkgroupAttribute>(Expr(1_i))}); |
dan sinclair | 4abf28e | 2022-08-02 15:55:35 +0000 | [diff] [blame] | 545 | |
| 546 | EXPECT_FALSE(r()->Resolve()); |
| 547 | EXPECT_EQ(r()->error(), |
| 548 | R"(9:10 error: entry point 'main' uses two different 'push_constant' variables. |
| 549 | 3:4 note: first 'push_constant' variable declaration is here |
| 550 | 7:8 note: called by function 'uses_b' |
| 551 | 9:10 note: called by entry point 'main' |
| 552 | 1:2 note: second 'push_constant' variable declaration is here |
| 553 | 5:6 note: called by function 'uses_a' |
| 554 | 9:10 note: called by entry point 'main')"); |
| 555 | } |
| 556 | |
| 557 | TEST_F(ResolverEntryPointValidationTest, PushConstantTwoVariablesUsedInDifferentEntryPoint) { |
| 558 | // enable chromium_experimental_push_constant; |
| 559 | // var<push_constant> a : u32; |
| 560 | // var<push_constant> b : u32; |
| 561 | // @compute @workgroup_size(1) fn uses_a() { |
| 562 | // _ = a; |
| 563 | // } |
| 564 | // @compute @workgroup_size(1) fn uses_b() { |
| 565 | // _ = a; |
| 566 | // } |
| 567 | Enable(ast::Extension::kChromiumExperimentalPushConstant); |
dan sinclair | ff7cf21 | 2022-10-03 14:05:23 +0000 | [diff] [blame] | 568 | GlobalVar("a", ty.u32(), ast::AddressSpace::kPushConstant); |
| 569 | GlobalVar("b", ty.u32(), ast::AddressSpace::kPushConstant); |
dan sinclair | 4abf28e | 2022-08-02 15:55:35 +0000 | [diff] [blame] | 570 | |
dan sinclair | ab5fc1c | 2022-08-02 19:43:14 +0000 | [diff] [blame] | 571 | Func("uses_a", {}, ty.void_(), utils::Vector{Assign(Phony(), "a")}, |
| 572 | utils::Vector{Stage(ast::PipelineStage::kCompute), |
| 573 | create<ast::WorkgroupAttribute>(Expr(1_i))}); |
| 574 | Func("uses_b", {}, ty.void_(), utils::Vector{Assign(Phony(), "b")}, |
| 575 | utils::Vector{Stage(ast::PipelineStage::kCompute), |
| 576 | create<ast::WorkgroupAttribute>(Expr(1_i))}); |
dan sinclair | 4abf28e | 2022-08-02 15:55:35 +0000 | [diff] [blame] | 577 | |
| 578 | EXPECT_TRUE(r()->Resolve()); |
| 579 | } |
| 580 | |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 581 | namespace TypeValidationTests { |
| 582 | struct Params { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 583 | builder::ast_type_func_ptr create_ast_type; |
| 584 | bool is_valid; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 585 | }; |
| 586 | |
| 587 | template <typename T> |
| 588 | constexpr Params ParamsFor(bool is_valid) { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 589 | return Params{DataType<T>::AST, is_valid}; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | using TypeValidationTest = resolver::ResolverTestWithParam<Params>; |
| 593 | |
| 594 | static constexpr Params cases[] = { |
| 595 | ParamsFor<f32>(true), // |
| 596 | ParamsFor<i32>(true), // |
| 597 | ParamsFor<u32>(true), // |
| 598 | ParamsFor<bool>(false), // |
| 599 | ParamsFor<vec2<f32>>(true), // |
| 600 | ParamsFor<vec3<f32>>(true), // |
| 601 | ParamsFor<vec4<f32>>(true), // |
| 602 | ParamsFor<mat2x2<f32>>(false), // |
| 603 | ParamsFor<mat3x3<f32>>(false), // |
| 604 | ParamsFor<mat4x4<f32>>(false), // |
| 605 | ParamsFor<alias<f32>>(true), // |
| 606 | ParamsFor<alias<i32>>(true), // |
| 607 | ParamsFor<alias<u32>>(true), // |
| 608 | ParamsFor<alias<bool>>(false), // |
Zhaoming Jiang | 9c71174 | 2022-07-08 19:35:05 +0000 | [diff] [blame] | 609 | // Currently entry point IO of f16 types are not implemented yet. |
| 610 | // TODO(tint:1473, tint:1502): Change f16 and vecN<f16> cases to valid after f16 is supported in |
| 611 | // entry point IO. |
| 612 | ParamsFor<f16>(false), // |
| 613 | ParamsFor<vec2<f16>>(false), // |
| 614 | ParamsFor<vec3<f16>>(false), // |
| 615 | ParamsFor<vec4<f16>>(false), // |
| 616 | ParamsFor<mat2x2<f16>>(false), // |
| 617 | ParamsFor<mat3x3<f16>>(false), // |
| 618 | ParamsFor<mat4x4<f16>>(false), // |
| 619 | ParamsFor<alias<f16>>(false), // |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 620 | }; |
| 621 | |
| 622 | TEST_P(TypeValidationTest, BareInputs) { |
dan sinclair | b29892b | 2022-06-07 13:55:34 +0000 | [diff] [blame] | 623 | // @fragment |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 624 | // fn main(@location(0) @interpolate(flat) a : *) {} |
| 625 | auto params = GetParam(); |
Zhaoming Jiang | 9c71174 | 2022-07-08 19:35:05 +0000 | [diff] [blame] | 626 | |
| 627 | Enable(ast::Extension::kF16); |
| 628 | |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 629 | auto* a = Param("a", params.create_ast_type(*this), |
| 630 | utils::Vector{ |
dan sinclair | f9eeed6 | 2022-09-07 22:25:24 +0000 | [diff] [blame] | 631 | Location(0_a), |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 632 | Flat(), |
| 633 | }); |
| 634 | Func(Source{{12, 34}}, "main", |
| 635 | utils::Vector{ |
| 636 | a, |
| 637 | }, |
| 638 | ty.void_(), utils::Empty, |
| 639 | utils::Vector{ |
| 640 | Stage(ast::PipelineStage::kFragment), |
| 641 | }); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 642 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 643 | if (params.is_valid) { |
| 644 | EXPECT_TRUE(r()->Resolve()) << r()->error(); |
| 645 | } else { |
| 646 | EXPECT_FALSE(r()->Resolve()); |
| 647 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | TEST_P(TypeValidationTest, StructInputs) { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 651 | // struct Input { |
| 652 | // @location(0) @interpolate(flat) a : *; |
| 653 | // }; |
dan sinclair | b29892b | 2022-06-07 13:55:34 +0000 | [diff] [blame] | 654 | // @fragment |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 655 | // fn main(a : Input) {} |
| 656 | auto params = GetParam(); |
Zhaoming Jiang | 9c71174 | 2022-07-08 19:35:05 +0000 | [diff] [blame] | 657 | |
| 658 | Enable(ast::Extension::kF16); |
| 659 | |
dan sinclair | f9eeed6 | 2022-09-07 22:25:24 +0000 | [diff] [blame] | 660 | auto* input = Structure("Input", utils::Vector{ |
| 661 | Member("a", params.create_ast_type(*this), |
| 662 | utils::Vector{Location(0_a), Flat()}), |
| 663 | }); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 664 | auto* a = Param("a", ty.Of(input), {}); |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 665 | Func(Source{{12, 34}}, "main", |
| 666 | utils::Vector{ |
| 667 | a, |
| 668 | }, |
| 669 | ty.void_(), utils::Empty, |
| 670 | utils::Vector{ |
| 671 | Stage(ast::PipelineStage::kFragment), |
| 672 | }); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 673 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 674 | if (params.is_valid) { |
| 675 | EXPECT_TRUE(r()->Resolve()) << r()->error(); |
| 676 | } else { |
| 677 | EXPECT_FALSE(r()->Resolve()); |
| 678 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | TEST_P(TypeValidationTest, BareOutputs) { |
dan sinclair | b29892b | 2022-06-07 13:55:34 +0000 | [diff] [blame] | 682 | // @fragment |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 683 | // fn main() -> @location(0) * { |
| 684 | // return *(); |
| 685 | // } |
| 686 | auto params = GetParam(); |
Zhaoming Jiang | 9c71174 | 2022-07-08 19:35:05 +0000 | [diff] [blame] | 687 | |
| 688 | Enable(ast::Extension::kF16); |
| 689 | |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 690 | Func(Source{{12, 34}}, "main", utils::Empty, params.create_ast_type(*this), |
| 691 | utils::Vector{ |
| 692 | Return(Construct(params.create_ast_type(*this))), |
| 693 | }, |
| 694 | utils::Vector{ |
| 695 | Stage(ast::PipelineStage::kFragment), |
| 696 | }, |
| 697 | utils::Vector{ |
dan sinclair | f9eeed6 | 2022-09-07 22:25:24 +0000 | [diff] [blame] | 698 | Location(0_a), |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 699 | }); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 700 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 701 | if (params.is_valid) { |
| 702 | EXPECT_TRUE(r()->Resolve()) << r()->error(); |
| 703 | } else { |
| 704 | EXPECT_FALSE(r()->Resolve()); |
| 705 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | TEST_P(TypeValidationTest, StructOutputs) { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 709 | // struct Output { |
| 710 | // @location(0) a : *; |
| 711 | // }; |
dan sinclair | b29892b | 2022-06-07 13:55:34 +0000 | [diff] [blame] | 712 | // @fragment |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 713 | // fn main() -> Output { |
| 714 | // return Output(); |
| 715 | // } |
| 716 | auto params = GetParam(); |
Zhaoming Jiang | 9c71174 | 2022-07-08 19:35:05 +0000 | [diff] [blame] | 717 | |
| 718 | Enable(ast::Extension::kF16); |
| 719 | |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 720 | auto* output = Structure( |
| 721 | "Output", utils::Vector{ |
dan sinclair | f9eeed6 | 2022-09-07 22:25:24 +0000 | [diff] [blame] | 722 | Member("a", params.create_ast_type(*this), utils::Vector{Location(0_a)}), |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 723 | }); |
| 724 | Func(Source{{12, 34}}, "main", utils::Empty, ty.Of(output), |
| 725 | utils::Vector{ |
| 726 | Return(Construct(ty.Of(output))), |
| 727 | }, |
| 728 | utils::Vector{ |
| 729 | Stage(ast::PipelineStage::kFragment), |
| 730 | }); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 731 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 732 | if (params.is_valid) { |
| 733 | EXPECT_TRUE(r()->Resolve()) << r()->error(); |
| 734 | } else { |
| 735 | EXPECT_FALSE(r()->Resolve()); |
| 736 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 737 | } |
| 738 | INSTANTIATE_TEST_SUITE_P(ResolverEntryPointValidationTest, |
| 739 | TypeValidationTest, |
| 740 | testing::ValuesIn(cases)); |
| 741 | |
| 742 | } // namespace TypeValidationTests |
| 743 | |
| 744 | namespace LocationAttributeTests { |
| 745 | namespace { |
| 746 | using LocationAttributeTests = ResolverTest; |
| 747 | |
| 748 | TEST_F(LocationAttributeTests, Pass) { |
dan sinclair | b29892b | 2022-06-07 13:55:34 +0000 | [diff] [blame] | 749 | // @fragment |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 750 | // fn frag_main(@location(0) @interpolate(flat) a: i32) {} |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 751 | |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 752 | auto* p = Param(Source{{12, 34}}, "a", ty.i32(), |
| 753 | utils::Vector{ |
dan sinclair | f9eeed6 | 2022-09-07 22:25:24 +0000 | [diff] [blame] | 754 | Location(0_a), |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 755 | Flat(), |
| 756 | }); |
| 757 | Func("frag_main", |
| 758 | utils::Vector{ |
| 759 | p, |
| 760 | }, |
| 761 | ty.void_(), utils::Empty, |
| 762 | utils::Vector{ |
| 763 | Stage(ast::PipelineStage::kFragment), |
| 764 | }); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 765 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 766 | EXPECT_TRUE(r()->Resolve()) << r()->error(); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | TEST_F(LocationAttributeTests, BadType_Input_bool) { |
dan sinclair | b29892b | 2022-06-07 13:55:34 +0000 | [diff] [blame] | 770 | // @fragment |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 771 | // fn frag_main(@location(0) a: bool) {} |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 772 | |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 773 | auto* p = Param(Source{{12, 34}}, "a", ty.bool_(), |
| 774 | utils::Vector{ |
dan sinclair | f9eeed6 | 2022-09-07 22:25:24 +0000 | [diff] [blame] | 775 | Location(Source{{34, 56}}, 0_a), |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 776 | }); |
| 777 | Func("frag_main", |
| 778 | utils::Vector{ |
| 779 | p, |
| 780 | }, |
| 781 | ty.void_(), utils::Empty, |
| 782 | utils::Vector{ |
| 783 | Stage(ast::PipelineStage::kFragment), |
| 784 | }); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 785 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 786 | EXPECT_FALSE(r()->Resolve()); |
| 787 | EXPECT_EQ(r()->error(), |
| 788 | "12:34 error: cannot apply 'location' attribute to declaration of " |
| 789 | "type 'bool'\n" |
| 790 | "34:56 note: 'location' attribute must only be applied to " |
| 791 | "declarations of numeric scalar or numeric vector type"); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | TEST_F(LocationAttributeTests, BadType_Output_Array) { |
dan sinclair | b29892b | 2022-06-07 13:55:34 +0000 | [diff] [blame] | 795 | // @fragment |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 796 | // fn frag_main()->@location(0) array<f32, 2> { return array<f32, 2>(); } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 797 | |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 798 | Func(Source{{12, 34}}, "frag_main", utils::Empty, ty.array<f32, 2>(), |
| 799 | utils::Vector{ |
| 800 | Return(Construct(ty.array<f32, 2>())), |
| 801 | }, |
| 802 | utils::Vector{ |
| 803 | Stage(ast::PipelineStage::kFragment), |
| 804 | }, |
| 805 | utils::Vector{ |
dan sinclair | f9eeed6 | 2022-09-07 22:25:24 +0000 | [diff] [blame] | 806 | Location(Source{{34, 56}}, 0_a), |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 807 | }); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 808 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 809 | EXPECT_FALSE(r()->Resolve()); |
| 810 | EXPECT_EQ(r()->error(), |
| 811 | "12:34 error: cannot apply 'location' attribute to declaration of " |
| 812 | "type 'array<f32, 2>'\n" |
| 813 | "34:56 note: 'location' attribute must only be applied to " |
| 814 | "declarations of numeric scalar or numeric vector type"); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | TEST_F(LocationAttributeTests, BadType_Input_Struct) { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 818 | // struct Input { |
| 819 | // a : f32; |
| 820 | // }; |
dan sinclair | b29892b | 2022-06-07 13:55:34 +0000 | [diff] [blame] | 821 | // @fragment |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 822 | // fn main(@location(0) param : Input) {} |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 823 | auto* input = Structure("Input", utils::Vector{ |
| 824 | Member("a", ty.f32()), |
| 825 | }); |
| 826 | auto* param = Param(Source{{12, 34}}, "param", ty.Of(input), |
| 827 | utils::Vector{ |
dan sinclair | f9eeed6 | 2022-09-07 22:25:24 +0000 | [diff] [blame] | 828 | Location(Source{{13, 43}}, 0_a), |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 829 | }); |
| 830 | Func(Source{{12, 34}}, "main", |
| 831 | utils::Vector{ |
| 832 | param, |
| 833 | }, |
| 834 | ty.void_(), utils::Empty, |
| 835 | utils::Vector{ |
| 836 | Stage(ast::PipelineStage::kFragment), |
| 837 | }); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 838 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 839 | EXPECT_FALSE(r()->Resolve()); |
| 840 | EXPECT_EQ(r()->error(), |
| 841 | "12:34 error: cannot apply 'location' attribute to declaration of " |
| 842 | "type 'Input'\n" |
| 843 | "13:43 note: 'location' attribute must only be applied to " |
| 844 | "declarations of numeric scalar or numeric vector type"); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 845 | } |
| 846 | |
| 847 | TEST_F(LocationAttributeTests, BadType_Input_Struct_NestedStruct) { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 848 | // struct Inner { |
| 849 | // @location(0) b : f32; |
| 850 | // }; |
| 851 | // struct Input { |
| 852 | // a : Inner; |
| 853 | // }; |
dan sinclair | b29892b | 2022-06-07 13:55:34 +0000 | [diff] [blame] | 854 | // @fragment |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 855 | // fn main(param : Input) {} |
dan sinclair | f9eeed6 | 2022-09-07 22:25:24 +0000 | [diff] [blame] | 856 | auto* inner = Structure( |
| 857 | "Inner", utils::Vector{ |
| 858 | Member(Source{{13, 43}}, "a", ty.f32(), utils::Vector{Location(0_a)}), |
| 859 | }); |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 860 | auto* input = Structure("Input", utils::Vector{ |
| 861 | Member(Source{{14, 52}}, "a", ty.Of(inner)), |
| 862 | }); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 863 | auto* param = Param("param", ty.Of(input)); |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 864 | Func(Source{{12, 34}}, "main", |
| 865 | utils::Vector{ |
| 866 | param, |
| 867 | }, |
| 868 | ty.void_(), utils::Empty, |
| 869 | utils::Vector{ |
| 870 | Stage(ast::PipelineStage::kFragment), |
| 871 | }); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 872 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 873 | EXPECT_FALSE(r()->Resolve()); |
| 874 | EXPECT_EQ(r()->error(), |
| 875 | "14:52 error: nested structures cannot be used for entry point IO\n" |
Ben Clayton | 4fe330f | 2022-10-13 13:33:25 +0000 | [diff] [blame] | 876 | "12:34 note: while analyzing entry point 'main'"); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | TEST_F(LocationAttributeTests, BadType_Input_Struct_RuntimeArray) { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 880 | // struct Input { |
| 881 | // @location(0) a : array<f32>; |
| 882 | // }; |
dan sinclair | b29892b | 2022-06-07 13:55:34 +0000 | [diff] [blame] | 883 | // @fragment |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 884 | // fn main(param : Input) {} |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 885 | auto* input = Structure( |
| 886 | "Input", utils::Vector{ |
dan sinclair | f9eeed6 | 2022-09-07 22:25:24 +0000 | [diff] [blame] | 887 | Member(Source{{13, 43}}, "a", ty.array<f32>(), utils::Vector{Location(0_a)}), |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 888 | }); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 889 | auto* param = Param("param", ty.Of(input)); |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 890 | Func(Source{{12, 34}}, "main", |
| 891 | utils::Vector{ |
| 892 | param, |
| 893 | }, |
| 894 | ty.void_(), utils::Empty, |
| 895 | utils::Vector{ |
| 896 | Stage(ast::PipelineStage::kFragment), |
| 897 | }); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 898 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 899 | EXPECT_FALSE(r()->Resolve()); |
| 900 | EXPECT_EQ(r()->error(), |
| 901 | "13:43 error: cannot apply 'location' attribute to declaration of " |
| 902 | "type 'array<f32>'\n" |
| 903 | "note: 'location' attribute must only be applied to declarations " |
| 904 | "of numeric scalar or numeric vector type"); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 905 | } |
| 906 | |
| 907 | TEST_F(LocationAttributeTests, BadMemberType_Input) { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 908 | // struct S { @location(0) m: array<i32>; }; |
dan sinclair | b29892b | 2022-06-07 13:55:34 +0000 | [diff] [blame] | 909 | // @fragment |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 910 | // fn frag_main( a: S) {} |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 911 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 912 | auto* m = Member(Source{{34, 56}}, "m", ty.array<i32>(), |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 913 | utils::Vector{ |
dan sinclair | f9eeed6 | 2022-09-07 22:25:24 +0000 | [diff] [blame] | 914 | Location(Source{{12, 34}}, 0_u), |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 915 | }); |
| 916 | auto* s = Structure("S", utils::Vector{m}); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 917 | auto* p = Param("a", ty.Of(s)); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 918 | |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 919 | Func("frag_main", |
| 920 | utils::Vector{ |
| 921 | p, |
| 922 | }, |
| 923 | ty.void_(), utils::Empty, |
| 924 | utils::Vector{ |
| 925 | Stage(ast::PipelineStage::kFragment), |
| 926 | }); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 927 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 928 | EXPECT_FALSE(r()->Resolve()); |
| 929 | EXPECT_EQ(r()->error(), |
| 930 | "34:56 error: cannot apply 'location' attribute to declaration of " |
| 931 | "type 'array<i32>'\n" |
| 932 | "12:34 note: 'location' attribute must only be applied to " |
| 933 | "declarations of numeric scalar or numeric vector type"); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | TEST_F(LocationAttributeTests, BadMemberType_Output) { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 937 | // struct S { @location(0) m: atomic<i32>; }; |
dan sinclair | b29892b | 2022-06-07 13:55:34 +0000 | [diff] [blame] | 938 | // @fragment |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 939 | // fn frag_main() -> S {} |
| 940 | auto* m = Member(Source{{34, 56}}, "m", ty.atomic<i32>(), |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 941 | utils::Vector{ |
dan sinclair | f9eeed6 | 2022-09-07 22:25:24 +0000 | [diff] [blame] | 942 | Location(Source{{12, 34}}, 0_u), |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 943 | }); |
| 944 | auto* s = Structure("S", utils::Vector{m}); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 945 | |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 946 | Func("frag_main", utils::Empty, ty.Of(s), |
| 947 | utils::Vector{ |
| 948 | Return(Construct(ty.Of(s))), |
| 949 | }, |
| 950 | utils::Vector{ |
| 951 | Stage(ast::PipelineStage::kFragment), |
| 952 | }, |
| 953 | {}); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 954 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 955 | EXPECT_FALSE(r()->Resolve()); |
| 956 | EXPECT_EQ(r()->error(), |
| 957 | "34:56 error: cannot apply 'location' attribute to declaration of " |
| 958 | "type 'atomic<i32>'\n" |
| 959 | "12:34 note: 'location' attribute must only be applied to " |
| 960 | "declarations of numeric scalar or numeric vector type"); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | TEST_F(LocationAttributeTests, BadMemberType_Unused) { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 964 | // struct S { @location(0) m: mat3x2<f32>; }; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 965 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 966 | auto* m = Member(Source{{34, 56}}, "m", ty.mat3x2<f32>(), |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 967 | utils::Vector{ |
dan sinclair | f9eeed6 | 2022-09-07 22:25:24 +0000 | [diff] [blame] | 968 | Location(Source{{12, 34}}, 0_u), |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 969 | }); |
| 970 | Structure("S", utils::Vector{m}); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 971 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 972 | EXPECT_FALSE(r()->Resolve()); |
| 973 | EXPECT_EQ(r()->error(), |
| 974 | "34:56 error: cannot apply 'location' attribute to declaration of " |
| 975 | "type 'mat3x2<f32>'\n" |
| 976 | "12:34 note: 'location' attribute must only be applied to " |
| 977 | "declarations of numeric scalar or numeric vector type"); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | TEST_F(LocationAttributeTests, ReturnType_Struct_Valid) { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 981 | // struct Output { |
| 982 | // @location(0) a : f32; |
| 983 | // @builtin(frag_depth) b : f32; |
| 984 | // }; |
dan sinclair | b29892b | 2022-06-07 13:55:34 +0000 | [diff] [blame] | 985 | // @fragment |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 986 | // fn main() -> Output { |
| 987 | // return Output(); |
| 988 | // } |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 989 | auto* output = Structure( |
| 990 | "Output", utils::Vector{ |
dan sinclair | f9eeed6 | 2022-09-07 22:25:24 +0000 | [diff] [blame] | 991 | Member("a", ty.f32(), utils::Vector{Location(0_a)}), |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 992 | Member("b", ty.f32(), utils::Vector{Builtin(ast::BuiltinValue::kFragDepth)}), |
| 993 | }); |
| 994 | Func(Source{{12, 34}}, "main", utils::Empty, ty.Of(output), |
| 995 | utils::Vector{ |
| 996 | Return(Construct(ty.Of(output))), |
| 997 | }, |
| 998 | utils::Vector{ |
| 999 | Stage(ast::PipelineStage::kFragment), |
| 1000 | }); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1001 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1002 | EXPECT_TRUE(r()->Resolve()) << r()->error(); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | TEST_F(LocationAttributeTests, ReturnType_Struct) { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1006 | // struct Output { |
| 1007 | // a : f32; |
| 1008 | // }; |
dan sinclair | b29892b | 2022-06-07 13:55:34 +0000 | [diff] [blame] | 1009 | // @vertex |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1010 | // fn main() -> @location(0) Output { |
| 1011 | // return Output(); |
| 1012 | // } |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 1013 | auto* output = Structure("Output", utils::Vector{ |
| 1014 | Member("a", ty.f32()), |
| 1015 | }); |
| 1016 | Func(Source{{12, 34}}, "main", utils::Empty, ty.Of(output), |
| 1017 | utils::Vector{ |
| 1018 | Return(Construct(ty.Of(output))), |
| 1019 | }, |
| 1020 | utils::Vector{ |
| 1021 | Stage(ast::PipelineStage::kVertex), |
| 1022 | }, |
| 1023 | utils::Vector{ |
dan sinclair | f9eeed6 | 2022-09-07 22:25:24 +0000 | [diff] [blame] | 1024 | Location(Source{{13, 43}}, 0_a), |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 1025 | }); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1026 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1027 | EXPECT_FALSE(r()->Resolve()); |
| 1028 | EXPECT_EQ(r()->error(), |
| 1029 | "12:34 error: cannot apply 'location' attribute to declaration of " |
| 1030 | "type 'Output'\n" |
| 1031 | "13:43 note: 'location' attribute must only be applied to " |
| 1032 | "declarations of numeric scalar or numeric vector type"); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | TEST_F(LocationAttributeTests, ReturnType_Struct_NestedStruct) { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1036 | // struct Inner { |
| 1037 | // @location(0) b : f32; |
| 1038 | // }; |
| 1039 | // struct Output { |
| 1040 | // a : Inner; |
| 1041 | // }; |
dan sinclair | b29892b | 2022-06-07 13:55:34 +0000 | [diff] [blame] | 1042 | // @fragment |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1043 | // fn main() -> Output { return Output(); } |
dan sinclair | f9eeed6 | 2022-09-07 22:25:24 +0000 | [diff] [blame] | 1044 | auto* inner = Structure( |
| 1045 | "Inner", utils::Vector{ |
| 1046 | Member(Source{{13, 43}}, "a", ty.f32(), utils::Vector{Location(0_a)}), |
| 1047 | }); |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 1048 | auto* output = Structure("Output", utils::Vector{ |
| 1049 | Member(Source{{14, 52}}, "a", ty.Of(inner)), |
| 1050 | }); |
| 1051 | Func(Source{{12, 34}}, "main", utils::Empty, ty.Of(output), |
| 1052 | utils::Vector{ |
| 1053 | Return(Construct(ty.Of(output))), |
| 1054 | }, |
| 1055 | utils::Vector{ |
| 1056 | Stage(ast::PipelineStage::kFragment), |
| 1057 | }); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1058 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1059 | EXPECT_FALSE(r()->Resolve()); |
| 1060 | EXPECT_EQ(r()->error(), |
| 1061 | "14:52 error: nested structures cannot be used for entry point IO\n" |
Ben Clayton | 4fe330f | 2022-10-13 13:33:25 +0000 | [diff] [blame] | 1062 | "12:34 note: while analyzing entry point 'main'"); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | TEST_F(LocationAttributeTests, ReturnType_Struct_RuntimeArray) { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1066 | // struct Output { |
| 1067 | // @location(0) a : array<f32>; |
| 1068 | // }; |
dan sinclair | b29892b | 2022-06-07 13:55:34 +0000 | [diff] [blame] | 1069 | // @fragment |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1070 | // fn main() -> Output { |
| 1071 | // return Output(); |
| 1072 | // } |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 1073 | auto* output = Structure("Output", utils::Vector{ |
| 1074 | Member(Source{{13, 43}}, "a", ty.array<f32>(), |
dan sinclair | f9eeed6 | 2022-09-07 22:25:24 +0000 | [diff] [blame] | 1075 | utils::Vector{Location(Source{{12, 34}}, 0_a)}), |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 1076 | }); |
| 1077 | Func(Source{{12, 34}}, "main", utils::Empty, ty.Of(output), |
| 1078 | utils::Vector{ |
| 1079 | Return(Construct(ty.Of(output))), |
| 1080 | }, |
| 1081 | utils::Vector{ |
| 1082 | Stage(ast::PipelineStage::kFragment), |
| 1083 | }); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1084 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1085 | EXPECT_FALSE(r()->Resolve()); |
| 1086 | EXPECT_EQ(r()->error(), |
| 1087 | "13:43 error: cannot apply 'location' attribute to declaration of " |
| 1088 | "type 'array<f32>'\n" |
| 1089 | "12:34 note: 'location' attribute must only be applied to " |
| 1090 | "declarations of numeric scalar or numeric vector type"); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1091 | } |
| 1092 | |
| 1093 | TEST_F(LocationAttributeTests, ComputeShaderLocation_Input) { |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 1094 | Func("main", utils::Empty, ty.i32(), |
| 1095 | utils::Vector{ |
| 1096 | Return(Expr(1_i)), |
| 1097 | }, |
| 1098 | utils::Vector{ |
| 1099 | Stage(ast::PipelineStage::kCompute), |
| 1100 | create<ast::WorkgroupAttribute>(Source{{12, 34}}, Expr(1_i)), |
| 1101 | }, |
| 1102 | utils::Vector{ |
dan sinclair | f9eeed6 | 2022-09-07 22:25:24 +0000 | [diff] [blame] | 1103 | Location(Source{{12, 34}}, 1_a), |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 1104 | }); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1105 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1106 | EXPECT_FALSE(r()->Resolve()); |
| 1107 | EXPECT_EQ(r()->error(), "12:34 error: attribute is not valid for compute shader output"); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1108 | } |
| 1109 | |
| 1110 | TEST_F(LocationAttributeTests, ComputeShaderLocation_Output) { |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 1111 | auto* input = Param("input", ty.i32(), |
| 1112 | utils::Vector{ |
dan sinclair | f9eeed6 | 2022-09-07 22:25:24 +0000 | [diff] [blame] | 1113 | Location(Source{{12, 34}}, 0_u), |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 1114 | }); |
| 1115 | Func("main", utils::Vector{input}, ty.void_(), utils::Empty, |
| 1116 | utils::Vector{ |
| 1117 | Stage(ast::PipelineStage::kCompute), |
| 1118 | create<ast::WorkgroupAttribute>(Source{{12, 34}}, Expr(1_i)), |
| 1119 | }); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1120 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1121 | EXPECT_FALSE(r()->Resolve()); |
| 1122 | EXPECT_EQ(r()->error(), "12:34 error: attribute is not valid for compute shader inputs"); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1123 | } |
| 1124 | |
| 1125 | TEST_F(LocationAttributeTests, ComputeShaderLocationStructMember_Output) { |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 1126 | auto* m = Member("m", ty.i32(), |
| 1127 | utils::Vector{ |
dan sinclair | f9eeed6 | 2022-09-07 22:25:24 +0000 | [diff] [blame] | 1128 | Location(Source{{12, 34}}, 0_u), |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 1129 | }); |
| 1130 | auto* s = Structure("S", utils::Vector{m}); |
| 1131 | Func(Source{{56, 78}}, "main", utils::Empty, ty.Of(s), |
| 1132 | utils::Vector{ |
| 1133 | Return(Expr(Construct(ty.Of(s)))), |
| 1134 | }, |
| 1135 | utils::Vector{ |
| 1136 | Stage(ast::PipelineStage::kCompute), |
| 1137 | create<ast::WorkgroupAttribute>(Source{{12, 34}}, Expr(1_i)), |
| 1138 | }); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1139 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1140 | EXPECT_FALSE(r()->Resolve()); |
| 1141 | EXPECT_EQ(r()->error(), |
| 1142 | "12:34 error: attribute is not valid for compute shader output\n" |
Ben Clayton | 4fe330f | 2022-10-13 13:33:25 +0000 | [diff] [blame] | 1143 | "56:78 note: while analyzing entry point 'main'"); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1144 | } |
| 1145 | |
| 1146 | TEST_F(LocationAttributeTests, ComputeShaderLocationStructMember_Input) { |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 1147 | auto* m = Member("m", ty.i32(), |
| 1148 | utils::Vector{ |
dan sinclair | f9eeed6 | 2022-09-07 22:25:24 +0000 | [diff] [blame] | 1149 | Location(Source{{12, 34}}, 0_u), |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 1150 | }); |
| 1151 | auto* s = Structure("S", utils::Vector{m}); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1152 | auto* input = Param("input", ty.Of(s)); |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 1153 | Func(Source{{56, 78}}, "main", utils::Vector{input}, ty.void_(), utils::Empty, |
| 1154 | utils::Vector{ |
| 1155 | Stage(ast::PipelineStage::kCompute), |
| 1156 | create<ast::WorkgroupAttribute>(Source{{12, 34}}, Expr(1_i)), |
| 1157 | }); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1158 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1159 | EXPECT_FALSE(r()->Resolve()); |
| 1160 | EXPECT_EQ(r()->error(), |
| 1161 | "12:34 error: attribute is not valid for compute shader inputs\n" |
Ben Clayton | 4fe330f | 2022-10-13 13:33:25 +0000 | [diff] [blame] | 1162 | "56:78 note: while analyzing entry point 'main'"); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1163 | } |
| 1164 | |
| 1165 | TEST_F(LocationAttributeTests, Duplicate_input) { |
dan sinclair | b29892b | 2022-06-07 13:55:34 +0000 | [diff] [blame] | 1166 | // @fragment |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1167 | // fn main(@location(1) param_a : f32, |
| 1168 | // @location(1) param_b : f32) {} |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 1169 | auto* param_a = Param("param_a", ty.f32(), |
| 1170 | utils::Vector{ |
dan sinclair | f9eeed6 | 2022-09-07 22:25:24 +0000 | [diff] [blame] | 1171 | Location(1_a), |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 1172 | }); |
| 1173 | auto* param_b = Param("param_b", ty.f32(), |
| 1174 | utils::Vector{ |
dan sinclair | f9eeed6 | 2022-09-07 22:25:24 +0000 | [diff] [blame] | 1175 | Location(Source{{12, 34}}, 1_a), |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 1176 | }); |
| 1177 | Func(Source{{12, 34}}, "main", |
| 1178 | utils::Vector{ |
| 1179 | param_a, |
| 1180 | param_b, |
| 1181 | }, |
| 1182 | ty.void_(), utils::Empty, |
| 1183 | utils::Vector{ |
| 1184 | Stage(ast::PipelineStage::kFragment), |
| 1185 | }); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1186 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1187 | EXPECT_FALSE(r()->Resolve()); |
| 1188 | EXPECT_EQ(r()->error(), "12:34 error: location(1) attribute appears multiple times"); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1189 | } |
| 1190 | |
| 1191 | TEST_F(LocationAttributeTests, Duplicate_struct) { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1192 | // struct InputA { |
| 1193 | // @location(1) a : f32; |
| 1194 | // }; |
| 1195 | // struct InputB { |
| 1196 | // @location(1) a : f32; |
| 1197 | // }; |
dan sinclair | b29892b | 2022-06-07 13:55:34 +0000 | [diff] [blame] | 1198 | // @fragment |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1199 | // fn main(param_a : InputA, param_b : InputB) {} |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 1200 | auto* input_a = Structure("InputA", utils::Vector{ |
dan sinclair | f9eeed6 | 2022-09-07 22:25:24 +0000 | [diff] [blame] | 1201 | Member("a", ty.f32(), utils::Vector{Location(1_a)}), |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 1202 | }); |
dan sinclair | f9eeed6 | 2022-09-07 22:25:24 +0000 | [diff] [blame] | 1203 | auto* input_b = Structure( |
| 1204 | "InputB", utils::Vector{ |
| 1205 | Member("a", ty.f32(), utils::Vector{Location(Source{{34, 56}}, 1_a)}), |
| 1206 | }); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1207 | auto* param_a = Param("param_a", ty.Of(input_a)); |
| 1208 | auto* param_b = Param("param_b", ty.Of(input_b)); |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 1209 | Func(Source{{12, 34}}, "main", |
| 1210 | utils::Vector{ |
| 1211 | param_a, |
| 1212 | param_b, |
| 1213 | }, |
| 1214 | ty.void_(), utils::Empty, |
| 1215 | utils::Vector{ |
| 1216 | Stage(ast::PipelineStage::kFragment), |
| 1217 | }); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1218 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1219 | EXPECT_FALSE(r()->Resolve()); |
| 1220 | EXPECT_EQ(r()->error(), |
| 1221 | "34:56 error: location(1) attribute appears multiple times\n" |
Ben Clayton | 4fe330f | 2022-10-13 13:33:25 +0000 | [diff] [blame] | 1222 | "12:34 note: while analyzing entry point 'main'"); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1223 | } |
| 1224 | |
| 1225 | } // namespace |
| 1226 | } // namespace LocationAttributeTests |
| 1227 | |
| 1228 | } // namespace |
dan sinclair | d209379 | 2022-04-07 17:45:45 +0000 | [diff] [blame] | 1229 | } // namespace tint::resolver |