[Tizen] Reducing uniform memory usage
authorHosang Kim <hosang12.kim@samsung.com>
Tue, 2 Jan 2024 06:27:14 +0000 (15:27 +0900)
committerHosang Kim <hosang12.kim@samsung.com>
Tue, 2 Jan 2024 06:27:14 +0000 (15:27 +0900)
This reverts commit 8462c0c0a2132cff269b1bae309447922ce32596.

dali/internal/event/common/property-input-impl.h
dali/internal/render/renderers/render-renderer.cpp
dali/internal/render/renderers/render-renderer.h
dali/internal/update/common/animatable-property.h
dali/internal/update/common/inherited-property.h
dali/internal/update/gestures/gesture-properties.h
dali/internal/update/manager/transform-manager-property.h

index 2bb3a3b..ab2ee09 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_PROPERTY_INPUT_IMPL_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.
@@ -181,6 +181,18 @@ public:
     return reinterpret_cast<const Matrix&>(*this);
   }
 
+  /**
+   * Retrieve the address of the property value. Only for use
+   * when writing uniforms.
+   */
+  virtual const void* GetValueAddress(BufferIndex bufferIndex) const = 0;
+
+  /**
+   * Retrieve the size of the property value for use in copying.
+   * Only for use when writing uniforms.
+   */
+  virtual size_t GetValueSize() const = 0;
+
   // Accessors for Constraint functions
 
   /**
index 4baebf9..11a20f9 100644 (file)
@@ -46,98 +46,6 @@ uint32_t      mvpBufferIndex;
 
 namespace
 {
-// Helper to get the property value getter by type
-typedef const float& (PropertyInputImpl::*FuncGetter)(BufferIndex) const;
-constexpr FuncGetter GetPropertyValueGetter(Property::Type type)
-{
-  switch(type)
-  {
-    case Property::BOOLEAN:
-    {
-      return FuncGetter(&PropertyInputImpl::GetBoolean);
-    }
-    case Property::INTEGER:
-    {
-      return FuncGetter(&PropertyInputImpl::GetInteger);
-    }
-    case Property::FLOAT:
-    {
-      return FuncGetter(&PropertyInputImpl::GetFloat);
-    }
-    case Property::VECTOR2:
-    {
-      return FuncGetter(&PropertyInputImpl::GetVector2);
-    }
-    case Property::VECTOR3:
-    {
-      return FuncGetter(&PropertyInputImpl::GetVector3);
-    }
-    case Property::VECTOR4:
-    {
-      return FuncGetter(&PropertyInputImpl::GetVector4);
-    }
-    case Property::MATRIX3:
-    {
-      return FuncGetter(&PropertyInputImpl::GetMatrix3);
-    }
-    case Property::MATRIX:
-    {
-      return FuncGetter(&PropertyInputImpl::GetMatrix);
-    }
-    default:
-    {
-      return nullptr;
-    }
-  }
-}
-
-/**
- * Helper function that returns size of uniform datatypes based
- * on property type.
- */
-constexpr int GetPropertyValueSizeForUniform(Property::Type type)
-{
-  switch(type)
-  {
-    case Property::Type::BOOLEAN:
-    {
-      return sizeof(bool);
-    }
-    case Property::Type::FLOAT:
-    {
-      return sizeof(float);
-    }
-    case Property::Type::INTEGER:
-    {
-      return sizeof(int);
-    }
-    case Property::Type::VECTOR2:
-    {
-      return sizeof(Vector2);
-    }
-    case Property::Type::VECTOR3:
-    {
-      return sizeof(Vector3);
-    }
-    case Property::Type::VECTOR4:
-    {
-      return sizeof(Vector4);
-    }
-    case Property::Type::MATRIX3:
-    {
-      return sizeof(Matrix3);
-    }
-    case Property::Type::MATRIX:
-    {
-      return sizeof(Matrix);
-    }
-    default:
-    {
-      return 0;
-    }
-  };
-}
-
 /**
  * Helper function to calculate the correct alignment of data for uniform buffers
  * @param dataSize size of uniform buffer
@@ -927,7 +835,7 @@ void Renderer::FillUniformBuffer(Program&
   {
     auto& uniform    = iter;
     int   arrayIndex = uniform.arrayIndex;
-    if(!uniform.uniformFunc)
+    if(!uniform.initialized)
     {
       auto uniformInfo  = Graphics::UniformInfo{};
       auto uniformFound = program.GetUniform(uniform.uniformName.GetStringView(),
@@ -948,15 +856,13 @@ void Renderer::FillUniformBuffer(Program&
       uniform.uniformOffset     = uniformInfo.offset;
       uniform.uniformLocation   = uniformInfo.location;
       uniform.uniformBlockIndex = uniformInfo.bufferIndex;
+      uniform.initialized       = true;
 
       auto       dst      = ubo->GetOffset() + uniformInfo.offset;
-      const auto typeSize = GetPropertyValueSizeForUniform(iter.propertyValue->GetType());
+      const auto typeSize = iter.propertyValue->GetValueSize();
       const auto dest     = dst + static_cast<uint32_t>(typeSize) * arrayIndex;
-      const auto func     = GetPropertyValueGetter(iter.propertyValue->GetType());
-      uniform.uniformSize = typeSize;
-      uniform.uniformFunc = func;
 
-      ubo->Write(&(iter.propertyValue->*func)(updateBufferIndex),
+      ubo->Write(iter.propertyValue->GetValueAddress(updateBufferIndex),
                  typeSize,
                  dest);
     }
@@ -965,11 +871,10 @@ void Renderer::FillUniformBuffer(Program&
       UniformBufferView* ubo = uboViews[uniform.uniformBlockIndex].get();
 
       auto       dst      = ubo->GetOffset() + uniform.uniformOffset;
-      const auto typeSize = uniform.uniformSize;
+      const auto typeSize = iter.propertyValue->GetValueSize();
       const auto dest     = dst + static_cast<uint32_t>(typeSize) * arrayIndex;
-      const auto func     = uniform.uniformFunc;
 
-      ubo->Write(&(iter.propertyValue->*func)(updateBufferIndex),
+      ubo->Write(iter.propertyValue->GetValueAddress(updateBufferIndex),
                  typeSize,
                  dest);
     }
index c8e9d3c..af05bcc 100644 (file)
@@ -630,8 +630,6 @@ private:
 
   using Hash = std::size_t;
 
-  typedef const float& (PropertyInputImpl::*FuncGetter)(BufferIndex) const;
-
   struct UniformIndexMap
   {
     ConstString              uniformName;            ///< The uniform name
@@ -640,11 +638,10 @@ private:
     Hash                     uniformNameHashNoArray{0u};
     int32_t                  arrayIndex{-1}; ///< The array index
 
-    int16_t    uniformLocation{0u};
-    uint16_t   uniformOffset{0u};
-    uint16_t   uniformSize{0u};
-    uint16_t   uniformBlockIndex{0u};
-    FuncGetter uniformFunc{0};
+    int16_t  uniformLocation{0u};
+    uint16_t uniformOffset{0u};
+    uint16_t uniformBlockIndex{0u};
+    bool     initialized{false};
   };
 
   StencilParameters mStencilParameters; ///< Struct containing all stencil related options
index 612af3f..c2bb6fe 100644 (file)
@@ -174,6 +174,22 @@ public:
   }
 
   /**
+   * @copydoc Dali::Internal::PropertyInputImpl::GetValueAddress()
+   */
+  const void* GetValueAddress(BufferIndex bufferIndex) const override
+  {
+    return &mValue[bufferIndex];
+  }
+
+  /**
+   * @copydoc Dali::Internal::PropertyInputImpl::GetValueSize()
+   */
+  size_t GetValueSize() const override
+  {
+    return sizeof(bool);
+  }
+
+  /**
    * Set the property value. This will only persist for the current frame; the property
    * will be reset with the base value, at the beginning of the next frame.
    * @param[in] bufferIndex The buffer to write.
@@ -340,6 +356,22 @@ public:
   }
 
   /**
+   * @copydoc Dali::Internal::PropertyInputImpl::GetValueAddress()
+   */
+  const void* GetValueAddress(BufferIndex bufferIndex) const override
+  {
+    return &mValue[bufferIndex];
+  }
+
+  /**
+   * @copydoc Dali::Internal::PropertyInputImpl::GetValueSize()
+   */
+  size_t GetValueSize() const override
+  {
+    return sizeof(int);
+  }
+
+  /**
    * Set the property value. This will only persist for the current frame; the property
    * will be reset with the base value, at the beginning of the next frame.
    * @param[in] bufferIndex The buffer to write.
@@ -515,6 +547,22 @@ public:
   }
 
   /**
+   * @copydoc Dali::Internal::PropertyInputImpl::GetValueAddress()
+   */
+  const void* GetValueAddress(BufferIndex bufferIndex) const override
+  {
+    return &mValue[bufferIndex];
+  }
+
+  /**
+   * @copydoc Dali::Internal::PropertyInputImpl::GetValueSize()
+   */
+  size_t GetValueSize() const override
+  {
+    return sizeof(float);
+  }
+
+  /**
    * Set the property value. This will only persist for the current frame; the property
    * will be reset with the base value, at the beginning of the next frame.
    * @param[in] bufferIndex The buffer to write.
@@ -692,6 +740,22 @@ public:
   }
 
   /**
+   * @copydoc Dali::Internal::PropertyInputImpl::GetValueAddress()
+   */
+  const void* GetValueAddress(BufferIndex bufferIndex) const override
+  {
+    return &mValue[bufferIndex];
+  }
+
+  /**
+   * @copydoc Dali::Internal::PropertyInputImpl::GetValueSize()
+   */
+  size_t GetValueSize() const override
+  {
+    return sizeof(Vector2);
+  }
+
+  /**
    * Set the property value. This will only persist for the current frame; the property
    * will be reset with the base value, at the beginning of the next frame.
    * @param[in] bufferIndex The buffer to write.
@@ -958,6 +1022,22 @@ public:
   }
 
   /**
+   * @copydoc Dali::Internal::PropertyInputImpl::GetValueAddress()
+   */
+  const void* GetValueAddress(BufferIndex bufferIndex) const override
+  {
+    return &mValue[bufferIndex];
+  }
+
+  /**
+   * @copydoc Dali::Internal::PropertyInputImpl::GetValueSize()
+   */
+  size_t GetValueSize() const override
+  {
+    return sizeof(Vector3);
+  }
+
+  /**
    * Set the property value. This will only persist for the current frame; the property
    * will be reset with the base value, at the beginning of the next frame.
    * @param[in] bufferIndex The buffer to write.
@@ -1278,6 +1358,22 @@ public:
   }
 
   /**
+   * @copydoc Dali::Internal::PropertyInputImpl::GetValueAddress()
+   */
+  const void* GetValueAddress(BufferIndex bufferIndex) const override
+  {
+    return &mValue[bufferIndex];
+  }
+
+  /**
+   * @copydoc Dali::Internal::PropertyInputImpl::GetValueSize()
+   */
+  size_t GetValueSize() const override
+  {
+    return sizeof(Vector4);
+  }
+
+  /**
    * Set the property value. This will only persist for the current frame; the property
    * will be reset with the base value, at the beginning of the next frame.
    * @param[in] bufferIndex The buffer to write.
@@ -1670,6 +1766,22 @@ public:
   }
 
   /**
+   * @copydoc Dali::Internal::PropertyInputImpl::GetValueAddress()
+   */
+  const void* GetValueAddress(BufferIndex bufferIndex) const override
+  {
+    return &mValue[bufferIndex];
+  }
+
+  /**
+   * @copydoc Dali::Internal::PropertyInputImpl::GetValueSize()
+   */
+  size_t GetValueSize() const override
+  {
+    return sizeof(Vector4);
+  }
+
+  /**
    * Change the property value by a relative amount.
    * @param[in] bufferIndex The buffer to write.
    * @param[in] delta The property will change by this amount.
@@ -1810,6 +1922,22 @@ public:
   }
 
   /**
+   * @copydoc Dali::Internal::PropertyInputImpl::GetValueAddress()
+   */
+  const void* GetValueAddress(BufferIndex bufferIndex) const override
+  {
+    return &mValue[bufferIndex];
+  }
+
+  /**
+   * @copydoc Dali::Internal::PropertyInputImpl::GetValueSize()
+   */
+  size_t GetValueSize() const override
+  {
+    return sizeof(Matrix);
+  }
+
+  /**
    * Set the property value. This will only persist for the current frame; the property
    * will be reset with the base value, at the beginning of the next frame.
    * @param[in] bufferIndex The buffer to write.
@@ -1966,6 +2094,22 @@ public:
   }
 
   /**
+   * @copydoc Dali::Internal::PropertyInputImpl::GetValueAddress()
+   */
+  const void* GetValueAddress(BufferIndex bufferIndex) const override
+  {
+    return &mValue[bufferIndex];
+  }
+
+  /**
+   * @copydoc Dali::Internal::PropertyInputImpl::GetValueSize()
+   */
+  size_t GetValueSize() const override
+  {
+    return sizeof(Matrix3);
+  }
+
+  /**
    * Set the property value. This will only persist for the current frame; the property
    * will be reset with the base value, at the beginning of the next frame.
    * @param[in] bufferIndex The buffer to write.
index e4a8446..08d62b4 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_SCENE_GRAPH_INHERITED_PROPERTY_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.
@@ -123,6 +123,22 @@ public:
   }
 
   /**
+   * @copydoc Dali::Internal::PropertyInputImpl::GetValueAddress()
+   */
+  const void* GetValueAddress(BufferIndex bufferIndex) const override
+  {
+    return &mValue[bufferIndex];
+  }
+
+  /**
+   * @copydoc Dali::Internal::PropertyInputImpl::GetValueSize()
+   */
+  size_t GetValueSize() const override
+  {
+    return sizeof(Vector3);
+  }
+
+  /**
    * @copydoc Dali::PropertyInput::GetConstraintInputVector3()
    */
   const Vector3& GetConstraintInputVector3(BufferIndex bufferIndex) const override
