Merge "Added rotation support to frame-callback" into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / render / common / render-manager.cpp
index 2d63a0a..3a1466d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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.
@@ -31,6 +31,8 @@
 #include <dali/internal/update/nodes/scene-graph-layer.h>
 #include <dali/internal/update/render-tasks/scene-graph-camera.h>
 
+#include <dali/internal/common/owner-key-container.h>
+
 #include <dali/internal/render/common/render-algorithms.h>
 #include <dali/internal/render/common/render-debug.h>
 #include <dali/internal/render/common/render-instruction.h>
@@ -96,6 +98,7 @@ inline Graphics::Rect2D RecalculateScissorArea(Graphics::Rect2D scissorArea, int
   return newScissorArea;
 }
 } // namespace
+
 /**
  * Structure to contain internal data
  */
@@ -106,15 +109,7 @@ struct RenderManager::Impl
        Integration::StencilBufferAvailable stencilBufferAvailableParam,
        Integration::PartialUpdateAvailable partialUpdateAvailableParam)
   : graphicsController(graphicsController),
-    renderQueue(),
     renderAlgorithms(graphicsController),
-    frameCount(0u),
-    renderBufferIndex(SceneGraphBuffers::INITIAL_UPDATE_BUFFER_INDEX),
-    rendererContainer(),
-    samplerContainer(),
-    textureContainer(),
-    frameBufferContainer(),
-    lastFrameWasRendered(false),
     programController(graphicsController),
     shaderCache(graphicsController),
     depthBufferAvailable(depthBufferAvailableParam),
@@ -154,26 +149,18 @@ struct RenderManager::Impl
   }
 
   // the order is important for destruction,
-  Graphics::Controller& graphicsController;
-  RenderQueue           renderQueue; ///< A message queue for receiving messages from the update-thread.
-
-  std::vector<SceneGraph::Scene*> sceneContainer; ///< List of pointers to the scene graph objects of the scenes
-
-  Render::RenderAlgorithms renderAlgorithms; ///< The RenderAlgorithms object is used to action the renders required by a RenderInstruction
-
-  uint32_t    frameCount;        ///< The current frame count
-  BufferIndex renderBufferIndex; ///< The index of the buffer to read from; this is opposite of the "update" buffer
-
-  OwnerContainer<Render::Renderer*>     rendererContainer;     ///< List of owned renderers
-  OwnerContainer<Render::Sampler*>      samplerContainer;      ///< List of owned samplers
-  OwnerContainer<Render::Texture*>      textureContainer;      ///< List of owned textures
-  OwnerContainer<Render::FrameBuffer*>  frameBufferContainer;  ///< List of owned framebuffers
-  OwnerContainer<Render::VertexBuffer*> vertexBufferContainer; ///< List of owned vertex buffers
-  OwnerContainer<Render::Geometry*>     geometryContainer;     ///< List of owned Geometries
-
-  bool lastFrameWasRendered; ///< Keeps track of the last frame being rendered due to having render instructions
-
-  OwnerContainer<Render::RenderTracker*> mRenderTrackers; ///< List of render trackers
+  Graphics::Controller&           graphicsController;
+  RenderQueue                     renderQueue;      ///< A message queue for receiving messages from the update-thread.
+  std::vector<SceneGraph::Scene*> sceneContainer;   ///< List of pointers to the scene graph objects of the scenes
+  Render::RenderAlgorithms        renderAlgorithms; ///< The RenderAlgorithms object is used to action the renders required by a RenderInstruction
+
+  OwnerContainer<Render::Sampler*>       samplerContainer;      ///< List of owned samplers
+  OwnerContainer<Render::FrameBuffer*>   frameBufferContainer;  ///< List of owned framebuffers
+  OwnerContainer<Render::VertexBuffer*>  vertexBufferContainer; ///< List of owned vertex buffers
+  OwnerContainer<Render::Geometry*>      geometryContainer;     ///< List of owned Geometries
+  OwnerContainer<Render::RenderTracker*> mRenderTrackers;       ///< List of render trackers
+  OwnerKeyContainer<Render::Renderer>    rendererContainer;     ///< List of owned renderers
+  OwnerKeyContainer<Render::Texture>     textureContainer;      ///< List of owned textures
 
   ProgramController   programController; ///< Owner of the programs
   Render::ShaderCache shaderCache;       ///< The cache for the graphics shaders
