[Tizen] Revert "Remove unused program / shader caches" 97/299697/1
authorseungho baek <sbsh.baek@samsung.com>
Fri, 6 Oct 2023 11:57:44 +0000 (20:57 +0900)
committerseungho baek <sbsh.baek@samsung.com>
Fri, 6 Oct 2023 11:57:50 +0000 (20:57 +0900)
This reverts commit 45111f90d336ae8edd661d36b4deca328bd3ade5.

Change-Id: Ib5da9d57c9d77915d2acd2ca6974cd5c46ef9951

dali/internal/render/common/render-manager.cpp
dali/internal/render/renderers/shader-cache.cpp
dali/internal/render/renderers/shader-cache.h
dali/internal/render/shaders/program-controller.cpp
dali/internal/render/shaders/program-controller.h

index a5b4953..8423471 100644 (file)
@@ -64,8 +64,6 @@ Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_REN
 
 namespace
 {
-constexpr uint32_t CACHE_CLEAN_FRAME_COUNT = 600u; // 60fps * 10sec
-
 inline Graphics::Rect2D RecalculateScissorArea(const Graphics::Rect2D& scissorArea, int orientation, const Rect<int32_t>& viewportRect)
 {
   Graphics::Rect2D newScissorArea;
@@ -517,13 +515,6 @@ void RenderManager::PreRender(Integration::RenderStatus& status, bool forceClear
   // Reset pipeline cache before rendering
   mImpl->pipelineCache->PreRender();
 
-  // Let we collect reference counts during CACHE_CLEAN_FRAME_COUNT frames.
-  if(mImpl->frameCount % CACHE_CLEAN_FRAME_COUNT == 1)
-  {
-    mImpl->programController.ResetReferenceCount();
-    mImpl->shaderCache.ResetReferenceCount();
-  }
-
   mImpl->commandBufferSubmitted = false;
 }
 
@@ -1199,13 +1190,6 @@ void RenderManager::PostRender()
     count += scene->GetRenderInstructions().Count(mImpl->renderBufferIndex);
   }
 
-  // Remove unused shader and programs during CACHE_CLEAN_FRAME_COUNT frames.
-  if(mImpl->frameCount % CACHE_CLEAN_FRAME_COUNT == 0)
-  {
-    mImpl->programController.ClearUnusedCache();
-    mImpl->shaderCache.ClearUnusedCache();
-  }
-
   const bool haveInstructions = count > 0u;
 
   // If this frame was rendered due to instructions existing, we mark this so we know to clear the next frame.
index 90d042c..d4f5f16 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -34,7 +34,6 @@ Dali::Graphics::Shader& ShaderCache::GetShader(const std::vector<char>& shaderCo
   {
     if(item.shaderCode == shaderCode && item.stage == stage && item.type == type)
     {
-      ++item.refCount;
       return *item.shader.get();
     }
   }
@@ -51,29 +50,6 @@ Dali::Graphics::Shader& ShaderCache::GetShader(const std::vector<char>& shaderCo
   return *mItems.back().shader.get();
 }
 
-void ShaderCache::ResetReferenceCount()
-{
-  for(auto&& item : mItems)
-  {
-    item.refCount = 0u;
-  }
-}
-
-void ShaderCache::ClearUnusedCache()
-{
-  for(auto iter = mItems.begin(); iter != mItems.end();)
-  {
-    if(iter->refCount == 0u)
-    {
-      iter = mItems.erase(iter);
-    }
-    else
-    {
-      ++iter;
-    }
-  }
-}
-
 } // namespace Render
 } // namespace Internal
 } // namespace Dali
