[Tizen] Discard deleted VAO at matched context 00/302900/1 accepted/tizen/7.0/unified/20231218.071009 accepted/tizen/7.0/unified/20231219.155810 accepted/tizen/7.0/unified/20231220.124902 accepted/tizen/7.0/unified/20231220.134947 accepted/tizen/7.0/unified/20231220.170054
authorEunki, Hong <eunkiki.hong@samsung.com>
Wed, 13 Dec 2023 10:30:28 +0000 (19:30 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Fri, 15 Dec 2023 07:25:32 +0000 (16:25 +0900)
Since InvalidateCachedPipeline() can be called not for currented context,
we should not call gl.DeleteVertexArrays() that timming.

Instead, let we keep discarded VAO items, and then delete them immediately,
if we call BindProgramVAO, where we can assume that the context is current.

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

index 2b56974..addd1ad 100644 (file)
@@ -63,8 +63,15 @@ struct Context::Impl
       hash ^= std::hash<uint32_t>{}(attr.location);
     }
 
-    auto& gl   = *mController.GetGL();
-    auto  iter = mProgramVAOMap.find(program);
+    auto& gl = *mController.GetGL();
+
+    if(DALI_UNLIKELY(!mDiscardedVAOList.empty()))
+    {
+      gl.DeleteVertexArrays(static_cast<Dali::GLsizei>(mDiscardedVAOList.size()), mDiscardedVAOList.data());
+      mDiscardedVAOList.clear();
+    }
+
+    auto iter = mProgramVAOMap.find(program);
     if(iter != mProgramVAOMap.end())
     {
       auto attributeIter = iter->second.find(hash);
@@ -228,6 +235,7 @@ struct Context::Impl
   std::unordered_map<const GLES::ProgramImpl*, std::map<std::size_t, uint32_t>> mProgramVAOMap;              ///< GL program-VAO map
   uint32_t                                                                      mProgramVAOCurrentState{0u}; ///< Currently bound VAO
   GLStateCache                                                                  mGlStateCache{};             ///< GL status cache
+  std::vector<Dali::GLuint>                                                     mDiscardedVAOList{};
 
   bool mGlContextCreated{false}; ///< True if the OpenGL context has been created
 
@@ -1074,12 +1082,18 @@ void Context::InvalidateCachedPipeline(GLES::Pipeline* pipeline)
           for(auto& attributeHashPair : iter->second)
           {
             auto vao = attributeHashPair.second;
-            gl->DeleteVertexArrays(1, &vao);
+
+            // 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();
+
           mImpl->mProgramVAOMap.erase(iter);
         }
       }