Flush pipeline cache only if required. 97/301097/4
authorEunki, Hong <eunkiki.hong@samsung.com>
Wed, 8 Nov 2023 10:46:25 +0000 (19:46 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Mon, 13 Nov 2023 02:02:51 +0000 (11:02 +0900)
Previously, we always flush pipeline cache every frame.

But actually, PipelineImpl / ProgramImpl reference count never be reduced
when we don't call destructor.

So, let we flush cache only if DiscardQueue exist at this frame.

Change-Id: I2a7dfb03d2580d10651a9f924991e0e943e29a24
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
dali/internal/graphics/gles-impl/egl-graphics-controller.cpp
dali/internal/graphics/gles-impl/gles-graphics-pipeline-cache.cpp [changed mode: 0755->0644]
dali/internal/graphics/gles-impl/gles-graphics-pipeline-cache.h

index 12c4723..505201c 100644 (file)
@@ -446,9 +446,17 @@ void EglGraphicsController::ProcessDiscardQueues()
   ProcessDiscardQueue<GLES::RenderTarget>(mDiscardRenderTargetQueue);
 
   // Process pipelines
+  if(mPipelineCache && !mDiscardPipelineQueue.empty())
+  {
+    mPipelineCache->MarkPipelineCacheFlushRequired();
+  }
   ProcessDiscardQueue(mDiscardPipelineQueue);
 
   // Process programs
+  if(mPipelineCache && !mDiscardProgramQueue.empty())
+  {
+    mPipelineCache->MarkProgramCacheFlushRequired();
+  }
   ProcessDiscardQueue<GLES::Program>(mDiscardProgramQueue);
 
   // Process shaders
old mode 100755 (executable)
new mode 100644 (file)
index e35faaa..7f14016
@@ -245,7 +245,9 @@ struct PipelineCache::Impl
    * @brief Constructor
    */
   explicit Impl(EglGraphicsController& _controller)
-  : controller(_controller)
+  : controller(_controller),
+    pipelineEntriesFlushRequired(false),
+    programEntriesFlushRequired(false)
   {
     // Initialise lookup table
     InitialiseStateCompareLookupTable();
@@ -299,6 +301,9 @@ struct PipelineCache::Impl
   };
 
   std::vector<ProgramCacheEntry> programEntries;
+
+  bool pipelineEntriesFlushRequired : 1;
+  bool programEntriesFlushRequired : 1;
 };
 
 PipelineCache::PipelineCache(EglGraphicsController& controller)
@@ -464,36 +469,56 @@ Graphics::UniquePtr<Graphics::Program> PipelineCache::GetProgram(const ProgramCr
 
 void PipelineCache::FlushCache()
 {
-  decltype(mImpl->entries) newEntries;
-  newEntries.reserve(mImpl->entries.size());
-
-  for(auto& entry : mImpl->entries)
+  if(mImpl->pipelineEntriesFlushRequired)
   {
-    // Move items which are still in use into the new array
-    if(entry.pipeline->GetRefCount() != 0)
+    decltype(mImpl->entries) newEntries;
+    newEntries.reserve(mImpl->entries.size());
+
+    for(auto& entry : mImpl->entries)
     {
-      newEntries.emplace_back(std::move(entry));
+      // Move items which are still in use into the new array
+      if(entry.pipeline->GetRefCount() != 0)
+      {
+        newEntries.emplace_back(std::move(entry));
+      }
     }
-  }
 
-  // Move temporary array in place of stored cache
-  // Unused pipelines will be deleted automatically
-  mImpl->entries = std::move(newEntries);
+    // Move temporary array in place of stored cache
+    // Unused pipelines will be deleted automatically
+    mImpl->entries = std::move(newEntries);
 
-  // Program cache require similar action.
-  decltype(mImpl->programEntries) newProgramEntries;
-  newProgramEntries.reserve(mImpl->programEntries.size());
+    mImpl->pipelineEntriesFlushRequired = false;
+  }
 
-  for(auto& entry : mImpl->programEntries)
+  if(mImpl->programEntriesFlushRequired)
   {
-    // Move items which are still in use into the new array
-    if(entry.program->GetRefCount() != 0)
+    // Program cache require similar action.
+    decltype(mImpl->programEntries) newProgramEntries;
+    newProgramEntries.reserve(mImpl->programEntries.size());
+
+    for(auto& entry : mImpl->programEntries)
     {
-      newProgramEntries.emplace_back(std::move(entry));
+      // Move items which are still in use into the new array
+      if(entry.program->GetRefCount() != 0)
+      {
+        newProgramEntries.emplace_back(std::move(entry));
+      }
     }
+
+    mImpl->programEntries = std::move(newProgramEntries);
+
+    mImpl->programEntriesFlushRequired = false;
   }
+}
 
-  mImpl->programEntries = std::move(newProgramEntries);
+void PipelineCache::MarkPipelineCacheFlushRequired()
+{
+  mImpl->pipelineEntriesFlushRequired = true;
+}
+
+void PipelineCache::MarkProgramCacheFlushRequired()
+{
+  mImpl->programEntriesFlushRequired = true;
 }
 
 } // namespace Dali::Graphics::GLES
index 9c1a16b..2a1fd6b 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_GRAPHICS_GLES_PIPELINE_CACHE_H
 
 /*
- * Copyright (c) 2021 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.
@@ -85,6 +85,16 @@ public:
    */
   void FlushCache();
 
+  /**
+   * @brief Notify that we need to flush pipeline cache next FlushCache API.
+   */
+  void MarkPipelineCacheFlushRequired();
+
+  /**
+   * @brief Notify that we need to flush program cache next FlushCache API.
+   */
+  void MarkProgramCacheFlushRequired();
+
 private:
   /**
    * @brief Finds pipeline implementation based on the spec