[Tizen] Add lock for shader-precompiler 90/300390/2
authorsunghyun kim <scholb.kim@samsung.com>
Mon, 23 Oct 2023 09:55:14 +0000 (18:55 +0900)
committersunghyun kim <scholb.kim@samsung.com>
Tue, 24 Oct 2023 05:57:21 +0000 (14:57 +0900)
Change-Id: Ibea2b0295c27bd7f5b2b9c76ad1bc0f0566adacf

dali/internal/adaptor/common/combined-update-render-controller.cpp
dali/internal/adaptor/common/combined-update-render-controller.h

index e2961d1..55a557a 100644 (file)
@@ -116,6 +116,7 @@ CombinedUpdateRenderController::CombinedUpdateRenderController(AdaptorInternalSe
   mUpdateRenderThreadCanSleep(FALSE),
   mPendingRequestUpdate(FALSE),
   mUseElapsedTimeAfterWait(FALSE),
+  mIsQuitedPreCompile(FALSE),
   mNewSurface(NULL),
   mDeletedSurface(nullptr),
   mPostRendering(FALSE),
@@ -313,6 +314,11 @@ void CombinedUpdateRenderController::ReplaceSurface(Dali::RenderSurfaceInterface
       ConditionalWait::ScopedLock lock(mUpdateRenderThreadWaitCondition);
       mPostRendering = FALSE; // Clear the post-rendering flag as Update/Render thread will replace the surface now
       mNewSurface    = newSurface;
+      if(mIsQuitedPreCompile == FALSE)
+      {
+        mIsQuitedPreCompile = TRUE;
+        Integration::ShaderPrecompiler::Get().StopPrecompile();
+      }
       mUpdateRenderThreadWaitCondition.Notify(lock);
     }
 
@@ -336,6 +342,11 @@ void CombinedUpdateRenderController::DeleteSurface(Dali::RenderSurfaceInterface*
       ConditionalWait::ScopedLock lock(mUpdateRenderThreadWaitCondition);
       mPostRendering  = FALSE; // Clear the post-rendering flag as Update/Render thread will delete the surface now
       mDeletedSurface = surface;
+      if(mIsQuitedPreCompile == FALSE)
+      {
+        mIsQuitedPreCompile = TRUE;
+        Integration::ShaderPrecompiler::Get().StopPrecompile();
+      }
       mUpdateRenderThreadWaitCondition.Notify(lock);
     }
 
@@ -372,6 +383,11 @@ void CombinedUpdateRenderController::ResizeSurface()
     ConditionalWait::ScopedLock lock(mUpdateRenderThreadWaitCondition);
     // Surface is resized and the surface resized count is increased.
     mSurfaceResized++;
+    if(mIsQuitedPreCompile == FALSE)
+    {
+      mIsQuitedPreCompile = TRUE;
+      Integration::ShaderPrecompiler::Get().StopPrecompile();
+    }
     mUpdateRenderThreadWaitCondition.Notify(lock);
   }
 }
@@ -450,6 +466,11 @@ void CombinedUpdateRenderController::RunUpdateRenderThread(int numberOfCycles, A
   mUpdateRenderThreadCanSleep = FALSE;
   mUploadWithoutRendering     = (updateMode == UpdateMode::SKIP_RENDER);
   LOG_COUNTER_EVENT("mUpdateRenderRunCount: %d, mUseElapsedTimeAfterWait: %d", mUpdateRenderRunCount, mUseElapsedTimeAfterWait);
+  if(mIsQuitedPreCompile == FALSE)
+  {
+    mIsQuitedPreCompile = TRUE;
+    Integration::ShaderPrecompiler::Get().StopPrecompile();
+  }
   mUpdateRenderThreadWaitCondition.Notify(lock);
 }
 
@@ -463,6 +484,11 @@ void CombinedUpdateRenderController::StopUpdateRenderThread()
 {
   ConditionalWait::ScopedLock lock(mUpdateRenderThreadWaitCondition);
   mDestroyUpdateRenderThread = TRUE;
+  if(mIsQuitedPreCompile == FALSE)
+  {
+    mIsQuitedPreCompile = TRUE;
+    Integration::ShaderPrecompiler::Get().StopPrecompile();
+  }
   mUpdateRenderThreadWaitCondition.Notify(lock);
 }
 
@@ -570,26 +596,37 @@ void CombinedUpdateRenderController::UpdateRenderThread()
   const bool         renderToFboEnabled  = 0u != renderToFboInterval;
   unsigned int       frameCount          = 0u;
 
