auto offset = ubo->GetCurrentOffset();
auto retval = Graphics::UniquePtr<UniformBufferView>(UniformBufferView::TryRecycle(oldView, *ubo.get(), offset));
- // make sure new offset will meet alignment requirements
- uint32_t alignedSize = ubo->AlignSize(size);
- ubo->IncrementOffsetBy(alignedSize);
+ ubo->IncrementOffsetBy(size);
return retval;
}
namespace Dali::Internal::Render
{
+namespace
+{
// GPU UBOs need to be double-buffered in order to avoid stalling the CPU during mapping/unmapping
constexpr uint32_t INTERNAL_UBO_BUFFER_COUNT = 2u;
constexpr uint32_t DEFAUT_MEMORY_ALIGNMENT{1};
+/**
+ * Align size to the current block size.
+ */
+int AlignSize(int size, int align)
+{
+ return (size % align == 0) ? size : ((size / align) + 1) * align;
+}
+
+} // namespace
+
Graphics::UniquePtr<UniformBufferV2> UniformBufferV2::New(Dali::Graphics::Controller* controller, bool emulated, uint32_t alignment)
{
return Graphics::UniquePtr<UniformBufferV2>(new UniformBufferV2(controller, emulated, alignment));
{
if(mEmulated && !mBufferList.empty())
{
- mBufferList[mCurrentGraphicsBufferIndex].currentOffset += value; // reset offset
+ mBufferList[mCurrentGraphicsBufferIndex].currentOffset += AlignSize(value, mBlockAlignment); // reset offset
return mBufferList[mCurrentGraphicsBufferIndex].currentOffset;
} // GPU
else if(!mBufferList.empty())
{
- mBufferList[mCurrentGraphicsBufferIndex].currentOffset += value; // reset offset
+ mBufferList[mCurrentGraphicsBufferIndex].currentOffset += AlignSize(value, mBlockAlignment); // reset offset
return mBufferList[mCurrentGraphicsBufferIndex].currentOffset;
}
DALI_LOG_INFO(gUniformBufferLogFilter, Debug::General, "Buffer should be allocated before incrementing offset\n");
void Rollback();
/**
- * Align size to the current block size
+ * Increase offset by value.
+ * Note that new offset will meet alignment requirements
*/
- uint32_t AlignSize(uint32_t size) const
- {
- if(size % mBlockAlignment != 0)
- {
- size = ((size / mBlockAlignment) + 1) * mBlockAlignment;
- }
- return size;
- }
-
uint32_t IncrementOffsetBy(uint32_t value);
bool MemoryCompare(void* data, uint32_t offset, uint32_t size);