@@ -188,6 +175,12 @@ struct RenderManager::Impl
   std::unique_ptr<Dali::ThreadPool> threadPool;            ///< The thread pool
   Vector<Graphics::Texture*>        boundTextures;         ///< The textures bound for rendering
   Vector<Graphics::Texture*>        textureDependencyList; ///< The dependency list of bound textures
+
+  uint32_t    frameCount{0u};                                                    ///< The current frame count
+  BufferIndex renderBufferIndex{SceneGraphBuffers::INITIAL_UPDATE_BUFFER_INDEX}; ///< The index of the buffer to read from; this is opposite of the "update" buffer
+
+  bool lastFrameWasRendered{false}; ///< Keeps track of the last frame being rendered due to having render instructions
+  bool commandBufferSubmitted{false};
 };
 
 RenderManager* RenderManager::New(Graphics::Controller&               graphicsController,
@@ -222,17 +215,17 @@ void RenderManager::SetShaderSaver(ShaderSaver& upstream)
 {
 }
 
-void RenderManager::AddRenderer(OwnerPointer<Render::Renderer>& renderer)
+void RenderManager::AddRenderer(const Render::RendererKey& renderer)
 {
   // Initialize the renderer as we are now in render thread
   renderer->Initialize(mImpl->graphicsController, mImpl->programController, mImpl->shaderCache, *(mImpl->uniformBufferManager.get()), *(mImpl->pipelineCache.get()));
 
-  mImpl->rendererContainer.PushBack(renderer.Release());
+  mImpl->rendererContainer.PushBack(renderer);
 }
 
-void RenderManager::RemoveRenderer(Render::Renderer* renderer)
+void RenderManager::RemoveRenderer(const Render::RendererKey& renderer)
 {
-  mImpl->rendererContainer.EraseObject(renderer);
+  mImpl->rendererContainer.EraseKey(renderer);
 }
 
 void RenderManager::AddSampler(OwnerPointer<Render::Sampler>& sampler)
@@ -246,34 +239,38 @@ void RenderManager::RemoveSampler(Render::Sampler* sampler)
   mImpl->samplerContainer.EraseObject(sampler);
 }
 
-void RenderManager::AddTexture(OwnerPointer<Render::Texture>& texture)
+void RenderManager::AddTexture(const Render::TextureKey& textureKey)
 {
-  texture->Initialize(mImpl->graphicsController);
-  mImpl->textureContainer.PushBack(texture.Release());
+  DALI_ASSERT_DEBUG(textureKey && "Trying to add empty texture key");
+
+  textureKey->Initialize(mImpl->graphicsController);
+  mImpl->textureContainer.PushBack(textureKey);
 }
 
-void RenderManager::RemoveTexture(Render::Texture* texture)
+void RenderManager::RemoveTexture(const Render::TextureKey& textureKey)
 {
-  DALI_ASSERT_DEBUG(NULL != texture);
+  DALI_ASSERT_DEBUG(textureKey && "Trying to remove empty texture key");
 
   // Find the texture, use std::find so we can do the erase safely
-  auto iter = std::find(mImpl->textureContainer.begin(), mImpl->textureContainer.end(), texture);
+  auto iter = std::find(mImpl->textureContainer.begin(), mImpl->textureContainer.end(), textureKey);
 
   if(iter != mImpl->textureContainer.end())
   {
-    texture->Destroy();
+    textureKey->Destroy();
     mImpl->textureContainer.Erase(iter); // Texture found; now destroy it
   }
 }
 
-void RenderManager::UploadTexture(Render::Texture* texture, PixelDataPtr pixelData, const Texture::UploadParams& params)
+void RenderManager::UploadTexture(const Render::TextureKey& textureKey, PixelDataPtr pixelData, const Texture::UploadParams& params)
 {
-  texture->Upload(pixelData, params);
+  DALI_ASSERT_DEBUG(textureKey && "Trying to upload to empty texture key");
+  textureKey->Upload(pixelData, params);
 }
 
-void RenderManager::GenerateMipmaps(Render::Texture* texture)
+void RenderManager::GenerateMipmaps(const Render::TextureKey& textureKey)
 {
-  texture->GenerateMipmaps();
+  DALI_ASSERT_DEBUG(textureKey && "Trying to generate mipmaps on empty texture key");
+  textureKey->GenerateMipmaps();
 }
 
 void RenderManager::SetFilterMode(Render::Sampler* sampler, uint32_t minFilterMode, uint32_t magFilterMode)