@@ -269,6 +285,22 @@ public:
   }
 
   /**
+   * @copydoc Dali::Internal::PropertyInputImpl::GetValueAddress()
+   */
+  const void* GetValueAddress(BufferIndex bufferIndex) const override
+  {
+    return &mValue[bufferIndex];
+  }
+
+  /**
+   * @copydoc Dali::Internal::PropertyInputImpl::GetValueSize()
+   */
+  size_t GetValueSize() const override
+  {
+    return sizeof(Vector4);
+  }
+
+  /**
    * @copydoc Dali::PropertyInput::GetConstraintInputVector4()
    */
   const Vector4& GetConstraintInputVector4(BufferIndex bufferIndex) const override
@@ -433,6 +465,22 @@ public:
   }
 
   /**
+   * @copydoc Dali::Internal::PropertyInputImpl::GetValueAddress()
+   */
+  const void* GetValueAddress(BufferIndex bufferIndex) const override
+  {
+    return &mValue[bufferIndex];
+  }
+
+  /**
+   * @copydoc Dali::Internal::PropertyInputImpl::GetValueSize()
+   */
+  size_t GetValueSize() const override
+  {
+    return sizeof(Vector4);
+  }
+
+  /**
    * @copydoc Dali::PropertyInput::GetConstraintInputQuaternion()
    */
   const Quaternion& GetConstraintInputQuaternion(BufferIndex bufferIndex) const override
