Reset array of uniform buffer only required 37/289437/2
authorEunki, Hong <eunkiki.hong@samsung.com>
Tue, 7 Mar 2023 17:47:13 +0000 (02:47 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Tue, 7 Mar 2023 18:15:35 +0000 (03:15 +0900)
Previously, we reset 64 x sizeof(UniformBufferBindingDescriptor) everytimes.
for each BindUniformBuffer commands.

It is useless job for standalone case. So move initialize process
only required.

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

index 0e72a8c..70dfbb8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
@@ -270,10 +270,7 @@ void CommandBuffer::BindUniformBuffers(const std::vector<Graphics::UniformBuffer
   // TODO: could use vector?
   static thread_local UniformBufferBindingDescriptor sTempBindings[MAX_UNIFORM_BUFFER_BINDINGS];
 
-  // reset temp bindings
-  std::fill_n(sTempBindings, MAX_UNIFORM_BUFFER_BINDINGS, UniformBufferBindingDescriptor());
-
-  auto maxBinding = 0u;
+  auto maxBindingCount = 0u;
 
   // find max binding and standalone UBO
   for(const auto& binding : bindings)
@@ -290,12 +287,18 @@ void CommandBuffer::BindUniformBuffers(const std::vector<Graphics::UniformBuffer
       }
       else // Bind regular UBO
       {
+        if(DALI_UNLIKELY(maxBindingCount == 0u))
+        {
+          // We can assume here comes first time. Reset temp bindings
+          std::fill_n(sTempBindings, MAX_UNIFORM_BUFFER_BINDINGS, UniformBufferBindingDescriptor());
+        }
         auto& slot    = sTempBindings[binding.binding];
         slot.buffer   = glesBuffer;
         slot.offset   = binding.offset;
         slot.binding  = binding.binding;
         slot.emulated = false;
-        maxBinding    = std::max(maxBinding, binding.binding);
+
+        maxBindingCount = std::max(maxBindingCount, binding.binding + 1u);
       }
     }
   }
@@ -303,13 +306,13 @@ void CommandBuffer::BindUniformBuffers(const std::vector<Graphics::UniformBuffer
   bindCmd.uniformBufferBindingsCount = 0u;
 
   // copy data
-  if(maxBinding)
+  if(maxBindingCount)
   {
-    auto destBindings = mCommandPool->Allocate<UniformBufferBindingDescriptor>(maxBinding + 1);
+    auto destBindings = mCommandPool->Allocate<UniformBufferBindingDescriptor>(maxBindingCount);
     // copy
-    memcpy(destBindings.Ptr(), sTempBindings, sizeof(UniformBufferBindingDescriptor) * (maxBinding + 1));
+    memcpy(destBindings.Ptr(), sTempBindings, sizeof(UniformBufferBindingDescriptor) * (maxBindingCount));
     bindCmd.uniformBufferBindings      = destBindings;
-    bindCmd.uniformBufferBindingsCount = maxBinding + 1;
+    bindCmd.uniformBufferBindingsCount = maxBindingCount;
   }
 }