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.h>
25 #include "egl-graphics-controller.h"
26 #include "gles-graphics-pipeline.h"
27 #include "gles-graphics-types.h"
29 namespace Dali::Graphics::GLES
36 enum class CommandType
50 * Command structure allocates memory to store a single command
63 * @brief Copy constructor
64 * @param[in] rhs Command
66 Command(const Command& rhs)
70 case CommandType::BIND_VERTEX_BUFFERS:
72 bindVertexBuffers = rhs.bindVertexBuffers;
75 case CommandType::BIND_INDEX_BUFFER:
77 bindIndexBuffer = rhs.bindIndexBuffer;
80 case CommandType::BIND_SAMPLERS:
82 bindSamplers = rhs.bindSamplers;
85 case CommandType::BIND_TEXTURES:
87 bindTextures = rhs.bindTextures;
90 case CommandType::BIND_PIPELINE:
92 bindPipeline = rhs.bindPipeline;
95 case CommandType::DRAW:
97 draw.type = rhs.draw.type;
98 draw.draw = rhs.draw.draw;
101 case CommandType::DRAW_INDEXED:
103 draw.type = rhs.draw.type;
104 draw.drawIndexed = rhs.draw.drawIndexed;
107 case CommandType::DRAW_INDEXED_INDIRECT:
109 draw.type = rhs.draw.type;
110 draw.drawIndexedIndirect = rhs.draw.drawIndexedIndirect;
113 case CommandType::FLUSH:
123 * @brief Copy constructor
124 * @param[in] rhs Command
126 Command(Command&& rhs) noexcept
130 case CommandType::BIND_VERTEX_BUFFERS:
132 bindVertexBuffers = std::move(rhs.bindVertexBuffers);
135 case CommandType::BIND_INDEX_BUFFER:
137 bindIndexBuffer = rhs.bindIndexBuffer;
140 case CommandType::BIND_SAMPLERS:
142 bindSamplers = std::move(rhs.bindSamplers);
145 case CommandType::BIND_TEXTURES:
147 bindTextures = std::move(rhs.bindTextures);
150 case CommandType::BIND_PIPELINE:
152 bindPipeline = rhs.bindPipeline;
155 case CommandType::DRAW:
157 draw.type = rhs.draw.type;
158 draw.draw = rhs.draw.draw;
161 case CommandType::DRAW_INDEXED:
163 draw.type = rhs.draw.type;
164 draw.drawIndexed = rhs.draw.drawIndexed;
167 case CommandType::DRAW_INDEXED_INDIRECT:
169 draw.type = rhs.draw.type;
170 draw.drawIndexedIndirect = rhs.draw.drawIndexedIndirect;
173 case CommandType::FLUSH:
182 CommandType type{CommandType::FLUSH}; ///< Type of command
188 std::vector<Graphics::TextureBinding> textureBindings;
191 // BindSampler command
194 std::vector<Graphics::SamplerBinding> samplerBindings;
199 using Binding = GLES::VertexBufferBindingDescriptor;
200 std::vector<Binding> vertexBufferBindings;
203 struct : public IndexBufferBindingDescriptor
209 const GLES::Pipeline* pipeline{nullptr};
212 struct : public DrawCallDescriptor
218 using CommandBufferResource = Resource<Graphics::CommandBuffer, Graphics::CommandBufferCreateInfo>;
220 class CommandBuffer : public CommandBufferResource
223 CommandBuffer(const Graphics::CommandBufferCreateInfo& createInfo, EglGraphicsController& controller)
224 : CommandBufferResource(createInfo, controller)
228 ~CommandBuffer() override = default;
230 void BindVertexBuffers(uint32_t firstBinding,
231 std::vector<const Graphics::Buffer*> buffers,
232 std::vector<uint32_t> offsets) override
234 mCommands.emplace_back();
235 mCommands.back().type = CommandType::BIND_VERTEX_BUFFERS;
236 auto& bindings = mCommands.back().bindVertexBuffers.vertexBufferBindings;
237 if(bindings.size() < firstBinding + buffers.size())
239 bindings.resize(firstBinding + buffers.size());
240 auto index = firstBinding;
241 for(auto& buf : buffers)
243 bindings[index].buffer = static_cast<const GLES::Buffer*>(buf);
244 bindings[index].offset = offsets[index - firstBinding];
250 void BindUniformBuffers(const std::vector<Graphics::UniformBufferBinding>& bindings) override
254 void BindPipeline(const Graphics::Pipeline& pipeline) override
256 mCommands.emplace_back();
257 mCommands.back().type = CommandType::BIND_PIPELINE;
258 mCommands.back().bindPipeline.pipeline = static_cast<const GLES::Pipeline*>(&pipeline);
261 void BindTextures(std::vector<TextureBinding>& textureBindings) override
263 mCommands.emplace_back();
264 mCommands.back().type = CommandType::BIND_TEXTURES;
265 mCommands.back().bindTextures.textureBindings = std::move(textureBindings);
268 void BindSamplers(std::vector<SamplerBinding>& samplerBindings) override
270 mCommands.emplace_back();
271 mCommands.back().bindSamplers.samplerBindings = std::move(samplerBindings);
274 void BindPushConstants(void* data,
276 uint32_t binding) override
280 void BindIndexBuffer(const Graphics::Buffer& buffer,
282 Format format) override
284 mCommands.emplace_back();
285 mCommands.back().type = CommandType::BIND_INDEX_BUFFER;
286 mCommands.back().bindIndexBuffer.buffer = static_cast<const GLES::Buffer*>(&buffer);
287 mCommands.back().bindIndexBuffer.offset = offset;
288 mCommands.back().bindIndexBuffer.format = format;
291 void BeginRenderPass(
292 Graphics::RenderPass& renderPass,
293 Graphics::RenderTarget& renderTarget,
295 std::vector<ClearValue> clearValues) override
300 * @brief Ends current render pass
302 * This command must be issued in order to finalize the render pass.
303 * It's up to the implementation whether anything has to be done but
304 * the Controller may use end RP marker in order to resolve resource
305 * dependencies (for example, to know when target texture is ready
306 * before passing it to another render pass).
308 void EndRenderPass() override
313 uint32_t vertexCount,
314 uint32_t instanceCount,
315 uint32_t firstVertex,
316 uint32_t firstInstance) override
318 mCommands.emplace_back();
319 mCommands.back().type = CommandType::DRAW;
320 auto& cmd = mCommands.back().draw;
321 cmd.type = DrawCallDescriptor::Type::DRAW;
322 cmd.draw.vertexCount = vertexCount;
323 cmd.draw.instanceCount = instanceCount;
324 cmd.draw.firstInstance = firstInstance;
325 cmd.draw.firstVertex = firstVertex;
330 uint32_t instanceCount,
332 int32_t vertexOffset,
333 uint32_t firstInstance) override
335 mCommands.emplace_back();
336 mCommands.back().type = CommandType::DRAW_INDEXED;
337 auto& cmd = mCommands.back().draw;
338 cmd.type = DrawCallDescriptor::Type::DRAW_INDEXED;
339 cmd.drawIndexed.firstIndex = firstIndex;
340 cmd.drawIndexed.firstInstance = firstInstance;
341 cmd.drawIndexed.indexCount = indexCount;
342 cmd.drawIndexed.vertexOffset = vertexOffset;
343 cmd.drawIndexed.instanceCount = instanceCount;
346 void DrawIndexedIndirect(
347 Graphics::Buffer& buffer,
350 uint32_t stride) override
352 mCommands.emplace_back();
353 mCommands.back().type = CommandType::DRAW_INDEXED_INDIRECT;
354 auto& cmd = mCommands.back().draw;
355 cmd.type = DrawCallDescriptor::Type::DRAW_INDEXED_INDIRECT;
356 cmd.drawIndexedIndirect.buffer = static_cast<const GLES::Buffer*>(&buffer);
357 cmd.drawIndexedIndirect.offset = offset;
358 cmd.drawIndexedIndirect.drawCount = drawCount;
359 cmd.drawIndexedIndirect.stride = stride;
362 void Reset(Graphics::CommandBuffer& commandBuffer) override
367 void SetScissor(Extent2D value) override
371 void SetScissorTestEnable(bool value) override
375 void SetViewport(Viewport value) override
379 void SetViewportEnable(bool value) override
383 [[nodiscard]] const std::vector<Command>& GetCommands() const
388 void DestroyResource() override
393 bool InitializeResource() override
399 void DiscardResource() override
405 std::vector<Command> mCommands;
407 } // namespace Dali::Graphics::GLES