@@ -578,6 +626,22 @@ public:
   }
 
   /**
+   * @copydoc Dali::Internal::PropertyInputImpl::GetValueAddress()
+   */
+  const void* GetValueAddress(BufferIndex bufferIndex) const override
+  {
+    return &mValue[bufferIndex];
+  }
+
+  /**
+   * @copydoc Dali::Internal::PropertyInputImpl::GetValueSize()
+   */
+  size_t GetValueSize() const override
+  {
+    return sizeof(Matrix);
+  }
+
+  /**
    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputMatrix()
    */
   const Matrix& GetConstraintInputMatrix(BufferIndex bufferIndex) const override
index 33e28b5..92e635e 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_SCENE_GRAPH_GESTURE_PROPERTIES_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.
@@ -151,6 +151,22 @@ public:
   {
     return mValue;
   }
+
+  /**
+   * @copydoc Dali::Internal::PropertyInputImpl::GetValueAddress()
+   */
+  const void* GetValueAddress(BufferIndex bufferIndex) const override
+  {
+    return &mValue;
+  }
+
+  /**
+   * @copydoc Dali::Internal::PropertyInputImpl::GetValueSize()
+   */
+  size_t GetValueSize() const override
+  {
+    return sizeof(Vector2);
+  }
 };
 
 /**
@@ -171,6 +187,22 @@ public:
   {
     return mValue;
   }
+
+  /**
+   * @copydoc Dali::Internal::PropertyInputImpl::GetValueAddress()
+   */
+  const void* GetValueAddress(BufferIndex bufferIndex) const override
+  {
+    return &mValue;
+  }
+
+  /**
+   * @copydoc Dali::Internal::PropertyInputImpl::GetValueSize()
+   */
+  size_t GetValueSize() const override
+  {
+    return sizeof(bool);
+  }
 };
 
 } // namespace SceneGraph
