Merge "Make property resetter age down correctly" into devel/master
authorDavid Steele <david.steele@samsung.com>
Thu, 3 Aug 2023 17:06:40 +0000 (17:06 +0000)
committerGerrit Code Review <gerrit@review>
Thu, 3 Aug 2023 17:06:40 +0000 (17:06 +0000)
dali/graphics-api/graphics-texture-create-info.h
dali/graphics-api/graphics-types.h
dali/internal/render/renderers/render-renderer.cpp
dali/internal/render/renderers/render-renderer.h
dali/internal/render/renderers/render-texture.cpp
dali/internal/render/renderers/render-texture.h
dali/internal/update/nodes/node.cpp

index f4862ed..fee65af 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_GRAPHICS_TEXTURE_CREATE_INFO_H
 
 /*
- * Copyright (c) 2021 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.
@@ -145,6 +145,22 @@ struct TextureCreateInfo
   }
 
   /**
+   * @brief Sets texture GPU data allocation policy
+   *
+   * CREATION will allocate GPU memory at creation time.
+   * UPLOAD will allocate GPU memory at creation with non-empty data,
+   * or upload data time.
+   *
+   * @param[in] value texture allocation policy
+   * @return reference to this structure
+   */
+  auto& SetAllocationPolicy(TextureAllocationPolicy value)
+  {
+    allocationPolicy = value;
+    return *this;
+  }
+
+  /**
    * @brief Sets texture usage flags
    *
    * The usage flags may affect the way the texture is
@@ -193,6 +209,7 @@ struct TextureCreateInfo
   Format                  format{};
   TextureMipMapFlag       mipMapFlag{};
   TextureLayout           layout{};
+  TextureAllocationPolicy allocationPolicy{};
   TextureUsageFlags       usageFlags{};
   void*                   data{};
   uint32_t                dataSize{0u};
index e271bc2..a9dc532 100644 (file)
@@ -1261,6 +1261,15 @@ enum class TextureLayout
 };
 
 /**
+ * @brief Texture allocation policy defines when the GPU texture memory is allocated.
+ */
+enum class TextureAllocationPolicy
+{
+  CREATION, ///< GPU Memory will be allocated when creation.
+  UPLOAD,   ///< GPU Memory will be allocated when upload image data.
+};
+
+/**
  * @brief Level of command buffer
  */
 enum class CommandBufferLevel
