X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Frender%2Frenderers%2Frender-renderer.cpp;h=45aa582d4e2da75fbcc8a71ecd0faea97c0e7872;hb=a513234144a775134eff3a24144983a5e374d1d5;hp=db30a4e68f067561bd53050b24788d1d432fe968;hpb=82eba25935835ef78d113414981eaf1e1fc046c5;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/render/renderers/render-renderer.cpp b/dali/internal/render/renderers/render-renderer.cpp index db30a4e..45aa582 100644 --- a/dali/internal/render/renderers/render-renderer.cpp +++ b/dali/internal/render/renderers/render-renderer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 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. @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -145,22 +146,57 @@ inline uint32_t GetUniformBufferDataAlignment(uint32_t dataSize) return ((dataSize / 256u) + ((dataSize % 256u) ? 1u : 0u)) * 256u; } +/** + * @brief Store latest binded RenderGeometry, and help that we can skip duplicated vertex attributes bind. + * + * @param[in] geometry Current geometry to be used, or nullptr if render finished + * @return True if we can reuse latest binded vertex attributes. False otherwise. + */ +inline bool ReuseLatestBindedVertexAttributes(const Render::Geometry* geometry) +{ + static const Render::Geometry* gLatestVertexBindedGeometry = nullptr; + if(gLatestVertexBindedGeometry == geometry) + { + return true; + } + gLatestVertexBindedGeometry = geometry; + return false; +} + } // namespace namespace Render { -Renderer* Renderer::New(SceneGraph::RenderDataProvider* dataProvider, - Render::Geometry* geometry, - uint32_t blendingBitmask, - const Vector4& blendColor, - FaceCullingMode::Type faceCullingMode, - bool preMultipliedAlphaEnabled, - DepthWriteMode::Type depthWriteMode, - DepthTestMode::Type depthTestMode, - DepthFunction::Type depthFunction, - StencilParameters& stencilParameters) +namespace { - return new Renderer(dataProvider, geometry, blendingBitmask, blendColor, faceCullingMode, preMultipliedAlphaEnabled, depthWriteMode, depthTestMode, depthFunction, stencilParameters); +MemoryPoolObjectAllocator gRenderRendererMemoryPool; +} + +void Renderer::PrepareCommandBuffer() +{ + // Reset latest geometry informations, So we can bind the first of geometry. + ReuseLatestBindedVertexAttributes(nullptr); + + // todo : Fill here as many caches as we can store for reduce the number of command buffers +} + +RendererKey Renderer::NewKey(SceneGraph::RenderDataProvider* dataProvider, + Render::Geometry* geometry, + uint32_t blendingBitmask, + const Vector4& blendColor, + FaceCullingMode::Type faceCullingMode, + bool preMultipliedAlphaEnabled, + DepthWriteMode::Type depthWriteMode, + DepthTestMode::Type depthTestMode, + DepthFunction::Type depthFunction, + StencilParameters& stencilParameters) +{ + void* ptr = gRenderRendererMemoryPool.AllocateRawThreadSafe(); + auto key = gRenderRendererMemoryPool.GetKeyFromPtr(static_cast(ptr)); + + // Use placement new to construct renderer. + new(ptr) Renderer(dataProvider, geometry, blendingBitmask, blendColor, faceCullingMode, preMultipliedAlphaEnabled, depthWriteMode, depthTestMode, depthFunction, stencilParameters); + return RendererKey(key); } Renderer::Renderer(SceneGraph::RenderDataProvider* dataProvider, @@ -207,10 +243,21 @@ void Renderer::Initialize(Graphics::Controller& graphicsController, ProgramCache Renderer::~Renderer() = default; +void Renderer::operator delete(void* ptr) +{ + gRenderRendererMemoryPool.FreeThreadSafe(static_cast(ptr)); +} + +Renderer* Renderer::Get(RendererKey::KeyType rendererKey) +{ + return gRenderRendererMemoryPool.GetPtrFromKey(rendererKey); +} + void Renderer::SetGeometry(Render::Geometry* geometry) { mGeometry = geometry; } + void Renderer::SetDrawCommands(Dali::DevelRenderer::DrawCommand* pDrawCommands, uint32_t size) { mDrawCommands.clear(); @@ -221,8 +268,8 @@ void Renderer::BindTextures(Graphics::CommandBuffer& commandBuffer, Vector* textures(mRenderDataProvider->GetTextures()); - const Dali::Vector* samplers(mRenderDataProvider->GetSamplers()); + auto textures(mRenderDataProvider->GetTextures()); + auto samplers(mRenderDataProvider->GetSamplers()); std::vector textureBindings; @@ -450,7 +497,7 @@ bool Renderer::Render(Graphics::CommandBuffer& comma for(auto& texture : textureResources) { auto& textureImpl = GetImplementation(texture); - auto graphicsTexture = textureImpl.GetRenderObject()->GetGraphicsObject(); + auto graphicsTexture = textureImpl.GetRenderTextureKey()->GetGraphicsObject(); auto properties = mGraphicsController->GetTextureProperties(*graphicsTexture); @@ -465,7 +512,7 @@ bool Renderer::Render(Graphics::CommandBuffer& comma mRenderCallbackInput->size = size; mRenderCallbackInput->projection = projectionMatrix; - MatrixUtils::Multiply(mRenderCallbackInput->mvp, modelViewMatrix, projectionMatrix); + MatrixUtils::MultiplyProjectionMatrix(mRenderCallbackInput->mvp, modelViewMatrix, projectionMatrix); // submit draw commandBuffer.DrawNative(&info); @@ -549,16 +596,25 @@ bool Renderer::Render(Graphics::CommandBuffer& comma bool drawn = false; // Draw can fail if there are no vertex buffers or they haven't been uploaded yet // @todo We should detect this case much earlier to prevent unnecessary work - if(mDrawCommands.empty()) + // Reuse latest binded vertex attributes location, or Bind buffers to attribute locations. + if(ReuseLatestBindedVertexAttributes(mGeometry) || mGeometry->BindVertexAttributes(commandBuffer)) { - drawn = mGeometry->Draw(*mGraphicsController, commandBuffer, mIndexedDrawFirstElement, mIndexedDrawElementsCount); + if(mDrawCommands.empty()) + { + drawn = mGeometry->Draw(*mGraphicsController, commandBuffer, mIndexedDrawFirstElement, mIndexedDrawElementsCount); + } + else + { + for(auto& cmd : commands) + { + drawn |= mGeometry->Draw(*mGraphicsController, commandBuffer, cmd->firstIndex, cmd->elementCount); + } + } } else { - for(auto& cmd : commands) - { - mGeometry->Draw(*mGraphicsController, commandBuffer, cmd->firstIndex, cmd->elementCount); - } + // BindVertexAttributes failed. Reset cached geometry. + ReuseLatestBindedVertexAttributes(nullptr); } return drawn; @@ -717,7 +773,7 @@ void Renderer::WriteUniformBuffer( if(mvpUniformInfo && !mvpUniformInfo->name.empty()) { Matrix modelViewProjectionMatrix(false); - MatrixUtils::Multiply(modelViewProjectionMatrix, modelViewMatrix, projectionMatrix); + MatrixUtils::MultiplyProjectionMatrix(modelViewProjectionMatrix, modelViewMatrix, projectionMatrix); WriteDefaultUniform(mvpUniformInfo, *uboView, modelViewProjectionMatrix); }