Merge changes I6d6c0232,I6667d1d6,I43e227fc into devel/master
authorDavid Steele <david.steele@samsung.com>
Mon, 19 Jul 2021 09:24:29 +0000 (09:24 +0000)
committerGerrit Code Review <gerrit@review>
Mon, 19 Jul 2021 09:24:29 +0000 (09:24 +0000)
* changes:
  Removed memcpy() from uniform write
  Uniform data cached locally in the uniform map
  Updating geometry without iterating render items

dali/internal/render/common/render-manager.cpp
dali/internal/render/renderers/render-geometry.h
dali/internal/render/renderers/render-renderer.cpp
dali/internal/render/renderers/render-renderer.h
dali/internal/render/renderers/uniform-buffer.cpp

index c44c328..4a309fd 100644 (file)
@@ -382,7 +382,15 @@ void RenderManager::AddGeometry(OwnerPointer<Render::Geometry>& geometry)
 
 void RenderManager::RemoveGeometry(Render::Geometry* geometry)
 {
-  mImpl->geometryContainer.EraseObject(geometry);
+  auto it = std::find_if( mImpl->geometryContainer.begin(), mImpl->geometryContainer.end(),[geometry]( auto& item )
+  {
+    return geometry == item;
+  });
+
+  if(it != mImpl->geometryContainer.end())
+  {
+    mImpl->geometryContainer.Erase(it);
+  }
 }
 
 void RenderManager::AttachVertexBuffer(Render::Geometry* geometry, Render::VertexBuffer* vertexBuffer)
@@ -459,43 +467,9 @@ void RenderManager::PreRender(Integration::RenderStatus& status, bool forceClear
     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 );
     }
   }
 }
index 1de282f..54d9ee4 100644 (file)
@@ -86,7 +86,7 @@ public:
    * Check if the attributes for the geometry have changed
    * @return True if vertex buffers have been added or removed since last frame, false otherwise
    */
-  [[nodiscard]] bool AttributesChanged() const
+  [[maybe_unused]] [[nodiscard]] bool AttributesChanged() const
   {
     return mAttributesChanged;
   }
index 5eb8289..6681a54 100644 (file)
@@ -698,21 +698,43 @@ void Renderer::FillUniformBuffer(Program&                                      p
         iter != end;
         ++iter)
     {
-      // @todo This means parsing the uniform string every frame. Instead, store the array index if present.
-      int arrayIndex = (*iter).arrayIndex;
+      auto& uniform = *iter;
+      int arrayIndex = uniform.arrayIndex;
 
-      auto uniformInfo  = Graphics::UniformInfo{};
-      auto uniformFound = program.GetUniform((*iter).uniformName.GetCString(),
-                                             (*iter).uniformNameHashNoArray ? (*iter).uniformNameHashNoArray
-                                                                            : (*iter).uniformNameHash,
-                                             uniformInfo);
+      if(!uniform.uniformFunc)
+      {
+        auto uniformInfo  = Graphics::UniformInfo{};
+        auto uniformFound = program.GetUniform(uniform.uniformName.GetCString(),
+                                               uniform.uniformNameHashNoArray ? uniform.uniformNameHashNoArray
+                                                                              : uniform.uniformNameHash,
+                                               uniformInfo);
+
+        uniform.uniformOffset   = uniformInfo.offset;
+        uniform.uniformLocation = uniformInfo.location;
+
+        if (uniformFound)
+        {
+          auto       dst      = ubo.GetOffset() + uniformInfo.offset;
+          const auto typeSize = GetPropertyValueSizeForUniform((*iter).propertyValue->GetType());
+          const auto dest     = dst + static_cast<uint32_t>(typeSize) * arrayIndex;
+          const auto func     = GetPropertyValueGetter((*iter).propertyValue->GetType());
+
+          ubo.Write(&((*iter).propertyValue->*func)(updateBufferIndex),
+                    typeSize,
+                    dest);
 
-      if(uniformFound)
+          uniform.uniformSize = typeSize;
+          uniform.uniformFunc = func;
+        }
+      }
+      else
       {
-        auto dst = ubo.GetOffset() + uniformInfo.offset;
-        const auto typeSize = GetPropertyValueSizeForUniform( (*iter).propertyValue->GetType() );
-        const auto dest = dst + static_cast<uint32_t>(typeSize) * arrayIndex;
-        const auto func = GetPropertyValueGetter((*iter).propertyValue->GetType());
+        auto       dst      = ubo.GetOffset() + uniform.uniformOffset;
+        const auto typeSize = uniform.uniformSize;
+        const auto dest     = dst + static_cast<uint32_t>(typeSize) * arrayIndex;
+        const auto func     = uniform.uniformFunc;
+
+
         ubo.Write(&((*iter).propertyValue->*func)(updateBufferIndex),
                   typeSize,
                   dest);
index b57490f..5583fe0 100644 (file)
@@ -516,6 +516,9 @@ private:
   Render::PipelineCache* mPipelineCache{nullptr};
 
   using Hash = unsigned long;
+
+  typedef const float&(PropertyInputImpl::*FuncGetter )(BufferIndex) const;
+
   struct UniformIndexMap
   {
     ConstString              uniformName;            ///< The uniform name
@@ -523,6 +526,11 @@ private:
     Hash                     uniformNameHash{0u};
     Hash                     uniformNameHashNoArray{0u};
     int32_t                  arrayIndex{-1}; ///< The array index
+
+    int16_t                  uniformLocation{0u};
+    uint16_t                 uniformOffset{0u};
+    uint16_t                 uniformSize{0u};
+    FuncGetter               uniformFunc{0};
   };
 
   using UniformIndexMappings = Dali::Vector<UniformIndexMap>;
index ecae483..c944880 100644 (file)
@@ -181,7 +181,13 @@ void UniformBuffer::Write(const void* data, uint32_t size, uint32_t dstOffset)
     void* ptr = bufferDesc.memory->LockRegion(bufferOffset, size);
     if(ptr && bufferOffset + size < mSize)
     {
-      memcpy(ptr, data, size);
+      // size always divides by 4 (std140 alignment rules, so we can replace memcpy with unrolled assignments)
+      auto ptr32 = reinterpret_cast<uint32_t*>(ptr);
+      auto data32 = reinterpret_cast<const uint32_t*>(data);
+      for(auto i = 0u; i < size; i +=4 )
+      {
+        *ptr32++ = *data32++;;
+      }
     }
     bufferDesc.memory->Unlock(true);
   }