// INTERNAL INCLUDES
#include <dali/devel-api/threading/thread-pool.h>
#include <dali/integration-api/core.h>
-#include <dali/integration-api/gl-context-helper-abstraction.h>
#include <dali/internal/event/common/scene-impl.h>
#include <dali/internal/update/common/scene-graph-scene.h>
+#include <dali/internal/update/nodes/scene-graph-layer.h>
#include <dali/internal/update/render-tasks/scene-graph-camera.h>
#include <dali/internal/render/common/render-algorithms.h>
#include <dali/internal/render/common/render-instruction.h>
#include <dali/internal/render/common/render-tracker.h>
#include <dali/internal/render/queue/render-queue.h>
+#include <dali/internal/render/renderers/pipeline-cache.h>
#include <dali/internal/render/renderers/render-frame-buffer.h>
#include <dali/internal/render/renderers/render-texture.h>
#include <dali/internal/render/renderers/shader-cache.h>
#include <dali/internal/render/renderers/uniform-buffer-manager.h>
+#include <dali/internal/render/renderers/uniform-buffer-view-pool.h>
#include <dali/internal/render/shaders/program-controller.h>
+#include <memory>
+
namespace Dali
{
namespace Internal
} // unnamed namespace
#endif
+namespace
+{
+inline Graphics::Rect2D RecalculateScissorArea(Graphics::Rect2D scissorArea, int orientation, Rect<int32_t> viewportRect)
+{
+ Graphics::Rect2D newScissorArea;
+
+ if(orientation == 90)
+ {
+ newScissorArea.x = viewportRect.height - (scissorArea.y + scissorArea.height);
+ newScissorArea.y = scissorArea.x;
+ newScissorArea.width = scissorArea.height;
+ newScissorArea.height = scissorArea.width;
+ }
+ else if(orientation == 180)
+ {
+ newScissorArea.x = viewportRect.width - (scissorArea.x + scissorArea.width);
+ newScissorArea.y = viewportRect.height - (scissorArea.y + scissorArea.height);
+ newScissorArea.width = scissorArea.width;
+ newScissorArea.height = scissorArea.height;
+ }
+ else if(orientation == 270)
+ {
+ newScissorArea.x = scissorArea.y;
+ newScissorArea.y = viewportRect.width - (scissorArea.x + scissorArea.width);
+ newScissorArea.width = scissorArea.height;
+ newScissorArea.height = scissorArea.width;
+ }
+ else
+ {
+ newScissorArea.x = scissorArea.x;
+ newScissorArea.y = scissorArea.y;
+ newScissorArea.width = scissorArea.width;
+ newScissorArea.height = scissorArea.height;
+ }
+ return newScissorArea;
+}
+} // namespace
/**
* Structure to contain internal data
*/
partialUpdateAvailable(partialUpdateAvailableParam)
{
// Create thread pool with just one thread ( there may be a need to create more threads in the future ).
- threadPool = std::unique_ptr<Dali::ThreadPool>(new Dali::ThreadPool());
+ threadPool = std::make_unique<Dali::ThreadPool>();
threadPool->Initialize(1u);
- uniformBufferManager.reset(new Render::UniformBufferManager(&graphicsController));
+ uniformBufferManager = std::make_unique<Render::UniformBufferManager>(&graphicsController);
+ pipelineCache = std::make_unique<Render::PipelineCache>(graphicsController);
}
~Impl()
OwnerContainer<Render::RenderTracker*> mRenderTrackers; ///< List of render trackers
- ProgramController programController; ///< Owner of the GL programs
+ ProgramController programController; ///< Owner of the programs
Render::ShaderCache shaderCache; ///< The cache for the graphics shaders
std::unique_ptr<Render::UniformBufferManager> uniformBufferManager; ///< The uniform buffer manager
+ std::unique_ptr<Render::PipelineCache> pipelineCache;
Integration::DepthBufferAvailable depthBufferAvailable; ///< Whether the depth buffer is available
Integration::StencilBufferAvailable stencilBufferAvailable; ///< Whether the stencil buffer is available
void RenderManager::AddRenderer(OwnerPointer<Render::Renderer>& renderer)
{
// Initialize the renderer as we are now in render thread
- renderer->Initialize(mImpl->graphicsController, mImpl->programController, mImpl->shaderCache, *(mImpl->uniformBufferManager.get()));
+ renderer->Initialize(mImpl->graphicsController, mImpl->programController, mImpl->shaderCache, *(mImpl->uniformBufferManager.get()), *(mImpl->pipelineCache.get()));
mImpl->rendererContainer.PushBack(renderer.Release());
}
{
DALI_ASSERT_DEBUG(NULL != texture);
- // Find the texture, use reference to pointer so we can do the erase safely
- for(auto&& iter : mImpl->textureContainer)
+ // Find the texture, use std::find so we can do the erase safely
+ auto iter = std::find(mImpl->textureContainer.begin(), mImpl->textureContainer.end(), texture);
+
+ if(iter != mImpl->textureContainer.end())
{
- if(iter == texture)
- {
- texture->Destroy();
- mImpl->textureContainer.Erase(&iter); // Texture found; now destroy it
- return;
- }
+ texture->Destroy();
+ mImpl->textureContainer.Erase(iter); // Texture found; now destroy it
}
}
{
DALI_ASSERT_DEBUG(nullptr != frameBuffer);
- // Find the sampler, use reference so we can safely do the erase
- for(auto&& iter : mImpl->frameBufferContainer)
- {
- if(iter == frameBuffer)
- {
- frameBuffer->Destroy();
- mImpl->frameBufferContainer.Erase(&iter); // frameBuffer found; now destroy it
+ // Find the framebuffer, use std:find so we can safely do the erase
+ auto iter = std::find(mImpl->frameBufferContainer.begin(), mImpl->frameBufferContainer.end(), frameBuffer);
- break;
- }
+ if(iter != mImpl->frameBufferContainer.end())
+ {
+ frameBuffer->Destroy();
+ mImpl->frameBufferContainer.Erase(iter); // frameBuffer found; now destroy it
}
}
void RenderManager::RemoveGeometry(Render::Geometry* geometry)
{
- mImpl->geometryContainer.EraseObject(geometry);
+ auto iter = std::find(mImpl->geometryContainer.begin(), mImpl->geometryContainer.end(), geometry);
+
+ if(iter != mImpl->geometryContainer.end())
+ {
+ mImpl->geometryContainer.Erase(iter);
+ }
}
void RenderManager::AttachVertexBuffer(Render::Geometry* geometry, Render::VertexBuffer* vertexBuffer)
{
DALI_PRINT_RENDER_START(mImpl->renderBufferIndex);
+ // Rollback
+ mImpl->uniformBufferManager->GetUniformBufferViewPool(mImpl->renderBufferIndex)->Rollback();
+
// Increment the frame count at the beginning of each frame
++mImpl->frameCount;
DALI_LOG_INFO(gLogFilter, Debug::General, "Render: Processing\n");
// Upload the geometries
- for(auto& i : mImpl->sceneContainer)
+ for(auto&& geom : mImpl->geometryContainer)
{
- RenderInstructionContainer& instructions = i->GetRenderInstructions();
- for(uint32_t j = 0; j < instructions.Count(mImpl->renderBufferIndex); ++j)
- {
- RenderInstruction& instruction = instructions.At(mImpl->renderBufferIndex, j);
-
- const Matrix* viewMatrix = instruction.GetViewMatrix(mImpl->renderBufferIndex);
- const Matrix* projectionMatrix = instruction.GetProjectionMatrix(mImpl->renderBufferIndex);
-
- DALI_ASSERT_DEBUG(viewMatrix);
- DALI_ASSERT_DEBUG(projectionMatrix);
-
- if(viewMatrix && projectionMatrix)
- {
- const RenderListContainer::SizeType renderListCount = instruction.RenderListCount();
-
- // Iterate through each render list.
- for(RenderListContainer::SizeType index = 0; index < renderListCount; ++index)
- {
- const RenderList* renderList = instruction.GetRenderList(index);
-
- if(renderList && !renderList->IsEmpty())
- {
- const std::size_t itemCount = renderList->Count();
- for(uint32_t itemIndex = 0u; itemIndex < itemCount; ++itemIndex)
- {
- const RenderItem& item = renderList->GetItem(itemIndex);
- if(DALI_LIKELY(item.mRenderer))
- {
- item.mRenderer->Upload();
- }
- }
- }
- }
- }
- }
+ geom->Upload(mImpl->graphicsController);
}
}
}
-void RenderManager::PreRender(Integration::Scene& scene, std::vector<Rect<int>>& damagedRects)
+void RenderManager::PreRender(Integration::RenderStatus& status, Integration::Scene& scene, std::vector<Rect<int>>& damagedRects)
{
if(mImpl->partialUpdateAvailable != Integration::PartialUpdateAvailable::TRUE)
{
if(sceneObject->IsRenderingSkipped())
{
// We don't need to calculate dirty rects
+ status.SetNeedsUpdate(false);
return;
}
+ status.SetNeedsUpdate(true);
+
class DamagedRectsCleaner
{
public:
- explicit DamagedRectsCleaner(std::vector<Rect<int>>& damagedRects)
+ explicit DamagedRectsCleaner(std::vector<Rect<int>>& damagedRects, Rect<int>& surfaceRect)
: mDamagedRects(damagedRects),
+ mSurfaceRect(surfaceRect),
mCleanOnReturn(true)
{
}
if(mCleanOnReturn)
{
mDamagedRects.clear();
+ mDamagedRects.push_back(mSurfaceRect);
}
}
private:
std::vector<Rect<int>>& mDamagedRects;
+ Rect<int> mSurfaceRect;
bool mCleanOnReturn;
};
Rect<int32_t> surfaceRect = sceneObject->GetSurfaceRect();
// Clean collected dirty/damaged rects on exit if 3d layer or 3d node or other conditions.
- DamagedRectsCleaner damagedRectCleaner(damagedRects);
+ DamagedRectsCleaner damagedRectCleaner(damagedRects, surfaceRect);
// 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();
+ std::vector<DirtyRect>& itemsDirtyRects = sceneObject->GetItemsDirtyRects();
for(DirtyRect& dirtyRect : itemsDirtyRects)
{
dirtyRect.visited = false;
for(RenderListContainer::SizeType index = 0u; index < count; ++index)
{
const RenderList* renderList = instruction.GetRenderList(index);
- if(renderList && !renderList->IsEmpty())
+ if(renderList)
{
- const std::size_t listCount = renderList->Count();
- for(uint32_t listIndex = 0u; listIndex < listCount; ++listIndex)
+ if(!renderList->IsEmpty())
{
- 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)
+ const std::size_t listCount = renderList->Count();
+ for(uint32_t listIndex = 0u; listIndex < listCount; ++listIndex)
{
- return;
- }
+ 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)
+ {
+ return;
+ }
- Rect<int> rect;
- DirtyRect dirtyRect(item.mNode, item.mRenderer, mImpl->frameCount, rect);
- // 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.mIsUpdated = false;
- item.mNode->SetUpdated(false);
+ Rect<int> rect;
+ DirtyRect dirtyRect(item.mNode, item.mRenderer, mImpl->frameCount, rect);
+ // 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.mIsUpdated = false;
- rect = item.CalculateViewportSpaceAABB(item.mUpdateSize, viewportRect.width, viewportRect.height);
- if(rect.IsValid() && rect.Intersect(viewportRect) && !rect.IsEmpty())
+ rect = RenderItem::CalculateViewportSpaceAABB(item.mModelViewMatrix, item.mUpdateSize, viewportRect.width, viewportRect.height);
+ if(rect.IsValid() && rect.Intersect(viewportRect) && !rect.IsEmpty())
+ {
+ const int left = rect.x;
+ const int top = rect.y;
+ const int right = rect.x + rect.width;
+ const int bottom = rect.y + rect.height;
+ rect.x = (left / 16) * 16;
+ rect.y = (top / 16) * 16;
+ rect.width = ((right + 16) / 16) * 16 - rect.x;
+ 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())
+ {
+ 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;
+ }
+ }
+
+ damagedRects.push_back(rect);
+ }
+ }
+ else
{
- const int left = rect.x;
- const int top = rect.y;
- const int right = rect.x + rect.width;
- const int bottom = rect.y + rect.height;
- rect.x = (left / 16) * 16;
- rect.y = (top / 16) * 16;
- rect.width = ((right + 16) / 16) * 16 - rect.x;
- rect.height = ((bottom + 16) / 16) * 16 - rect.y;
-
- // Found valid dirty rect.
- // 1. Insert it in the sorted array of the dirty rects.
+ // 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.
- // 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())
+ while(dirtyRectPos != itemsDirtyRects.end())
{
if(dirtyRectPos->node != item.mNode || dirtyRectPos->renderer != item.mRenderer)
{
}
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;
- }
+ dirtyRectPos++;
}
-
- damagedRects.push_back(rect);
}
}
- else
- {
- // 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())
- {
- if(dirtyRectPos->node != item.mNode || dirtyRectPos->renderer != item.mRenderer)
- {
- break;
- }
+ }
- dirtyRectPos->visited = true;
- dirtyRectPos++;
- }
- }
+ // Reset updated flag from the root
+ Layer* sourceLayer = renderList->GetSourceLayer();
+ if(sourceLayer)
+ {
+ sourceLayer->SetUpdatedTree(false);
}
}
}
void RenderManager::RenderScene(Integration::RenderStatus& status, Integration::Scene& scene, bool renderToFbo)
{
- Rect<int> clippingRect;
+ SceneGraph::Scene* sceneObject = GetImplementation(scene).GetSceneObject();
+ Rect<int> clippingRect = sceneObject->GetSurfaceRect();
+
RenderScene(status, scene, renderToFbo, clippingRect);
}
void RenderManager::RenderScene(Integration::RenderStatus& status, Integration::Scene& scene, bool renderToFbo, Rect<int>& clippingRect)
{
+ if(mImpl->partialUpdateAvailable == Integration::PartialUpdateAvailable::TRUE && !renderToFbo && clippingRect.IsEmpty())
+ {
+ // ClippingRect is empty. Skip rendering
+ return;
+ }
+
// Reset main algorithms command buffer
mImpl->renderAlgorithms.ResetCommandBuffer();
std::vector<Graphics::RenderTarget*> targetstoPresent;
+ Rect<int32_t> surfaceRect = sceneObject->GetSurfaceRect();
+ if(clippingRect == surfaceRect)
+ {
+ // Full rendering case
+ // Make clippingRect empty because we're doing full rendering now if the clippingRect is empty.
+ // To reduce side effects, keep this logic now.
+ clippingRect = Rect<int>();
+ }
+
for(uint32_t i = 0; i < count; ++i)
{
RenderInstruction& instruction = sceneObject->GetRenderInstructions().At(mImpl->renderBufferIndex, i);
Rect<int32_t> viewportRect;
- Rect<int32_t> surfaceRect = sceneObject->GetSurfaceRect();
- int32_t surfaceOrientation = sceneObject->GetSurfaceOrientation();
+ int32_t surfaceOrientation = sceneObject->GetSurfaceOrientation();
// @todo Should these be part of scene?
Integration::DepthBufferAvailable depthBufferAvailable = mImpl->depthBufferAvailable;
// Offscreen buffer rendering
if(instruction.mIsViewportSet)
{
- // For glViewport the lower-left corner is (0,0)
+ // For Viewport the lower-left corner is (0,0)
const int32_t y = (instruction.mFrameBuffer->GetHeight() - instruction.mViewport.height) - instruction.mViewport.y;
viewportRect.Set(instruction.mViewport.x, y, instruction.mViewport.width, instruction.mViewport.height);
}
// Check whether a viewport is specified, otherwise the full surface size is used
if(instruction.mIsViewportSet)
{
- // For glViewport the lower-left corner is (0,0)
+ // For Viewport the lower-left corner is (0,0)
const int32_t y = (surfaceRect.height - instruction.mViewport.height) - instruction.mViewport.y;
viewportRect.Set(instruction.mViewport.x, y, instruction.mViewport.width, instruction.mViewport.height);
}
}
}
+ // 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);
+
// Begin render pass
mainCommandBuffer->BeginRenderPass(
currentRenderPass,
clippingRect,
surfaceOrientation);
- // Synchronise the FBO/Texture access
-
- // Check whether any bound texture is in the dependency list
- bool textureFound = false;
-
- if(mImpl->boundTextures.Count() > 0u && mImpl->textureDependencyList.Count() > 0u)
- {
- for(auto texture : mImpl->textureDependencyList)
- {
- textureFound = std::find_if(mImpl->boundTextures.Begin(), mImpl->boundTextures.End(), [texture](Graphics::Texture* graphicsTexture) {
- return texture == graphicsTexture;
- }) != mImpl->boundTextures.End();
- }
- }
-
- if(textureFound)
- {
- if(instruction.mFrameBuffer)
- {
- // For off-screen buffer
-
- // Clear the dependency list
- mImpl->textureDependencyList.Clear();
- }
- else
- {
- // Worker thread lambda function
- auto& glContextHelperAbstraction = mImpl->graphicsController.GetGlContextHelperAbstraction();
- auto workerFunction = [&glContextHelperAbstraction](int workerThread) {
- // Switch to the shared context in the worker thread
- glContextHelperAbstraction.MakeSurfacelessContextCurrent();
-
- // Wait until all rendering calls for the shared context are executed
- glContextHelperAbstraction.WaitClient();
-
- // Must clear the context in the worker thread
- // Otherwise the shared context cannot be switched to from the render thread
- glContextHelperAbstraction.MakeContextNull();
- };
-
- auto future = mImpl->threadPool->SubmitTask(0u, workerFunction);
- if(future)
- {
- mImpl->threadPool->Wait();
-
- // Clear the dependency list
- mImpl->textureDependencyList.Clear();
- }
- }
- }
-
+ Graphics::SyncObject* syncObject{nullptr};
+ // If the render instruction has an associated render tracker (owned separately)
+ // and framebuffer, create a one shot sync object, and use it to determine when
+ // the render pass has finished executing on GPU.
if(instruction.mRenderTracker && instruction.mFrameBuffer)
{
- // This will create a sync object every frame this render tracker
- // is alive (though it should be now be created only for
- // render-once render tasks)
- // @todo Add syncing to Graphics API
- instruction.mRenderTracker->CreateSyncObject(mImpl->graphicsController.GetGlSyncAbstraction());
- instruction.mRenderTracker = nullptr; // Only create once.
+ syncObject = instruction.mRenderTracker->CreateSyncObject(mImpl->graphicsController);
+ instruction.mRenderTracker = nullptr;
}
-
- // End render pass
- mainCommandBuffer->EndRenderPass();
+ mainCommandBuffer->EndRenderPass(syncObject);
}
mImpl->renderAlgorithms.SubmitCommandBuffer();