1 // Copyright 2020 The Amber 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 parseried.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "gtest/gtest.h"
16 #include "src/amberscript/parser.h"
17
18 namespace amber {
19 namespace amberscript {
20
21 using AmberScriptParserTest = testing::Test;
22
TEST_F(AmberScriptParserTest,SubgroupSizeControlMissingRequiredFeaturecomputeFullSubgroups)23 TEST_F(AmberScriptParserTest,
24 SubgroupSizeControlMissingRequiredFeaturecomputeFullSubgroups) {
25 std::string in = R"(
26 SHADER compute test_shader GLSL
27 # GLSL
28 END
29 PIPELINE compute pipeline
30 ATTACH test_shader
31 SUBGROUP test_shader
32 FULLY_POPULATED on
33 END
34 END)";
35
36 Parser parser;
37 Result r = parser.Parse(in);
38 ASSERT_FALSE(r.IsSuccess());
39 EXPECT_EQ(
40 "8: missing DEVICE_FEATURE SubgroupSizeControl.computeFullSubgroups",
41 r.Error());
42 }
43
TEST_F(AmberScriptParserTest,SubgroupSizeControlMissingRequiredFeaturesubgroupSizeControl)44 TEST_F(AmberScriptParserTest,
45 SubgroupSizeControlMissingRequiredFeaturesubgroupSizeControl) {
46 std::string in = R"(
47 SHADER compute test_shader GLSL
48 # GLSL
49 END
50 PIPELINE compute pipeline
51 ATTACH test_shader
52 SUBGROUP test_shader
53 VARYING_SIZE on
54 END
55 END)";
56
57 Parser parser;
58 Result r = parser.Parse(in);
59 ASSERT_FALSE(r.IsSuccess());
60 EXPECT_EQ("8: missing DEVICE_FEATURE SubgroupSizeControl.subgroupSizeControl",
61 r.Error());
62 }
63
TEST_F(AmberScriptParserTest,SubgroupSizeControlMissingRequiredFeaturesubgroupSizeControl2)64 TEST_F(AmberScriptParserTest,
65 SubgroupSizeControlMissingRequiredFeaturesubgroupSizeControl2) {
66 std::string in = R"(
67 SHADER compute test_shader GLSL
68 # GLSL
69 END
70 PIPELINE compute pipeline
71 ATTACH test_shader
72 SUBGROUP test_shader
73 REQUIRED_SIZE 32
74 END
75 END)";
76
77 Parser parser;
78 Result r = parser.Parse(in);
79 ASSERT_FALSE(r.IsSuccess());
80 EXPECT_EQ("8: missing DEVICE_FEATURE SubgroupSizeControl.subgroupSizeControl",
81 r.Error());
82 }
83
TEST_F(AmberScriptParserTest,SubgroupSizeControlNoShader)84 TEST_F(AmberScriptParserTest, SubgroupSizeControlNoShader) {
85 std::string in = R"(
86 DEVICE_FEATURE SubgroupSizeControl.computeFullSubgroups
87 SHADER compute test_shader GLSL
88 # GLSL
89 END
90 PIPELINE compute pipeline
91 ATTACH test_shader
92 SUBGROUP
93 END
94 END)";
95
96 Parser parser;
97 Result r = parser.Parse(in);
98 ASSERT_FALSE(r.IsSuccess());
99 EXPECT_EQ("9: missing shader name in SUBGROUP command", r.Error());
100 }
101
TEST_F(AmberScriptParserTest,SubgroupSizeControlUnknownShader)102 TEST_F(AmberScriptParserTest, SubgroupSizeControlUnknownShader) {
103 std::string in = R"(
104 DEVICE_FEATURE SubgroupSizeControl.computeFullSubgroups
105 SHADER compute test_shader GLSL
106 # GLSL
107 END
108 PIPELINE compute pipeline
109 ATTACH test_shader
110 SUBGROUP unused
111 END
112 END)";
113
114 Parser parser;
115 Result r = parser.Parse(in);
116 ASSERT_FALSE(r.IsSuccess());
117 EXPECT_EQ("8: unknown shader in SUBGROUP command", r.Error());
118 }
119
TEST_F(AmberScriptParserTest,SubgroupSizeControlUnknownIdentifier)120 TEST_F(AmberScriptParserTest, SubgroupSizeControlUnknownIdentifier) {
121 std::string in = R"(
122 DEVICE_FEATURE SubgroupSizeControl.subgroupSizeControl
123 SHADER compute test_shader GLSL
124 # GLSL
125 END
126 PIPELINE compute pipeline
127 ATTACH test_shader
128 SUBGROUP test_shader
129 UNKNOWN_SETTING
130 END
131 END)";
132
133 Parser parser;
134 Result r = parser.Parse(in);
135 ASSERT_FALSE(r.IsSuccess());
136 EXPECT_EQ("9: SUBGROUP invalid value for SUBGROUP UNKNOWN_SETTING",
137 r.Error());
138 }
139
TEST_F(AmberScriptParserTest,SubgroupSizeControlUnknownIdentifier2)140 TEST_F(AmberScriptParserTest, SubgroupSizeControlUnknownIdentifier2) {
141 std::string in = R"(
142 DEVICE_FEATURE SubgroupSizeControl.subgroupSizeControl
143 SHADER compute test_shader GLSL
144 # GLSL
145 END
146 PIPELINE compute pipeline
147 ATTACH test_shader
148 SUBGROUP test_shader
149 REQUIRED_SIZE 2 UNKNOWN_SETTING
150 END
151 END)";
152
153 Parser parser;
154 Result r = parser.Parse(in);
155 ASSERT_FALSE(r.IsSuccess());
156 EXPECT_EQ("9: SUBGROUP invalid value for SUBGROUP UNKNOWN_SETTING",
157 r.Error());
158 }
159
TEST_F(AmberScriptParserTest,SubgroupSizeControlRequiredSubgroupSizeInvalidSubgroupSize)160 TEST_F(AmberScriptParserTest,
161 SubgroupSizeControlRequiredSubgroupSizeInvalidSubgroupSize) {
162 std::string in = R"(
163 DEVICE_FEATURE SubgroupSizeControl.subgroupSizeControl
164 SHADER compute test_shader GLSL
165 # GLSL
166 END
167 PIPELINE compute pipeline
168 ATTACH test_shader
169 SUBGROUP test_shader
170 REQUIRED_SIZE unused
171 END
172 END)";
173
174 Parser parser;
175 Result r = parser.Parse(in);
176 ASSERT_FALSE(r.IsSuccess());
177 EXPECT_EQ("9: invalid size for REQUIRED_SIZE command", r.Error());
178 }
179
TEST_F(AmberScriptParserTest,SubgroupSizeControlRequiredSubgroupSizeInvalidSubgroupSize2)180 TEST_F(AmberScriptParserTest,
181 SubgroupSizeControlRequiredSubgroupSizeInvalidSubgroupSize2) {
182 std::string in = R"(
183 DEVICE_FEATURE SubgroupSizeControl.subgroupSizeControl
184 SHADER compute test_shader GLSL
185 # GLSL
186 END
187 PIPELINE compute pipeline
188 ATTACH test_shader
189 SUBGROUP test_shader
190 REQUIRED_SIZE 0
191 END
192 END)";
193
194 Parser parser;
195 Result r = parser.Parse(in);
196 ASSERT_FALSE(r.IsSuccess());
197 EXPECT_EQ(
198 "9: invalid required subgroup size 0 specified for shader name "
199 "test_shader",
200 r.Error());
201 }
202
TEST_F(AmberScriptParserTest,SubgroupSizeControlRequiredSubgroupSizeInvalidSubgroupSize3)203 TEST_F(AmberScriptParserTest,
204 SubgroupSizeControlRequiredSubgroupSizeInvalidSubgroupSize3) {
205 std::string in = R"(
206 DEVICE_FEATURE SubgroupSizeControl.subgroupSizeControl
207 SHADER compute test_shader GLSL
208 # GLSL
209 END
210 PIPELINE compute pipeline
211 ATTACH test_shader
212 SUBGROUP test_shader
213 REQUIRED_SIZE 256
214 END
215 END)";
216
217 Parser parser;
218 Result r = parser.Parse(in);
219 ASSERT_FALSE(r.IsSuccess());
220 EXPECT_EQ(
221 "9: invalid required subgroup size 256 specified for shader name "
222 "test_shader",
223 r.Error());
224 }
225
TEST_F(AmberScriptParserTest,SubgroupSizeControlRequiredSubgroupSizeInvalidSubgroupSize4)226 TEST_F(AmberScriptParserTest,
227 SubgroupSizeControlRequiredSubgroupSizeInvalidSubgroupSize4) {
228 std::string in = R"(
229 DEVICE_FEATURE SubgroupSizeControl.subgroupSizeControl
230 SHADER compute test_shader GLSL
231 # GLSL
232 END
233 PIPELINE compute pipeline
234 ATTACH test_shader
235 SUBGROUP test_shader
236 REQUIRED_SIZE 7
237 END
238 END)";
239
240 Parser parser;
241 Result r = parser.Parse(in);
242 ASSERT_FALSE(r.IsSuccess());
243 EXPECT_EQ(
244 "9: invalid required subgroup size 7 specified for shader name "
245 "test_shader",
246 r.Error());
247 }
248
TEST_F(AmberScriptParserTest,SubgroupSizeControlRequireFullSubgroupsInvalidValue)249 TEST_F(AmberScriptParserTest,
250 SubgroupSizeControlRequireFullSubgroupsInvalidValue) {
251 std::string in = R"(
252 DEVICE_FEATURE SubgroupSizeControl.computeFullSubgroups
253 SHADER compute test_shader GLSL
254 # GLSL
255 END
256 PIPELINE compute pipeline
257 ATTACH test_shader
258 SUBGROUP test_shader
259 FULLY_POPULATED unused
260 END
261 END)";
262 Parser parser;
263 Result r = parser.Parse(in);
264 ASSERT_FALSE(r.IsSuccess());
265 EXPECT_EQ("9: invalid value for FULLY_POPULATED command", r.Error());
266 }
267
TEST_F(AmberScriptParserTest,SubgroupSizeControlRequireVaryingSubgroupsInvalidValue)268 TEST_F(AmberScriptParserTest,
269 SubgroupSizeControlRequireVaryingSubgroupsInvalidValue) {
270 std::string in = R"(
271 DEVICE_FEATURE SubgroupSizeControl.subgroupSizeControl
272 SHADER compute test_shader GLSL
273 # GLSL
274 END
275 PIPELINE compute pipeline
276 ATTACH test_shader
277 SUBGROUP test_shader
278 VARYING_SIZE unused
279 END
280 END)";
281 Parser parser;
282 Result r = parser.Parse(in);
283 ASSERT_FALSE(r.IsSuccess());
284 EXPECT_EQ("9: invalid value for VARYING_SIZE command", r.Error());
285 }
286
TEST_F(AmberScriptParserTest,SubgroupSizeControlRequireFullSubgroupsSet)287 TEST_F(AmberScriptParserTest, SubgroupSizeControlRequireFullSubgroupsSet) {
288 std::string in = R"(
289 DEVICE_FEATURE SubgroupSizeControl.computeFullSubgroups
290 SHADER compute test_shader GLSL
291 # GLSL
292 END
293 PIPELINE compute pipeline
294 ATTACH test_shader
295 SUBGROUP test_shader
296 FULLY_POPULATED on
297 END
298 END)";
299 Parser parser;
300 Result r = parser.Parse(in);
301 ASSERT_TRUE(r.IsSuccess()) << r.Error();
302 auto script = parser.GetScript();
303 const auto& pipelines = script->GetPipelines();
304 ASSERT_EQ(1U, pipelines.size());
305
306 const auto* pipeline = pipelines[0].get();
307 const auto& shaders = pipeline->GetShaders();
308 ASSERT_EQ(1U, shaders.size());
309 ASSERT_TRUE(shaders[0].GetShader() != nullptr);
310 ASSERT_TRUE(shaders[0].GetRequireFullSubgroups() == true);
311 }
312
TEST_F(AmberScriptParserTest,SubgroupSizeControlVaryingSubgroupsSet)313 TEST_F(AmberScriptParserTest, SubgroupSizeControlVaryingSubgroupsSet) {
314 std::string in = R"(
315 DEVICE_FEATURE SubgroupSizeControl.subgroupSizeControl
316 SHADER compute test_shader GLSL
317 # GLSL
318 END
319 PIPELINE compute pipeline
320 ATTACH test_shader
321 SUBGROUP test_shader
322 VARYING_SIZE on
323 END
324 END)";
325 Parser parser;
326 Result r = parser.Parse(in);
327 ASSERT_TRUE(r.IsSuccess()) << r.Error();
328 auto script = parser.GetScript();
329 const auto& pipelines = script->GetPipelines();
330 ASSERT_EQ(1U, pipelines.size());
331
332 const auto* pipeline = pipelines[0].get();
333 const auto& shaders = pipeline->GetShaders();
334 ASSERT_EQ(1U, shaders.size());
335 ASSERT_TRUE(shaders[0].GetShader() != nullptr);
336 ASSERT_TRUE(shaders[0].GetVaryingSubgroupSize() == true);
337 }
338
TEST_F(AmberScriptParserTest,SubgroupSizeControlRequiredSubgroupSizeSetTo8)339 TEST_F(AmberScriptParserTest, SubgroupSizeControlRequiredSubgroupSizeSetTo8) {
340 std::string in = R"(
341 DEVICE_FEATURE SubgroupSizeControl.subgroupSizeControl
342 SHADER compute test_shader GLSL
343 # GLSL
344 END
345 PIPELINE compute pipeline
346 ATTACH test_shader
347 SUBGROUP test_shader
348 REQUIRED_SIZE 8
349 END
350 END)";
351
352 Parser parser;
353 Result r = parser.Parse(in);
354 ASSERT_TRUE(r.IsSuccess()) << r.Error();
355 auto script = parser.GetScript();
356 const auto& pipelines = script->GetPipelines();
357 ASSERT_EQ(1U, pipelines.size());
358
359 const auto* pipeline = pipelines[0].get();
360 const auto& shaders = pipeline->GetShaders();
361 ASSERT_EQ(1U, shaders.size());
362 ASSERT_TRUE(shaders[0].GetShader() != nullptr);
363 ASSERT_TRUE(shaders[0].GetRequiredSubgroupSizeSetting() ==
364 amber::Pipeline::ShaderInfo::RequiredSubgroupSizeSetting::
365 kSetToSpecificSize);
366 ASSERT_EQ(8U, shaders[0].GetRequiredSubgroupSize());
367 }
368
TEST_F(AmberScriptParserTest,SubgroupSizeControlRequiredSubgroupSizeSetToMax)369 TEST_F(AmberScriptParserTest, SubgroupSizeControlRequiredSubgroupSizeSetToMax) {
370 std::string in = R"(
371 DEVICE_FEATURE SubgroupSizeControl.subgroupSizeControl
372 SHADER compute test_shader GLSL
373 # GLSL
374 END
375 PIPELINE compute pipeline
376 ATTACH test_shader
377 SUBGROUP test_shader
378 REQUIRED_SIZE MAX
379 END
380 END)";
381
382 Parser parser;
383 Result r = parser.Parse(in);
384 ASSERT_TRUE(r.IsSuccess()) << r.Error();
385 auto script = parser.GetScript();
386 const auto& pipelines = script->GetPipelines();
387 ASSERT_EQ(1U, pipelines.size());
388
389 const auto* pipeline = pipelines[0].get();
390 const auto& shaders = pipeline->GetShaders();
391 ASSERT_EQ(1U, shaders.size());
392 ASSERT_TRUE(shaders[0].GetShader() != nullptr);
393 ASSERT_TRUE(shaders[0].GetRequiredSubgroupSizeSetting() ==
394 amber::Pipeline::ShaderInfo::RequiredSubgroupSizeSetting::
395 kSetToMaximumSize);
396 }
397
TEST_F(AmberScriptParserTest,SubgroupSizeControlRequiredSubgroupSizeSetToMin)398 TEST_F(AmberScriptParserTest, SubgroupSizeControlRequiredSubgroupSizeSetToMin) {
399 std::string in = R"(
400 DEVICE_FEATURE SubgroupSizeControl.subgroupSizeControl
401 SHADER compute test_shader GLSL
402 # GLSL
403 END
404 PIPELINE compute pipeline
405 ATTACH test_shader
406 SUBGROUP test_shader
407 REQUIRED_SIZE MIN
408 END
409 END)";
410
411 Parser parser;
412 Result r = parser.Parse(in);
413 ASSERT_TRUE(r.IsSuccess()) << r.Error();
414 auto script = parser.GetScript();
415 const auto& pipelines = script->GetPipelines();
416 ASSERT_EQ(1U, pipelines.size());
417
418 const auto* pipeline = pipelines[0].get();
419 const auto& shaders = pipeline->GetShaders();
420 ASSERT_EQ(1U, shaders.size());
421 ASSERT_TRUE(shaders[0].GetShader() != nullptr);
422 ASSERT_TRUE(shaders[0].GetRequiredSubgroupSizeSetting() ==
423 amber::Pipeline::ShaderInfo::RequiredSubgroupSizeSetting::
424 kSetToMinimumSize);
425 }
426
TEST_F(AmberScriptParserTest,SubgroupSizeControlRequireFullAndVaryingSubgroups)427 TEST_F(AmberScriptParserTest,
428 SubgroupSizeControlRequireFullAndVaryingSubgroups) {
429 std::string in = R"(
430 DEVICE_FEATURE SubgroupSizeControl.computeFullSubgroups
431 DEVICE_FEATURE SubgroupSizeControl.subgroupSizeControl
432 SHADER compute test_shader GLSL
433 # GLSL
434 END
435 PIPELINE compute pipeline
436 ATTACH test_shader
437 SUBGROUP test_shader
438 FULLY_POPULATED on
439 VARYING_SIZE on
440 END
441 END)";
442 Parser parser;
443 Result r = parser.Parse(in);
444 ASSERT_TRUE(r.IsSuccess()) << r.Error();
445 auto script = parser.GetScript();
446 const auto& pipelines = script->GetPipelines();
447 ASSERT_EQ(1U, pipelines.size());
448
449 const auto* pipeline = pipelines[0].get();
450 const auto& shaders = pipeline->GetShaders();
451 ASSERT_EQ(1U, shaders.size());
452 ASSERT_TRUE(shaders[0].GetShader() != nullptr);
453 ASSERT_TRUE(shaders[0].GetRequireFullSubgroups() == true);
454 ASSERT_TRUE(shaders[0].GetVaryingSubgroupSize() == true);
455 }
456
TEST_F(AmberScriptParserTest,SubgroupSizeControlRequireFullAndMinSubgroups)457 TEST_F(AmberScriptParserTest, SubgroupSizeControlRequireFullAndMinSubgroups) {
458 std::string in = R"(
459 DEVICE_FEATURE SubgroupSizeControl.computeFullSubgroups
460 DEVICE_FEATURE SubgroupSizeControl.subgroupSizeControl
461 SHADER compute test_shader GLSL
462 # GLSL
463 END
464 PIPELINE compute pipeline
465 ATTACH test_shader
466 SUBGROUP test_shader
467 FULLY_POPULATED on
468 REQUIRED_SIZE MIN
469 END
470 END)";
471 Parser parser;
472 Result r = parser.Parse(in);
473 ASSERT_TRUE(r.IsSuccess()) << r.Error();
474 auto script = parser.GetScript();
475 const auto& pipelines = script->GetPipelines();
476 ASSERT_EQ(1U, pipelines.size());
477
478 const auto* pipeline = pipelines[0].get();
479 const auto& shaders = pipeline->GetShaders();
480 ASSERT_EQ(1U, shaders.size());
481 ASSERT_TRUE(shaders[0].GetShader() != nullptr);
482 ASSERT_TRUE(shaders[0].GetRequireFullSubgroups() == true);
483 ASSERT_TRUE(shaders[0].GetRequiredSubgroupSizeSetting() ==
484 amber::Pipeline::ShaderInfo::RequiredSubgroupSizeSetting::
485 kSetToMinimumSize);
486 }
487
488 } // namespace amberscript
489 } // namespace amber
490