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