@@ -345,6 +342,11 @@ void RenderManager::AttachDepthStencilTextureToFrameBuffer(Render::FrameBuffer*
   frameBuffer->AttachDepthStencilTexture(texture, mipmapLevel);
 }
 
+void RenderManager::SetMultiSamplingLevelToFrameBuffer(Render::FrameBuffer* frameBuffer, uint8_t multiSamplingLevel)
+{
+  frameBuffer->SetMultiSamplingLevel(multiSamplingLevel);
+}
+
 void RenderManager::AddVertexBuffer(OwnerPointer<Render::VertexBuffer>& vertexBuffer)
 {
   mImpl->vertexBufferContainer.PushBack(vertexBuffer.Release());
@@ -430,7 +432,7 @@ void RenderManager::RemoveRenderTracker(Render::RenderTracker* renderTracker)
   mImpl->RemoveRenderTracker(renderTracker);
 }
 
-void RenderManager::PreRender(Integration::RenderStatus& status, bool forceClear, bool uploadOnly)
+void RenderManager::PreRender(Integration::RenderStatus& status, bool forceClear)
 {
   DALI_PRINT_RENDER_START(mImpl->renderBufferIndex);
 
@@ -464,6 +466,8 @@ void RenderManager::PreRender(Integration::RenderStatus& status, bool forceClear
       geom->Upload(mImpl->graphicsController);
     }
   }
+
+  mImpl->commandBufferSubmitted = false;
 }
 
 void RenderManager::PreRender(Integration::Scene& scene, std::vector<Rect<int>>& damagedRects)
