X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fadaptor%2Fcommon%2Fcombined-update-render-controller.cpp;h=712992d387a475500645d730e0e78d12df89ee45;hb=a0ff11296a578e09317e90d32623b86884feb82d;hp=e271f089b78fce3de5ed4d378bec4600b1bfed3b;hpb=5fc501fe479edca0f57178238bf352d0a57222d7;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git diff --git a/dali/internal/adaptor/common/combined-update-render-controller.cpp b/dali/internal/adaptor/common/combined-update-render-controller.cpp index e271f08..712992d 100644 --- a/dali/internal/adaptor/common/combined-update-render-controller.cpp +++ b/dali/internal/adaptor/common/combined-update-render-controller.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. @@ -20,12 +20,12 @@ // EXTERNAL INCLUDES #include -#include #include #include #include "dali/public-api/common/dali-common.h" // INTERNAL INCLUDES +#include #include #include #include @@ -45,7 +45,6 @@ namespace Adaptor { namespace { - const unsigned int CREATED_THREAD_COUNT = 1u; const int CONTINUOUS = -1; @@ -82,6 +81,15 @@ const uint64_t DEFAULT_FRAME_DURATION_IN_NANOSECONDS(DEFAULT_FRAME_DURATION_IN_S * 3) MAIN THREAD: Sleep Request: COUNTER = 0 -> Go to sleep */ const unsigned int MAXIMUM_UPDATE_REQUESTS = 2; + +inline std::vector StringToVector(const std::string& str) +{ + auto retval = std::vector{}; + retval.insert(retval.begin(), str.begin(), str.end()); + retval.push_back('\0'); + return retval; +} + } // unnamed namespace /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -109,6 +117,7 @@ CombinedUpdateRenderController::CombinedUpdateRenderController(AdaptorInternalSe mDefaultHalfFrameNanoseconds(0u), mUpdateRequestCount(0u), mRunning(FALSE), + mVsyncRender(TRUE), mThreadId(0), mThreadMode(threadMode), mUpdateRenderRunCount(0), @@ -116,6 +125,7 @@ CombinedUpdateRenderController::CombinedUpdateRenderController(AdaptorInternalSe mUpdateRenderThreadCanSleep(FALSE), mPendingRequestUpdate(FALSE), mUseElapsedTimeAfterWait(FALSE), + mIsPreCompileCancelled(FALSE), mNewSurface(NULL), mDeletedSurface(nullptr), mPostRendering(FALSE), @@ -136,6 +146,8 @@ CombinedUpdateRenderController::CombinedUpdateRenderController(AdaptorInternalSe currentSurface->SetThreadSynchronization(*this); } + mVsyncRender = environmentOptions.VsyncRenderRequired(); + mSleepTrigger = TriggerEventFactory::CreateTriggerEvent(MakeCallback(this, &CombinedUpdateRenderController::ProcessSleepRequest), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER); } @@ -313,6 +325,7 @@ 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; + CancelPreCompile(); mUpdateRenderThreadWaitCondition.Notify(lock); } @@ -336,6 +349,7 @@ 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; + CancelPreCompile(); mUpdateRenderThreadWaitCondition.Notify(lock); } @@ -372,6 +386,7 @@ void CombinedUpdateRenderController::ResizeSurface() ConditionalWait::ScopedLock lock(mUpdateRenderThreadWaitCondition); // Surface is resized and the surface resized count is increased. mSurfaceResized++; + CancelPreCompile(); mUpdateRenderThreadWaitCondition.Notify(lock); } } @@ -450,6 +465,7 @@ void CombinedUpdateRenderController::RunUpdateRenderThread(int numberOfCycles, A mUpdateRenderThreadCanSleep = FALSE; mUploadWithoutRendering = (updateMode == UpdateMode::SKIP_RENDER); LOG_COUNTER_EVENT("mUpdateRenderRunCount: %d, mUseElapsedTimeAfterWait: %d", mUpdateRenderRunCount, mUseElapsedTimeAfterWait); + CancelPreCompile(); mUpdateRenderThreadWaitCondition.Notify(lock); } @@ -463,6 +479,7 @@ void CombinedUpdateRenderController::StopUpdateRenderThread() { ConditionalWait::ScopedLock lock(mUpdateRenderThreadWaitCondition); mDestroyUpdateRenderThread = TRUE; + CancelPreCompile(); mUpdateRenderThreadWaitCondition.Notify(lock); } @@ -573,33 +590,43 @@ void CombinedUpdateRenderController::UpdateRenderThread() unsigned int frameCount = 0u; TRACE_UPDATE_RENDER_END("DALI_RENDER_THREAD_INIT"); - - if(Integration::ShaderPrecompiler::Get().IsEnable()) + if(!mDestroyUpdateRenderThread) { - std::vector 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) + ShaderPreCompiler::Get().Wait(); + if(ShaderPreCompiler::Get().IsEnable()) { - auto numberOfPrecomipledShader = precompiledShader->shaderCount; - for(int i= 0; i precompiledShaderList; + 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(mIsPreCompileCancelled == TRUE) + { + ShaderPreCompiler::Get().Awake(); + DALI_LOG_RELEASE_INFO("ShaderPreCompiler[ENABLE], but stop precompile"); + break; + } + + auto numberOfPrecompiledShader = precompiledShader->shaderCount; + for(int i = 0; i < numberOfPrecompiledShader; ++i) + { + auto vertexShader = graphics.GetController().GetGlAbstraction().GetVertexShaderPrefix() + std::string(precompiledShader->vertexPrefix[i].data()) + std::string(precompiledShader->vertexShader.data()); + auto fragmentShader = graphics.GetController().GetGlAbstraction().GetFragmentShaderPrefix() + std::string(precompiledShader->fragmentPrefix[i].data()) + std::string(precompiledShader->fragmentShader.data()); + PreCompileShader(std::move(vertexShader), std::move(fragmentShader)); + } + DALI_LOG_RELEASE_INFO("ShaderPreCompiler[ENABLE], shader count :%d \n", numberOfPrecompiledShader); } - 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)) { LOG_UPDATE_RENDER_TRACE; - TRACE_UPDATE_RENDER_SCOPE("DALI_UPDATE_RENDER"); + TRACE_UPDATE_RENDER_BEGIN("DALI_UPDATE_RENDER"); // For thread safe bool uploadOnly = mUploadWithoutRendering; @@ -709,6 +736,12 @@ void CombinedUpdateRenderController::UpdateRenderThread() mNotificationTrigger.Trigger(); LOG_UPDATE_RENDER("Notification Triggered"); } + + if(uploadOnly && (keepUpdatingStatus & Dali::Integration::KeepUpdating::STAGE_KEEP_RENDERING)) + { + // Render forcely if there exist some keep rendering required. + uploadOnly = false; + } // Optional logging of update/render status mUpdateStatusLogger.Log(keepUpdatingStatus); @@ -774,7 +807,7 @@ void CombinedUpdateRenderController::UpdateRenderThread() TRACE_UPDATE_RENDER_SCOPE("DALI_RENDER_SCENE"); Integration::RenderStatus windowRenderStatus; - const bool sceneSurfaceResized = scene.IsSurfaceRectChanged(); + const uint32_t sceneSurfaceResized = scene.GetSurfaceRectChangedCount(); // clear previous frame damaged render items rects, buffer history is tracked on surface level mDamagedRects.clear(); @@ -788,7 +821,7 @@ void CombinedUpdateRenderController::UpdateRenderThread() Rect clippingRect; // Empty for fbo rendering // Switch to the context of the surface, merge damaged areas for previous frames - windowSurface->PreRender(sceneSurfaceResized, mDamagedRects, clippingRect); // Switch GL context + windowSurface->PreRender(sceneSurfaceResized > 0u, mDamagedRects, clippingRect); // Switch GL context // Render the surface mCore.RenderScene(windowRenderStatus, scene, false, clippingRect); @@ -796,13 +829,17 @@ void CombinedUpdateRenderController::UpdateRenderThread() // Buffer swapping now happens when the surface render target is presented. // If surface is resized, the surface resized count is decreased. - if(DALI_UNLIKELY(sceneSurfaceResized)) + if(DALI_UNLIKELY(sceneSurfaceResized > 0u)) { - SurfaceResized(); + SurfaceResized(sceneSurfaceResized); } } } } + else + { + DALI_LOG_RELEASE_INFO("DALI Rendering skip (upload only)\n"); + } TRACE_UPDATE_RENDER_BEGIN("DALI_POST_RENDER"); if(!uploadOnly) @@ -885,8 +922,10 @@ void CombinedUpdateRenderController::UpdateRenderThread() } } + TRACE_UPDATE_RENDER_END("DALI_UPDATE_RENDER"); + // Render to FBO is intended to measure fps above 60 so sleep is not wanted. - if(0u == renderToFboInterval) + if(mVsyncRender && 0u == renderToFboInterval) { TRACE_UPDATE_RENDER_SCOPE("DALI_UPDATE_RENDER_SLEEP"); // Sleep until at least the the default frame duration has elapsed. This will return immediately if the specified end-time has already passed. @@ -1006,12 +1045,61 @@ void CombinedUpdateRenderController::SurfaceDeleted() mSurfaceSemaphore.Release(1); } -void CombinedUpdateRenderController::SurfaceResized() +void CombinedUpdateRenderController::SurfaceResized(uint32_t resizedCount) { ConditionalWait::ScopedLock lock(mUpdateRenderThreadWaitCondition); - if(mSurfaceResized) + + if(mSurfaceResized >= resizedCount) + { + mSurfaceResized -= resizedCount; + } + else + { + mSurfaceResized = 0u; + } +} + +void CombinedUpdateRenderController::PreCompileShader(std::string vertexShader, std::string fragmentShader) +{ + GraphicsInterface& graphics = mAdaptorInterfaces.GetGraphicsInterface(); + + Graphics::ShaderCreateInfo vertexShaderCreateInfo; + vertexShaderCreateInfo.SetPipelineStage(Graphics::PipelineStage::VERTEX_SHADER); + vertexShaderCreateInfo.SetSourceMode(Graphics::ShaderSourceMode::TEXT); + const std::vector& vertexShaderSrc = StringToVector(std::move(vertexShader)); + vertexShaderCreateInfo.SetSourceSize(vertexShaderSrc.size()); + vertexShaderCreateInfo.SetSourceData(static_cast(vertexShaderSrc.data())); + auto vertexGraphicsShader = graphics.GetController().CreateShader(vertexShaderCreateInfo, nullptr); + + Graphics::ShaderCreateInfo fragmentShaderCreateInfo; + fragmentShaderCreateInfo.SetPipelineStage(Graphics::PipelineStage::FRAGMENT_SHADER); + fragmentShaderCreateInfo.SetSourceMode(Graphics::ShaderSourceMode::TEXT); + const std::vector& fragmentShaderSrc = StringToVector(std::move(fragmentShader)); + fragmentShaderCreateInfo.SetSourceSize(fragmentShaderSrc.size()); + fragmentShaderCreateInfo.SetSourceData(static_cast(fragmentShaderSrc.data())); + auto fragmentGraphicsShader = graphics.GetController().CreateShader(fragmentShaderCreateInfo, nullptr); + + std::vector shaderStates{ + Graphics::ShaderState() + .SetShader(*vertexGraphicsShader.get()) + .SetPipelineStage(Graphics::PipelineStage::VERTEX_SHADER), + Graphics::ShaderState() + .SetShader(*fragmentGraphicsShader.get()) + .SetPipelineStage(Graphics::PipelineStage::FRAGMENT_SHADER)}; + + auto createInfo = Graphics::ProgramCreateInfo(); + createInfo.SetShaderState(shaderStates); + + auto graphicsProgram = graphics.GetController().CreateProgram(createInfo, nullptr); + ShaderPreCompiler::Get().AddPreCompiledProgram(std::move(graphicsProgram)); +} + +void CombinedUpdateRenderController::CancelPreCompile() +{ + if(mIsPreCompileCancelled == FALSE) { - mSurfaceResized--; + mIsPreCompileCancelled = TRUE; + ShaderPreCompiler::Get().Awake(); } } @@ -1046,6 +1134,7 @@ void CombinedUpdateRenderController::PostRenderComplete() { ConditionalWait::ScopedLock lock(mUpdateRenderThreadWaitCondition); mPostRendering = FALSE; + CancelPreCompile(); mUpdateRenderThreadWaitCondition.Notify(lock); }