1 // Copyright 2018 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 implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "src/executor.h"
16
17 #include <memory>
18 #include <string>
19 #include <utility>
20 #include <vector>
21
22 #include "gtest/gtest.h"
23 #include "src/engine.h"
24 #include "src/make_unique.h"
25 #include "src/vkscript/parser.h"
26
27 namespace amber {
28 namespace vkscript {
29 namespace {
30
31 class EngineStub : public Engine {
32 public:
EngineStub()33 EngineStub() : Engine() {}
34 ~EngineStub() override = default;
35
36 // Engine
Initialize(EngineConfig *,Delegate *,const std::vector<std::string> & features,const std::vector<std::string> & properties,const std::vector<std::string> & instance_exts,const std::vector<std::string> & device_exts)37 Result Initialize(EngineConfig*,
38 Delegate*,
39 const std::vector<std::string>& features,
40 const std::vector<std::string>& properties,
41 const std::vector<std::string>& instance_exts,
42 const std::vector<std::string>& device_exts) override {
43 features_ = features;
44 properties_ = properties;
45 instance_extensions_ = instance_exts;
46 device_extensions_ = device_exts;
47 return {};
48 }
49
GetFeatures() const50 const std::vector<std::string>& GetFeatures() const { return features_; }
GetDeviceExtensions() const51 const std::vector<std::string>& GetDeviceExtensions() const {
52 return device_extensions_;
53 }
GetFenceTimeoutMs()54 uint32_t GetFenceTimeoutMs() { return GetEngineData().fence_timeout_ms; }
55
CreatePipeline(Pipeline *)56 Result CreatePipeline(Pipeline*) override { return {}; }
57
FailClearColorCommand()58 void FailClearColorCommand() { fail_clear_color_command_ = true; }
DidClearColorCommand()59 bool DidClearColorCommand() { return did_clear_color_command_ = true; }
GetLastClearColorCommand()60 ClearColorCommand* GetLastClearColorCommand() { return last_clear_color_; }
DoClearColor(const ClearColorCommand * cmd)61 Result DoClearColor(const ClearColorCommand* cmd) override {
62 did_clear_color_command_ = true;
63
64 if (fail_clear_color_command_)
65 return Result("clear color command failed");
66
67 last_clear_color_ = const_cast<ClearColorCommand*>(cmd);
68 return {};
69 }
70
FailClearStencilCommand()71 void FailClearStencilCommand() { fail_clear_stencil_command_ = true; }
DidClearStencilCommand() const72 bool DidClearStencilCommand() const { return did_clear_stencil_command_; }
DoClearStencil(const ClearStencilCommand *)73 Result DoClearStencil(const ClearStencilCommand*) override {
74 did_clear_stencil_command_ = true;
75
76 if (fail_clear_stencil_command_)
77 return Result("clear stencil command failed");
78
79 return {};
80 }
81
FailClearDepthCommand()82 void FailClearDepthCommand() { fail_clear_depth_command_ = true; }
DidClearDepthCommand() const83 bool DidClearDepthCommand() const { return did_clear_depth_command_; }
DoClearDepth(const ClearDepthCommand *)84 Result DoClearDepth(const ClearDepthCommand*) override {
85 did_clear_depth_command_ = true;
86
87 if (fail_clear_depth_command_)
88 return Result("clear depth command failed");
89
90 return {};
91 }
92
FailClearCommand()93 void FailClearCommand() { fail_clear_command_ = true; }
DidClearCommand() const94 bool DidClearCommand() const { return did_clear_command_; }
DoClear(const ClearCommand *)95 Result DoClear(const ClearCommand*) override {
96 did_clear_command_ = true;
97
98 if (fail_clear_command_)
99 return Result("clear command failed");
100 return {};
101 }
102
FailDrawRectCommand()103 void FailDrawRectCommand() { fail_draw_rect_command_ = true; }
DidDrawRectCommand() const104 bool DidDrawRectCommand() const { return did_draw_rect_command_; }
DoDrawRect(const DrawRectCommand *)105 Result DoDrawRect(const DrawRectCommand*) override {
106 did_draw_rect_command_ = true;
107
108 if (fail_draw_rect_command_)
109 return Result("draw rect command failed");
110 return {};
111 }
112
DoDrawGrid(const DrawGridCommand *)113 Result DoDrawGrid(const DrawGridCommand*) override {
114 did_draw_grid_command_ = true;
115
116 if (fail_draw_grid_command_)
117 return Result("draw grid command failed");
118 return {};
119 }
120
FailDrawArraysCommand()121 void FailDrawArraysCommand() { fail_draw_arrays_command_ = true; }
DidDrawArraysCommand() const122 bool DidDrawArraysCommand() const { return did_draw_arrays_command_; }
DoDrawArrays(const DrawArraysCommand *)123 Result DoDrawArrays(const DrawArraysCommand*) override {
124 did_draw_arrays_command_ = true;
125
126 if (fail_draw_arrays_command_)
127 return Result("draw arrays command failed");
128 return {};
129 }
130
FailComputeCommand()131 void FailComputeCommand() { fail_compute_command_ = true; }
DidComputeCommand() const132 bool DidComputeCommand() const { return did_compute_command_; }
DoCompute(const ComputeCommand *)133 Result DoCompute(const ComputeCommand*) override {
134 did_compute_command_ = true;
135
136 if (fail_compute_command_)
137 return Result("compute command failed");
138 return {};
139 }
140
FailEntryPointCommand()141 void FailEntryPointCommand() { fail_entry_point_command_ = true; }
DidEntryPointCommand() const142 bool DidEntryPointCommand() const { return did_entry_point_command_; }
DoEntryPoint(const EntryPointCommand *)143 Result DoEntryPoint(const EntryPointCommand*) override {
144 did_entry_point_command_ = true;
145
146 if (fail_entry_point_command_)
147 return Result("entrypoint command failed");
148 return {};
149 }
150
FailPatchParameterVerticesCommand()151 void FailPatchParameterVerticesCommand() { fail_patch_command_ = true; }
DidPatchParameterVerticesCommand() const152 bool DidPatchParameterVerticesCommand() const { return did_patch_command_; }
DoPatchParameterVertices(const PatchParameterVerticesCommand *)153 Result DoPatchParameterVertices(
154 const PatchParameterVerticesCommand*) override {
155 did_patch_command_ = true;
156
157 if (fail_patch_command_)
158 return Result("patch command failed");
159 return {};
160 }
161
FailBufferCommand()162 void FailBufferCommand() { fail_buffer_command_ = true; }
DidBufferCommand() const163 bool DidBufferCommand() const { return did_buffer_command_; }
DoBuffer(const BufferCommand *)164 Result DoBuffer(const BufferCommand*) override {
165 did_buffer_command_ = true;
166
167 if (fail_buffer_command_)
168 return Result("buffer command failed");
169 return {};
170 }
171
DoTraceRays(const RayTracingCommand *)172 Result DoTraceRays(const RayTracingCommand*) override {
173 return Result("traceray stub not implemented");
174 }
175
176 private:
177 bool fail_clear_command_ = false;
178 bool fail_clear_color_command_ = false;
179 bool fail_clear_stencil_command_ = false;
180 bool fail_clear_depth_command_ = false;
181 bool fail_draw_rect_command_ = false;
182 bool fail_draw_grid_command_ = false;
183 bool fail_draw_arrays_command_ = false;
184 bool fail_compute_command_ = false;
185 bool fail_entry_point_command_ = false;
186 bool fail_patch_command_ = false;
187 bool fail_buffer_command_ = false;
188
189 bool did_clear_command_ = false;
190 bool did_clear_color_command_ = false;
191 bool did_clear_stencil_command_ = false;
192 bool did_clear_depth_command_ = false;
193 bool did_draw_rect_command_ = false;
194 bool did_draw_grid_command_ = false;
195 bool did_draw_arrays_command_ = false;
196 bool did_compute_command_ = false;
197 bool did_entry_point_command_ = false;
198 bool did_patch_command_ = false;
199 bool did_buffer_command_ = false;
200
201 std::vector<std::string> features_;
202 std::vector<std::string> properties_;
203 std::vector<std::string> instance_extensions_;
204 std::vector<std::string> device_extensions_;
205
206 ClearColorCommand* last_clear_color_ = nullptr;
207 };
208
209 class VkScriptExecutorTest : public testing::Test {
210 public:
211 VkScriptExecutorTest() = default;
212 ~VkScriptExecutorTest() override = default;
213
MakeEngine()214 std::unique_ptr<Engine> MakeEngine() { return MakeUnique<EngineStub>(); }
MakeAndInitializeEngine(const std::vector<std::string> & features,const std::vector<std::string> & properties,const std::vector<std::string> & instance_extensions,const std::vector<std::string> & device_extensions)215 std::unique_ptr<Engine> MakeAndInitializeEngine(
216 const std::vector<std::string>& features,
217 const std::vector<std::string>& properties,
218 const std::vector<std::string>& instance_extensions,
219 const std::vector<std::string>& device_extensions) {
220 std::unique_ptr<Engine> engine = MakeUnique<EngineStub>();
221 engine->Initialize(nullptr, nullptr, features, properties,
222 instance_extensions, device_extensions);
223 return engine;
224 }
ToStub(Engine * engine)225 EngineStub* ToStub(Engine* engine) {
226 return static_cast<EngineStub*>(engine);
227 }
228 };
229
230 } // namespace
231
TEST_F(VkScriptExecutorTest,ExecutesRequiredFeatures)232 TEST_F(VkScriptExecutorTest, ExecutesRequiredFeatures) {
233 std::string input = R"(
234 [require]
235 robustBufferAccess
236 logicOp)";
237
238 Parser parser;
239 parser.SkipValidationForTest();
240 ASSERT_TRUE(parser.Parse(input).IsSuccess());
241
242 auto script = parser.GetScript();
243 auto engine = MakeAndInitializeEngine(script->GetRequiredFeatures(),
244 script->GetRequiredProperties(),
245 script->GetRequiredInstanceExtensions(),
246 script->GetRequiredDeviceExtensions());
247
248 Options options;
249 Executor ex;
250 Result r =
251 ex.Execute(engine.get(), script.get(), ShaderMap(), &options, nullptr);
252 ASSERT_TRUE(r.IsSuccess());
253
254 const auto& features = ToStub(engine.get())->GetFeatures();
255 ASSERT_EQ(2U, features.size());
256 EXPECT_EQ("robustBufferAccess", features[0]);
257 EXPECT_EQ("logicOp", features[1]);
258
259 const auto& extensions = ToStub(engine.get())->GetDeviceExtensions();
260 ASSERT_EQ(static_cast<size_t>(0U), extensions.size());
261 }
262
TEST_F(VkScriptExecutorTest,ExecutesRequiredExtensions)263 TEST_F(VkScriptExecutorTest, ExecutesRequiredExtensions) {
264 std::string input = R"(
265 [require]
266 VK_KHR_storage_buffer_storage_class
267 VK_KHR_variable_pointers)";
268
269 Parser parser;
270 parser.SkipValidationForTest();
271 ASSERT_TRUE(parser.Parse(input).IsSuccess());
272
273 auto script = parser.GetScript();
274 auto engine = MakeAndInitializeEngine(script->GetRequiredFeatures(),
275 script->GetRequiredProperties(),
276 script->GetRequiredInstanceExtensions(),
277 script->GetRequiredDeviceExtensions());
278
279 Options options;
280 Executor ex;
281 Result r =
282 ex.Execute(engine.get(), script.get(), ShaderMap(), &options, nullptr);
283 ASSERT_TRUE(r.IsSuccess());
284
285 const auto& features = ToStub(engine.get())->GetFeatures();
286 ASSERT_EQ(static_cast<size_t>(0U), features.size());
287
288 const auto& extensions = ToStub(engine.get())->GetDeviceExtensions();
289 ASSERT_EQ(2U, extensions.size());
290 EXPECT_EQ("VK_KHR_storage_buffer_storage_class", extensions[0]);
291 EXPECT_EQ("VK_KHR_variable_pointers", extensions[1]);
292 }
293
TEST_F(VkScriptExecutorTest,ExecutesRequiredFrameBuffers)294 TEST_F(VkScriptExecutorTest, ExecutesRequiredFrameBuffers) {
295 std::string input = R"(
296 [require]
297 framebuffer R32G32B32A32_SFLOAT
298 depthstencil D24_UNORM_S8_UINT)";
299
300 Parser parser;
301 parser.SkipValidationForTest();
302 ASSERT_TRUE(parser.Parse(input).IsSuccess());
303
304 auto script = parser.GetScript();
305 auto engine = MakeAndInitializeEngine(script->GetRequiredFeatures(),
306 script->GetRequiredProperties(),
307 script->GetRequiredInstanceExtensions(),
308 script->GetRequiredDeviceExtensions());
309
310 Options options;
311 Executor ex;
312 Result r =
313 ex.Execute(engine.get(), script.get(), ShaderMap(), &options, nullptr);
314 ASSERT_TRUE(r.IsSuccess());
315
316 const auto& features = ToStub(engine.get())->GetFeatures();
317 ASSERT_EQ(static_cast<size_t>(0U), features.size());
318
319 const auto& extensions = ToStub(engine.get())->GetDeviceExtensions();
320 ASSERT_EQ(static_cast<size_t>(0U), extensions.size());
321 }
322
TEST_F(VkScriptExecutorTest,ExecutesRequiredFenceTimeout)323 TEST_F(VkScriptExecutorTest, ExecutesRequiredFenceTimeout) {
324 std::string input = R"(
325 [require]
326 fence_timeout 12345)";
327
328 Parser parser;
329 parser.SkipValidationForTest();
330 ASSERT_TRUE(parser.Parse(input).IsSuccess());
331
332 auto script = parser.GetScript();
333 auto engine = MakeAndInitializeEngine(script->GetRequiredFeatures(),
334 script->GetRequiredProperties(),
335 script->GetRequiredInstanceExtensions(),
336 script->GetRequiredDeviceExtensions());
337
338 Options options;
339 Executor ex;
340 Result r =
341 ex.Execute(engine.get(), script.get(), ShaderMap(), &options, nullptr);
342 ASSERT_TRUE(r.IsSuccess());
343
344 const auto& features = ToStub(engine.get())->GetFeatures();
345 ASSERT_EQ(static_cast<size_t>(0U), features.size());
346
347 const auto& extensions = ToStub(engine.get())->GetDeviceExtensions();
348 ASSERT_EQ(static_cast<size_t>(0U), extensions.size());
349
350 EXPECT_EQ(12345U, ToStub(engine.get())->GetFenceTimeoutMs());
351 }
352
TEST_F(VkScriptExecutorTest,ExecutesRequiredAll)353 TEST_F(VkScriptExecutorTest, ExecutesRequiredAll) {
354 std::string input = R"(
355 [require]
356 robustBufferAccess
357 logicOp
358 VK_KHR_storage_buffer_storage_class
359 VK_KHR_variable_pointers
360 framebuffer R32G32B32A32_SFLOAT
361 depthstencil D24_UNORM_S8_UINT
362 fence_timeout 12345)";
363
364 Parser parser;
365 parser.SkipValidationForTest();
366 ASSERT_TRUE(parser.Parse(input).IsSuccess());
367
368 auto script = parser.GetScript();
369 auto engine = MakeAndInitializeEngine(script->GetRequiredFeatures(),
370 script->GetRequiredProperties(),
371 script->GetRequiredInstanceExtensions(),
372 script->GetRequiredDeviceExtensions());
373
374 Options options;
375 Executor ex;
376 Result r =
377 ex.Execute(engine.get(), script.get(), ShaderMap(), &options, nullptr);
378 ASSERT_TRUE(r.IsSuccess());
379
380 const auto& features = ToStub(engine.get())->GetFeatures();
381 ASSERT_EQ(2U, features.size());
382 EXPECT_EQ("robustBufferAccess", features[0]);
383 EXPECT_EQ("logicOp", features[1]);
384
385 const auto& extensions = ToStub(engine.get())->GetDeviceExtensions();
386 ASSERT_EQ(2U, extensions.size());
387 EXPECT_EQ("VK_KHR_storage_buffer_storage_class", extensions[0]);
388 EXPECT_EQ("VK_KHR_variable_pointers", extensions[1]);
389
390 EXPECT_EQ(12345U, ToStub(engine.get())->GetFenceTimeoutMs());
391 }
392
TEST_F(VkScriptExecutorTest,ClearCommand)393 TEST_F(VkScriptExecutorTest, ClearCommand) {
394 std::string input = R"(
395 [test]
396 clear)";
397
398 Parser parser;
399 parser.SkipValidationForTest();
400 ASSERT_TRUE(parser.Parse(input).IsSuccess());
401
402 auto engine = MakeEngine();
403 auto script = parser.GetScript();
404
405 Options options;
406 Executor ex;
407 Result r =
408 ex.Execute(engine.get(), script.get(), ShaderMap(), &options, nullptr);
409 ASSERT_TRUE(r.IsSuccess());
410 EXPECT_TRUE(ToStub(engine.get())->DidClearCommand());
411 }
412
TEST_F(VkScriptExecutorTest,ClearCommandFailure)413 TEST_F(VkScriptExecutorTest, ClearCommandFailure) {
414 std::string input = R"(
415 [test]
416 clear)";
417
418 Parser parser;
419 parser.SkipValidationForTest();
420 ASSERT_TRUE(parser.Parse(input).IsSuccess());
421
422 auto engine = MakeEngine();
423 ToStub(engine.get())->FailClearCommand();
424 auto script = parser.GetScript();
425
426 Options options;
427 Executor ex;
428 Result r =
429 ex.Execute(engine.get(), script.get(), ShaderMap(), &options, nullptr);
430 ASSERT_FALSE(r.IsSuccess());
431 EXPECT_EQ("clear command failed", r.Error());
432 }
433
TEST_F(VkScriptExecutorTest,ClearColorCommand)434 TEST_F(VkScriptExecutorTest, ClearColorCommand) {
435 std::string input = R"(
436 [test]
437 clear color 244 123 123 13)";
438
439 Parser parser;
440 parser.SkipValidationForTest();
441 ASSERT_TRUE(parser.Parse(input).IsSuccess());
442
443 auto engine = MakeEngine();
444 auto script = parser.GetScript();
445
446 Options options;
447 Executor ex;
448 Result r =
449 ex.Execute(engine.get(), script.get(), ShaderMap(), &options, nullptr);
450 ASSERT_TRUE(r.IsSuccess());
451 ASSERT_TRUE(ToStub(engine.get())->DidClearColorCommand());
452
453 auto* cmd = ToStub(engine.get())->GetLastClearColorCommand();
454 ASSERT_TRUE(cmd != nullptr);
455 ASSERT_TRUE(cmd->IsClearColor());
456
457 EXPECT_EQ(244U, cmd->GetR());
458 EXPECT_EQ(123U, cmd->GetG());
459 EXPECT_EQ(123U, cmd->GetB());
460 EXPECT_EQ(13U, cmd->GetA());
461 }
462
TEST_F(VkScriptExecutorTest,ClearColorCommandFailure)463 TEST_F(VkScriptExecutorTest, ClearColorCommandFailure) {
464 std::string input = R"(
465 [test]
466 clear color 123 123 123 123)";
467
468 Parser parser;
469 parser.SkipValidationForTest();
470 ASSERT_TRUE(parser.Parse(input).IsSuccess());
471
472 auto engine = MakeEngine();
473 ToStub(engine.get())->FailClearColorCommand();
474 auto script = parser.GetScript();
475
476 Options options;
477 Executor ex;
478 Result r =
479 ex.Execute(engine.get(), script.get(), ShaderMap(), &options, nullptr);
480 ASSERT_FALSE(r.IsSuccess());
481 EXPECT_EQ("clear color command failed", r.Error());
482 }
483
TEST_F(VkScriptExecutorTest,ClearDepthCommand)484 TEST_F(VkScriptExecutorTest, ClearDepthCommand) {
485 std::string input = R"(
486 [test]
487 clear depth 24)";
488
489 Parser parser;
490 parser.SkipValidationForTest();
491 ASSERT_TRUE(parser.Parse(input).IsSuccess());
492
493 auto engine = MakeEngine();
494 auto script = parser.GetScript();
495
496 Options options;
497 Executor ex;
498 Result r =
499 ex.Execute(engine.get(), script.get(), ShaderMap(), &options, nullptr);
500 ASSERT_TRUE(r.IsSuccess());
501 ASSERT_TRUE(ToStub(engine.get())->DidClearDepthCommand());
502 }
503
TEST_F(VkScriptExecutorTest,ClearDepthCommandFailure)504 TEST_F(VkScriptExecutorTest, ClearDepthCommandFailure) {
505 std::string input = R"(
506 [test]
507 clear depth 24)";
508
509 Parser parser;
510 parser.SkipValidationForTest();
511 ASSERT_TRUE(parser.Parse(input).IsSuccess());
512
513 auto engine = MakeEngine();
514 ToStub(engine.get())->FailClearDepthCommand();
515 auto script = parser.GetScript();
516
517 Options options;
518 Executor ex;
519 Result r =
520 ex.Execute(engine.get(), script.get(), ShaderMap(), &options, nullptr);
521 ASSERT_FALSE(r.IsSuccess());
522 EXPECT_EQ("clear depth command failed", r.Error());
523 }
524
TEST_F(VkScriptExecutorTest,ClearStencilCommand)525 TEST_F(VkScriptExecutorTest, ClearStencilCommand) {
526 std::string input = R"(
527 [test]
528 clear stencil 24)";
529
530 Parser parser;
531 parser.SkipValidationForTest();
532 ASSERT_TRUE(parser.Parse(input).IsSuccess());
533
534 auto engine = MakeEngine();
535 auto script = parser.GetScript();
536
537 Options options;
538 Executor ex;
539 Result r =
540 ex.Execute(engine.get(), script.get(), ShaderMap(), &options, nullptr);
541 ASSERT_TRUE(r.IsSuccess());
542 ASSERT_TRUE(ToStub(engine.get())->DidClearStencilCommand());
543 }
544
TEST_F(VkScriptExecutorTest,ClearStencilCommandFailure)545 TEST_F(VkScriptExecutorTest, ClearStencilCommandFailure) {
546 std::string input = R"(
547 [test]
548 clear stencil 24)";
549
550 Parser parser;
551 parser.SkipValidationForTest();
552 ASSERT_TRUE(parser.Parse(input).IsSuccess());
553
554 auto engine = MakeEngine();
555 ToStub(engine.get())->FailClearStencilCommand();
556 auto script = parser.GetScript();
557
558 Options options;
559 Executor ex;
560 Result r =
561 ex.Execute(engine.get(), script.get(), ShaderMap(), &options, nullptr);
562 ASSERT_FALSE(r.IsSuccess());
563 EXPECT_EQ("clear stencil command failed", r.Error());
564 }
565
TEST_F(VkScriptExecutorTest,DrawRectCommand)566 TEST_F(VkScriptExecutorTest, DrawRectCommand) {
567 std::string input = R"(
568 [test]
569 draw rect 2 4 10 20)";
570
571 Parser parser;
572 parser.SkipValidationForTest();
573 ASSERT_TRUE(parser.Parse(input).IsSuccess());
574
575 auto engine = MakeEngine();
576 auto script = parser.GetScript();
577
578 Options options;
579 Executor ex;
580 Result r =
581 ex.Execute(engine.get(), script.get(), ShaderMap(), &options, nullptr);
582 ASSERT_TRUE(r.IsSuccess());
583 ASSERT_TRUE(ToStub(engine.get())->DidDrawRectCommand());
584 }
585
TEST_F(VkScriptExecutorTest,DrawRectCommandFailure)586 TEST_F(VkScriptExecutorTest, DrawRectCommandFailure) {
587 std::string input = R"(
588 [test]
589 draw rect 2 4 10 20)";
590
591 Parser parser;
592 parser.SkipValidationForTest();
593 ASSERT_TRUE(parser.Parse(input).IsSuccess());
594
595 auto engine = MakeEngine();
596 ToStub(engine.get())->FailDrawRectCommand();
597 auto script = parser.GetScript();
598
599 Options options;
600 Executor ex;
601 Result r =
602 ex.Execute(engine.get(), script.get(), ShaderMap(), &options, nullptr);
603 ASSERT_FALSE(r.IsSuccess());
604 EXPECT_EQ("draw rect command failed", r.Error());
605 }
606
TEST_F(VkScriptExecutorTest,DrawArraysCommand)607 TEST_F(VkScriptExecutorTest, DrawArraysCommand) {
608 std::string input = R"(
609 [test]
610 draw arrays TRIANGLE_LIST 0 0)";
611
612 Parser parser;
613 parser.SkipValidationForTest();
614 ASSERT_TRUE(parser.Parse(input).IsSuccess());
615
616 auto engine = MakeEngine();
617 auto script = parser.GetScript();
618
619 Options options;
620 Executor ex;
621 Result r =
622 ex.Execute(engine.get(), script.get(), ShaderMap(), &options, nullptr);
623 ASSERT_TRUE(r.IsSuccess());
624 ASSERT_TRUE(ToStub(engine.get())->DidDrawArraysCommand());
625 }
626
TEST_F(VkScriptExecutorTest,DrawArraysCommandFailure)627 TEST_F(VkScriptExecutorTest, DrawArraysCommandFailure) {
628 std::string input = R"(
629 [test]
630 draw arrays TRIANGLE_LIST 0 0)";
631
632 Parser parser;
633 parser.SkipValidationForTest();
634 ASSERT_TRUE(parser.Parse(input).IsSuccess());
635
636 auto engine = MakeEngine();
637 ToStub(engine.get())->FailDrawArraysCommand();
638 auto script = parser.GetScript();
639
640 Options options;
641 Executor ex;
642 Result r =
643 ex.Execute(engine.get(), script.get(), ShaderMap(), &options, nullptr);
644 ASSERT_FALSE(r.IsSuccess());
645 EXPECT_EQ("draw arrays command failed", r.Error());
646 }
647
TEST_F(VkScriptExecutorTest,ComputeCommand)648 TEST_F(VkScriptExecutorTest, ComputeCommand) {
649 std::string input = R"(
650 [test]
651 compute 2 3 4)";
652
653 Parser parser;
654 parser.SkipValidationForTest();
655 ASSERT_TRUE(parser.Parse(input).IsSuccess());
656
657 auto engine = MakeEngine();
658 auto script = parser.GetScript();
659
660 Options options;
661 Executor ex;
662 Result r =
663 ex.Execute(engine.get(), script.get(), ShaderMap(), &options, nullptr);
664 ASSERT_TRUE(r.IsSuccess());
665 ASSERT_TRUE(ToStub(engine.get())->DidComputeCommand());
666 }
667
TEST_F(VkScriptExecutorTest,ComputeCommandFailure)668 TEST_F(VkScriptExecutorTest, ComputeCommandFailure) {
669 std::string input = R"(
670 [test]
671 compute 2 3 4)";
672
673 Parser parser;
674 parser.SkipValidationForTest();
675 ASSERT_TRUE(parser.Parse(input).IsSuccess());
676
677 auto engine = MakeEngine();
678 ToStub(engine.get())->FailComputeCommand();
679 auto script = parser.GetScript();
680
681 Options options;
682 Executor ex;
683 Result r =
684 ex.Execute(engine.get(), script.get(), ShaderMap(), &options, nullptr);
685 ASSERT_FALSE(r.IsSuccess());
686 EXPECT_EQ("compute command failed", r.Error());
687 }
688
TEST_F(VkScriptExecutorTest,EntryPointCommand)689 TEST_F(VkScriptExecutorTest, EntryPointCommand) {
690 std::string input = R"(
691 [test]
692 vertex entrypoint main)";
693
694 Parser parser;
695 parser.SkipValidationForTest();
696 ASSERT_TRUE(parser.Parse(input).IsSuccess());
697
698 auto engine = MakeEngine();
699 auto script = parser.GetScript();
700
701 Options options;
702 Executor ex;
703 Result r =
704 ex.Execute(engine.get(), script.get(), ShaderMap(), &options, nullptr);
705 ASSERT_TRUE(r.IsSuccess());
706 ASSERT_TRUE(ToStub(engine.get())->DidEntryPointCommand());
707 }
708
TEST_F(VkScriptExecutorTest,EntryPointCommandFailure)709 TEST_F(VkScriptExecutorTest, EntryPointCommandFailure) {
710 std::string input = R"(
711 [test]
712 vertex entrypoint main)";
713
714 Parser parser;
715 parser.SkipValidationForTest();
716 ASSERT_TRUE(parser.Parse(input).IsSuccess());
717
718 auto engine = MakeEngine();
719 ToStub(engine.get())->FailEntryPointCommand();
720 auto script = parser.GetScript();
721
722 Options options;
723 Executor ex;
724 Result r =
725 ex.Execute(engine.get(), script.get(), ShaderMap(), &options, nullptr);
726 ASSERT_FALSE(r.IsSuccess());
727 EXPECT_EQ("entrypoint command failed", r.Error());
728 }
729
TEST_F(VkScriptExecutorTest,PatchParameterVerticesCommand)730 TEST_F(VkScriptExecutorTest, PatchParameterVerticesCommand) {
731 std::string input = R"(
732 [test]
733 patch parameter vertices 10)";
734
735 Parser parser;
736 parser.SkipValidationForTest();
737 ASSERT_TRUE(parser.Parse(input).IsSuccess());
738
739 auto engine = MakeEngine();
740 auto script = parser.GetScript();
741
742 Options options;
743 Executor ex;
744 Result r =
745 ex.Execute(engine.get(), script.get(), ShaderMap(), &options, nullptr);
746 ASSERT_TRUE(r.IsSuccess());
747 ASSERT_TRUE(ToStub(engine.get())->DidPatchParameterVerticesCommand());
748 }
749
TEST_F(VkScriptExecutorTest,PatchParameterVerticesCommandFailure)750 TEST_F(VkScriptExecutorTest, PatchParameterVerticesCommandFailure) {
751 std::string input = R"(
752 [test]
753 patch parameter vertices 10)";
754
755 Parser parser;
756 parser.SkipValidationForTest();
757 ASSERT_TRUE(parser.Parse(input).IsSuccess());
758
759 auto engine = MakeEngine();
760 ToStub(engine.get())->FailPatchParameterVerticesCommand();
761 auto script = parser.GetScript();
762
763 Options options;
764 Executor ex;
765 Result r =
766 ex.Execute(engine.get(), script.get(), ShaderMap(), &options, nullptr);
767 ASSERT_FALSE(r.IsSuccess());
768 EXPECT_EQ("patch command failed", r.Error());
769 }
770
TEST_F(VkScriptExecutorTest,DISABLED_ProbeCommand)771 TEST_F(VkScriptExecutorTest, DISABLED_ProbeCommand) {
772 std::string input = R"(
773 [test]
774 probe rect rgba 2 3 40 40 0.2 0.4 0.4 0.3)";
775
776 Parser parser;
777 ASSERT_TRUE(parser.Parse(input).IsSuccess());
778
779 auto engine = MakeEngine();
780 auto script = parser.GetScript();
781
782 Options options;
783 Executor ex;
784 Result r =
785 ex.Execute(engine.get(), script.get(), ShaderMap(), &options, nullptr);
786 ASSERT_TRUE(r.IsSuccess());
787 // ASSERT_TRUE(ToStub(engine.get())->DidProbeCommand());
788 }
789
TEST_F(VkScriptExecutorTest,DISABLED_ProbeCommandFailure)790 TEST_F(VkScriptExecutorTest, DISABLED_ProbeCommandFailure) {
791 std::string input = R"(
792 [test]
793 probe rect rgba 2 3 40 40 0.2 0.4 0.4 0.3)";
794
795 Parser parser;
796 ASSERT_TRUE(parser.Parse(input).IsSuccess());
797
798 auto engine = MakeEngine();
799 // ToStub(engine.get())->FailProbeCommand();
800 auto script = parser.GetScript();
801
802 Options options;
803 Executor ex;
804 Result r =
805 ex.Execute(engine.get(), script.get(), ShaderMap(), &options, nullptr);
806 ASSERT_FALSE(r.IsSuccess());
807 EXPECT_EQ("probe command failed", r.Error());
808 }
809
TEST_F(VkScriptExecutorTest,BufferCommand)810 TEST_F(VkScriptExecutorTest, BufferCommand) {
811 std::string input = R"(
812 [test]
813 ssbo 0 24)";
814
815 Parser parser;
816 parser.SkipValidationForTest();
817 ASSERT_TRUE(parser.Parse(input).IsSuccess());
818
819 auto engine = MakeEngine();
820 auto script = parser.GetScript();
821
822 Options options;
823 Executor ex;
824 Result r =
825 ex.Execute(engine.get(), script.get(), ShaderMap(), &options, nullptr);
826 ASSERT_TRUE(r.IsSuccess());
827 ASSERT_TRUE(ToStub(engine.get())->DidBufferCommand());
828 }
829
TEST_F(VkScriptExecutorTest,BufferCommandFailure)830 TEST_F(VkScriptExecutorTest, BufferCommandFailure) {
831 std::string input = R"(
832 [test]
833 ssbo 0 24)";
834
835 Parser parser;
836 parser.SkipValidationForTest();
837 ASSERT_TRUE(parser.Parse(input).IsSuccess());
838
839 auto engine = MakeEngine();
840 ToStub(engine.get())->FailBufferCommand();
841 auto script = parser.GetScript();
842
843 Options options;
844 Executor ex;
845 Result r =
846 ex.Execute(engine.get(), script.get(), ShaderMap(), &options, nullptr);
847 ASSERT_FALSE(r.IsSuccess());
848 EXPECT_EQ("buffer command failed", r.Error());
849 }
850
TEST_F(VkScriptExecutorTest,DISABLED_ProbeSSBOCommand)851 TEST_F(VkScriptExecutorTest, DISABLED_ProbeSSBOCommand) {
852 std::string input = R"(
853 [test]
854 probe ssbo vec3 0 2 <= 2 3 4)";
855
856 Parser parser;
857 ASSERT_TRUE(parser.Parse(input).IsSuccess());
858
859 auto engine = MakeEngine();
860 auto script = parser.GetScript();
861
862 Options options;
863 Executor ex;
864 Result r =
865 ex.Execute(engine.get(), script.get(), ShaderMap(), &options, nullptr);
866 ASSERT_TRUE(r.IsSuccess());
867 // ASSERT_TRUE(ToStub(engine.get())->DidProbeSSBOCommand());
868 }
869
TEST_F(VkScriptExecutorTest,DISABLED_ProbeSSBOCommandFailure)870 TEST_F(VkScriptExecutorTest, DISABLED_ProbeSSBOCommandFailure) {
871 std::string input = R"(
872 [test]
873 probe ssbo vec3 0 2 <= 2 3 4)";
874
875 Parser parser;
876 ASSERT_TRUE(parser.Parse(input).IsSuccess());
877
878 auto engine = MakeEngine();
879 // ToStub(engine.get())->FailProbeSSBOCommand();
880 auto script = parser.GetScript();
881
882 Options options;
883 Executor ex;
884 Result r =
885 ex.Execute(engine.get(), script.get(), ShaderMap(), &options, nullptr);
886 ASSERT_FALSE(r.IsSuccess());
887 EXPECT_EQ("probe ssbo command failed", r.Error());
888 }
889
890 } // namespace vkscript
891 } // namespace amber
892