@@ -516,13 +520,13 @@ void RenderManager::PreRender(Integration::Scene& scene, std::vector<Rect<int>>&
 
   // Clean collected dirty/damaged rects on exit if 3d layer or 3d node or other conditions.
   DamagedRectsCleaner damagedRectCleaner(damagedRects, surfaceRect);
+  bool                cleanDamagedRect = false;
 
-  // Mark previous dirty rects in the sorted array. The array is already sorted by node and renderer, frame number.
-  // so you don't need to sort: std::stable_sort(itemsDirtyRects.begin(), itemsDirtyRects.end());
-  std::vector<DirtyRect>& itemsDirtyRects = sceneInternal.GetItemsDirtyRects();
-  for(DirtyRect& dirtyRect : itemsDirtyRects)
+  // Mark previous dirty rects in the std::unordered_map.
+  Scene::ItemsDirtyRectsContainer& itemsDirtyRects = sceneObject->GetItemsDirtyRects();
+  for(auto& dirtyRectPair : itemsDirtyRects)
   {
-    dirtyRect.visited = false;
+    dirtyRectPair.second.visited = false;
   }
 
   uint32_t instructionCount = sceneObject->GetRenderInstructions().Count(mImpl->renderBufferIndex);
@@ -532,37 +536,36 @@ void RenderManager::PreRender(Integration::Scene& scene, std::vector<Rect<int>>&
 
     if(instruction.mFrameBuffer)
     {
-      return; // TODO: reset, we don't deal with render tasks with framebuffers (for now)
+      cleanDamagedRect = true;
+      continue; // TODO: reset, we don't deal with render tasks with framebuffers (for now)
     }
 
     const Camera* camera = instruction.GetCamera();
-    if(camera->mType == Camera::DEFAULT_TYPE && camera->mTargetPosition == Camera::DEFAULT_TARGET_POSITION)
+    if(camera && camera->mType == Camera::DEFAULT_TYPE && camera->mTargetPosition == Camera::DEFAULT_TARGET_POSITION)
     {
-      const Node* node = instruction.GetCamera()->GetNode();
-      if(node)
+      Vector3    position;
+      Vector3    scale;
+      Quaternion orientation;
+      camera->GetWorldMatrix(mImpl->renderBufferIndex).GetTransformComponents(position, orientation, scale);
+
+      Vector3 orientationAxis;
+      Radian  orientationAngle;
+      orientation.ToAxisAngle(orientationAxis, orientationAngle);
+
+      if(position.x > Math::MACHINE_EPSILON_10000 ||
+         position.y > Math::MACHINE_EPSILON_10000 ||
+         orientationAxis != Vector3(0.0f, 1.0f, 0.0f) ||
+         orientationAngle != ANGLE_180 ||
+         scale != Vector3(1.0f, 1.0f, 1.0f))
       {
-        Vector3    position;
-        Vector3    scale;
-        Quaternion orientation;
-        node->GetWorldMatrix(mImpl->renderBufferIndex).GetTransformComponents(position, orientation, scale);
-
-        Vector3 orientationAxis;
-        Radian  orientationAngle;
-        orientation.ToAxisAngle(orientationAxis, orientationAngle);
-
-        if(position.x > Math::MACHINE_EPSILON_10000 ||
-           position.y > Math::MACHINE_EPSILON_10000 ||
-           orientationAxis != Vector3(0.0f, 1.0f, 0.0f) ||
-           orientationAngle != ANGLE_180 ||
-           scale != Vector3(1.0f, 1.0f, 1.0f))
-        {
-          return;
-        }
+        cleanDamagedRect = true;
+        continue;
       }
     }
     else
     {
-      return;
+      cleanDamagedRect = true;
+      continue;
     }
 
     Rect<int32_t> viewportRect;
@@ -572,7 +575,8 @@ void RenderManager::PreRender(Integration::Scene& scene, std::vector<Rect<int>>&
       viewportRect.Set(instruction.mViewport.x, y, instruction.mViewport.width, instruction.mViewport.height);
       if(viewportRect.IsEmpty() || !viewportRect.IsValid())
       {
-        return; // just skip funny use cases for now, empty viewport means it is set somewhere else
+        cleanDamagedRect = true;
+        continue; // just skip funny use cases for now, empty viewport means it is set somewhere else
       }
     }
     else
@@ -596,22 +600,40 @@ void RenderManager::PreRender(Integration::Scene& scene, std::vector<Rect<int>>&
             for(uint32_t listIndex = 0u; listIndex < listCount; ++listIndex)
             {
               RenderItem& item = renderList->GetItem(listIndex);
-              // If the item does 3D transformation, do early exit and clean the damaged rect array
-              if(item.mUpdateSize == Vector3::ZERO)
+              // If the item does 3D transformation, make full update
+              if(item.mUpdateArea == Vector4::ZERO)
               {
-                return;
+                cleanDamagedRect = true;
+
+                // Save the full rect in the damaged list. We need it when this item is removed
+                DirtyRectKey dirtyRectKey(item.mNode, item.mRenderer);
+                auto         dirtyRectPos = itemsDirtyRects.find(dirtyRectKey);
+                if(dirtyRectPos != itemsDirtyRects.end())
+                {
+                  // Replace the rect
+                  dirtyRectPos->second.visited = true;
+                  dirtyRectPos->second.rect    = surfaceRect;
+                }
+                else
+                {
+                  // Else, just insert the new dirtyrect
+                  itemsDirtyRects.insert({dirtyRectKey, surfaceRect});
+                }
+                continue;
               }
 
-              Rect<int> rect;
-              DirtyRect dirtyRect(item.mNode, item.mRenderer, mImpl->frameCount, rect);
+              Rect<int>    rect;
+              DirtyRectKey dirtyRectKey(item.mNode, item.mRenderer);
               // If the item refers to updated node or renderer.
               if(item.mIsUpdated ||
                  (item.mNode &&
-                  (item.mNode->Updated() || (item.mRenderer && item.mRenderer->Updated(mImpl->renderBufferIndex, item.mNode)))))
+                  (item.mNode->Updated() || (item.mRenderer && item.mRenderer->Updated(mImpl->renderBufferIndex)))))
               {
                 item.mIsUpdated = false;
 
-                rect = RenderItem::CalculateViewportSpaceAABB(item.mModelViewMatrix, item.mUpdateSize, viewportRect.width, viewportRect.height);
+                Vector4 updateArea = item.mRenderer ? item.mRenderer->GetVisualTransformedUpdateArea(mImpl->renderBufferIndex, item.mUpdateArea) : item.mUpdateArea;
+
+                rect = RenderItem::CalculateViewportSpaceAABB(item.mModelViewMatrix, Vector3(updateArea.x, updateArea.y, 0.0f), Vector3(updateArea.z, updateArea.w, 0.0f), viewportRect.width, viewportRect.height);
                 if(rect.IsValid() && rect.Intersect(viewportRect) && !rect.IsEmpty())
                 {
                   const int left   = rect.x;
@@ -624,31 +646,22 @@ void RenderManager::PreRender(Integration::Scene& scene, std::vector<Rect<int>>&
                   rect.height      = ((bottom + 16) / 16) * 16 - rect.y;
 
                   // Found valid dirty rect.
-                  // 1. Insert it in the sorted array of the dirty rects.
-                  // 2. Mark the related dirty rects as visited so they will not be removed below.
-                  // 3. Keep only last 3 dirty rects for the same node and renderer (Tizen uses 3 back buffers, Ubuntu 1).
-                  dirtyRect.rect    = rect;
-                  auto dirtyRectPos = std::lower_bound(itemsDirtyRects.begin(), itemsDirtyRects.end(), dirtyRect);
-                  dirtyRectPos      = itemsDirtyRects.insert(dirtyRectPos, dirtyRect);
-
-                  int c = 1;
-                  while(++dirtyRectPos != itemsDirtyRects.end())
+                  auto dirtyRectPos = itemsDirtyRects.find(dirtyRectKey);
+                  if(dirtyRectPos != itemsDirtyRects.end())
+                  {
+                    Rect<int> currentRect = rect;
+
+                    // Same item, merge it with the previous rect
+                    rect.Merge(dirtyRectPos->second.rect);
+
+                    // Replace the rect as current
+                    dirtyRectPos->second.visited = true;
+                    dirtyRectPos->second.rect    = currentRect;
+                  }
+                  else
                   {
-                    if(dirtyRectPos->node != item.mNode || dirtyRectPos->renderer != item.mRenderer)
-                    {
-                      break;
-                    }
-
-                    dirtyRectPos->visited = true;
-                    Rect<int>& dirtRect   = dirtyRectPos->rect;
-                    rect.Merge(dirtRect);
-
-                    c++;
-                    if(c > 3) // no more then 3 previous rects
-                    {
-                      itemsDirtyRects.erase(dirtyRectPos);
-                      break;
-                    }
+                    // Else, just insert the new dirtyrect
+                    itemsDirtyRects.insert({dirtyRectKey, rect});
                   }
 
                   damagedRects.push_back(rect);
@@ -658,51 +671,44 @@ void RenderManager::PreRender(Integration::Scene& scene, std::vector<Rect<int>>&
               {
                 // 1. The item is not dirty, the node and renderer referenced by the item are still exist.
                 // 2. Mark the related dirty rects as visited so they will not be removed below.
-                auto dirtyRectPos = std::lower_bound(itemsDirtyRects.begin(), itemsDirtyRects.end(), dirtyRect);
-                while(dirtyRectPos != itemsDirtyRects.end())
+                auto dirtyRectPos = itemsDirtyRects.find(dirtyRectKey);
+                if(dirtyRectPos != itemsDirtyRects.end())
                 {
-                  if(dirtyRectPos->node != item.mNode || dirtyRectPos->renderer != item.mRenderer)
-                  {
-                    break;
-                  }
-
-                  dirtyRectPos->visited = true;
-                  dirtyRectPos++;
+                  dirtyRectPos->second.visited = true;
+                }
+                else
+                {
+                  // The item is not in the list for some reason. Add it!
+                  itemsDirtyRects.insert({dirtyRectKey, surfaceRect});
+                  cleanDamagedRect = true; // And make full update at this frame
                 }
               }
             }
           }
-
-          // Reset updated flag from the root
-          Layer* sourceLayer = renderList->GetSourceLayer();
-          if(sourceLayer)
-          {
-            sourceLayer->SetUpdatedTree(false);
-          }
         }
       }
     }
   }
 
   // Check removed nodes or removed renderers dirty rects