-  if(Integration::ShaderPrecompiler::Get().IsEnable())
+  if(!mDestroyUpdateRenderThread)
   {
-    std::vector<RawShaderData> precompiledShaderList;
-    Integration::ShaderPrecompiler::Get().GetPrecompileShaderList(precompiledShaderList);
-    DALI_LOG_RELEASE_INFO("ShaderPrecompiler[ENABLE], list size:%d \n",precompiledShaderList.size());
-    for(auto precompiledShader = precompiledShaderList.begin(); precompiledShader != precompiledShaderList.end(); ++precompiledShader)
+    Integration::ShaderPrecompiler::Get().WaitPrecompileList();
+    if(Integration::ShaderPrecompiler::Get().IsEnable())
     {
-      auto numberOfPrecomipledShader = precompiledShader->shaderCount;
-      for(int i= 0; i<numberOfPrecomipledShader; ++i)
+      std::vector<RawShaderData> precompiledShaderList;
+      Integration::ShaderPrecompiler::Get().GetPrecompileShaderList(precompiledShaderList);
+      DALI_LOG_RELEASE_INFO("ShaderPrecompiler[ENABLE], list size:%d \n", precompiledShaderList.size());
+      for(auto precompiledShader = precompiledShaderList.begin(); precompiledShader != precompiledShaderList.end(); ++precompiledShader)
       {
-        auto vertexShader   = std::string(graphics.GetController().GetGlAbstraction().GetVertexShaderPrefix() + precompiledShader->vertexPrefix[i].data() + precompiledShader->vertexShader.data());
-        auto fragmentShader = std::string(graphics.GetController().GetGlAbstraction().GetFragmentShaderPrefix() + precompiledShader->fragmentPrefix[i].data() + precompiledShader->fragmentShader.data());
-        mCore.PreCompileShader(vertexShader.data(), fragmentShader.data());
+        if(mIsQuitedPreCompile == TRUE)
+        {
+          Integration::ShaderPrecompiler::Get().StopPrecompile();
+          DALI_LOG_RELEASE_INFO("ShaderPrecompiler[ENABLE], but stop precompile");
+          break;
+        }
+
+        auto numberOfPrecomipledShader = precompiledShader->shaderCount;
+        for(int i = 0; i < numberOfPrecomipledShader; ++i)
+        {
+          auto vertexShader   = std::string(graphics.GetController().GetGlAbstraction().GetVertexShaderPrefix() + precompiledShader->vertexPrefix[i].data() + precompiledShader->vertexShader.data());
+          auto fragmentShader = std::string(graphics.GetController().GetGlAbstraction().GetFragmentShaderPrefix() + precompiledShader->fragmentPrefix[i].data() + precompiledShader->fragmentShader.data());
+          mCore.PreCompileShader(vertexShader.data(), fragmentShader.data());
+        }
+        DALI_LOG_RELEASE_INFO("ShaderPrecompiler[ENABLE], shader count :%d \n", numberOfPrecomipledShader);
       }
-      DALI_LOG_RELEASE_INFO("ShaderPrecompiler[ENABLE], shader count :%d \n",numberOfPrecomipledShader);
     }
-  }
-  else
-  {
-    DALI_LOG_RELEASE_INFO("ShaderPrecompiler[DISABLE] \n");
+    else
+    {
+      DALI_LOG_RELEASE_INFO("ShaderPrecompiler[DISABLE] \n");
+    }
   }
 
   while(UpdateRenderReady(useElapsedTime, updateRequired, timeToSleepUntil))
@@ -1036,6 +1073,11 @@ void CombinedUpdateRenderController::PostRenderComplete()
 {
   ConditionalWait::ScopedLock lock(mUpdateRenderThreadWaitCondition);
   mPostRendering = FALSE;
+  if(mIsQuitedPreCompile == FALSE)
+  {
+    mIsQuitedPreCompile = TRUE;
+    Integration::ShaderPrecompiler::Get().StopPrecompile();
+  }
   mUpdateRenderThreadWaitCondition.Notify(lock);
 }
 
index bec2f70..abb40d9 100644 (file)
@@ -377,6 +377,7 @@ private:
                                                      ///< Ensures we do not go to sleep if we have not processed the most recent update-request.
 
   volatile unsigned int mUseElapsedTimeAfterWait; ///< Whether we should use the elapsed time after waiting (set by the event-thread, read by the update-render-thread).
+  volatile unsigned int mIsQuitedPreCompile;      ///< Whether we need to do precompile shader.
 
   Dali::RenderSurfaceInterface* volatile mNewSurface;     ///< Will be set to the new-surface if requested (set by the event-thread, read & cleared by the update-render thread).
   Dali::RenderSurfaceInterface* volatile mDeletedSurface; ///< Will be set to the deleted surface if requested (set by the event-thread, read & cleared by the update-render thread).