Lock uniform buffer only 1 times per each render + minor fixup of uniforms
[platform/core/uifw/dali-core.git] / dali / internal / render / renderers / uniform-buffer-manager.h
1 #ifndef DALI_INTERNAL_UNIFORM_BUFFER_MANAGER_H
2 #define DALI_INTERNAL_UNIFORM_BUFFER_MANAGER_H
3
4 /*
5  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/graphics-api/graphics-controller.h>
23
24 namespace Dali::Internal::Render
25 {
26 class UniformBuffer;
27 class UniformBufferView;
28 class UniformBufferViewPool;
29
30 /**
31  * Class UniformBufferManager
32  *
33  * Manages the uniform buffers.
34  *
35  */
36 class UniformBufferManager
37 {
38 public:
39   explicit UniformBufferManager(Dali::Graphics::Controller* controller);
40
41   ~UniformBufferManager();
42
43   /**
44    * @brief Allocates uniform buffer with given size and alignment
45    * @param size Size of uniform buffer
46    * @param alignment Alignment
47    * @return new UniformBuffer
48    */
49   Graphics::UniquePtr<UniformBuffer> AllocateUniformBuffer(uint32_t size, uint32_t alignment = 256);
50
51   /**
52    * @brief Creates a view on UniformBuffer
53    *
54    * @param uniformBuffer
55    * @param size
56    * @return Uniform buffer view
57    */
58   Graphics::UniquePtr<UniformBufferView> CreateUniformBufferView(UniformBuffer* uniformBuffer, uint32_t offset, uint32_t size);
59
60   /**
61    * @brief Creates uniform buffer pool view
62    * @param size
63    * @return
64    */
65   Graphics::UniquePtr<UniformBufferViewPool> CreateUniformBufferViewPool();
66
67   /**
68    * @brief Returns Controller object
69    * @return controller object
70    */
71   [[nodiscard]] Graphics::Controller& GetController() const
72   {
73     return *mController;
74   }
75
76   /**
77    * @brief Returns embedded uniform buffer pool view for specified DAli buffer index
78    * @return Pointer to valid uniform buffer pool view
79    */
80   [[nodiscard]] UniformBufferViewPool* GetUniformBufferViewPool(uint32_t bufferIndex);
81
82   /**
83    * @brief Prepare to lock the uniform buffer so we can write to the standalone uniform map directly.
84    * Uniform buffer will be locked at the first call of UniformBuffer::Write after call this API.
85    * @note After all write done, We should call UnlockUniformBuffer.
86    *
87    * @param bufferIndex current update/render buffer index
88    */
89   void ReadyToLockUniformBuffer(uint32_t bufferIndex);
90
91   /**
92    * @brief Unlock the uniform buffer.
93    * @note We should call ReadyToLockUniformBuffer before call this.
94    *
95    * @param bufferIndex current update/render buffer index
96    */
97   void UnlockUniformBuffer(uint32_t bufferIndex);
98
99 private:
100   Dali::Graphics::Controller* mController;
101
102   Graphics::UniquePtr<UniformBufferViewPool> mUniformBufferPoolStorage[2u]; ///< The pool view into UniformBuffer (double buffered)
103 };
104
105 } // namespace Dali::Internal::Render
106
107 #endif // DALI_INTERNAL_UNIFORM_BUFFER_MANAGER_H