-  auto i = itemsDirtyRects.begin();
-  auto j = itemsDirtyRects.begin();
-  while(i != itemsDirtyRects.end())
+  // Note, std::unordered_map end iterator is validate if we call erase.
+  for(auto iter = itemsDirtyRects.cbegin(), iterEnd = itemsDirtyRects.cend(); iter != iterEnd;)
   {
-    if(i->visited)
+    if(!iter->second.visited)
     {
-      *j++ = *i;
+      damagedRects.push_back(iter->second.rect);
+      iter = itemsDirtyRects.erase(iter);
     }
     else
     {
-      Rect<int>& dirtRect = i->rect;
-      damagedRects.push_back(dirtRect);
+      ++iter;
     }
-    i++;
   }
 
-  itemsDirtyRects.resize(j - itemsDirtyRects.begin());
-  damagedRectCleaner.SetCleanOnReturn(false);
+  if(!cleanDamagedRect)
+  {
+    damagedRectCleaner.SetCleanOnReturn(false);
+  }
 }
 
 void RenderManager::RenderScene(Integration::RenderStatus& status, Integration::Scene& scene, bool renderToFbo)
@@ -742,6 +748,9 @@ void RenderManager::RenderScene(Integration::RenderStatus& status, Integration::
     clippingRect = Rect<int>();
   }
 
