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,
72 * @brief Helper function to invoke destructor on anonymous struct
75 static void InvokeDestructor(T& object)
81 * Command structure allocates memory to store a single command
89 explicit Command(CommandType commandType)
97 * @brief Copy constructor
98 * @param[in] rhs Command
100 Command(const Command& rhs) = default;
101 Command& operator=(const Command& rhs) = default;
102 Command(Command&& rhs) noexcept = delete;
103 Command& operator=(Command&& rhs) = delete;
105 CommandType type{CommandType::FLUSH}; ///< Type of command
111 IndirectPtr<Graphics::TextureBinding> textureBindings;
112 uint32_t textureBindingsCount;
115 // BindSampler command
118 IndirectPtr<Graphics::SamplerBinding> samplerBindings;
119 uint32_t samplerBindingsCount;
124 using Binding = GLES::VertexBufferBindingDescriptor;
125 IndirectPtr<Binding> vertexBufferBindings;
126 uint32_t vertexBufferBindingsCount;
129 struct : public IndexBufferBindingDescriptor
135 IndirectPtr<UniformBufferBindingDescriptor> uniformBufferBindings;
136 uint32_t uniformBufferBindingsCount;
137 UniformBufferBindingDescriptor standaloneUniformsBufferBinding{};
138 } bindUniformBuffers;
142 const GLES::Pipeline* pipeline{nullptr};
145 struct : public DrawCallDescriptor
151 Graphics::Rect2D region;
161 Graphics::Viewport region;
164 struct BeginRenderPassDescriptor
169 Graphics::SyncObject* syncObject;
174 IndirectPtr<const GLES::CommandBuffer*> buffers;
175 uint32_t buffersCount;
176 } executeCommandBuffers;
180 GLES::RenderTarget* targetToPresent;
181 } presentRenderTarget;
185 Graphics::CompareOp compareOp;
192 Graphics::StencilOp failOp;
193 Graphics::StencilOp passOp;
194 Graphics::StencilOp depthFailOp;
204 uint32_t compareMask;
205 Graphics::CompareOp compareOp;
221 using CommandBufferResource = Resource<Graphics::CommandBuffer, Graphics::CommandBufferCreateInfo>;
223 class CommandBuffer : public CommandBufferResource
226 CommandBuffer(const Graphics::CommandBufferCreateInfo& createInfo, EglGraphicsController& controller);
228 ~CommandBuffer() override;
231 * @copydoc Dali::Graphics::CommandBuffer::BindVertexBuffers
233 void BindVertexBuffers(uint32_t firstBinding,
234 const std::vector<const Graphics::Buffer*>& buffers,
235 const std::vector<uint32_t>& offsets) override;
238 * @copydoc Dali::Graphics::CommandBuffer::BindUniformBuffers
240 void BindUniformBuffers(const std::vector<Graphics::UniformBufferBinding>& bindings) override;
243 * @copydoc Dali::Graphics::CommandBuffer::BindPipeline
245 void BindPipeline(const Graphics::Pipeline& pipeline) override;
248 * @copydoc Dali::Graphics::CommandBuffer::BindTextures
250 void BindTextures(const std::vector<TextureBinding>& textureBindings) override;
253 * @copydoc Dali::Graphics::CommandBuffer::BindSamplers
255 void BindSamplers(const std::vector<SamplerBinding>& samplerBindings) override;
258 * @copydoc Dali::Graphics::CommandBuffer::BindPushConstants
260 void BindPushConstants(void* data,
262 uint32_t binding) override;
265 * @copydoc Dali::Graphics::CommandBuffer::BindIndexBuffer
267 void BindIndexBuffer(const Graphics::Buffer& buffer,
269 Format format) override;
272 * @copydoc Dali::Graphics::CommandBuffer::BeginRenderPass
274 void BeginRenderPass(
275 Graphics::RenderPass* renderPass,
276 Graphics::RenderTarget* renderTarget,
278 const std::vector<ClearValue>& clearValues) override;
281 * @copydoc Dali::Graphics::CommandBuffer::EndRenderPass
283 void EndRenderPass(Graphics::SyncObject* syncObject) override;
286 * @copydoc Dali::Graphics::CommandBuffer::ExecuteCommandBuffers
288 void ExecuteCommandBuffers(std::vector<const Graphics::CommandBuffer*>&& commandBuffers) override;
291 * @copydoc Dali::Graphics::CommandBuffer::Draw
294 uint32_t vertexCount,
295 uint32_t instanceCount,
296 uint32_t firstVertex,
297 uint32_t firstInstance) override;
300 * @copydoc Dali::Graphics::CommandBuffer::DrawIndexed
304 uint32_t instanceCount,
306 int32_t vertexOffset,
307 uint32_t firstInstance) override;
310 * @copydoc Dali::Graphics::CommandBuffer::DrawIndexedIndirect
312 void DrawIndexedIndirect(
313 Graphics::Buffer& buffer,
316 uint32_t stride) override;
319 * @copydoc Dali::Graphics::CommandBuffer::Reset
321 void Reset() override;
324 * @copydoc Dali::Graphics::CommandBuffer::SetScissor
326 void SetScissor(Graphics::Rect2D value) override;
329 * @copydoc Dali::Graphics::CommandBuffer::SetScissorTestEnable
331 void SetScissorTestEnable(bool value) override;
334 * @copydoc Dali::Graphics::CommandBuffer::SetViewport
336 void SetViewport(Viewport value) override;
339 * @copydoc Dali::Graphics::CommandBuffer::SetViewportEnable
341 void SetViewportEnable(bool value) override;
344 * @copydoc Dali::Graphics::CommandBuffer::SetColorMask
346 void SetColorMask(bool enabled) override;
349 * @copydoc Dali::Graphics::CommandBuffer::ClearStencilBuffer
351 void ClearStencilBuffer() override;
354 * @copydoc Dali::Graphics::CommandBuffer::SetStencilTestEnable
356 void SetStencilTestEnable(bool stencilEnable) override;
359 * @copydoc Dali::Graphics::CommandBuffer::SetStencilWriteMask
361 void SetStencilWriteMask(uint32_t writeMask) override;
364 * @copydoc Dali::Graphics::CommandBuffer::SetStencilOp
366 void SetStencilOp(Graphics::StencilOp failOp,
367 Graphics::StencilOp passOp,
368 Graphics::StencilOp depthFailOp) override;
371 * @copydoc Dali::Graphics::CommandBuffer::SetStencilFunc
373 void SetStencilFunc(Graphics::CompareOp compareOp,
375 uint32_t compareMask) override;
378 * @copydoc Dali::Graphics::CommandBuffer::SetDepthCompareOp
380 void SetDepthCompareOp(Graphics::CompareOp compareOp) override;
383 * @copydoc Dali::Graphics::CommandBuffer::SetDepthTestEnable
385 void SetDepthTestEnable(bool depthTestEnable) override;
388 * @copydoc Dali::Graphics::CommandBuffer::SetDepthWriteEnable
390 void SetDepthWriteEnable(bool depthWriteEnable) override;
393 * @copydoc Dali::Graphics::CommandBuffer::ClearDepthBuffer
395 void ClearDepthBuffer() override;
398 * @brief Presents specified render target
400 * @param[in] renderTarget Valid pointer to a RenderTarget
402 * It's internal command that schedules presentation of
403 * specified render target.
405 void PresentRenderTarget(GLES::RenderTarget* renderTarget);
408 * @brief Returns pointer to the list of command and size of the list
410 * @param[out] size Size of the list
411 * @return Valid pointer to the list of commands
413 [[nodiscard]] const Command* GetCommands(uint32_t& size) const;
416 * @brief Destroy the associated resources
418 void DestroyResource() override;
421 * @brief Initialize associated resources
423 bool InitializeResource() override;
426 * @brief Add this resource to the discard queue
428 void DiscardResource() override;
431 std::unique_ptr<CommandPool> mCommandPool; ///< Pool of commands and transient memory
433 } // namespace Dali::Graphics::GLES