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"
47 } // namespace Integration
65 * @brief Controller class controls render loop
67 * Controller class is responsible for executing render calls
68 * and controlling pipeline state.
74 * Get graphics configuration for info about the graphics subsystem.
76 virtual Integration::GraphicsConfig& GetGraphicsConfig() = 0;
79 * @brief Destroys controller
81 virtual ~Controller() = default;
84 * @brief Submits array of command buffers
86 * Submits command buffers to the graphics pipeline. Submitted commands
87 * may be executed instantly or postponed.
89 * @param[in] submitInfo Valid SubmitInfo structure
91 virtual void SubmitCommandBuffers(const SubmitInfo& submitInfo) = 0;
94 * @brief Presents render target
95 * @param renderTarget render target to present
97 virtual void PresentRenderTarget(RenderTarget* renderTarget) = 0;
100 * @brief Waits until the GPU is idle
102 virtual void WaitIdle() = 0;
105 * @brief Lifecycle pause event
107 virtual void Pause() = 0;
110 * @brief Lifecycle resume event
112 virtual void Resume() = 0;
115 * @brief Lifecycle shutdown event
117 virtual void Shutdown() = 0;
120 * @brief Lifecycle destroy event
122 virtual void Destroy() = 0;
125 * @brief Executes batch update of textures
127 * This function may perform full or partial update of many textures.
128 * The data source may come from:
129 * - CPU memory (client side)
130 * - GPU memory (another Texture or Buffer)
132 * UpdateTextures() is the only way to update unmappable Texture objects.
133 * It is recommended to batch updates as it may help with optimizing
134 * memory transfers based on dependencies.
137 virtual void UpdateTextures(const std::vector<TextureUpdateInfo>& updateInfoList,
138 const std::vector<TextureUpdateSourceInfo>& sourceList) = 0;
141 * Auto generates mipmaps for the texture
142 * @param[in] texture The texture
144 virtual void GenerateTextureMipmaps(const Texture& texture) = 0;
147 * @brief Enables depth/stencil buffer
149 * @param[in] enableDepth True to enable depth
150 * @param[in] enableStencil True to enable stencil
151 * @return True on success
153 virtual bool EnableDepthStencilBuffer(bool enableDepth, bool enableStencil) = 0;
156 * @brief Runs garbage collector (if supported)
158 * @param[in] numberOfDiscardedRenderers number of discarded renderers
160 virtual void RunGarbageCollector(size_t numberOfDiscardedRenderers) = 0;
163 * @brief Discards unused resources
165 virtual void DiscardUnusedResources() = 0;
168 * @brief Tests whether discard queue is empty
170 * @return True if empty
172 virtual bool IsDiscardQueueEmpty() = 0;
175 * @brief Test if the graphics subsystem has resumed & should force a draw
177 * @return true if the graphics subsystem requires a re-draw
179 virtual bool IsDrawOnResumeRequired() = 0;
182 * @brief Creates new Buffer object
184 * The Buffer object is created with underlying memory. The Buffer
185 * specification is immutable. Based on the BufferCreateInfo::usage,
186 * the memory may be client-side mappable or not.
188 * The old buffer may be passed as BufferCreateInfo::oldbuffer, however,
189 * it's up to the implementation whether the object will be reused or
190 * discarded and replaced by the new one.
192 * @param[in] bufferCreateInfo The valid BufferCreateInfo structure
193 * @param[in] oldBuffer The valid pointer to the old object or nullptr. The object will be reused or destroyed.
194 * @return pointer to the Buffer object
196 virtual UniquePtr<Buffer> CreateBuffer(const BufferCreateInfo& bufferCreateInfo, UniquePtr<Buffer>&& oldBuffer) = 0;
199 * @brief Creates new CommandBuffer object
201 * @param[in] bufferCreateInfo The valid BufferCreateInfo structure
202 * @param[in] oldCommandBuffer The valid pointer to the old object or nullptr. The object will be reused or destroyed.
203 * @return pointer to the CommandBuffer object
205 virtual UniquePtr<CommandBuffer> CreateCommandBuffer(const CommandBufferCreateInfo& commandBufferCreateInfo, UniquePtr<CommandBuffer>&& oldCommandBuffer) = 0;
208 * @brief Creates new RenderPass object
210 * @param[in] renderPassCreateInfo The valid RenderPassCreateInfo structure
211 * @param[in] oldRenderPass The valid pointer to the old object or nullptr. The object will be reused or destroyed.
212 * @return pointer to the RenderPass object
214 virtual UniquePtr<RenderPass> CreateRenderPass(const RenderPassCreateInfo& renderPassCreateInfo, UniquePtr<RenderPass>&& oldRenderPass) = 0;
217 * @brief Creates new Texture object
219 * @param[in] textureCreateInfo The valid TextureCreateInfo structure
220 * @param[in] oldTexture The valid pointer to the old object or nullptr. The object will be reused or destroyed.
221 * @return pointer to the TextureCreateInfo object
223 virtual UniquePtr<Texture> CreateTexture(const TextureCreateInfo& textureCreateInfo, UniquePtr<Texture>&& oldTexture) = 0;
226 * @brief Creates new Framebuffer object
228 * @param[in] framebufferCreateInfo The valid FramebufferCreateInfo structure
229 * @param[in] oldFramebuffer The valid pointer to the old object or nullptr. The object will be reused or destroyed.
230 * @return pointer to the Framebuffer object
232 virtual UniquePtr<Framebuffer> CreateFramebuffer(const FramebufferCreateInfo& framebufferCreateInfo, UniquePtr<Framebuffer>&& oldFramebuffer) = 0;
235 * @brief Creates new Pipeline object
237 * @param[in] pipelineCreateInfo The valid PipelineCreateInfo structure
238 * @param[in] oldPipeline The valid pointer to the old object or nullptr. The object will be reused or destroyed.
239 * @return pointer to the Pipeline object
241 virtual UniquePtr<Pipeline> CreatePipeline(const PipelineCreateInfo& pipelineCreateInfo, UniquePtr<Pipeline>&& oldPipeline) = 0;
244 * @brief Creates new Program object
246 * @param[in] ProgramCreateInfo The valid ProgramCreateInfo structure
247 * @param[in] oldProgram The valid pointer to the old object or nullptr. The object will be reused or destroyed.
248 * @return pointer to the Program object
250 virtual UniquePtr<Program> CreateProgram(const ProgramCreateInfo& programCreateInfo, UniquePtr<Program>&& oldProgram) = 0;
253 * @brief Creates new Shader object
255 * @param[in] shaderCreateInfo The valid ShaderCreateInfo structure
256 * @param[in] oldShader The valid pointer to the old object or nullptr. The object will be reused or destroyed.
257 * @return pointer to the Shader object
259 virtual UniquePtr<Shader> CreateShader(const ShaderCreateInfo& shaderCreateInfo, UniquePtr<Shader>&& oldShader) = 0;
262 * @brief Creates new Sampler object
264 * @param[in] samplerCreateInfo The valid SamplerCreateInfo structure
265 * @param[in] oldSampler The valid pointer to the old object or nullptr. The object will be reused or destroyed.
266 * @return pointer to the Sampler object
268 virtual UniquePtr<Sampler> CreateSampler(const SamplerCreateInfo& samplerCreateInfo, UniquePtr<Sampler>&& oldSampler) = 0;
271 * @brief Creates new RenderTarget object
273 * @param[in] renderTargetCreateInfo The valid RenderTargetCreateInfo structure
274 * @param[in] oldRenderTarget The valid pointer to the old object or nullptr. The object will be reused or destroyed.
275 * @return pointer to the RenderTarget object
277 virtual UniquePtr<RenderTarget> CreateRenderTarget(const RenderTargetCreateInfo& renderTargetCreateInfo, UniquePtr<RenderTarget>&& oldRenderTarget) = 0;
280 * Create a synchronisation object.
282 * @return A pointer to an opaque sync object
283 * @param[in] syncObjectCreateInfo The valid SyncObjectCreateInfo structure
284 * @param[in] oldSyncObject The valid pointer to the old object or nullptr. The object will be reused or destroyed.
286 virtual UniquePtr<SyncObject> CreateSyncObject(const SyncObjectCreateInfo& syncObjectCreateInfo,
287 UniquePtr<SyncObject>&& oldSyncObject) = 0;
290 * @brief Maps memory associated with Buffer object
292 * @param[in] mapInfo Filled details of mapped resource
293 * @return Returns pointer to Memory object or nullptr on error
295 virtual UniquePtr<Memory> MapBufferRange(const MapBufferInfo& mapInfo) = 0;
298 * @brief Maps memory associated with the texture.
300 * Only Texture objects that are backed with linear memory (staging memory) can be mapped.
302 * 1) GLES implementation may create PBO object as staging memory and couple it
303 * with the texture. Texture can be mapped and the memory can be read/write on demand.
305 * 2) Vulkan implementation may allocate DeviceMemory and use linear layout.
307 * @param[in] mapInfo Filled details of mapped resource
309 * @return Valid Memory object or nullptr on error
311 virtual UniquePtr<Memory> MapTextureRange(const MapTextureInfo& mapInfo) = 0;
314 * @brief Unmaps memory and discards Memory object
316 * This function automatically removes lock if Memory has been
319 * @param[in] memory Valid and previously mapped Memory object
321 virtual void UnmapMemory(UniquePtr<Memory> memory) = 0;
324 * @brief Returns memory requirements of the Texture object.
326 * Call this function whenever it's necessary to know how much memory
327 * is needed to store all the texture data and what memory alignment
328 * the data should follow.
330 * @return Returns memory requirements of Texture
332 virtual MemoryRequirements GetTextureMemoryRequirements(Texture& texture) const = 0;
335 * @brief Returns memory requirements of the Buffer object.
337 * Call this function whenever it's necessary to know how much memory
338 * is needed to store all the buffer data and what memory alignment
339 * the data should follow.
341 * @return Returns memory requirements of Buffer
343 virtual MemoryRequirements GetBufferMemoryRequirements(Buffer& buffer) const = 0;
346 * @brief Returns specification of the Texture object
348 * Function obtains specification of the Texture object. It may retrieve
349 * implementation dependent details like ie. whether the texture is
350 * emulated (for example, RGB emulated on RGBA), compressed etc.
352 * @return Returns the TextureProperties object
354 virtual TextureProperties GetTextureProperties(const Texture& texture) = 0;
357 * @brief Returns the reflection of the given program
359 * @param[in] program The program
360 * @return The reflection of the program
362 virtual const Reflection& GetProgramReflection(const Program& program) = 0;
365 * @brief Tests whether two Pipelines are the same.
367 * On the higher level, this function may help wit creating pipeline cache.
369 * @return true if pipeline objects match
371 virtual bool PipelineEquals(const Pipeline& pipeline0, const Pipeline& pipeline1) const = 0;
374 * @brief Retrieves program parameters
376 * This function can be used to retrieve data from internal implementation
378 * @param[in] program Valid program object
379 * @param[in] parameterId Integer parameter id
380 * @param[out] outData Pointer to output memory
381 * @return True on success
383 virtual bool GetProgramParameter(Graphics::Program& program, uint32_t parameterId, void* outData) = 0;
385 public: // ResourceId relative API.
387 * @brief Create Graphics::Texture as resourceId.
388 * The ownership of Graphics::Texture will be hold on this controller.
389 * @note If some Graphics::Texture already created before, assert.
390 * @post DiscardTextureFromResourceId() or ReleaseTextureFromResourceId() should be called when we don't use resourceId texture anymore.
392 * @param[in] resourceId The unique id of resouces.
393 * @return Pointer of Graphics::Texture, or nullptr if we fail to create.
395 virtual Graphics::Texture* CreateTextureByResourceId(uint32_t resourceId, const Graphics::TextureCreateInfo& createInfo) = 0;
398 * @brief Discard Graphics::Texture as resourceId.
400 * @param[in] resourceId The unique id of resouces.
402 virtual void DiscardTextureFromResourceId(uint32_t resourceId) = 0;
405 * @brief Get the Graphics::Texture as resourceId.
407 * @param[in] resourceId The unique id of resouces.
408 * @return Pointer of Graphics::Texture, or nullptr if there is no valid objects.
410 virtual Graphics::Texture* GetTextureFromResourceId(uint32_t resourceId) = 0;
413 * @brief Get the ownership of Graphics::Texture as resourceId.
415 * @param[in] resourceId The unique id of resouces.
416 * @return Pointer of Graphics::Texture.
418 virtual UniquePtr<Graphics::Texture> ReleaseTextureFromResourceId(uint32_t resourceId) = 0;
424 Controller() = default;
426 } // namespace Graphics