index fe5fec4..e093e01 100644 (file)
@@ -196,6 +196,22 @@ struct TransformManagerPropertyVector3 final : public TransformManagerPropertyHa
     return Get(bufferIndex);
   }
 
+  /**
+   * @copydoc Dali::Internal::PropertyInputImpl::GetValueAddress()
+   */
+  const void* GetValueAddress(BufferIndex bufferIndex) const override
+  {
+    return &GetVector3(bufferIndex);
+  }
+
+  /**
+   * @copydoc Dali::Internal::PropertyInputImpl::GetValueSize()
+   */
+  size_t GetValueSize() const override
+  {
+    return sizeof(Vector3);
+  }
+
   const float& GetFloatComponent(uint32_t component) const override
   {
     return GetTxManagerData()->Manager()->GetVector3PropertyComponentValue(GetTxManagerData()->Id(), PropertyT, component);
@@ -312,6 +328,22 @@ public:
   {
     return Get(bufferIndex);
   }
+
+  /**
+   * @copydoc Dali::Internal::PropertyInputImpl::GetValueAddress()
+   */
+  const void* GetValueAddress(BufferIndex bufferIndex) const override
+  {
+    return &Get(bufferIndex);
+  }
+
+  /**
+   * @copydoc Dali::Internal::PropertyInputImpl::GetValueSize()
+   */
+  size_t GetValueSize() const override
+  {
+    return sizeof(Vector4);
+  }
 };
 
 /**
@@ -415,6 +447,22 @@ public:
   }
 
   /**
+   * @copydoc Dali::Internal::PropertyInputImpl::GetValueAddress()
+   */
+  const void* GetValueAddress(BufferIndex bufferIndex) const override
+  {
+    return &GetVector3(bufferIndex);
+  }
+
+  /**
+   * @copydoc Dali::Internal::PropertyInputImpl::GetValueSize()
+   */
+  size_t GetValueSize() const override
+  {
+    return sizeof(Vector3);
+  }
+
+  /**
    * @copydoc Dali::PropertyInput::GetConstraintInputVector3()
    */
   const Vector3& GetConstraintInputVector3(BufferIndex bufferIndex) const override
