Reset vertex buffer cache at the end of flush 51/320151/2
authorEunki, Hong <eunkiki.hong@samsung.com>
Mon, 24 Feb 2025 13:55:45 +0000 (22:55 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Tue, 25 Feb 2025 08:04:24 +0000 (17:04 +0900)
We only check the internal value of VertexBufferBindingDescriptor.

But if the size of mImpl->mCurrentVertexBufferBindings changed, or cleared,
the vertex buffer's pointer might be same as previos old items.
In this case, we might miss vertex attribute, or VAO relative actions.

To avoid this case, let we clear current binded vertex
whenever if the size of mImpl->mCurrentVertexBufferBindings changed.

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

index e8c9fe94523edfa8b0f313f239eb36fc70684b25..c280afd04c525413739cb84b276507b89d6f4059 100644 (file)
@@ -579,6 +579,7 @@ void Context::BindVertexBuffers(const GLES::VertexBufferBindingDescriptor* bindi
   if(count > mImpl->mCurrentVertexBufferBindings.size())
   {
     mImpl->mCurrentVertexBufferBindings.resize(count);
+    mImpl->mVertexBuffersChanged = true;
   }
   // Copy only set slots
   auto toIter = mImpl->mCurrentVertexBufferBindings.begin();
@@ -963,6 +964,21 @@ void Context::ClearState()
   mImpl->mCurrentUBOBindings.Clear();
 }
 
+void Context::ClearVertexBufferCache()
+{
+  mImpl->mCurrentVertexBufferBindings.clear();
+  mImpl->mVertexBuffersChanged   = true;
+  mImpl->mProgramVAOCurrentState = 0;
+  if(DALI_LIKELY(!EglGraphicsController::IsShuttingDown()))
+  {
+    if(!(mImpl->mController.GetGLESVersion() >= GLESVersion::GLES_30))
+    {
+      memset(&mImpl->mGlStateCache.mVertexAttributeCachedState, 0, sizeof(mImpl->mGlStateCache.mVertexAttributeCachedState));
+      memset(&mImpl->mGlStateCache.mVertexAttributeCurrentState, 0, sizeof(mImpl->mGlStateCache.mVertexAttributeCurrentState));
+    }
+  }
+}
+
 void Context::ColorMask(bool enabled)
 {
   auto* gl = mImpl->GetGL();
@@ -1282,14 +1298,12 @@ void Context::InvalidateCachedPipeline(GLES::Pipeline* pipeline)
 
             // Do not delete vao now. (Since Context might not be current.)
             mImpl->mDiscardedVAOList.emplace_back(vao);
-            if(mImpl->mProgramVAOCurrentState == vao)
-            {
-              mImpl->mProgramVAOCurrentState = 0u;
-            }
           }
 
           // Clear cached Vertex buffer.
-          mImpl->mCurrentVertexBufferBindings.clear();
+          ClearVertexBufferCache();
+
+          mImpl->mGlStateCache.ResetBufferCache();
 
           mImpl->mProgramVAOMap.erase(iter);
         }
@@ -1361,14 +1375,12 @@ void Context::ResetGLESState()
   mImpl->mGlStateCache.ResetTextureCache();
   mImpl->mCurrentPipeline = nullptr;
 
-  mImpl->mCurrentVertexBufferBindings.clear();
   mImpl->mCurrentRenderTarget       = nullptr;
   mImpl->mCurrentRenderPass         = nullptr;
-  mImpl->mVertexBuffersChanged      = true;
   mImpl->mCurrentIndexBufferBinding = {};
-  mImpl->mProgramVAOCurrentState    = 0;
 
   ClearState();
+  ClearVertexBufferCache();
   mImpl->InitializeGlState();
 }
 
index 9086769d38ae42c922be62ebcb702a0f6e43e876..7532772372544eedeef9482f94ab35dfbf6519e2 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_GRAPHICS_GLES_CONTEXT_H
 
 /*
- * 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.
@@ -237,6 +237,11 @@ private:
    */
   void ClearState();
 
+  /**
+   * @brief Clear vertex buffer relative caches.
+   */
+  void ClearVertexBufferCache();
+
 private:
   struct Impl;
   std::unique_ptr<Impl> mImpl;