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 #ifndef SRC_ENGINE_H_ 16 #define SRC_ENGINE_H_ 17 18 #include <memory> 19 #include <string> 20 #include <utility> 21 #include <vector> 22 23 #include "amber/amber.h" 24 #include "amber/result.h" 25 #include "src/buffer.h" 26 #include "src/command.h" 27 #include "src/format.h" 28 #include "src/pipeline.h" 29 30 namespace amber { 31 32 class VirtualFileStore; 33 34 /// EngineData stores information used during engine execution. 35 struct EngineData { 36 /// The timeout to use for fences, in milliseconds. 37 uint32_t fence_timeout_ms = 10000; 38 }; 39 40 /// Abstract class which describes a backing engine for Amber. 41 /// 42 /// The engine class has a defined lifecycle. 43 /// 1. The engine is created through Engine::Create. 44 /// 2. Engine::Initialize is called to provide the engine with the configured 45 /// graphics device. 46 /// 3. Engine::CreatePipeline is called for each pipeline. The pipelines are 47 /// fully specified at this point and include: 48 /// * All compiled shader binaries 49 /// * Vertex, Index, Storage, Uniform, Push Constant buffers 50 /// * Colour attachment, and depth/stencil attachment buffers. 51 /// * Extra engine data. 52 /// The buffers all may have default values to be loaded into the device. 53 /// 4. Engine::Do* is called for each command. 54 /// Note, it is assumed that the amber::Buffers are updated at the end of 55 /// each Do* command and can be used immediately for comparisons. 56 /// 5. Engine destructor is called. 57 class Engine { 58 public: 59 /// Creates a new engine of the requested |type|. 60 static std::unique_ptr<Engine> Create(EngineType type); 61 62 virtual ~Engine(); 63 64 /// Initialize the engine with the provided config. The config is _not_ owned 65 /// by the engine and will not be destroyed. The |features| and |extensions| 66 /// are for validation purposes only. If possible the engine should verify 67 /// that the constraints in |features| and |extensions| are valid and fail 68 /// otherwise. 69 virtual Result Initialize( 70 EngineConfig* config, 71 Delegate* delegate, 72 const std::vector<std::string>& features, 73 const std::vector<std::string>& instance_extensions, 74 const std::vector<std::string>& device_extensions) = 0; 75 76 /// Create graphics pipeline. 77 virtual Result CreatePipeline(Pipeline* pipeline) = 0; 78 79 /// Execute the clear color command 80 virtual Result DoClearColor(const ClearColorCommand* cmd) = 0; 81 82 /// Execute the clear stencil command 83 virtual Result DoClearStencil(const ClearStencilCommand* cmd) = 0; 84 85 /// Execute the clear depth command 86 virtual Result DoClearDepth(const ClearDepthCommand* cmd) = 0; 87 88 /// Execute the clear command 89 virtual Result DoClear(const ClearCommand* cmd) = 0; 90 91 /// Execute the draw rect command 92 virtual Result DoDrawRect(const DrawRectCommand* cmd) = 0; 93 94 /// Execute the draw grid command 95 virtual Result DoDrawGrid(const DrawGridCommand* cmd) = 0; 96 97 /// Execute the draw arrays command 98 virtual Result DoDrawArrays(const DrawArraysCommand* cmd) = 0; 99 100 /// Execute the compute command 101 virtual Result DoCompute(const ComputeCommand* cmd) = 0; 102 103 /// Execute the entry point command 104 virtual Result DoEntryPoint(const EntryPointCommand* cmd) = 0; 105 106 /// Execute the patch command 107 virtual Result DoPatchParameterVertices( 108 const PatchParameterVerticesCommand* cmd) = 0; 109 110 /// Execute the buffer command. 111 /// This declares an Amber buffer to be bound to a descriptor. 112 /// This covers both Vulkan buffers and images. 113 virtual Result DoBuffer(const BufferCommand* cmd) = 0; 114 115 /// Sets the engine data to use. SetEngineData(const EngineData & data)116 void SetEngineData(const EngineData& data) { engine_data_ = data; } 117 118 protected: 119 Engine(); 120 121 /// Retrieves the engine data. GetEngineData()122 const EngineData& GetEngineData() const { return engine_data_; } 123 124 private: 125 EngineData engine_data_; 126 }; 127 128 } // namespace amber 129 130 #endif // SRC_ENGINE_H_ 131