1 #ifndef DALI_GRAPHICS_CONTROLLER_H
2 #define DALI_GRAPHICS_CONTROLLER_H
5 * Copyright (c) 2024 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.
22 #include <dali/integration-api/graphics-config.h>
23 #include <dali/public-api/common/vector-wrapper.h>
27 #include "graphics-buffer-create-info.h"
28 #include "graphics-command-buffer-create-info.h"
29 #include "graphics-framebuffer-create-info.h"
30 #include "graphics-memory.h"
31 #include "graphics-pipeline-create-info.h"
32 #include "graphics-program-create-info.h"
33 #include "graphics-reflection.h"
34 #include "graphics-render-pass-create-info.h"
35 #include "graphics-render-target-create-info.h"
36 #include "graphics-sampler-create-info.h"
37 #include "graphics-shader-create-info.h"
38 #include "graphics-sync-object-create-info.h"
39 #include "graphics-texture-create-info.h"
40 #include "graphics-texture-upload-helper.h"
60 * @brief Controller class controls render loop
62 * Controller class is responsible for executing render calls
63 * and controlling pipeline state.
69 * Get graphics configuration for info about the graphics subsystem.
71 virtual Integration::GraphicsConfig& GetGraphicsConfig() = 0;
74 * @brief Destroys controller
76 virtual ~Controller() = default;
79 * @brief Submits array of command buffers
81 * Submits command buffers to the graphics pipeline. Submitted commands
82 * may be executed instantly or postponed.
84 * @param[in] submitInfo Valid SubmitInfo structure
86 virtual void SubmitCommandBuffers(const SubmitInfo& submitInfo) = 0;
89 * @brief Presents render target
90 * @param renderTarget render target to present
92 virtual void PresentRenderTarget(RenderTarget* renderTarget) = 0;
95 * @brief Waits until the GPU is idle
97 virtual void WaitIdle() = 0;
100 * @brief Lifecycle pause event
102 virtual void Pause() = 0;
105 * @brief Lifecycle resume event
107 virtual void Resume() = 0;
110 * @brief Lifecycle shutdown event
112 virtual void Shutdown() = 0;
115 * @brief Lifecycle destroy event
117 virtual void Destroy() = 0;
120 * @brief Executes batch update of textures
122 * This function may perform full or partial update of many textures.
123 * The data source may come from:
124 * - CPU memory (client side)
125 * - GPU memory (another Texture or Buffer)
127 * UpdateTextures() is the only way to update unmappable Texture objects.
128 * It is recommended to batch updates as it may help with optimizing
129 * memory transfers based on dependencies.
132 virtual void UpdateTextures(const std::vector<TextureUpdateInfo>& updateInfoList,
133 const std::vector<TextureUpdateSourceInfo>& sourceList) = 0;
136 * Auto generates mipmaps for the texture
137 * @param[in] texture The texture
139 virtual void GenerateTextureMipmaps(const Texture& texture) = 0;
142 * @brief Enables depth/stencil buffer
144 * @param[in] enableDepth True to enable depth
145 * @param[in] enableStencil True to enable stencil
146 * @return True on success
148 virtual bool EnableDepthStencilBuffer(bool enableDepth, bool enableStencil) = 0;
151 * @brief Runs garbage collector (if supported)
153 * @param[in] numberOfDiscardedRenderers number of discarded renderers
155 virtual void RunGarbageCollector(size_t numberOfDiscardedRenderers) = 0;
158 * @brief Discards unused resources
160 virtual void DiscardUnusedResources() = 0;
163 * @brief Tests whether discard queue is empty
165 * @return True if empty
167 virtual bool IsDiscardQueueEmpty() = 0;
170 * @brief Test if the graphics subsystem has resumed & should force a draw
172 * @return true if the graphics subsystem requires a re-draw
174 virtual bool IsDrawOnResumeRequired() = 0;
177 * @brief Creates new Buffer object
179 * The Buffer object is created with underlying memory. The Buffer
180 * specification is immutable. Based on the BufferCreateInfo::usage,
181 * the memory may be client-side mappable or not.
183 * The old buffer may be passed as BufferCreateInfo::oldbuffer, however,
184 * it's up to the implementation whether the object will be reused or
185 * discarded and replaced by the new one.
187 * @param[in] bufferCreateInfo The valid BufferCreateInfo structure
188 * @param[in] oldBuffer The valid pointer to the old object or nullptr. The object will be reused or destroyed.
189 * @return pointer to the Buffer object
191 virtual UniquePtr<Buffer> CreateBuffer(const BufferCreateInfo& bufferCreateInfo, UniquePtr<Buffer>&& oldBuffer) = 0;
194 * @brief Creates new CommandBuffer object
196 * @param[in] bufferCreateInfo The valid BufferCreateInfo structure
197 * @param[in] oldCommandBuffer The valid pointer to the old object or nullptr. The object will be reused or destroyed.
198 * @return pointer to the CommandBuffer object
200 virtual UniquePtr<CommandBuffer> CreateCommandBuffer(const CommandBufferCreateInfo& commandBufferCreateInfo, UniquePtr<CommandBuffer>&& oldCommandBuffer) = 0;
203 * @brief Creates new RenderPass object
205 * @param[in] renderPassCreateInfo The valid RenderPassCreateInfo structure
206 * @param[in] oldRenderPass The valid pointer to the old object or nullptr. The object will be reused or destroyed.
207 * @return pointer to the RenderPass object
209 virtual UniquePtr<RenderPass> CreateRenderPass(const RenderPassCreateInfo& renderPassCreateInfo, UniquePtr<RenderPass>&& oldRenderPass) = 0;
212 * @brief Creates new Texture object
214 * @param[in] textureCreateInfo The valid TextureCreateInfo structure
215 * @param[in] oldTexture The valid pointer to the old object or nullptr. The object will be reused or destroyed.
216 * @return pointer to the TextureCreateInfo object
218 virtual UniquePtr<Texture> CreateTexture(const TextureCreateInfo& textureCreateInfo, UniquePtr<Texture>&& oldTexture) = 0;
221 * @brief Creates new Framebuffer object
223 * @param[in] framebufferCreateInfo The valid FramebufferCreateInfo structure
224 * @param[in] oldFramebuffer The valid pointer to the old object or nullptr. The object will be reused or destroyed.
225 * @return pointer to the Framebuffer object
227 virtual UniquePtr<Framebuffer> CreateFramebuffer(const FramebufferCreateInfo& framebufferCreateInfo, UniquePtr<Framebuffer>&& oldFramebuffer) = 0;
230 * @brief Creates new Pipeline object
232 * @param[in] pipelineCreateInfo The valid PipelineCreateInfo structure
233 * @param[in] oldPipeline The valid pointer to the old object or nullptr. The object will be reused or destroyed.
234 * @return pointer to the Pipeline object
236 virtual UniquePtr<Pipeline> CreatePipeline(const PipelineCreateInfo& pipelineCreateInfo, UniquePtr<Pipeline>&& oldPipeline) = 0;
239 * @brief Creates new Program object
241 * @param[in] ProgramCreateInfo The valid ProgramCreateInfo structure
242 * @param[in] oldProgram The valid pointer to the old object or nullptr. The object will be reused or destroyed.
243 * @return pointer to the Program object
245 virtual UniquePtr<Program> CreateProgram(const ProgramCreateInfo& programCreateInfo, UniquePtr<Program>&& oldProgram) = 0;
248 * @brief Creates new Shader object
250 * @param[in] shaderCreateInfo The valid ShaderCreateInfo structure
251 * @param[in] oldShader The valid pointer to the old object or nullptr. The object will be reused or destroyed.
252 * @return pointer to the Shader object
254 virtual UniquePtr<Shader> CreateShader(const ShaderCreateInfo& shaderCreateInfo, UniquePtr<Shader>&& oldShader) = 0;
257 * @brief Creates new Sampler object
259 * @param[in] samplerCreateInfo The valid SamplerCreateInfo structure
260 * @param[in] oldSampler The valid pointer to the old object or nullptr. The object will be reused or destroyed.
261 * @return pointer to the Sampler object
263 virtual UniquePtr<Sampler> CreateSampler(const SamplerCreateInfo& samplerCreateInfo, UniquePtr<Sampler>&& oldSampler) = 0;
266 * @brief Creates new RenderTarget object
268 * @param[in] renderTargetCreateInfo The valid RenderTargetCreateInfo structure
269 * @param[in] oldRenderTarget The valid pointer to the old object or nullptr. The object will be reused or destroyed.
270 * @return pointer to the RenderTarget object
272 virtual UniquePtr<RenderTarget> CreateRenderTarget(const RenderTargetCreateInfo& renderTargetCreateInfo, UniquePtr<RenderTarget>&& oldRenderTarget) = 0;
275 * Create a synchronisation object.
277 * @return A pointer to an opaque sync object
278 * @param[in] syncObjectCreateInfo The valid SyncObjectCreateInfo structure
279 * @param[in] oldSyncObject The valid pointer to the old object or nullptr. The object will be reused or destroyed.
281 virtual UniquePtr<SyncObject> CreateSyncObject(const SyncObjectCreateInfo& syncObjectCreateInfo,
282 UniquePtr<SyncObject>&& oldSyncObject) = 0;
285 * @brief Maps memory associated with Buffer object
287 * @param[in] mapInfo Filled details of mapped resource
288 * @return Returns pointer to Memory object or nullptr on error
290 virtual UniquePtr<Memory> MapBufferRange(const MapBufferInfo& mapInfo) = 0;
293 * @brief Maps memory associated with the texture.
295 * Only Texture objects that are backed with linear memory (staging memory) can be mapped.
297 * 1) GLES implementation may create PBO object as staging memory and couple it
298 * with the texture. Texture can be mapped and the memory can be read/write on demand.
300 * 2) Vulkan implementation may allocate DeviceMemory and use linear layout.
302 * @param[in] mapInfo Filled details of mapped resource
304 * @return Valid Memory object or nullptr on error
306 virtual UniquePtr<Memory> MapTextureRange(const MapTextureInfo& mapInfo) = 0;
309 * @brief Unmaps memory and discards Memory object
311 * This function automatically removes lock if Memory has been
314 * @param[in] memory Valid and previously mapped Memory object
316 virtual void UnmapMemory(UniquePtr<Memory> memory) = 0;
319 * @brief Returns memory requirements of the Texture object.
321 * Call this function whenever it's necessary to know how much memory
322 * is needed to store all the texture data and what memory alignment
323 * the data should follow.
325 * @return Returns memory requirements of Texture
327 virtual MemoryRequirements GetTextureMemoryRequirements(Texture& texture) const = 0;
330 * @brief Returns memory requirements of the Buffer object.
332 * Call this function whenever it's necessary to know how much memory
333 * is needed to store all the buffer data and what memory alignment
334 * the data should follow.
336 * @return Returns memory requirements of Buffer
338 virtual MemoryRequirements GetBufferMemoryRequirements(Buffer& buffer) const = 0;
341 * @brief Returns specification of the Texture object
343 * Function obtains specification of the Texture object. It may retrieve
344 * implementation dependent details like ie. whether the texture is
345 * emulated (for example, RGB emulated on RGBA), compressed etc.
347 * @return Returns the TextureProperties object
349 virtual TextureProperties GetTextureProperties(const Texture& texture) = 0;
352 * @brief Returns the reflection of the given program
354 * @param[in] program The program
355 * @return The reflection of the program
357 virtual const Reflection& GetProgramReflection(const Program& program) = 0;
360 * @brief Tests whether two Pipelines are the same.
362 * On the higher level, this function may help wit creating pipeline cache.
364 * @return true if pipeline objects match
366 virtual bool PipelineEquals(const Pipeline& pipeline0, const Pipeline& pipeline1) const = 0;
369 * @brief Retrieves program parameters
371 * This function can be used to retrieve data from internal implementation
373 * @param[in] program Valid program object
374 * @param[in] parameterId Integer parameter id
375 * @param[out] outData Pointer to output memory
376 * @return True on success
378 virtual bool GetProgramParameter(Graphics::Program& program, uint32_t parameterId, void* outData) = 0;
380 public: // ResourceId relative API.
382 * @brief Create Graphics::Texture as resourceId.
383 * The ownership of Graphics::Texture will be hold on this controller.
384 * @note If some Graphics::Texture already created before, assert.
385 * @post DiscardTextureFromResourceId() or ReleaseTextureFromResourceId() should be called when we don't use resourceId texture anymore.
387 * @param[in] resourceId The unique id of resouces.
388 * @return Pointer of Graphics::Texture, or nullptr if we fail to create.
390 virtual Graphics::Texture* CreateTextureByResourceId(uint32_t resourceId, const Graphics::TextureCreateInfo& createInfo) = 0;
393 * @brief Discard Graphics::Texture as resourceId.
395 * @param[in] resourceId The unique id of resouces.
397 virtual void DiscardTextureFromResourceId(uint32_t resourceId) = 0;
400 * @brief Get the Graphics::Texture as resourceId.
402 * @param[in] resourceId The unique id of resouces.
403 * @return Pointer of Graphics::Texture, or nullptr if there is no valid objects.
405 virtual Graphics::Texture* GetTextureFromResourceId(uint32_t resourceId) = 0;
408 * @brief Get the ownership of Graphics::Texture as resourceId.
410 * @param[in] resourceId The unique id of resouces.
411 * @return Pointer of Graphics::Texture.
413 virtual UniquePtr<Graphics::Texture> ReleaseTextureFromResourceId(uint32_t resourceId) = 0;
419 Controller() = default;
421 } // namespace Graphics