index 9ed2034..5f00aba 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_SHADER_CACHE_H
 
 /*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -38,8 +38,6 @@ struct ShaderCache
     Item()            = default;
     Item(const Item&) = delete;
     Item(Item&&)      = default;
-    Item& operator=(const Item&) = delete;
-    Item& operator=(Item&&) = default;
 
     Item(Graphics::UniquePtr<Dali::Graphics::Shader> shader,
          const std::vector<char>&                    shaderCode,
@@ -48,8 +46,7 @@ struct ShaderCache
     : shader(std::move(shader)),
       shaderCode(shaderCode),
       stage(stage),
-      type(type),
-      refCount{1u}
+      type(type)
     {
     }
 
@@ -59,7 +56,6 @@ struct ShaderCache
     std::vector<char>                           shaderCode;
     Graphics::PipelineStage                     stage;
     Graphics::ShaderSourceMode                  type;
-    uint16_t                                    refCount;
   };
 
   /**
@@ -71,7 +67,6 @@ struct ShaderCache
 
   /**
    * Get a shader from it's source code
-   * It will increate getted shader item reference count.
    *
    * @param[in] shaderCode The shader code
    * @param[in] stage The pipeline stage (e.g. VERTEX_SHADER or FRAGMENT_SHADER etc.)
@@ -80,16 +75,6 @@ struct ShaderCache
    */
   Dali::Graphics::Shader& GetShader(const std::vector<char>& shaderCode, Graphics::PipelineStage stage, Graphics::ShaderSourceMode type);
 
-  /**
-   * @brief Reset all items reference count as 0.
-   */
-  void ResetReferenceCount();
-
-  /**
-   * @brief Clear items who the reference count is 0.
-   */
-  void ClearUnusedCache();
-
 private:
   std::vector<Item>           mItems;
   Dali::Graphics::Controller& mController;
index b15715e..f72f937 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -45,29 +45,6 @@ void ProgramController::ResetProgramMatrices()
   }
 }
 
-void ProgramController::ResetReferenceCount()
-{
-  for(auto&& item : mProgramCache)
-  {
-    item->ClearReferenceCount();
-  }
-}
-
-void ProgramController::ClearUnusedCache()
-{
-  for(auto iter = mProgramCache.Begin(); iter != mProgramCache.End();)
-  {
-    if((*iter)->GetReferenceCount() == 0u)
-    {
-      iter = mProgramCache.Erase(iter);
-    }
-    else
-    {
-      ++iter;
-    }
-  }
-}
-
 Program* ProgramController::GetProgram(size_t shaderHash)
 {
   Program*              program = nullptr;
@@ -77,7 +54,6 @@ Program* ProgramController::GetProgram(size_t shaderHash)
     size_t hash = (*iter)->GetHash();
     if(shaderHash == hash)
     {
-      (*iter)->Reference();
       program = (*iter)->GetProgram();
       break;
     }
index 062a96f..0ea1a7a 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_PROGRAM_CONTROLLER_H
 
 /*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -50,8 +50,7 @@ public:
      */
     ProgramPair(Program* program, size_t shaderHash)
     : mProgram(program),
-      mShaderHash(shaderHash),
-      mRefCount{1u}
+      mShaderHash(shaderHash)
     {
     }
 
@@ -81,28 +80,12 @@ public:
       return mShaderHash;
     }
 
-    [[nodiscard]] inline uint16_t GetReferenceCount() const
-    {
-      return mRefCount;
-    }
-
-    void Reference()
-    {
-      ++mRefCount;
-    }
-
-    void ClearReferenceCount()
-    {
-      mRefCount = 0u;
-    }
-
     ProgramPair(const ProgramPair&) = delete;
     ProgramPair& operator=(const ProgramPair&) = delete;
 
   private: // Data
     Program* mProgram;
     size_t   mShaderHash;
-    uint16_t mRefCount;
   };
 
   /**
@@ -125,16 +108,6 @@ public: // API
    */
   void ResetProgramMatrices();
 
-  /**
-   * @brief Reset all program reference count as 0.
-   */
-  void ResetReferenceCount();
-
-  /**
-   * @brief Clear program who the reference count is 0.
-   */
-  void ClearUnusedCache();
-
 private: // From ProgramCache
   /**
    * @copydoc ProgramCache::GetProgram