Allow to allocate texture's GPU memory at upload timing 27/296327/6
authorEunki Hong <eunkiki.hong@samsung.com>
Tue, 25 Jul 2023 17:45:24 +0000 (02:45 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Wed, 2 Aug 2023 00:46:32 +0000 (09:46 +0900)
Let we make creation info property s.t. do not allocate gpu memory
right now.

For gl case, we don't call glTexImage2D function at creation time.

To support this behaviour, let we make TextureAllocationPolicy enum.

Change-Id: Iaa98a6b875cec60e4981eca259d9bfd760f903a3
Signed-off-by: Eunki Hong <eunkiki.hong@samsung.com>
dali/graphics-api/graphics-texture-create-info.h
dali/graphics-api/graphics-types.h
dali/internal/render/renderers/render-texture.cpp
dali/internal/render/renderers/render-texture.h

index f4862ed9e8ff9025ac2a0055bd26ed7c6c23edcd..fee65af7b57fef4c18e6ad62c8e86a2aae5ab1dc 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.
@@ -144,6 +144,22 @@ struct TextureCreateInfo
     return *this;
   }
 
+  /**
+   * @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
    *
@@ -193,6 +209,7 @@ struct TextureCreateInfo
   Format                  format{};
   TextureMipMapFlag       mipMapFlag{};
   TextureLayout           layout{};
+  TextureAllocationPolicy allocationPolicy{};
   TextureUsageFlags       usageFlags{};
   void*                   data{};
   uint32_t                dataSize{0u};
index e271bc2050d9cd65c69e51bf5f8e505c9181f391..a9dc5327ca20c2c1195f87fb292eb2ecefba513b 100644 (file)
@@ -1260,6 +1260,15 @@ enum class TextureLayout
   OPTIMAL ///< Usually, read-only memory, driver-optimal layout
 };
 
+/**
+ * @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
  */
index a38ede906668917e8bfcd35057eeafb8965d56b4..0607d99561d0f8dcd74515a20cbc415048bc868b 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 8895cfcac068a30a24d50b9a6427bfd5ebcb4d9b..0ffed60364dc51d4c198869a490bddebdd46c901 100644 (file)
@@ -224,13 +224,21 @@ 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;