Implement some more speed-up : Reserve TextureBindings + don't copy geometry 33/271533/3
authorEunki, Hong <eunkiki.hong@samsung.com>
Tue, 22 Feb 2022 12:39:36 +0000 (21:39 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Wed, 23 Feb 2022 02:34:37 +0000 (11:34 +0900)
Make some GraphicsCommand API's input as const vector<>&

These will not copy the internal values. and also we can assume that
inputed data didn't change in that API

+

We reserve textureBinding's capacity as the Count of textures.
Most of texture have graphics object, and it will fitin that
reserved memory area.
This patch reduce unuseful re-allocation internal std::vector.

Change-Id: Ic9eee1ae2fe171431cf20a58c47af344edc977ef
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
automated-tests/src/dali/dali-test-suite-utils/test-graphics-command-buffer.h
dali/graphics-api/graphics-command-buffer.h
dali/internal/render/renderers/render-renderer.cpp

index 3df3219..96b0021 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TEST_GRAPHICS_COMMAND_BUFFER_H
 
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 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.
@@ -647,9 +647,9 @@ public:
   {
   }
 
-  void BindVertexBuffers(uint32_t                             firstBinding,
-                         std::vector<const Graphics::Buffer*> buffers,
-                         std::vector<uint32_t>                offsets) override
+  void BindVertexBuffers(uint32_t                                    firstBinding,
+                         const std::vector<const Graphics::Buffer*>& buffers,
+                         const std::vector<uint32_t>&                offsets) override
   {
     mCommands.emplace_back();
     mCommands.back().type = CommandType::BIND_VERTEX_BUFFERS;
@@ -712,7 +712,7 @@ public:
     mCallStack.PushCall("BindPipeline", "");
   }
 
-  void BindTextures(std::vector<Graphics::TextureBinding>& textureBindings) override
+  void BindTextures(const std::vector<Graphics::TextureBinding>& textureBindings) override
   {
     mCommands.emplace_back();
     mCommands.back().type                              = CommandType::BIND_TEXTURES;
@@ -720,7 +720,7 @@ public:
     mCallStack.PushCall("BindTextures", "");
   }
 
-  void BindSamplers(std::vector<Graphics::SamplerBinding>& samplerBindings) override
+  void BindSamplers(const std::vector<Graphics::SamplerBinding>& samplerBindings) override
   {
     mCommands.emplace_back();
     mCommands.back().data.bindSamplers.samplerBindings = std::move(samplerBindings);
@@ -747,10 +747,10 @@ public:
   }
 
   void BeginRenderPass(
-    Graphics::RenderPass*             renderPass,
-    Graphics::RenderTarget*           renderTarget,
-    Graphics::Rect2D                  renderArea,
-    std::vector<Graphics::ClearValue> clearValues) override
+    Graphics::RenderPass*                    renderPass,
+    Graphics::RenderTarget*                  renderTarget,
+    Graphics::Rect2D                         renderArea,
+    const std::vector<Graphics::ClearValue>& clearValues) override
   {
     mCommands.emplace_back(CommandType::BEGIN_RENDER_PASS);
     auto& cmd                             = mCommands.back();
index 2ac5417..476dd78 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_GRAPHICS_COMMAND_BUFFER_H
 
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 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.
@@ -111,9 +111,9 @@ public:
    * @param[in] buffers List of buffers to bind
    * @param[in] offsets List of offsets for each buffer
    */
-  virtual void BindVertexBuffers(uint32_t                   firstBinding,
-                                 std::vector<const Buffer*> buffers,
-                                 std::vector<uint32_t>      offsets) = 0;
+  virtual void BindVertexBuffers(uint32_t                          firstBinding,
+                                 const std::vector<const Buffer*>& buffers,
+                                 const std::vector<uint32_t>&      offsets) = 0;
 
   /**
    * @brief Binds uniform buffers
@@ -134,14 +134,14 @@ public:
    *
    * @param[in] textureBindings List of texture bindings
    */
-  virtual void BindTextures(std::vector<TextureBinding>& textureBindings) = 0;
+  virtual void BindTextures(const std::vector<TextureBinding>& textureBindings) = 0;
 
   /**
    * @brief Binds samplers
    *
    * @param[in] samplerBindings List of sampler bindings
    */
-  virtual void BindSamplers(std::vector<SamplerBinding>& samplerBindings) = 0;
+  virtual void BindSamplers(const std::vector<SamplerBinding>& samplerBindings) = 0;
 
   /**
    * @brief Binds buffer containing push constants
@@ -183,10 +183,10 @@ public:
    * @param[in] clearValues clear values (compatible with renderpass spec)
    */
   virtual void BeginRenderPass(
-    RenderPass*             renderPass,
-    RenderTarget*           renderTarget,
-    Rect2D                  renderArea,
-    std::vector<ClearValue> clearValues) = 0;
+    RenderPass*                    renderPass,
+    RenderTarget*                  renderTarget,
+    Rect2D                         renderArea,
+    const std::vector<ClearValue>& clearValues) = 0;
 
   /**
    * @brief Ends current render pass
index 9c8dd47..b76c15f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 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.
@@ -229,10 +229,14 @@ void Renderer::BindTextures(Graphics::CommandBuffer& commandBuffer, Vector<Graph
 
   if(textures != nullptr)
   {
-    for(uint32_t i = 0; i < static_cast<uint32_t>(textures->Count()); ++i) // not expecting more than uint32_t of textures
+    const std::uint32_t texturesCount(static_cast<std::uint32_t>(textures->Count()));
+    textureBindings.reserve(texturesCount);
+
+    for(uint32_t i = 0; i < texturesCount; ++i) // not expecting more than uint32_t of textures
     {
       if((*textures)[i] && (*textures)[i]->GetGraphicsObject())
       {
+        Graphics::Texture* graphicsTexture = (*textures)[i]->GetGraphicsObject();
         // if the sampler exists,
         //   if it's default, delete the graphics object
         //   otherwise re-initialize it if dirty
@@ -241,8 +245,8 @@ void Renderer::BindTextures(Graphics::CommandBuffer& commandBuffer, Vector<Graph
                                                                               : nullptr)
                                                             : nullptr;
 
-        boundTextures.PushBack((*textures)[i]->GetGraphicsObject());
-        const Graphics::TextureBinding textureBinding{(*textures)[i]->GetGraphicsObject(), graphicsSampler, textureUnit};
+        boundTextures.PushBack(graphicsTexture);
+        const Graphics::TextureBinding textureBinding{graphicsTexture, graphicsSampler, textureUnit};
         textureBindings.push_back(textureBinding);
 
         ++textureUnit;