Set correct VMA allocation flag based on the memory usage of the image 14/320514/1
authorRichard Huang <r.huang@samsung.com>
Tue, 4 Mar 2025 11:17:04 +0000 (11:17 +0000)
committerRichard Huang <r.huang@samsung.com>
Tue, 4 Mar 2025 11:17:04 +0000 (11:17 +0000)
Change-Id: I1fa3ce0dce4f300167a945ed68422b17e6fdbeca

dali/internal/graphics/vulkan-impl/vulkan-image-impl.cpp

index 835f922afd7df9ae1526130092beafff2612e87c..df3b7852c65bd7861b719fde5d1341dd8d46f2b4 100644 (file)
@@ -92,9 +92,19 @@ void Image::Initialize(vk::MemoryPropertyFlags memoryProperties)
   {
     auto vmaAllocInfo = ::vma::AllocationCreateInfo{}
                           .setPreferredFlags(memoryProperties)
-                          .setFlags(::vma::AllocationCreateFlagBits::eHostAccessSequentialWrite)
                           .setUsage(::vma::MemoryUsage::eAuto);
 
+    // If the image is an attachment, prefer dedicated memory
+    constexpr vk::ImageUsageFlags attachmentOnlyFlags = vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eDepthStencilAttachment;
+    if(mCreateInfo.usage & attachmentOnlyFlags)
+    {
+      vmaAllocInfo.setFlags(::vma::AllocationCreateFlagBits::eDedicatedMemory);
+    }
+    else
+    {
+      vmaAllocInfo.setFlags(::vma::AllocationCreateFlagBits::eHostAccessSequentialWrite);
+    }
+
     mVmaAllocation = std::make_unique<::vma::Allocation>();
     // This creates the image, allocates appropriate memory for it, and binds the buffer with the memory.
     ::vma::AllocationInfo allocationInfo;