• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 The Amber Authors.
2 // Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef SRC_ENGINE_H_
17 #define SRC_ENGINE_H_
18 
19 #include <memory>
20 #include <string>
21 #include <utility>
22 #include <vector>
23 
24 #include "amber/amber.h"
25 #include "amber/result.h"
26 #include "src/buffer.h"
27 #include "src/command.h"
28 #include "src/format.h"
29 #include "src/pipeline.h"
30 
31 namespace amber {
32 
33 class VirtualFileStore;
34 
35 /// EngineData stores information used during engine execution.
36 struct EngineData {
37   /// The timeout to use for fences, in milliseconds.
38   uint32_t fence_timeout_ms = 10000;
39   bool pipeline_runtime_layer_enabled = false;
40 };
41 
42 /// Abstract class which describes a backing engine for Amber.
43 ///
44 /// The engine class has a defined lifecycle.
45 ///  1. The engine is created through Engine::Create.
46 ///  2. Engine::Initialize is called to provide the engine with the configured
47 ///     graphics device.
48 ///  3. Engine::CreatePipeline is called for each pipeline. The pipelines are
49 ///     fully specified at this point and include:
50 ///     * All compiled shader binaries
51 ///     * Vertex, Index, Storage, Uniform, Push Constant buffers
52 ///     * Colour attachment, and depth/stencil attachment buffers.
53 ///     * Extra engine data.
54 ///     The buffers all may have default values to be loaded into the device.
55 ///  4. Engine::Do* is called for each command.
56 ///     Note, it is assumed that the amber::Buffers are updated at the end of
57 ///     each Do* command and can be used immediately for comparisons.
58 ///  5. Engine destructor is called.
59 class Engine {
60  public:
61   /// Creates a new engine of the requested |type|.
62   static std::unique_ptr<Engine> Create(EngineType type);
63 
64   virtual ~Engine();
65 
66   /// Initialize the engine with the provided config. The config is _not_ owned
67   /// by the engine and will not be destroyed. The |features| and |extensions|
68   /// are for validation purposes only. If possible the engine should verify
69   /// that the constraints in |features| and |extensions| are valid and fail
70   /// otherwise.
71   virtual Result Initialize(
72       EngineConfig* config,
73       Delegate* delegate,
74       const std::vector<std::string>& features,
75       const std::vector<std::string>& properties,
76       const std::vector<std::string>& instance_extensions,
77       const std::vector<std::string>& device_extensions) = 0;
78 
79   /// Create graphics pipeline.
80   virtual Result CreatePipeline(Pipeline* pipeline) = 0;
81 
82   /// Execute the clear color command
83   virtual Result DoClearColor(const ClearColorCommand* cmd) = 0;
84 
85   /// Execute the clear stencil command
86   virtual Result DoClearStencil(const ClearStencilCommand* cmd) = 0;
87 
88   /// Execute the clear depth command
89   virtual Result DoClearDepth(const ClearDepthCommand* cmd) = 0;
90 
91   /// Execute the clear command
92   virtual Result DoClear(const ClearCommand* cmd) = 0;
93 
94   /// Execute the draw rect command
95   virtual Result DoDrawRect(const DrawRectCommand* cmd) = 0;
96 
97   /// Execute the draw grid command
98   virtual Result DoDrawGrid(const DrawGridCommand* cmd) = 0;
99 
100   /// Execute the draw arrays command
101   virtual Result DoDrawArrays(const DrawArraysCommand* cmd) = 0;
102 
103   /// Execute the compute command
104   virtual Result DoCompute(const ComputeCommand* cmd) = 0;
105 
106   /// Execute the trace rays command
107   virtual Result DoTraceRays(const RayTracingCommand* cmd) = 0;
108 
109   /// Execute the entry point command
110   virtual Result DoEntryPoint(const EntryPointCommand* cmd) = 0;
111 
112   /// Execute the patch command
113   virtual Result DoPatchParameterVertices(
114       const PatchParameterVerticesCommand* cmd) = 0;
115 
116   /// Execute the buffer command.
117   /// This declares an Amber buffer to be bound to a descriptor.
118   /// This covers both Vulkan buffers and images.
119   virtual Result DoBuffer(const BufferCommand* cmd) = 0;
120 
121   /// Sets the engine data to use.
SetEngineData(const EngineData & data)122   void SetEngineData(const EngineData& data) { engine_data_ = data; }
123 
124  protected:
125   Engine();
126 
127   /// Retrieves the engine data.
GetEngineData()128   const EngineData& GetEngineData() const { return engine_data_; }
129 
130  private:
131   EngineData engine_data_;
132 };
133 
134 }  // namespace amber
135 
136 #endif  // SRC_ENGINE_H_
137