1 #ifndef DALI_GRAPHICS_GLES_COMMAND_BUFFER_H
2 #define DALI_GRAPHICS_GLES_COMMAND_BUFFER_H
5 * Copyright (c) 2022 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/graphics-api/graphics-command-buffer-create-info.h>
23 #include <dali/graphics-api/graphics-command-buffer.h>
24 #include <dali/graphics-api/graphics-types.h>
27 #include "gles-graphics-resource.h"
28 #include "gles-graphics-types.h"
29 #include "gles-sync-object.h"
33 namespace Dali::Graphics::GLES
40 enum class CommandType
51 DRAW_INDEXED_INDIRECT,
57 EXECUTE_COMMAND_BUFFERS,
58 PRESENT_RENDER_TARGET,
62 SET_STENCIL_TEST_ENABLE,
63 SET_STENCIL_WRITE_MASK,
67 SET_DEPTH_TEST_ENABLE,
68 SET_DEPTH_WRITE_ENABLE,
73 * @brief Helper function to invoke destructor on anonymous struct
76 static void InvokeDestructor(T& object)
82 * Command structure allocates memory to store a single command
90 explicit Command(CommandType commandType)
98 * @brief Copy constructor
99 * @param[in] rhs Command
101 Command(const Command& rhs) = default;
102 Command& operator=(const Command& rhs) = default;
103 Command(Command&& rhs) noexcept = delete;
104 Command& operator=(Command&& rhs) = delete;
106 CommandType type{CommandType::FLUSH}; ///< Type of command
112 IndirectPtr<Graphics::TextureBinding> textureBindings;
113 uint32_t textureBindingsCount;
116 // BindSampler command
119 IndirectPtr<Graphics::SamplerBinding> samplerBindings;
120 uint32_t samplerBindingsCount;
125 using Binding = GLES::VertexBufferBindingDescriptor;
126 IndirectPtr<Binding> vertexBufferBindings;
127 uint32_t vertexBufferBindingsCount;
130 struct : public IndexBufferBindingDescriptor
136 IndirectPtr<UniformBufferBindingDescriptor> uniformBufferBindings;
137 uint32_t uniformBufferBindingsCount;
138 UniformBufferBindingDescriptor standaloneUniformsBufferBinding{};
139 } bindUniformBuffers;
143 const GLES::Pipeline* pipeline{nullptr};
146 struct : public DrawCallDescriptor
152 Graphics::Rect2D region;
162 Graphics::Viewport region;
165 struct BeginRenderPassDescriptor
170 Graphics::SyncObject* syncObject;
175 IndirectPtr<const GLES::CommandBuffer*> buffers;
176 uint32_t buffersCount;
177 } executeCommandBuffers;
181 GLES::RenderTarget* targetToPresent;
182 } presentRenderTarget;
186 Graphics::CompareOp compareOp;
193 Graphics::StencilOp failOp;
194 Graphics::StencilOp passOp;
195 Graphics::StencilOp depthFailOp;
205 uint32_t compareMask;
206 Graphics::CompareOp compareOp;
222 DrawNativeInfo drawNativeInfo;
227 using CommandBufferResource = Resource<Graphics::CommandBuffer, Graphics::CommandBufferCreateInfo>;
229 class CommandBuffer : public CommandBufferResource
232 CommandBuffer(const Graphics::CommandBufferCreateInfo& createInfo, EglGraphicsController& controller);
234 ~CommandBuffer() override;
237 * @copydoc Dali::Graphics::CommandBuffer::BindVertexBuffers
239 void BindVertexBuffers(uint32_t firstBinding,
240 const std::vector<const Graphics::Buffer*>& buffers,
241 const std::vector<uint32_t>& offsets) override;
244 * @copydoc Dali::Graphics::CommandBuffer::BindUniformBuffers
246 void BindUniformBuffers(const std::vector<Graphics::UniformBufferBinding>& bindings) override;
249 * @copydoc Dali::Graphics::CommandBuffer::BindPipeline
251 void BindPipeline(const Graphics::Pipeline& pipeline) override;
254 * @copydoc Dali::Graphics::CommandBuffer::BindTextures
256 void BindTextures(const std::vector<TextureBinding>& textureBindings) override;
259 * @copydoc Dali::Graphics::CommandBuffer::BindSamplers
261 void BindSamplers(const std::vector<SamplerBinding>& samplerBindings) override;
264 * @copydoc Dali::Graphics::CommandBuffer::BindPushConstants
266 void BindPushConstants(void* data,
268 uint32_t binding) override;
271 * @copydoc Dali::Graphics::CommandBuffer::BindIndexBuffer
273 void BindIndexBuffer(const Graphics::Buffer& buffer,
275 Format format) override;
278 * @copydoc Dali::Graphics::CommandBuffer::BeginRenderPass
280 void BeginRenderPass(
281 Graphics::RenderPass* renderPass,
282 Graphics::RenderTarget* renderTarget,
284 const std::vector<ClearValue>& clearValues) override;
287 * @copydoc Dali::Graphics::CommandBuffer::EndRenderPass
289 void EndRenderPass(Graphics::SyncObject* syncObject) override;
292 * @copydoc Dali::Graphics::CommandBuffer::ExecuteCommandBuffers
294 void ExecuteCommandBuffers(std::vector<const Graphics::CommandBuffer*>&& commandBuffers) override;
297 * @copydoc Dali::Graphics::CommandBuffer::Draw
300 uint32_t vertexCount,
301 uint32_t instanceCount,
302 uint32_t firstVertex,
303 uint32_t firstInstance) override;
306 * @copydoc Dali::Graphics::CommandBuffer::DrawIndexed
310 uint32_t instanceCount,
312 int32_t vertexOffset,
313 uint32_t firstInstance) override;
316 * @copydoc Dali::Graphics::CommandBuffer::DrawIndexedIndirect
318 void DrawIndexedIndirect(
319 Graphics::Buffer& buffer,
322 uint32_t stride) override;
325 * @copydoc Dali::Graphics::CommandBuffer::DrawNative
327 void DrawNative(const DrawNativeInfo* drawNativeInfo) override;
330 * @copydoc Dali::Graphics::CommandBuffer::Reset
332 void Reset() override;
335 * @copydoc Dali::Graphics::CommandBuffer::SetScissor
337 void SetScissor(Graphics::Rect2D value) override;
340 * @copydoc Dali::Graphics::CommandBuffer::SetScissorTestEnable
342 void SetScissorTestEnable(bool value) override;
345 * @copydoc Dali::Graphics::CommandBuffer::SetViewport
347 void SetViewport(Viewport value) override;
350 * @copydoc Dali::Graphics::CommandBuffer::SetViewportEnable
352 void SetViewportEnable(bool value) override;
355 * @copydoc Dali::Graphics::CommandBuffer::SetColorMask
357 void SetColorMask(bool enabled) override;
360 * @copydoc Dali::Graphics::CommandBuffer::ClearStencilBuffer
362 void ClearStencilBuffer() override;
365 * @copydoc Dali::Graphics::CommandBuffer::SetStencilTestEnable
367 void SetStencilTestEnable(bool stencilEnable) override;
370 * @copydoc Dali::Graphics::CommandBuffer::SetStencilWriteMask
372 void SetStencilWriteMask(uint32_t writeMask) override;
375 * @copydoc Dali::Graphics::CommandBuffer::SetStencilOp
377 void SetStencilOp(Graphics::StencilOp failOp,
378 Graphics::StencilOp passOp,
379 Graphics::StencilOp depthFailOp) override;
382 * @copydoc Dali::Graphics::CommandBuffer::SetStencilFunc
384 void SetStencilFunc(Graphics::CompareOp compareOp,
386 uint32_t compareMask) override;
389 * @copydoc Dali::Graphics::CommandBuffer::SetDepthCompareOp
391 void SetDepthCompareOp(Graphics::CompareOp compareOp) override;
394 * @copydoc Dali::Graphics::CommandBuffer::SetDepthTestEnable
396 void SetDepthTestEnable(bool depthTestEnable) override;
399 * @copydoc Dali::Graphics::CommandBuffer::SetDepthWriteEnable
401 void SetDepthWriteEnable(bool depthWriteEnable) override;
404 * @copydoc Dali::Graphics::CommandBuffer::ClearDepthBuffer
406 void ClearDepthBuffer() override;
409 * @brief Presents specified render target
411 * @param[in] renderTarget Valid pointer to a RenderTarget
413 * It's internal command that schedules presentation of
414 * specified render target.
416 void PresentRenderTarget(GLES::RenderTarget* renderTarget);
419 * @brief Returns pointer to the list of command and size of the list
421 * @param[out] size Size of the list
422 * @return Valid pointer to the list of commands
424 [[nodiscard]] const Command* GetCommands(uint32_t& size) const;
427 * @brief Destroy the associated resources
429 void DestroyResource() override;
432 * @brief Initialize associated resources
434 bool InitializeResource() override;
437 * @brief Add this resource to the discard queue
439 void DiscardResource() override;
442 std::unique_ptr<CommandPool> mCommandPool; ///< Pool of commands and transient memory
444 } // namespace Dali::Graphics::GLES