1 #ifndef DALI_GRAPHICS_CONTROLLER_H
2 #define DALI_GRAPHICS_CONTROLLER_H
5 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
26 #include "graphics-buffer-create-info.h"
27 #include "graphics-command-buffer-create-info.h"
28 #include "graphics-framebuffer-create-info.h"
29 #include "graphics-memory.h"
30 #include "graphics-pipeline-create-info.h"
31 #include "graphics-program-create-info.h"
32 #include "graphics-reflection.h"
33 #include "graphics-render-pass-create-info.h"
34 #include "graphics-render-target-create-info.h"
35 #include "graphics-sampler-create-info.h"
36 #include "graphics-shader-create-info.h"
37 #include "graphics-texture-create-info.h"
44 class GlSyncAbstraction;
45 class GlContextHelperAbstraction;
46 } // namespace Integration
63 * @brief Controller class controls render loop
65 * Controller class is responsible for executing render calls
66 * and controlling pipeline state.
71 // Temporary until graphics api is complete
72 virtual Integration::GlAbstraction& GetGlAbstraction() = 0;
73 virtual Integration::GlSyncAbstraction& GetGlSyncAbstraction() = 0;
74 virtual Integration::GlContextHelperAbstraction& GetGlContextHelperAbstraction() = 0;
77 * @brief Destroys controller
79 virtual ~Controller() = default;
82 * @brief Submits array of command buffers
84 * Submits command buffers to the graphics pipeline. Submitted commands
85 * may be executed instantly or postponed.
87 * @param[in] submitInfo Valid SubmitInfo structure
89 virtual void SubmitCommandBuffers(const SubmitInfo& submitInfo) = 0;
92 * @brief Presents render target
93 * @param renderTarget render target to present
95 virtual void PresentRenderTarget(RenderTarget* renderTarget) = 0;
98 * @brief Waits until the GPU is idle
100 virtual void WaitIdle() = 0;
103 * @brief Lifecycle pause event
105 virtual void Pause() = 0;
108 * @brief Lifecycle resume event
110 virtual void Resume() = 0;
113 * @brief Lifecycle shutdown event
115 virtual void Shutdown() = 0;
118 * @brief Lifecycle destroy event
120 virtual void Destroy() = 0;
123 * @brief Executes batch update of textures
125 * This function may perform full or partial update of many textures.
126 * The data source may come from:
127 * - CPU memory (client side)
128 * - GPU memory (another Texture or Buffer)
130 * UpdateTextures() is the only way to update unmappable Texture objects.
131 * It is recommended to batch updates as it may help with optimizing
132 * memory transfers based on dependencies.
135 virtual void UpdateTextures(const std::vector<TextureUpdateInfo>& updateInfoList,
136 const std::vector<TextureUpdateSourceInfo>& sourceList) = 0;
139 * @brief Enables depth/stencil buffer
141 * @param[in] enableDepth True to enable depth
142 * @param[in] enableStencil True to enable stencil
143 * @return True on success
145 virtual bool EnableDepthStencilBuffer(bool enableDepth, bool enableStencil) = 0;
148 * @brief Runs garbage collector (if supported)
150 * @param[in] numberOfDiscardedRenderers number of discarded renderers
152 virtual void RunGarbageCollector(size_t numberOfDiscardedRenderers) = 0;
155 * @brief Discards unused resources
157 virtual void DiscardUnusedResources() = 0;
160 * @brief Tests whether discard queue is empty
162 * @return True if empty
164 virtual bool IsDiscardQueueEmpty() = 0;
167 * @brief Test if the graphics subsystem has resumed & should force a draw
169 * @return true if the graphics subsystem requires a re-draw
171 virtual bool IsDrawOnResumeRequired() = 0;
174 * @brief Creates new Buffer object
176 * The Buffer object is created with underlying memory. The Buffer
177 * specification is immutable. Based on the BufferCreateInfo::usage,
178 * the memory may be client-side mappable or not.
180 * The old buffer may be passed as BufferCreateInfo::oldbuffer, however,
181 * it's up to the implementation whether the object will be reused or
182 * discarded and replaced by the new one.
184 * @param[in] bufferCreateInfo The valid BufferCreateInfo structure
185 * @param[in] oldBuffer The valid pointer to the old object or nullptr. The object will be reused or destroyed.
186 * @return pointer to the Buffer object
188 virtual UniquePtr<Buffer> CreateBuffer(const BufferCreateInfo& bufferCreateInfo, UniquePtr<Buffer>&& oldBuffer) = 0;
191 * @brief Creates new CommandBuffer object
193 * @param[in] bufferCreateInfo The valid BufferCreateInfo structure
194 * @param[in] oldCommandBuffer The valid pointer to the old object or nullptr. The object will be reused or destroyed.
195 * @return pointer to the CommandBuffer object
197 virtual UniquePtr<CommandBuffer> CreateCommandBuffer(const CommandBufferCreateInfo& commandBufferCreateInfo, UniquePtr<CommandBuffer>&& oldCommandBuffer) = 0;
200 * @brief Creates new RenderPass object
202 * @param[in] renderPassCreateInfo The valid RenderPassCreateInfo structure
203 * @param[in] oldRenderPass The valid pointer to the old object or nullptr. The object will be reused or destroyed.
204 * @return pointer to the RenderPass object
206 virtual UniquePtr<RenderPass> CreateRenderPass(const RenderPassCreateInfo& renderPassCreateInfo, UniquePtr<RenderPass>&& oldRenderPass) = 0;
209 * @brief Creates new Texture object
211 * @param[in] textureCreateInfo The valid TextureCreateInfo structure
212 * @param[in] oldTexture The valid pointer to the old object or nullptr. The object will be reused or destroyed.
213 * @return pointer to the TextureCreateInfo object
215 virtual UniquePtr<Texture> CreateTexture(const TextureCreateInfo& textureCreateInfo, UniquePtr<Texture>&& oldTexture) = 0;
218 * @brief Creates new Framebuffer object
220 * @param[in] framebufferCreateInfo The valid FramebufferCreateInfo structure
221 * @param[in] oldFramebuffer The valid pointer to the old object or nullptr. The object will be reused or destroyed.
222 * @return pointer to the Framebuffer object
224 virtual UniquePtr<Framebuffer> CreateFramebuffer(const FramebufferCreateInfo& framebufferCreateInfo, UniquePtr<Framebuffer>&& oldFramebuffer) = 0;
227 * @brief Creates new Pipeline object
229 * @param[in] pipelineCreateInfo The valid PipelineCreateInfo structure
230 * @param[in] oldPipeline The valid pointer to the old object or nullptr. The object will be reused or destroyed.
231 * @return pointer to the Pipeline object
233 virtual UniquePtr<Pipeline> CreatePipeline(const PipelineCreateInfo& pipelineCreateInfo, UniquePtr<Pipeline>&& oldPipeline) = 0;
236 * @brief Creates new Program object
238 * @param[in] ProgramCreateInfo The valid ProgramCreateInfo structure
239 * @param[in] oldProgram The valid pointer to the old object or nullptr. The object will be reused or destroyed.
240 * @return pointer to the Program object
242 virtual UniquePtr<Program> CreateProgram(const ProgramCreateInfo& programCreateInfo, UniquePtr<Program>&& oldProgram) = 0;
245 * @brief Creates new Shader object
247 * @param[in] shaderCreateInfo The valid ShaderCreateInfo structure
248 * @param[in] oldShader The valid pointer to the old object or nullptr. The object will be reused or destroyed.
249 * @return pointer to the Shader object
251 virtual UniquePtr<Shader> CreateShader(const ShaderCreateInfo& shaderCreateInfo, UniquePtr<Shader>&& oldShader) = 0;
254 * @brief Creates new Sampler object
256 * @param[in] samplerCreateInfo The valid SamplerCreateInfo structure
257 * @param[in] oldSampler The valid pointer to the old object or nullptr. The object will be reused or destroyed.
258 * @return pointer to the Sampler object
260 virtual UniquePtr<Sampler> CreateSampler(const SamplerCreateInfo& samplerCreateInfo, UniquePtr<Sampler>&& oldSampler) = 0;
263 * @brief Creates new RenderTarget object
265 * @param[in] renderTargetCreateInfo The valid RenderTargetCreateInfo structure
266 * @param[in] oldRenderTarget The valid pointer to the old object or nullptr. The object will be reused or destroyed.
267 * @return pointer to the RenderTarget object
269 virtual UniquePtr<RenderTarget> CreateRenderTarget(const RenderTargetCreateInfo& renderTargetCreateInfo, UniquePtr<RenderTarget>&& oldRenderTarget) = 0;
272 * @brief Maps memory associated with Buffer object
274 * @param[in] mapInfo Filled details of mapped resource
275 * @return Returns pointer to Memory object or nullptr on error
277 virtual UniquePtr<Memory> MapBufferRange(const MapBufferInfo& mapInfo) = 0;
280 * @brief Maps memory associated with the texture.
282 * Only Texture objects that are backed with linear memory (staging memory) can be mapped.
284 * 1) GLES implementation may create PBO object as staging memory and couple it
285 * with the texture. Texture can be mapped and the memory can be read/write on demand.
287 * 2) Vulkan implementation may allocate DeviceMemory and use linear layout.
289 * @param[in] mapInfo Filled details of mapped resource
291 * @return Valid Memory object or nullptr on error
293 virtual UniquePtr<Memory> MapTextureRange(const MapTextureInfo& mapInfo) = 0;
296 * @brief Unmaps memory and discards Memory object
298 * This function automatically removes lock if Memory has been
301 * @param[in] memory Valid and previously mapped Memory object
303 virtual void UnmapMemory(UniquePtr<Memory> memory) = 0;
306 * @brief Returns memory requirements of the Texture object.
308 * Call this function whenever it's necessary to know how much memory
309 * is needed to store all the texture data and what memory alignment
310 * the data should follow.
312 * @return Returns memory requirements of Texture
314 virtual MemoryRequirements GetTextureMemoryRequirements(Texture& texture) const = 0;
317 * @brief Returns memory requirements of the Buffer object.
319 * Call this function whenever it's necessary to know how much memory
320 * is needed to store all the buffer data and what memory alignment
321 * the data should follow.
323 * @return Returns memory requirements of Buffer
325 virtual MemoryRequirements GetBufferMemoryRequirements(Buffer& buffer) const = 0;
328 * @brief Returns specification of the Texture object
330 * Function obtains specification of the Texture object. It may retrieve
331 * implementation dependent details like ie. whether the texture is
332 * emulated (for example, RGB emulated on RGBA), compressed etc.
334 * @return Returns the TextureProperties object
336 virtual const TextureProperties& GetTextureProperties(const Texture& texture) = 0;
339 * @brief Returns the reflection of the given program
341 * @param[in] program The program
342 * @return The reflection of the program
344 virtual const Reflection& GetProgramReflection(const Program& program) = 0;
347 * @brief Tests whether two Pipelines are the same.
349 * On the higher level, this function may help wit creating pipeline cache.
351 * @return true if pipeline objects match
353 virtual bool PipelineEquals(const Pipeline& pipeline0, const Pipeline& pipeline1) const = 0;
356 * @brief Retrieves program parameters
358 * This function can be used to retrieve data from internal implementation
360 * @param[in] program Valid program object
361 * @param[in] parameterId Integer parameter id
362 * @param[out] outData Pointer to output memory
363 * @return True on success
365 virtual bool GetProgramParameter(Graphics::Program& program, uint32_t parameterId, void* outData ) = 0;
371 Controller() = default;
373 } // namespace Graphics