#define DALI_GRAPHICS_GLES_COMMAND_BUFFER_H
/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include "gles-graphics-types.h"
#include "gles-sync-object.h"
+#include <cstring>
+
namespace Dali::Graphics::GLES
{
class Pipeline;
class RenderPass;
class Framebuffer;
class CommandBuffer;
+class CommandPool;
enum class CommandType
{
FLUSH,
SET_DEPTH_COMPARE_OP,
SET_DEPTH_TEST_ENABLE,
SET_DEPTH_WRITE_ENABLE,
+ DRAW_NATIVE,
};
/**
*/
struct Command
{
- Command() = delete;
-
- Command(CommandType commandType)
+ Command()
{
- type = commandType;
- switch(type)
- {
- case CommandType::BIND_VERTEX_BUFFERS:
- {
- new(&bindVertexBuffers) decltype(bindVertexBuffers);
- break;
- }
- case CommandType::BIND_TEXTURES:
- {
- new(&bindTextures) decltype(bindTextures);
- break;
- }
- case CommandType::BEGIN_RENDERPASS:
- {
- // run destructor
- new(&beginRenderPass) decltype(beginRenderPass);
- break;
- }
- default:
- {
- }
- }
}
- ~Command()
+ explicit Command(CommandType commandType)
{
- switch(type)
- {
- case CommandType::BIND_VERTEX_BUFFERS:
- {
- InvokeDestructor(bindVertexBuffers);
- break;
- }
- case CommandType::BIND_TEXTURES:
- {
- InvokeDestructor(bindTextures);
- break;
- }
- case CommandType::BEGIN_RENDERPASS:
- {
- // run destructor
- InvokeDestructor(beginRenderPass);
- break;
- }
- default:
- {
- }
- }
+ type = commandType;
}
+ ~Command() = default;
+
/**
* @brief Copy constructor
* @param[in] rhs Command
*/
- Command(const Command& rhs)
- {
- switch(rhs.type)
- {
- case CommandType::BIND_VERTEX_BUFFERS:
- {
- new(&bindVertexBuffers) decltype(bindVertexBuffers);
- bindVertexBuffers = rhs.bindVertexBuffers;
- break;
- }
- case CommandType::BIND_INDEX_BUFFER:
- {
- bindIndexBuffer = rhs.bindIndexBuffer;
- break;
- }
- case CommandType::BIND_SAMPLERS:
- {
- bindSamplers = rhs.bindSamplers;
- break;
- }
- case CommandType::BIND_TEXTURES:
- {
- new(&bindTextures) decltype(bindTextures);
- bindTextures = rhs.bindTextures;
- break;
- }
- case CommandType::BIND_PIPELINE:
- {
- bindPipeline = rhs.bindPipeline;
- break;
- }
- case CommandType::BIND_UNIFORM_BUFFER:
- {
- bindUniformBuffers = rhs.bindUniformBuffers;
- break;
- }
- case CommandType::DRAW:
- {
- draw.type = rhs.draw.type;
- draw.draw = rhs.draw.draw;
- break;
- }
- case CommandType::DRAW_INDEXED:
- {
- draw.type = rhs.draw.type;
- draw.drawIndexed = rhs.draw.drawIndexed;
- break;
- }
- case CommandType::DRAW_INDEXED_INDIRECT:
- {
- draw.type = rhs.draw.type;
- draw.drawIndexedIndirect = rhs.draw.drawIndexedIndirect;
- break;
- }
- case CommandType::BEGIN_RENDERPASS:
- {
- new(&beginRenderPass) BeginRenderPassDescriptor(rhs.beginRenderPass);
- break;
- }
- case CommandType::END_RENDERPASS:
- {
- endRenderPass.syncObject = rhs.endRenderPass.syncObject;
- break;
- }
- case CommandType::EXECUTE_COMMAND_BUFFERS:
- {
- executeCommandBuffers = rhs.executeCommandBuffers;
- break;
- }
- case CommandType::FLUSH:
- {
- // Nothing to do
- break;
- }
- case CommandType::SET_SCISSOR:
- {
- scissor.region = rhs.scissor.region;
- break;
- }
- case CommandType::SET_SCISSOR_TEST:
- {
- scissorTest.enable = rhs.scissorTest.enable;
- break;
- }
- case CommandType::SET_VIEWPORT:
- {
- viewport.region = rhs.viewport.region;
- break;
- }
- case CommandType::PRESENT_RENDER_TARGET:
- {
- presentRenderTarget = rhs.presentRenderTarget;
- break;
- }
- case CommandType::SET_COLOR_MASK:
- {
- colorMask.enabled = rhs.colorMask.enabled;
- break;
- }
- case CommandType::CLEAR_STENCIL_BUFFER:
- {
- break;
- }
- case CommandType::CLEAR_DEPTH_BUFFER:
- {
- break;
- }
- case CommandType::SET_STENCIL_TEST_ENABLE:
- {
- stencilTest.enabled = rhs.stencilTest.enabled;
- break;
- }
- case CommandType::SET_STENCIL_FUNC:
- {
- stencilFunc.compareMask = rhs.stencilFunc.compareMask;
- stencilFunc.compareOp = rhs.stencilFunc.compareOp;
- stencilFunc.reference = rhs.stencilFunc.reference;
- break;
- }
- case CommandType::SET_STENCIL_WRITE_MASK:
- {
- stencilWriteMask.mask = rhs.stencilWriteMask.mask;
- break;
- }
- case CommandType::SET_STENCIL_OP:
- {
- stencilOp.failOp = rhs.stencilOp.failOp;
- stencilOp.depthFailOp = rhs.stencilOp.depthFailOp;
- stencilOp.passOp = rhs.stencilOp.passOp;
- break;
- }
-
- case CommandType::SET_DEPTH_COMPARE_OP:
- {
- depth.compareOp = rhs.depth.compareOp;
- break;
- }
- case CommandType::SET_DEPTH_TEST_ENABLE:
- {
- depth.testEnabled = rhs.depth.testEnabled;
- break;
- }
- case CommandType::SET_DEPTH_WRITE_ENABLE:
- {
- depth.writeEnabled = rhs.depth.writeEnabled;
- break;
- }
- }
- type = rhs.type;
- }
-
- /**
- * @brief Move constructor
- * @param[in] rhs Command
- */
- Command(Command&& rhs) noexcept
- {
- switch(rhs.type)
- {
- case CommandType::BIND_VERTEX_BUFFERS:
- {
- new(&bindVertexBuffers) decltype(bindVertexBuffers);
- bindVertexBuffers = std::move(rhs.bindVertexBuffers);
- break;
- }
- case CommandType::BIND_INDEX_BUFFER:
- {
- bindIndexBuffer = rhs.bindIndexBuffer;
- break;
- }
- case CommandType::BIND_UNIFORM_BUFFER:
- {
- bindUniformBuffers = std::move(rhs.bindUniformBuffers);
- break;
- }
- case CommandType::BIND_SAMPLERS:
- {
- bindSamplers = std::move(rhs.bindSamplers);
- break;
- }
- case CommandType::BIND_TEXTURES:
- {
- new(&bindTextures) decltype(bindTextures);
- bindTextures = std::move(rhs.bindTextures);
- break;
- }
- case CommandType::BIND_PIPELINE:
- {
- bindPipeline = rhs.bindPipeline;
- break;
- }
- case CommandType::DRAW:
- {
- draw.type = rhs.draw.type;
- draw.draw = rhs.draw.draw;
- break;
- }
- case CommandType::DRAW_INDEXED:
- {
- draw.type = rhs.draw.type;
- draw.drawIndexed = rhs.draw.drawIndexed;
- break;
- }
- case CommandType::DRAW_INDEXED_INDIRECT:
- {
- draw.type = rhs.draw.type;
- draw.drawIndexedIndirect = rhs.draw.drawIndexedIndirect;
- break;
- }
- case CommandType::BEGIN_RENDERPASS:
- {
- new(&beginRenderPass) BeginRenderPassDescriptor(std::move(rhs.beginRenderPass));
- break;
- }
- case CommandType::END_RENDERPASS:
- {
- endRenderPass.syncObject = rhs.endRenderPass.syncObject;
- break;
- }
- case CommandType::EXECUTE_COMMAND_BUFFERS:
- {
- executeCommandBuffers = std::move(rhs.executeCommandBuffers);
- break;
- }
- case CommandType::FLUSH:
- {
- // Nothing to do
- break;
- }
- case CommandType::SET_SCISSOR:
- {
- scissor.region = rhs.scissor.region;
- break;
- }
- case CommandType::SET_SCISSOR_TEST:
- {
- scissorTest.enable = rhs.scissorTest.enable;
- break;
- }
- case CommandType::SET_VIEWPORT:
- {
- viewport.region = rhs.viewport.region;
- break;
- }
- case CommandType::PRESENT_RENDER_TARGET:
- {
- presentRenderTarget = rhs.presentRenderTarget;
- break;
- }
- case CommandType::SET_COLOR_MASK:
- {
- colorMask.enabled = rhs.colorMask.enabled;
- break;
- }
- case CommandType::CLEAR_STENCIL_BUFFER:
- {
- break;
- }
- case CommandType::CLEAR_DEPTH_BUFFER:
- {
- break;
- }
- case CommandType::SET_STENCIL_TEST_ENABLE:
- {
- stencilTest.enabled = rhs.stencilTest.enabled;
- break;
- }
- case CommandType::SET_STENCIL_FUNC:
- {
- stencilFunc.compareMask = rhs.stencilFunc.compareMask;
- stencilFunc.compareOp = rhs.stencilFunc.compareOp;
- stencilFunc.reference = rhs.stencilFunc.reference;
- break;
- }
- case CommandType::SET_STENCIL_WRITE_MASK:
- {
- stencilWriteMask.mask = rhs.stencilWriteMask.mask;
- break;
- }
- case CommandType::SET_STENCIL_OP:
- {
- stencilOp.failOp = rhs.stencilOp.failOp;
- stencilOp.depthFailOp = rhs.stencilOp.depthFailOp;
- stencilOp.passOp = rhs.stencilOp.passOp;
- break;
- }
-
- case CommandType::SET_DEPTH_COMPARE_OP:
- {
- depth.compareOp = rhs.depth.compareOp;
- break;
- }
- case CommandType::SET_DEPTH_TEST_ENABLE:
- {
- depth.testEnabled = rhs.depth.testEnabled;
- break;
- }
- case CommandType::SET_DEPTH_WRITE_ENABLE:
- {
- depth.writeEnabled = rhs.depth.writeEnabled;
- break;
- }
- }
- type = rhs.type;
- }
+ Command(const Command& rhs) = default;
+ Command& operator=(const Command& rhs) = default;
+ Command(Command&& rhs) noexcept = delete;
+ Command& operator=(Command&& rhs) = delete;
CommandType type{CommandType::FLUSH}; ///< Type of command
{
struct
{
- std::vector<Graphics::TextureBinding> textureBindings;
+ IndirectPtr<Graphics::TextureBinding> textureBindings;
+ uint32_t textureBindingsCount;
} bindTextures{};
// BindSampler command
struct
{
- std::vector<Graphics::SamplerBinding> samplerBindings;
+ IndirectPtr<Graphics::SamplerBinding> samplerBindings;
+ uint32_t samplerBindingsCount;
} bindSamplers;
struct
{
using Binding = GLES::VertexBufferBindingDescriptor;
- std::vector<Binding> vertexBufferBindings;
+ IndirectPtr<Binding> vertexBufferBindings;
+ uint32_t vertexBufferBindingsCount;
} bindVertexBuffers;
struct : public IndexBufferBindingDescriptor
struct
{
- std::vector<UniformBufferBindingDescriptor> uniformBufferBindings{};
+ IndirectPtr<UniformBufferBindingDescriptor> uniformBufferBindings;
+ uint32_t uniformBufferBindingsCount;
UniformBufferBindingDescriptor standaloneUniformsBufferBinding{};
} bindUniformBuffers;
struct
{
- std::vector<const GLES::CommandBuffer*> buffers;
+ IndirectPtr<const GLES::CommandBuffer*> buffers;
+ uint32_t buffersCount;
} executeCommandBuffers;
struct
{
bool enabled;
} colorMask;
+
+ struct
+ {
+ DrawNativeInfo drawNativeInfo;
+ } drawNative;
};
};
/**
* @copydoc Dali::Graphics::CommandBuffer::BindVertexBuffers
*/
- void BindVertexBuffers(uint32_t firstBinding,
- std::vector<const Graphics::Buffer*> buffers,
- std::vector<uint32_t> offsets) override;
+ void BindVertexBuffers(uint32_t firstBinding,
+ const std::vector<const Graphics::Buffer*>& buffers,
+ const std::vector<uint32_t>& offsets) override;
/**
* @copydoc Dali::Graphics::CommandBuffer::BindUniformBuffers
/**
* @copydoc Dali::Graphics::CommandBuffer::BindTextures
*/
- void BindTextures(std::vector<TextureBinding>& textureBindings) override;
+ void BindTextures(const std::vector<TextureBinding>& textureBindings) override;
/**
* @copydoc Dali::Graphics::CommandBuffer::BindSamplers
*/
- void BindSamplers(std::vector<SamplerBinding>& samplerBindings) override;
+ void BindSamplers(const std::vector<SamplerBinding>& samplerBindings) override;
/**
* @copydoc Dali::Graphics::CommandBuffer::BindPushConstants
* @copydoc Dali::Graphics::CommandBuffer::BeginRenderPass
*/
void BeginRenderPass(
- Graphics::RenderPass* renderPass,
- Graphics::RenderTarget* renderTarget,
- Rect2D renderArea,
- std::vector<ClearValue> clearValues) override;
+ Graphics::RenderPass* renderPass,
+ Graphics::RenderTarget* renderTarget,
+ Rect2D renderArea,
+ const std::vector<ClearValue>& clearValues) override;
/**
* @copydoc Dali::Graphics::CommandBuffer::EndRenderPass
uint32_t stride) override;
/**
+ * @copydoc Dali::Graphics::CommandBuffer::DrawNative
+ */
+ void DrawNative(const DrawNativeInfo* drawNativeInfo) override;
+
+ /**
* @copydoc Dali::Graphics::CommandBuffer::Reset
*/
void Reset() override;
*/
void PresentRenderTarget(GLES::RenderTarget* renderTarget);
- [[nodiscard]] const std::vector<Command>& GetCommands() const;
+ /**
+ * @brief Returns pointer to the list of command and size of the list
+ *
+ * @param[out] size Size of the list
+ * @return Valid pointer to the list of commands
+ */
+ [[nodiscard]] const Command* GetCommands(uint32_t& size) const;
/**
* @brief Destroy the associated resources
*/
void DiscardResource() override;
+ // Get the total memory usage of this command buffer
+ std::size_t GetCapacity();
+
private:
- std::vector<Command> mCommands; ///< List of commands in this command buffer
+ std::unique_ptr<CommandPool> mCommandPool; ///< Pool of commands and transient memory
};
} // namespace Dali::Graphics::GLES