+  // Prepare to lock and map standalone uniform buffer.
+  mImpl->uniformBufferManager->ReadyToLockUniformBuffer(mImpl->renderBufferIndex);
+
   for(uint32_t i = 0; i < count; ++i)
   {
     RenderInstruction& instruction = sceneObject->GetRenderInstructions().At(mImpl->renderBufferIndex, i);
@@ -756,7 +765,11 @@ void RenderManager::RenderScene(Integration::RenderStatus& status, Integration::
 
     Rect<int32_t> viewportRect;
 
-    int32_t surfaceOrientation = sceneObject->GetSurfaceOrientation();
+    int32_t surfaceOrientation = sceneObject->GetSurfaceOrientation() + sceneObject->GetScreenOrientation();
+    if(surfaceOrientation >= 360)
+    {
+      surfaceOrientation -= 360;
+    }
 
     // @todo Should these be part of scene?
     Integration::DepthBufferAvailable   depthBufferAvailable   = mImpl->depthBufferAvailable;
@@ -915,7 +928,7 @@ void RenderManager::RenderScene(Integration::RenderStatus& status, Integration::
     // Scissor's value should be set based on the default system coordinates.
     // When the surface is rotated, the input values already were set with the rotated angle.
     // So, re-calculation is needed.
-    scissorArea = RecalculateScissorArea(scissorArea, surfaceOrientation, viewportRect);
+    scissorArea = RecalculateScissorArea(scissorArea, surfaceOrientation, surfaceRect);
 
     // Begin render pass
     mainCommandBuffer->BeginRenderPass(
@@ -940,7 +953,8 @@ void RenderManager::RenderScene(Integration::RenderStatus& status, Integration::
       mImpl->boundTextures,
       viewportRect,
       clippingRect,
-      surfaceOrientation);
+      surfaceOrientation,
+      Uint16Pair(surfaceRect.width, surfaceRect.height));
 
     Graphics::SyncObject* syncObject{nullptr};
     // If the render instruction has an associated render tracker (owned separately)
@@ -953,7 +967,12 @@ void RenderManager::RenderScene(Integration::RenderStatus& status, Integration::
     }
     mainCommandBuffer->EndRenderPass(syncObject);
   }
+
+  // Unlock standalone uniform buffer.
+  mImpl->uniformBufferManager->UnlockUniformBuffer(mImpl->renderBufferIndex);
+
   mImpl->renderAlgorithms.SubmitCommandBuffer();
+  mImpl->commandBufferSubmitted = true;
 
   std::sort(targetstoPresent.begin(), targetstoPresent.end());
 
@@ -968,14 +987,31 @@ void RenderManager::RenderScene(Integration::RenderStatus& status, Integration::
   }
 }
 
-void RenderManager::PostRender(bool uploadOnly)
+void RenderManager::PostRender()
 {
+  if(!mImpl->commandBufferSubmitted)
+  {
+    // Rendering is skipped but there may be pending tasks. Flush them.
+    Graphics::SubmitInfo submitInfo;
+    submitInfo.cmdBuffer.clear(); // Only flush
+    submitInfo.flags = 0 | Graphics::SubmitFlagBits::FLUSH;
+    mImpl->graphicsController.SubmitCommandBuffers(submitInfo);
+
+    mImpl->commandBufferSubmitted = true;
+  }
+
   // Notify RenderGeometries that rendering has finished
   for(auto&& iter : mImpl->geometryContainer)
   {
     iter->OnRenderFinished();
   }
 
+  // Notify RenderTexture that rendering has finished
+  for(auto&& iter : mImpl->textureContainer)
+  {
+    iter->OnRenderFinished();
+  }
+
   mImpl->UpdateTrackers();
 
   uint32_t count = 0u;