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"
24 namespace Dali::Graphics
35 * @brief Uniform buffer bindings.
37 struct UniformBufferBinding
39 Buffer* buffer; // Buffer
42 void* offsetPtr; // pointer to the client-side memory
43 uint32_t offset; // Offset within buffer
45 uint32_t dataSize; // Size of data to bind
46 uint32_t binding; // Binding index
50 * @brief Texture bindings
52 * Additionally, sampler may be used in case of having combined
58 const Texture* texture; // texture to be bound
59 const Sampler* sampler; // sampler to be bound
60 uint32_t binding; // binding index
64 * @brief Sampler binding
68 Sampler* sampler; // sampler to be bound
69 uint32_t binding; // binding index
73 * @brief ClearValue contains an union of RGBA and depthStencil values.
85 float depth; // glClearDepthf
86 uint32_t stencil; // glClearStencil
92 * @brief CommandBuffer contains a stream of commands to be executed
98 CommandBuffer() = default;
99 virtual ~CommandBuffer() = default;
102 CommandBuffer(const CommandBuffer&) = delete;
103 CommandBuffer& operator=(const CommandBuffer&) = delete;
106 * @brief Binds vertex buffers
108 * The buffers and offsets arrays must be same length
110 * @param[in] firstBinding First binding index
111 * @param[in] buffers List of buffers to bind
112 * @param[in] offsets List of offsets for each buffer
114 virtual void BindVertexBuffers(uint32_t firstBinding,
115 std::vector<const Buffer*> buffers,
116 std::vector<uint32_t> offsets) = 0;
119 * @brief Binds uniform buffers
121 * @param[in] bindings List of uniform buffer bindings
123 virtual void BindUniformBuffers(const std::vector<UniformBufferBinding>& bindings) = 0;
126 * @brief Binds pipeline
128 * @param[in] pipeline valid pipeline
130 virtual void BindPipeline(const Pipeline& pipeline) = 0;
133 * @brief Binds textures
135 * @param[in] textureBindings List of texture bindings
137 virtual void BindTextures(std::vector<TextureBinding>& textureBindings) = 0;
140 * @brief Binds samplers
142 * @param[in] samplerBindings List of sampler bindings
144 virtual void BindSamplers(std::vector<SamplerBinding>& samplerBindings) = 0;
147 * @brief Binds buffer containing push constants
149 * @param[in] data pointer to the buffer
150 * @param[in] size size of data in bytes
151 * @param[in] binding push constants binding index
153 virtual void BindPushConstants(void* data,
155 uint32_t binding) = 0;
158 * @brief Binds index buffer
160 * Most commonly used formats:
164 * @param[in] buffer Valid buffer
165 * @param[in] offset offset within buffer
166 * @param[in] format Format of index buffer
168 virtual void BindIndexBuffer(const Buffer& buffer,
172 * @brief Begins render pass
174 * The function initialises rendering for specified RenderPass object
175 * onto renderTarget. renderArea defines the scissor rect. Depends on the
176 * renderPass spec, the clearValues may be used.
178 * Calling EndRenderPass() is necessary to finalize the render pass.
180 * @param[in] renderPass valid render pass object
181 * @param[in] renderTarget valid render target, must not be used when framebuffer set
182 * @param[in] renderArea area to draw (clear operation is affected)
183 * @param[in] clearValues clear values (compatible with renderpass spec)
185 virtual void BeginRenderPass(
186 RenderPass* renderPass,
187 RenderTarget* renderTarget,
189 std::vector<ClearValue> clearValues) = 0;
192 * @brief Ends current render pass
194 * This command must be issued in order to finalize the render pass.
195 * It's up to the implementation whether anything has to be done but
196 * the Controller may use end RP marker in order to resolve resource
197 * dependencies (for example, to know when target texture is ready
198 * before passing it to another render pass).
200 * The caller may query the sync object to determine when this render
201 * pass has actually finished on the GPU.
203 * @param[in] syncObject If non-null, this object will ensure an
204 * appropriate fence sync object is created after the render pass is
207 virtual void EndRenderPass(Graphics::SyncObject* syncObject) = 0;
210 * @brief Executes a list of secondary command buffers
212 * The secondary command buffers will be executed as a part of a primary
213 * command buffer that calls this function.
215 * @param[in] commandBuffers List of buffers to execute
217 virtual void ExecuteCommandBuffers(std::vector<const CommandBuffer*>&& commandBuffers) = 0;
220 * @brief Draw primitives
222 * @param[in] vertexCount number of vertices
223 * @param[in] instanceCount number of instances
224 * @param[in] firstVertex index of first vertex
225 * @param[in] firstInstance index of first instance
228 uint32_t vertexCount,
229 uint32_t instanceCount,
230 uint32_t firstVertex,
231 uint32_t firstInstance) = 0;
234 * @brief Draws indexed primitives
236 * @param[in] indexCount Number of indices
237 * @param[in] instanceCount Number of instances
238 * @param[in] firstIndex first index
239 * @param[in] vertexOffset offset of first vertex
240 * @param[in] firstInstance first instance
242 virtual void DrawIndexed(
244 uint32_t instanceCount,
246 int32_t vertexOffset,
247 uint32_t firstInstance) = 0;
250 * @brief Draws indexed primitives indirectly
252 * Indirect draw uses additional buffer that holds render data.
254 * Indirect draw support depends on the hardware (most of modern hardware
255 * supports this drawing technique).
257 * @param[in] buffer Buffer containing draw parameters
258 * @param[in] offset Offset in bytes where parameters begin
259 * @param[in] drawCount number of draws to execute
260 * @param[in] stride stride between draw parameters
262 virtual void DrawIndexedIndirect(
266 uint32_t stride) = 0;
269 * @brief Resets CommandBuffer
271 * This function resets the command buffer and discards all previously
274 * Since the allocation may use internal memory pool of the CommandBuffer,
275 * resetting doesn't have to discard all the resources (for example, it doesn't
276 * need to destroy command but only move the pointer to the beginning of
277 * the command buffer).
279 * It is useful if the command buffer has to be re-recorded frequently, for example,
282 virtual void Reset() = 0;
285 * @brief Changes scissor rect
287 * @param[in] value 2D scissor rectangle
289 virtual void SetScissor(Rect2D value) = 0;
292 * @brief Enables/disables scissor test
294 * @param[in] value State of scissor test
296 virtual void SetScissorTestEnable(bool value) = 0;
299 * @brief Sets viewport
301 * @param[in] value 2D viewport area
303 virtual void SetViewport(Viewport value) = 0;
306 * @brief Sets whether the viewport should be changed
307 * @param[in] value state of viewport
309 virtual void SetViewportEnable(bool value) = 0;
312 * @brief Sets the color mask for all channels.
314 virtual void SetColorMask(bool enabled) = 0;
317 * @brief Clears the stencil buffer (outside of BeginRenderPass) to the current stencil mask
319 virtual void ClearStencilBuffer() = 0;
322 * @brief Clears the depth buffer (outside of BeginRenderPass) to the current depth mask
324 virtual void ClearDepthBuffer() = 0;
327 * @brief Enable or disable the stencil test
329 * @param[in] stencilEnable whether stencil test should be enabled
331 virtual void SetStencilTestEnable(bool stencilEnable) = 0;
334 * @brief The mask used for writing to the stencil buffer.
336 * It should be as wide as necessary for the stencil texture format.
337 * @param[in] writeMask The mask for wriing to / clearing the stencil buffer
339 virtual void SetStencilWriteMask(uint32_t writeMask) = 0;
342 * @brief Setup the stencil function
344 * @param[in] compareOp How the stencil buffer, reference and compareMask are combined to determine whether to draw a pixel or not.
345 * @param[in] reference A reference value that is ANDed with the mask in the compare op.
346 * @param[in] compareMask The bitplanes from the stencil buffer that are active.
348 virtual void SetStencilFunc(Graphics::CompareOp compareOp,
350 uint32_t compareMask) = 0;
353 * @brief Set how subsequent draws will affect the stencil buffer.
354 * @param[in] failOp What happens to stencil buffer if drawing a pixel fails the stencil test
355 * @param[in] passOp What happens to stencil buffer if drawing a pixel passes stencil & depth test
356 * @param[in] depthFailOp What happens to stencil buffer if drawing a pixel passes stencil but fails depth test.
358 virtual void SetStencilOp(Graphics::StencilOp failOp,
359 Graphics::StencilOp passOp,
360 Graphics::StencilOp depthFailOp) = 0;
363 * @brief Defines the comparison operator for passing the depth test.
365 * @param[in] compareOp The comparison operator
367 virtual void SetDepthCompareOp(Graphics::CompareOp compareOp) = 0;
370 * @brief Enables depth testing
372 * @param[in] depthTestEnable True if depth testing will be enabled.
374 virtual void SetDepthTestEnable(bool depthTestEnable) = 0;
377 * @brief Enables depth writing / clearing
379 * @param[in] depthWriteEnabled True if the depth buffer can be updated or cleared.
381 virtual void SetDepthWriteEnable(bool depthWriteEnable) = 0;
384 CommandBuffer(CommandBuffer&&) = default;
385 CommandBuffer& operator=(CommandBuffer&&) = default;
387 } // namespace Dali::Graphics