[Tizen] Fix typo error at ArrayBuffer bind + minor backport 23/292723/2
authorEunki Hong <eunkiki.hong@samsung.com>
Mon, 6 Mar 2023 17:52:49 +0000 (02:52 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Fri, 12 May 2023 08:11:25 +0000 (17:11 +0900)
This is a combination of 3 commits.

Fix typo error at ArrayBuffer bind

Previously, we don't consider glBindBuffer for
GL_ARRAY_BUFFER and GL_ELEMENT_ARRAY_BUFFER.
I think this is kind of typo error. So fix it.

Signed-off-by: Eunki Hong <eunkiki.hong@samsung.com>
Reset array of uniform buffer only required

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.

Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
Resetting the index buffer binding cache after binding VAO (seems like an NVIDIA bug causing crash)

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

index 32f490d..c6f0728 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.
@@ -74,6 +74,9 @@ struct Context::Impl
         {
           mProgramVAOCurrentState = attributeIter->second;
           gl.BindVertexArray(attributeIter->second);
+
+          // Binding VAO seems to reset the index buffer binding so the cache must be reset
+          mGlStateCache.mBoundElementArrayBufferId = 0;
         }
         return;
       }
@@ -82,6 +85,10 @@ struct Context::Impl
     uint32_t vao;
     gl.GenVertexArrays(1, &vao);
     gl.BindVertexArray(vao);
+
+    // Binding VAO seems to reset the index buffer binding so the cache must be reset
+    mGlStateCache.mBoundElementArrayBufferId = 0;
+
     mProgramVAOMap[program][hash] = vao;
     for(const auto& attr : vertexInputState.attributes)
     {
@@ -950,13 +957,31 @@ void Context::GenerateMipmap(GLenum target)
 
 void Context::BindBuffer(GLenum target, uint32_t bufferId)
 {
-  if(mImpl->mGlStateCache.mBoundArrayBufferId != bufferId)
+  switch(target)
   {
-    mImpl->mGlStateCache.mBoundArrayBufferId = bufferId;
-
-    auto& gl = *mImpl->mController.GetGL();
-    gl.BindBuffer(target, bufferId);
+    case GL_ARRAY_BUFFER:
+    {
+      if(mImpl->mGlStateCache.mBoundArrayBufferId == bufferId)
+      {
+        return;
+      }
+      mImpl->mGlStateCache.mBoundArrayBufferId = bufferId;
+      break;
+    }
+    case GL_ELEMENT_ARRAY_BUFFER:
+    {
+      if(mImpl->mGlStateCache.mBoundElementArrayBufferId == bufferId)
+      {
+        return;
+      }
+      mImpl->mGlStateCache.mBoundElementArrayBufferId = bufferId;
+      break;
+    }
   }
+
+  // Cache miss. Bind buffer.
+  auto& gl = *mImpl->mController.GetGL();
+  gl.BindBuffer(target, bufferId);
 }
 
 void Context::DrawBuffers(uint32_t count, const GLenum* buffers)
index 177b6b9..7cef89b 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.
@@ -265,10 +265,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
-  memset(sTempBindings, 0, sizeof(UniformBufferBindingDescriptor) * MAX_UNIFORM_BUFFER_BINDINGS);
-
-  auto maxBinding = 0u;
+  auto maxBindingCount = 0u;
 
   // find max binding and standalone UBO
   for(const auto& binding : bindings)
@@ -285,12 +282,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);
       }
     }
   }
@@ -298,13 +301,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;
   }
 }