@@ -555,6 +603,22 @@ public:
   }
 
   /**
+   * @copydoc Dali::Internal::PropertyInputImpl::GetValueAddress()
+   */
+  const void* GetValueAddress(BufferIndex bufferIndex) const override
+  {
+    return &GetQuaternion(bufferIndex);
+  }
+
+  /**
+   * @copydoc Dali::Internal::PropertyInputImpl::GetValueSize()
+   */
+  size_t GetValueSize() const override
+  {
+    return sizeof(Vector4);
+  }
+
+  /**
    * @copydoc Dali::PropertyInput::GetConstraintInputQuaternion()
    */
   const Quaternion& GetConstraintInputQuaternion(BufferIndex bufferIndex) const override
@@ -683,6 +747,29 @@ public:
   }
 
   /**
+   * @copydoc Dali::Internal::PropertyInputImpl::GetValueAddress()
+   */
+  const void* GetValueAddress(BufferIndex bufferIndex) const override
+  {
+    static const Matrix identityMatrix(Matrix::IDENTITY);
+    auto                transformManagerData = GetTxManagerData();
+    auto                id                   = transformManagerData->Id();
+    if(id != INVALID_TRANSFORM_ID)
+    {
+      return &(transformManagerData->Manager()->GetWorldMatrix(id));
+    }
+    return &identityMatrix;
+  }
+
+  /**
+   * @copydoc Dali::Internal::PropertyInputImpl::GetValueSize()
+   */
+  size_t GetValueSize() const override
+  {
+    return sizeof(Matrix);
+  }
+
+  /**
    * @copydoc Dali::PropertyInput::GetConstraintInputMatrix()
    */
   const Matrix& GetConstraintInputMatrix(BufferIndex bufferIndex) const override