1 #ifndef DALI_GRAPHICS_COMMAND_BUFFER_H
2 #define DALI_GRAPHICS_COMMAND_BUFFER_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.
22 #include "graphics-types.h"
36 * @brief Uniform buffer bindings.
38 struct UniformBufferBinding
40 Buffer* buffer; // Buffer
43 void* offsetPtr; // pointer to the client-side memory
44 uint32_t offset; // Offset within buffer
46 uint32_t dataSize; // Size of data to bind
47 uint32_t binding; // Binding index
51 * @brief Texture bindings
53 * Additionally, sampler may be used in case of having combined
59 const Texture* texture; // texture to be bound
60 const Sampler* sampler; // sampler to be bound
61 uint32_t binding; // binding index
65 * @brief Sampler binding
69 Sampler* sampler; // sampler to be bound
70 uint32_t binding; // binding index
74 * @brief ClearValue contains an union of RGBA and depthStencil values.
93 * @brief CommandBuffer contains a stream of commands to be executed
99 CommandBuffer() = default;
100 virtual ~CommandBuffer() = default;
103 CommandBuffer(const CommandBuffer&) = delete;
104 CommandBuffer& operator=(const CommandBuffer&) = delete;
107 * @brief Binds vertex buffers
109 * The buffers and offsets arrays must be same length
111 * @param[in] firstBinding First binding index
112 * @param[in] buffers List of buffers to bind
113 * @param[in] offsets List of offsets for each buffer
115 virtual void BindVertexBuffers(uint32_t firstBinding,
116 std::vector<const Buffer*> buffers,
117 std::vector<uint32_t> offsets) = 0;
120 * @brief Binds uniform buffers
122 * @param[in] bindings List of uniform buffer bindings
124 virtual void BindUniformBuffers(const std::vector<UniformBufferBinding>& bindings) = 0;
127 * @brief Binds pipeline
129 * @param[in] pipeline valid pipeline
131 virtual void BindPipeline(const Pipeline& pipeline) = 0;
134 * @brief Binds textures
136 * @param[in] textureBindings List of texture bindings
138 virtual void BindTextures(std::vector<TextureBinding>& textureBindings) = 0;
141 * @brief Binds samplers
143 * @param[in] samplerBindings List of sampler bindings
145 virtual void BindSamplers(std::vector<SamplerBinding>& samplerBindings) = 0;
148 * @brief Binds buffer containing push constants
150 * @param[in] data pointer to the buffer
151 * @param[in] size size of data in bytes
152 * @param[in] binding push constants binding index
154 virtual void BindPushConstants(void* data,
156 uint32_t binding) = 0;
159 * @brief Binds index buffer
161 * Most commonly used formats:
165 * @param[in] buffer Valid buffer
166 * @param[in] offset offset within buffer
167 * @param[in] format Format of index buffer
169 virtual void BindIndexBuffer(const Buffer& buffer,
173 * @brief Begins render pass
175 * The function initialises rendering for specified RenderPass object
176 * onto renderTarget. renderArea defines the scissor rect. Depends on the
177 * renderPass spec, the clearValues may be used.
179 * Calling EndRenderPass() is necessary to finalize the render pass.
181 * @param[in] renderPass valid render pass object
182 * @param[in] renderTarget valid render target
183 * @param[in] renderArea area to draw
184 * @param[in] clearValues clear values (compatible with renderpass spec)
186 virtual void BeginRenderPass(
187 RenderPass& renderPass,
188 RenderTarget& renderTarget,
190 std::vector<ClearValue> clearValues) = 0;
193 * @brief Ends current render pass
195 * This command must be issued in order to finalize the render pass.
196 * It's up to the implementation whether anything has to be done but
197 * the Controller may use end RP marker in order to resolve resource
198 * dependencies (for example, to know when target texture is ready
199 * before passing it to another render pass).
201 virtual void EndRenderPass() = 0;
204 * @brief Draw primitives
206 * @param[in] vertexCount number of vertices
207 * @param[in] instanceCount number of instances
208 * @param[in] firstVertex index of first vertex
209 * @param[in] firstInstance index of first instance
212 uint32_t vertexCount,
213 uint32_t instanceCount,
214 uint32_t firstVertex,
215 uint32_t firstInstance) = 0;
218 * @brief Draws indexed primitives
220 * @param[in] indexCount Number of indices
221 * @param[in] instanceCount Number of instances
222 * @param[in] firstIndex first index
223 * @param[in] vertexOffset offset of first vertex
224 * @param[in] firstInstance first instance
226 virtual void DrawIndexed(
228 uint32_t instanceCount,
230 int32_t vertexOffset,
231 uint32_t firstInstance) = 0;
234 * @brief Draws indexed primitives indirectly
236 * Indirect draw uses additional buffer that holds render data.
238 * Indirect draw support depends on the hardware (most of modern hardware
239 * supports this drawing technique).
241 * @param[in] buffer Buffer containing draw parameters
242 * @param[in] offset Offset in bytes where parameters begin
243 * @param[in] drawCount number of draws to execute
244 * @param[in] stride stride between draw parameters
246 virtual void DrawIndexedIndirect(
250 uint32_t stride) = 0;
253 * @brief Resets CommandBuffer
255 * This function resets the command buffer and discards all previously
258 * Since the allocation may use internal memory pool of the CommandBuffer,
259 * resetting doesn't have to discard all the resources (for example, it doesn't
260 * need to destroy command but only move the pointer to the beginning of
261 * the command buffer).
263 * It is useful if the command buffer has to be re-recorded frequently, for example,
266 virtual void Reset(CommandBuffer& commandBuffer) = 0;
269 * @brief Changes scissor rect
271 * @param[in] value 2D scissor area
273 virtual void SetScissor(Extent2D value) = 0;
276 * @brief Enables/disables scissor test
278 * @param[in] value State of scissor test
280 virtual void SetScissorTestEnable(bool value) = 0;
283 * @brief Sets viewport
285 * @param[in] value 2D viewport area
287 virtual void SetViewport(Viewport value) = 0;
290 * @brief Sets whether the viewport should be changed
291 * @param[in] value state of viewport
293 virtual void SetViewportEnable(bool value) = 0;
296 CommandBuffer(CommandBuffer&&) = default;
297 CommandBuffer& operator=(CommandBuffer&&) = default;
299 } // Namespace Graphics