X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Frender%2Fcommon%2Frender-manager.cpp;h=7a934f1e8761bd9477c7f49b930c9ffad66ed577;hb=refs%2Ftags%2Faccepted%2Ftizen%2Funified%2F20240228.170343;hp=afef026a95c9646159ee1acb8232225814286612;hpb=23121253a40937e67f2b3a91eb0dff275c718aa2;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/render/common/render-manager.cpp b/dali/internal/render/common/render-manager.cpp index afef026..7a934f1 100644 --- a/dali/internal/render/common/render-manager.cpp +++ b/dali/internal/render/common/render-manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * Copyright (c) 2024 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. @@ -22,7 +22,6 @@ #include // INTERNAL INCLUDES -#include #include #include @@ -42,7 +41,6 @@ #include #include #include -#include #include #include #include @@ -64,6 +62,9 @@ Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_REN namespace { +// TODO : Cache clean logic have some problem now. Just block it until bug resolved +//constexpr uint32_t CACHE_CLEAN_FRAME_COUNT = 600u; // 60fps * 10sec + inline Graphics::Rect2D RecalculateScissorArea(const Graphics::Rect2D& scissorArea, int orientation, const Rect& viewportRect) { Graphics::Rect2D newScissorArea; @@ -139,22 +140,16 @@ struct RenderManager::Impl : graphicsController(graphicsController), renderAlgorithms(graphicsController), programController(graphicsController), - shaderCache(graphicsController), depthBufferAvailable(depthBufferAvailableParam), stencilBufferAvailable(stencilBufferAvailableParam), partialUpdateAvailable(partialUpdateAvailableParam) { - // Create thread pool with just one thread ( there may be a need to create more threads in the future ). - threadPool = std::make_unique(); - threadPool->Initialize(1u); - uniformBufferManager = std::make_unique(&graphicsController); pipelineCache = std::make_unique(graphicsController); } ~Impl() { - threadPool.reset(nullptr); // reset now to maintain correct destruction order rendererContainer.Clear(); // clear now before the pipeline cache is deleted } @@ -192,8 +187,9 @@ struct RenderManager::Impl OrderedSet mRenderTrackers; ///< List of owned render trackers - ProgramController programController; ///< Owner of the programs - Render::ShaderCache shaderCache; ///< The cache for the graphics shaders + OwnerKeyContainer textureDiscardQueue; ///< Discarded textures + + ProgramController programController; ///< Owner of the programs std::unique_ptr uniformBufferManager; ///< The uniform buffer manager std::unique_ptr pipelineCache; @@ -202,10 +198,7 @@ struct RenderManager::Impl Integration::StencilBufferAvailable stencilBufferAvailable; ///< Whether the stencil buffer is available Integration::PartialUpdateAvailable partialUpdateAvailable; ///< Whether the partial update is available - std::unique_ptr threadPool; ///< The thread pool - Vector boundTextures; ///< The textures bound for rendering - Vector textureDependencyList; ///< The dependency list of bound textures - Vector updatedTextures{}; ///< The updated texture list + Vector updatedTextures{}; ///< The updated texture list uint32_t frameCount{0u}; ///< The current frame count BufferIndex renderBufferIndex{SceneGraphBuffers::INITIAL_UPDATE_BUFFER_INDEX}; ///< The index of the buffer to read from; @@ -249,7 +242,7 @@ void RenderManager::SetShaderSaver(ShaderSaver& upstream) 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())); + renderer->Initialize(mImpl->graphicsController, mImpl->programController, *(mImpl->uniformBufferManager.get()), *(mImpl->pipelineCache.get())); mImpl->rendererContainer.PushBack(renderer); } @@ -274,7 +267,7 @@ void RenderManager::AddTexture(const Render::TextureKey& textureKey) { DALI_ASSERT_DEBUG(textureKey && "Trying to add empty texture key"); - textureKey->Initialize(mImpl->graphicsController); + textureKey->Initialize(mImpl->graphicsController, *this); mImpl->textureContainer.PushBack(textureKey); mImpl->updatedTextures.PushBack(textureKey); } @@ -288,12 +281,15 @@ void RenderManager::RemoveTexture(const Render::TextureKey& textureKey) if(iter != mImpl->textureContainer.End()) { + // Destroy texture. textureKey->Destroy(); - mImpl->textureContainer.Erase(iter); // Texture found; now destroy it + + // Transfer ownership to the discard queue, this keeps the object alive, until the render-thread has finished with it + mImpl->textureDiscardQueue.PushBack(mImpl->textureContainer.Release(iter)); } } -void RenderManager::UploadTexture(const Render::TextureKey& textureKey, PixelDataPtr pixelData, const Texture::UploadParams& params) +void RenderManager::UploadTexture(const Render::TextureKey& textureKey, PixelDataPtr pixelData, const Graphics::UploadParams& params) { DALI_ASSERT_DEBUG(textureKey && "Trying to upload to empty texture key"); textureKey->Upload(pixelData, params); @@ -309,6 +305,19 @@ void RenderManager::GenerateMipmaps(const Render::TextureKey& textureKey) mImpl->updatedTextures.PushBack(textureKey); } +void RenderManager::SetTextureSize(const Render::TextureKey& textureKey, const Dali::ImageDimensions& size) +{ + DALI_ASSERT_DEBUG(textureKey && "Trying to set size on empty texture key"); + textureKey->SetWidth(size.GetWidth()); + textureKey->SetHeight(size.GetHeight()); +} + +void RenderManager::SetTextureFormat(const Render::TextureKey& textureKey, Dali::Pixel::Format pixelFormat) +{ + DALI_ASSERT_DEBUG(textureKey && "Trying to set pixel format on empty texture key"); + textureKey->SetPixelFormat(pixelFormat); +} + void RenderManager::SetTextureUpdated(const Render::TextureKey& textureKey) { DALI_ASSERT_DEBUG(textureKey && "Trying to set updated on empty texture key"); @@ -499,6 +508,15 @@ 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. + // TODO : Cache clean logic have some problem now. Just block it until bug resolved + /* + if(mImpl->frameCount % CACHE_CLEAN_FRAME_COUNT == 1) + { + mImpl->programController.ResetReferenceCount(); + } + */ + mImpl->commandBufferSubmitted = false; } @@ -515,6 +533,14 @@ void RenderManager::PreRender(Integration::Scene& scene, std::vector>& if(!sceneObject || sceneObject->IsRenderingSkipped()) { // We don't need to calculate dirty rects + if(!sceneObject) + { + DALI_LOG_ERROR("Scene was empty handle. Skip pre-rendering\n"); + } + else + { + DALI_LOG_RELEASE_INFO("RenderingSkipped set true. Skip pre-rendering\n"); + } return; } @@ -771,6 +797,7 @@ void RenderManager::RenderScene(Integration::RenderStatus& status, Integration:: if(mImpl->partialUpdateAvailable == Integration::PartialUpdateAvailable::TRUE && !renderToFbo && clippingRect.IsEmpty()) { // ClippingRect is empty. Skip rendering + DALI_LOG_DEBUG_INFO("ClippingRect is empty. Skip rendering\n"); return; } @@ -783,6 +810,7 @@ void RenderManager::RenderScene(Integration::RenderStatus& status, Integration:: SceneGraph::Scene* sceneObject = sceneInternal.GetSceneObject(); if(!sceneObject) { + DALI_LOG_ERROR("Scene was empty handle. Skip rendering\n"); return; } @@ -823,7 +851,7 @@ void RenderManager::RenderScene(Integration::RenderStatus& status, Integration:: auto program = item.mRenderer->PrepareProgram(instruction); if(program) { - auto memoryRequirements = program->GetUniformBlocksMemoryRequirements(); + const auto& memoryRequirements = program->GetUniformBlocksMemoryRequirements(); totalSizeCPU += memoryRequirements.totalCpuSizeRequired; totalSizeGPU += memoryRequirements.totalGpuSizeRequired; @@ -966,19 +994,6 @@ void RenderManager::RenderScene(Integration::RenderStatus& status, Integration:: targetstoPresent.emplace_back(currentRenderTarget); - // reset the program matrices for all programs once per frame - // this ensures we will set view and projection matrix once per program per camera - mImpl->programController.ResetProgramMatrices(); - - if(instruction.mFrameBuffer) - { - // For each offscreen buffer, update the dependency list with the new texture id used by this frame buffer. - for(unsigned int i0 = 0, i1 = instruction.mFrameBuffer->GetColorAttachmentCount(); i0 < i1; ++i0) - { - mImpl->textureDependencyList.PushBack(instruction.mFrameBuffer->GetTexture(i0)); - } - } - if(!instruction.mIgnoreRenderToFbo && (instruction.mFrameBuffer != nullptr)) { // Offscreen buffer rendering @@ -1060,15 +1075,11 @@ void RenderManager::RenderScene(Integration::RenderStatus& status, Integration:: float(viewportRect.width), float(viewportRect.height)}); - // Clear the list of bound textures - mImpl->boundTextures.Clear(); - mImpl->renderAlgorithms.ProcessRenderInstruction( instruction, mImpl->renderBufferIndex, depthBufferAvailable, stencilBufferAvailable, - mImpl->boundTextures, viewportRect, clippingRect, surfaceOrientation, @@ -1088,7 +1099,6 @@ void RenderManager::RenderScene(Integration::RenderStatus& status, Integration:: // Flush UBOs mImpl->uniformBufferManager->Flush(sceneObject, renderToFbo); - mImpl->renderAlgorithms.SubmitCommandBuffer(); mImpl->commandBufferSubmitted = true; @@ -1131,6 +1141,9 @@ void RenderManager::PostRender() } mImpl->updatedTextures.Clear(); + // Remove discarded textures after OnRenderFinished called + mImpl->textureDiscardQueue.Clear(); + mImpl->UpdateTrackers(); uint32_t count = 0u; @@ -1139,6 +1152,15 @@ void RenderManager::PostRender() count += scene->GetRenderInstructions().Count(mImpl->renderBufferIndex); } + // Remove unused shader and programs during CACHE_CLEAN_FRAME_COUNT frames. + // TODO : Cache clean logic have some problem now. Just block it until bug resolved + /* + if(mImpl->frameCount % CACHE_CLEAN_FRAME_COUNT == 0) + { + mImpl->programController.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.