(GLES::Buffer) Skip recycled buffer initialize multiple times 13/320513/2
authorEunki, Hong <eunkiki.hong@samsung.com>
Tue, 4 Mar 2025 11:04:43 +0000 (20:04 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Tue, 4 Mar 2025 11:12:35 +0000 (20:12 +0900)
It is possible that single buffer be recycled used multiple times.
If then, AddBuffer() called multiple time.

Until now, buffer only use single flags, so if buffer recycled 2 times, logic
will be broken.

To avoid this case, let we use recycled counter, and allow to recycle multiple times in a loop

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

index 107e4212b69dedd0e04d4da0ddf8aa5048098001..fc4cdfab1196850353f50fad715f029e106c1d2e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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.
@@ -52,8 +52,11 @@ Buffer::Buffer(const Graphics::BufferCreateInfo& createInfo, Graphics::EglGraphi
 
 bool Buffer::TryRecycle(const Graphics::BufferCreateInfo& createInfo, Graphics::EglGraphicsController& controller)
 {
-  // Compare whether specs are same and the buffer is allocated
-  mSetForGLRecycling = false;
+  if(DALI_UNLIKELY(EglGraphicsController::IsShuttingDown()))
+  {
+    // Cannot recycle buffer if shutting down.
+    return false;
+  }
 
   // if different buffer spec, we need new buffer
   if(!(createInfo.size == mCreateInfo.size &&
@@ -74,13 +77,20 @@ bool Buffer::TryRecycle(const Graphics::BufferCreateInfo& createInfo, Graphics::
   // Make sure the buffer will be reinitialized
   controller.AddBuffer(*this);
 
-  mSetForGLRecycling = true;
+  ++mSetForGLRecyclingCount;
 
   return true;
 }
 
 bool Buffer::InitializeResource()
 {
+  // Fast-skip multiple initialize resource
+  if(DALI_UNLIKELY(mSetForGLRecyclingCount > 1u))
+  {
+    --mSetForGLRecyclingCount;
+    return true;
+  }
+
   // CPU allocated uniform buffer is a special "compatibility" mode
   // for older GLES
   if(mCpuAllocated && !mTransient)
@@ -93,7 +103,10 @@ bool Buffer::InitializeResource()
   }
 
   // make sure recycling mode is disabled after (re)initializing resource
-  mSetForGLRecycling = false;
+  if(mSetForGLRecyclingCount)
+  {
+    --mSetForGLRecyclingCount;
+  }
   return true;
 }
 
@@ -104,7 +117,7 @@ void Buffer::InitializeCPUBuffer()
   const auto allocators = GetCreateInfo().allocationCallbacks;
 
   // Early out if we recycle the buffer
-  if(mBufferPtr && mSetForGLRecycling)
+  if(mBufferPtr && mSetForGLRecyclingCount)
   {
     return;
   }
@@ -138,7 +151,7 @@ void Buffer::InitializeGPUBuffer()
   }
 
   // If mBufferId is already set and we recycling the buffer (orphaning)
-  if(!mSetForGLRecycling && !mBufferId)
+  if(!mSetForGLRecyclingCount && !mBufferId)
   {
     gl->GenBuffers(1, &mBufferId);
   }
index 9810eea2fd30ae18fc9033300a14a2e4d9eb9f38..7e26d9991258009295763bfee7f19548beb83f8f 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_GRAPHICS_GLES_BUFFER_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.
@@ -88,7 +88,7 @@ private:
   bool     mCpuAllocated{false};
   bool     mTransient{false};
 
-  bool mSetForGLRecycling{false}; ///< If flag set true the buffer will recycle
+  uint32_t mSetForGLRecyclingCount{0u}; ///< If value is not zero, the buffer will recycle
 };
 } // namespace GLES
 } // namespace Dali::Graphics