1 #ifndef DALI_GRAPHICS_GLES_COMMAND_BUFFER_H
2 #define DALI_GRAPHICS_GLES_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 <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"
30 namespace Dali::Graphics::GLES
35 enum class CommandType
46 DRAW_INDEXED_INDIRECT,
53 * @brief Helper function to invoke destructor on anonymous struct
56 static void InvokeDestructor(T& object)
62 * Command structure allocates memory to store a single command
68 Command(CommandType commandType)
73 case CommandType::BIND_VERTEX_BUFFERS:
75 new(&bindVertexBuffers) decltype(bindVertexBuffers);
78 case CommandType::BIND_TEXTURES:
80 new(&bindTextures) decltype(bindTextures);
93 case CommandType::BIND_VERTEX_BUFFERS:
95 InvokeDestructor(bindVertexBuffers);
98 case CommandType::BIND_TEXTURES:
100 InvokeDestructor(bindTextures);
110 * @brief Copy constructor
111 * @param[in] rhs Command
113 Command(const Command& rhs)
117 case CommandType::BIND_VERTEX_BUFFERS:
119 new(&bindVertexBuffers) decltype(bindVertexBuffers);
120 bindVertexBuffers = rhs.bindVertexBuffers;
123 case CommandType::BIND_INDEX_BUFFER:
125 bindIndexBuffer = rhs.bindIndexBuffer;
128 case CommandType::BIND_SAMPLERS:
130 bindSamplers = rhs.bindSamplers;
133 case CommandType::BIND_TEXTURES:
135 new(&bindTextures) decltype(bindTextures);
136 bindTextures = rhs.bindTextures;
139 case CommandType::BIND_PIPELINE:
141 bindPipeline = rhs.bindPipeline;
144 case CommandType::BIND_UNIFORM_BUFFER:
146 bindUniformBuffers = rhs.bindUniformBuffers;
149 case CommandType::DRAW:
151 draw.type = rhs.draw.type;
152 draw.draw = rhs.draw.draw;
155 case CommandType::DRAW_INDEXED:
157 draw.type = rhs.draw.type;
158 draw.drawIndexed = rhs.draw.drawIndexed;
161 case CommandType::DRAW_INDEXED_INDIRECT:
163 draw.type = rhs.draw.type;
164 draw.drawIndexedIndirect = rhs.draw.drawIndexedIndirect;
167 case CommandType::FLUSH:
172 case CommandType::SET_SCISSOR:
174 scissor.region = rhs.scissor.region;
177 case CommandType::SET_SCISSOR_TEST:
179 scissorTest.enable = rhs.scissorTest.enable;
182 case CommandType::SET_VIEWPORT:
184 viewport.region = rhs.viewport.region;
192 * @brief Copy constructor
193 * @param[in] rhs Command
195 Command(Command&& rhs) noexcept
199 case CommandType::BIND_VERTEX_BUFFERS:
201 new(&bindVertexBuffers) decltype(bindVertexBuffers);
202 bindVertexBuffers = std::move(rhs.bindVertexBuffers);
205 case CommandType::BIND_INDEX_BUFFER:
207 bindIndexBuffer = rhs.bindIndexBuffer;
210 case CommandType::BIND_UNIFORM_BUFFER:
212 bindUniformBuffers = std::move(rhs.bindUniformBuffers);
215 case CommandType::BIND_SAMPLERS:
217 bindSamplers = std::move(rhs.bindSamplers);
220 case CommandType::BIND_TEXTURES:
222 new(&bindTextures) decltype(bindTextures);
223 bindTextures = std::move(rhs.bindTextures);
226 case CommandType::BIND_PIPELINE:
228 bindPipeline = rhs.bindPipeline;
231 case CommandType::DRAW:
233 draw.type = rhs.draw.type;
234 draw.draw = rhs.draw.draw;
237 case CommandType::DRAW_INDEXED:
239 draw.type = rhs.draw.type;
240 draw.drawIndexed = rhs.draw.drawIndexed;
243 case CommandType::DRAW_INDEXED_INDIRECT:
245 draw.type = rhs.draw.type;
246 draw.drawIndexedIndirect = rhs.draw.drawIndexedIndirect;
249 case CommandType::FLUSH:
254 case CommandType::SET_SCISSOR:
256 scissor.region = rhs.scissor.region;
259 case CommandType::SET_SCISSOR_TEST:
261 scissorTest.enable = rhs.scissorTest.enable;
264 case CommandType::SET_VIEWPORT:
266 viewport.region = rhs.viewport.region;
273 CommandType type{CommandType::FLUSH}; ///< Type of command
279 std::vector<Graphics::TextureBinding> textureBindings;
282 // BindSampler command
285 std::vector<Graphics::SamplerBinding> samplerBindings;
290 using Binding = GLES::VertexBufferBindingDescriptor;
291 std::vector<Binding> vertexBufferBindings;
294 struct : public IndexBufferBindingDescriptor
300 std::vector<UniformBufferBindingDescriptor> uniformBufferBindings{};
301 UniformBufferBindingDescriptor standaloneUniformsBufferBinding{};
302 } bindUniformBuffers;
306 const GLES::Pipeline* pipeline{nullptr};
309 struct : public DrawCallDescriptor
315 Graphics::Rect2D region;
325 Graphics::Viewport region;
330 using CommandBufferResource = Resource<Graphics::CommandBuffer, Graphics::CommandBufferCreateInfo>;
332 class CommandBuffer : public CommandBufferResource
335 CommandBuffer(const Graphics::CommandBufferCreateInfo& createInfo, EglGraphicsController& controller);
337 ~CommandBuffer() override;
339 void BindVertexBuffers(uint32_t firstBinding,
340 std::vector<const Graphics::Buffer*> buffers,
341 std::vector<uint32_t> offsets) override;
343 void BindUniformBuffers(const std::vector<Graphics::UniformBufferBinding>& bindings) override;
345 void BindPipeline(const Graphics::Pipeline& pipeline) override;
347 void BindTextures(std::vector<TextureBinding>& textureBindings) override;
349 void BindSamplers(std::vector<SamplerBinding>& samplerBindings) override;
351 void BindPushConstants(void* data,
353 uint32_t binding) override;
355 void BindIndexBuffer(const Graphics::Buffer& buffer,
357 Format format) override;
359 void BeginRenderPass(
360 Graphics::RenderPass& renderPass,
361 Graphics::RenderTarget& renderTarget,
363 std::vector<ClearValue> clearValues) override;
366 * @brief Ends current render pass
368 * This command must be issued in order to finalize the render pass.
369 * It's up to the implementation whether anything has to be done but
370 * the Controller may use end RP marker in order to resolve resource
371 * dependencies (for example, to know when target texture is ready
372 * before passing it to another render pass).
374 void EndRenderPass() override;
377 uint32_t vertexCount,
378 uint32_t instanceCount,
379 uint32_t firstVertex,
380 uint32_t firstInstance) override;
384 uint32_t instanceCount,
386 int32_t vertexOffset,
387 uint32_t firstInstance) override;
389 void DrawIndexedIndirect(
390 Graphics::Buffer& buffer,
393 uint32_t stride) override;
395 void Reset() override;
397 void SetScissor(Graphics::Rect2D value) override;
399 void SetScissorTestEnable(bool value) override;
401 void SetViewport(Viewport value) override;
403 void SetViewportEnable(bool value) override;
405 [[nodiscard]] const std::vector<Command>& GetCommands() const;
407 void DestroyResource() override;
408 bool InitializeResource() override;
410 void DiscardResource() override;
413 std::vector<Command> mCommands;
415 } // namespace Dali::Graphics::GLES