Per each Renderer::Render time, we create UniformBufferView the number of uniform blocks,
and destroy at that time.
Since we create & destroy UboView very frequency every frame, we'd better
keep this memory as pool system.
Moreover, let we remove some useless values and operations relative with
UBO View.
Let we make UboView.Write's offset parameter is relative of
View itself's offset, instead of UboBuffer's offset.
It will reduce useless offset getter calling
Change-Id: I583728ec1bd4cf0a1a34f6002a647f4f15a32e12
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
#define DALI_INTERNAL_MEMORY_POOL_OBJECT_ALLOCATOR_H
/*
- * Copyright (c) 2024 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2025 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.
*/
// EXTERNAL INCLUDES
+#include <dali/public-api/common/dali-common.h>
#include <memory> ///< for std::unique_ptr
// INTERNAL INCLUDES
// Ensure to release memory pool
Render::Renderer::ResetMemoryPool();
Render::Texture::ResetMemoryPool();
+ Render::UniformBufferView::ResetMemoryPool();
}
void RenderManager::ContextDestroyed()
template<>
void Renderer::WriteUniform<Matrix3>(Render::UniformBufferView& ubo, const Graphics::UniformInfo& uniformInfo, const Matrix3& matrix)
{
- auto dst = ubo.GetOffset() + uniformInfo.offset;
- uint32_t rowStride = 3 * sizeof(float); // Gles2 standalone buffer is tightly packed
+ const auto dst = uniformInfo.offset;
+ uint32_t rowStride = 3 * sizeof(float); // Gles2 standalone buffer is tightly packed
if(uniformInfo.bufferIndex > 0)
{
rowStride = uniformInfo.matrixStride; // Gles3/Vulkan uniform block, mat3 row is padded to vec4
void Renderer::WriteUniform(Render::UniformBufferView& ubo, const Graphics::UniformInfo& uniformInfo, const void* data, uint32_t size)
{
- ubo.Write(data, size, ubo.GetOffset() + uniformInfo.offset);
+ ubo.Write(data, size, uniformInfo.offset);
}
void Renderer::FillUniformBuffer(Program& program,
return;
}
- int arrayIndex = uniform.arrayIndex;
- auto dst = ubo->GetOffset() + uniform.uniformOffset;
- const auto dest = dst + uniform.arrayElementStride * arrayIndex;
+ const auto dest = uniform.uniformOffset + uniform.arrayElementStride * uniform.arrayIndex;
const auto valueAddress = propertyValue->GetValueAddress(updateBufferIndex);
UniformBufferView& ubo,
BufferIndex renderBufferIndex)
{
- int arrayIndex = uniform.arrayIndex;
- auto dst = ubo.GetOffset() + uniform.uniformOffset;
- const auto dest = dst + uniform.arrayElementStride * arrayIndex;
+ const auto dest = uniform.uniformOffset + uniform.arrayElementStride * uniform.arrayIndex;
const auto valueAddress = propertyValue->GetValueAddress(renderBufferIndex);
/*
- * Copyright (c) 2024 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2025 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.
// Use current offset and increment it after
auto offset = ubo->GetCurrentOffset();
- auto retval = Graphics::UniquePtr<UniformBufferView>(new UniformBufferView(*ubo.get(), offset, size));
+ auto retval = Graphics::UniquePtr<UniformBufferView>(UniformBufferView::New(*ubo.get(), offset));
// make sure new offset will meet alignment requirements
uint32_t alignedSize = ubo->AlignSize(size);
/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2025 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 <dali/internal/render/renderers/uniform-buffer-view.h>
// INTERNAL INCLUDES
+#include <dali/internal/common/memory-pool-object-allocator.h>
#include <dali/internal/render/renderers/uniform-buffer.h>
namespace Dali::Internal::Render
{
-UniformBufferView::UniformBufferView(UniformBufferV2& ubo, uint32_t offset, size_t size)
+namespace
+{
+// Memory pool used to allocate new uniform buffer view. Memory used by this pool will be released when process dies
+Dali::Internal::MemoryPoolObjectAllocator<Dali::Internal::Render::UniformBufferView>& GetUboViewMemoryPool()
+{
+ static Dali::Internal::MemoryPoolObjectAllocator<Dali::Internal::Render::UniformBufferView> gUboViewMemoryPool;
+ return gUboViewMemoryPool;
+}
+} // namespace
+
+UniformBufferView* UniformBufferView::New(UniformBufferV2& ubo, uint32_t offset)
+{
+ return new(GetUboViewMemoryPool().AllocateRaw()) UniformBufferView(ubo, offset);
+}
+
+void UniformBufferView::ResetMemoryPool()
+{
+ GetUboViewMemoryPool().ResetMemoryPool();
+}
+
+UniformBufferView::UniformBufferView(UniformBufferV2& ubo, uint32_t offset)
: mUniformBuffer(&ubo),
- mOffset(offset),
- mSize(size)
+ mOffset(offset)
{
}
UniformBufferView::~UniformBufferView() = default;
+void UniformBufferView::operator delete(void* ptr)
+{
+ GetUboViewMemoryPool().Free(static_cast<UniformBufferView*>(ptr));
+}
+
void UniformBufferView::Write(const void* data, uint32_t size, uint32_t offset)
{
// Write into mapped buffer
- mUniformBuffer->Write(data, size, offset);
+ mUniformBuffer->Write(data, size, offset + mOffset);
}
Graphics::Buffer* UniformBufferView::GetBuffer() const
#define DALI_INTERNAL_UNIFORM_BUFFER_VIEW_H
/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2025 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.
class UniformBufferView
{
public:
- UniformBufferView(UniformBufferV2& ubo, uint32_t offset, size_t size);
+ /**
+ * Construct a new UniformBufferView.
+ * @param[in] ubo The buffer for this view
+ * @param[in] offset The offset of this view from ubo
+ * @return A new UniformBufferView
+ */
+ static UniformBufferView* New(UniformBufferV2& ubo, uint32_t offset);
+
+ /**
+ * Clear memory pool of UniformBufferView.
+ * This should be called at the begin of Core.
+ * (Since Core could be recreated, we need to reset the memory pool.)
+ * After this API call, all UniformBufferView classes are invalid.
+ */
+ static void ResetMemoryPool();
~UniformBufferView();
+ /**
+ * Overriden delete operator
+ * Deletes the UniformBufferView from its global memory pool
+ */
+ void operator delete(void* ptr);
+
/**
* @brief Writes data into the current uniform buffer view.
* @note We prefer to call UniformBuffer::ReadyToLockUniformBuffer before call Write API.
*
* @param[in] data pointer to the source data
* @param[in] size size of source data
- * @param[in] offset destination offset
+ * @param[in] offset destination offset from the offset of this view
*/
void Write(const void* data, uint32_t size, uint32_t offset);
- /**
- * @brief Returns the size of the view
- *
- * @return size of view
- */
- [[nodiscard]] uint32_t GetSize() const
- {
- return mSize;
- }
-
/**
* @brief Returns the offset within the UBO
* @return Offset
*/
[[nodiscard]] Graphics::Buffer* GetBuffer() const;
+protected:
+ /**
+ * Protected constructor. See New()
+ */
+ UniformBufferView(UniformBufferV2& ubo, uint32_t offset);
+
private:
UniformBufferV2* mUniformBuffer{nullptr}; ///< UniformBuffer that the view views
uint32_t mOffset{0u}; ///< Offset within the buffer
- size_t mSize{0u}; ///< Size of view
};
} // Namespace Internal::Render
} // Namespace Dali