Fix CommandPool reallocation bugs 45/268645/3
authorEunki, Hong <eunkiki.hong@samsung.com>
Tue, 28 Dec 2021 10:49:36 +0000 (19:49 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Wed, 5 Jan 2022 07:30:57 +0000 (16:30 +0900)
When fixedCapacity is > 0 and data.size() == fixedCapacity,
There was some logical bugs when data.size() == offset + count.

We can hold 'data.size()'`s data, and after Allocate(count),
we will hold 'offset + count'`s data.
So we should reallocate only data.size() < offset + count.

+

Furthermore, We just set default Command Pool Increment as 32kb exactly.
Previous code increase 32 * sizeof(Command) kb = 2MB for each command pool.

Change-Id: I5e845839057bc75c40c275e884b7677fe2c4d812
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
dali/internal/graphics/gles-impl/gles-graphics-command-buffer.cpp

index 7cc24f8..98f4830 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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.
@@ -31,9 +31,9 @@ namespace Dali::Graphics::GLES
 {
 class CommandPool
 {
-  static const uint32_t COMMAND_POOL_DEFAULT_INCREMENT = 1024 * 32; // 32kb banks
-  static const uint32_t MEMORY_POOL_DEFAULT_INCREMENT  = 1024;      // 4kb memory pool increment
-  static const uint32_t MEMORY_POOL_DEFAULT_ALIGNMENT  = 64;        // 64bytes alignment
+  static constexpr uint32_t COMMAND_POOL_DEFAULT_INCREMENT = 1024 * 32 / sizeof(Command); // 32kb banks
+  static const     uint32_t MEMORY_POOL_DEFAULT_INCREMENT  = 1024;                        // 1kb memory pool increment
+  static const     uint32_t MEMORY_POOL_DEFAULT_ALIGNMENT  = 64;                          // 64bytes alignment
 
   template<class T>
   struct Block
@@ -94,17 +94,25 @@ class CommandPool
 
     IndirectPtr<T> Allocate(uint32_t count)
     {
-      // set fixed capacity
-      if(fixedCapacity && data.size() != fixedCapacity)
+      // Set fixed capacity
+      if(fixedCapacity)
       {
-        data.resize(fixedCapacity);
-        totalCapacity = data.size();
+        // resize data size when capacity is not setuped.
+        // Note if totalCapacity is bigger than fixedCapacity,
+        // just skip here and resize dynamically
+        if(DALI_UNLIKELY(totalCapacity < fixedCapacity))
+        {
+          data.resize(fixedCapacity);
+          totalCapacity = data.size();
+        }
       }
 
-      // or resize dynamically
-      else if(data.size() <= offset + count)
+      // Resize dynamically
+      if(DALI_UNLIKELY(totalCapacity < offset + count))
       {
-        data.resize(data.size() + Increment);
+        // Resize the memory size as ceil((offset + count - totalCapacity)) / Increment) * Increment
+        // So the incremented size of data is always multiplied of the value Increment.
+        data.resize(data.size() + ((offset + count - totalCapacity - 1) / Increment + 1) * Increment);
 
         // update base pointer, required for address translation
         totalCapacity = data.size();