index 60f3a53..06d8b68 100644 (file)
@@ -696,11 +696,12 @@ std::size_t Renderer::BuildUniformIndexMap(BufferIndex bufferIndex, const SceneG
   // Specially, if node don't have uniformMap, we mark nodePtr as nullptr.
   // So, all nodes without uniformMap will share same UniformIndexMap, contains only render data providers.
   const auto nodePtr = uniformMapNode.Count() ? &node : nullptr;
+  const auto programPtr = &program;
 
   const auto nodeChangeCounter          = nodePtr ? uniformMapNode.GetChangeCounter() : 0;
   const auto renderItemMapChangeCounter = uniformMap.GetChangeCounter();
 
-  auto iter = std::find_if(mNodeIndexMap.begin(), mNodeIndexMap.end(), [nodePtr](RenderItemLookup& element) { return element.node == nodePtr; });
+  auto iter = std::find_if(mNodeIndexMap.begin(), mNodeIndexMap.end(), [nodePtr, programPtr](RenderItemLookup& element) { return (element.node == nodePtr && element.program == programPtr); });
 
   std::size_t renderItemMapIndex;
   if(iter == mNodeIndexMap.end())
@@ -708,6 +709,7 @@ std::size_t Renderer::BuildUniformIndexMap(BufferIndex bufferIndex, const SceneG
     renderItemMapIndex = mUniformIndexMaps.size();
     RenderItemLookup renderItemLookup;
     renderItemLookup.node                       = nodePtr;
+    renderItemLookup.program                    = programPtr;
     renderItemLookup.index                      = renderItemMapIndex;
     renderItemLookup.nodeChangeCounter          = nodeChangeCounter;
     renderItemLookup.renderItemMapChangeCounter = renderItemMapChangeCounter;
@@ -1017,8 +1019,7 @@ void Renderer::DetachFromNodeDataProvider(const SceneGraph::NodeDataProvider& no
 
   // Remove mNodeIndexMap and mUniformIndexMaps.
   auto iter = std::find_if(mNodeIndexMap.begin(), mNodeIndexMap.end(), [&node](RenderItemLookup& element) { return element.node == &node; });
-
-  if(iter != mNodeIndexMap.end())
+  while(iter != mNodeIndexMap.end())
   {
     // Swap between end of mUniformIndexMaps and removed.
     auto nodeIndex           = iter->index;
@@ -1043,6 +1044,8 @@ void Renderer::DetachFromNodeDataProvider(const SceneGraph::NodeDataProvider& no
 
     // Remove uniform index maps.
     mUniformIndexMaps.pop_back();
+
+    iter = std::find_if(mNodeIndexMap.begin(), mNodeIndexMap.end(), [&node](RenderItemLookup& element) { return element.node == &node; });
   }
 }
 
index a348bb4..c12d253 100644 (file)
@@ -657,7 +657,8 @@ private:
   /** Struct to map node to index into mNodeMapCounters and mUniformIndexMaps */
   struct RenderItemLookup
   {
-    const SceneGraph::NodeDataProvider* node{nullptr}; ///<Node key. It can be nullptr if this NodeIndex don't need node uniform
+    const SceneGraph::NodeDataProvider* node{nullptr};    ///< Node key. It can be nullptr if this NodeIndex don't need node uniform
+    const Program*                      program{nullptr}; ///< Program key.
 
     std::size_t index{0};                       ///<Index into mUniformIndexMap
     std::size_t nodeChangeCounter{0};           ///<The last known change counter for this node's uniform map
index a38ede9..0607d99 100644 (file)
@@ -296,10 +296,15 @@ Graphics::Texture* Texture::GetGraphicsObject() const
 
 void Texture::Create(Graphics::TextureUsageFlags usage)
 {
-  CreateWithData(usage, nullptr, 0u);
+  Create(usage, Graphics::TextureAllocationPolicy::CREATION);
 }
 
-void Texture::CreateWithData(Graphics::TextureUsageFlags usage, uint8_t* data, uint32_t size)
+void Texture::Create(Graphics::TextureUsageFlags usage, Graphics::TextureAllocationPolicy allocationPolicy)
+{
+  CreateWithData(usage, allocationPolicy, nullptr, 0u);
+}
+
+void Texture::CreateWithData(Graphics::TextureUsageFlags usage, Graphics::TextureAllocationPolicy allocationPolicy, uint8_t* data, uint32_t size)
 {
   auto createInfo = Graphics::TextureCreateInfo();
   createInfo
@@ -308,6 +313,7 @@ void Texture::CreateWithData(Graphics::TextureUsageFlags usage, uint8_t* data, u
     .SetFormat(ConvertPixelFormat(mPixelFormat))
     .SetSize({mWidth, mHeight})
     .SetLayout(Graphics::TextureLayout::LINEAR)
+    .SetAllocationPolicy(allocationPolicy)
     .SetData(data)
     .SetDataSize(size)
     .SetNativeImage(mNativeImage)
@@ -378,7 +384,10 @@ void Texture::Upload(PixelDataPtr pixelData, const Internal::Texture::UploadPara
   // Always create new graphics texture object if we use uploaded parameter as texture.
   if(!mGraphicsTexture || mUseUploadedParameter)
   {
-    Create(static_cast<Graphics::TextureUsageFlags>(Graphics::TextureUsageFlagBits::SAMPLE));
+    const bool isSubImage(params.xOffset != 0u || params.yOffset != 0u ||
+                          uploadedDataWidth != (mWidth >> params.mipmap) ||
+                          uploadedDataHeight != (mHeight >> params.mipmap));
+    Create(static_cast<Graphics::TextureUsageFlags>(Graphics::TextureUsageFlagBits::SAMPLE), isSubImage ? Graphics::TextureAllocationPolicy::CREATION : Graphics::TextureAllocationPolicy::UPLOAD);
   }
 
   Graphics::TextureUpdateInfo info{};
index 8895cfc..0ffed60 100644 (file)
@@ -225,12 +225,20 @@ private:
   void ApplySampler(Render::Sampler* sampler);
 
   /**
+   * Create the texture without a buffer
+   * @param[in] usage How texture will be used
+   * @param[in] allocationPolicy Policy of texture allocation
+   */
+  void Create(Graphics::TextureUsageFlags usage, Graphics::TextureAllocationPolicy allocationPolicy);
+
+  /**
    * Create a texture with a buffer if non-null
    * @param[in] usage How texture will be used
+   * @param[in] allocationPolicy Policy of texture allocation
    * @param[in] buffer Buffer to copy
    * @param[in] bufferSize Size of buffer to copy
    */
-  void CreateWithData(Graphics::TextureUsageFlags usage, uint8_t* buffer, uint32_t bufferSize);
+  void CreateWithData(Graphics::TextureUsageFlags usage, Graphics::TextureAllocationPolicy allocationPolicy, uint8_t* buffer, uint32_t bufferSize);
 
 private:
   Graphics::Controller*                  mGraphicsController;
index 91e3a0a..55447df 100644 (file)
@@ -82,7 +82,8 @@ void Node::Delete(Node* node)
 }
 
 Node::Node()
-: mOrientation(),                                                               // Initialized to identity by default
+: mTransformManagerData(),                                                      // Initialized to use invalid id by default
+  mOrientation(),                                                               // Initialized to identity by default
   mWorldPosition(TRANSFORM_PROPERTY_WORLD_POSITION, Vector3(0.0f, 0.0f, 0.0f)), // Zero initialized by default
   mWorldScale(TRANSFORM_PROPERTY_WORLD_SCALE, Vector3(1.0f, 1.0f, 1.0f)),
   mWorldOrientation(), // Initialized to identity by default