Memory allocation size fix.
authorMichal Pawlowski <michal.m.pawlowski@mobica.com>
Mon, 24 Aug 2020 14:26:56 +0000 (16:26 +0200)
committerAlexander Galazin <Alexander.Galazin@arm.com>
Sat, 5 Sep 2020 07:49:48 +0000 (03:49 -0400)
This commit fixes an issue where wrong memory size was used for allocation.

Affects:
dEQP-VK.memory.allocation.*

Component: Vulkan

Public issue: 224

Change-Id: I2488d9427197f1f4a40bfeee863e6b0bc2cf889e

external/vulkancts/modules/vulkan/memory/vktMemoryAllocationTests.cpp

index a1bc6104b81fa4f50086de98734801dc063ac0ee..cca45b2129fc591be373dbf71e53fcb15be89906 100644 (file)
@@ -321,22 +321,6 @@ tcu::TestStatus AllocateFreeTestInstance::iterate (void)
                createFlags |= vk::VK_BUFFER_CREATE_PROTECTED_BIT;
        }
 
-       // Create a minimal buffer first to get the supported memory types
-       VkBufferCreateInfo                              bufferParams                                    =
-       {
-               VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,                       // VkStructureType          sType;
-               DE_NULL,                                                    // const void*              pNext;
-               createFlags,                                                // VkBufferCreateFlags      flags;
-               1u,                                                         // VkDeviceSize             size;
-               usageFlags,                                                 // VkBufferUsageFlags       usage;
-               sharingMode,                                                // VkSharingMode            sharingMode;
-               1u,                                                         // uint32_t                 queueFamilyIndexCount;
-               &queueFamilyIndex,                                          // const uint32_t*          pQueueFamilyIndices;
-       };
-
-       buffer = createBuffer(vkd, device, &bufferParams);
-       vkd.getBufferMemoryRequirements(device, *buffer, &memReqs);
-
        DE_ASSERT(m_config.memoryAllocationCount <= MAX_ALLOCATION_COUNT);
 
        if (m_memoryTypeIndex == 0)
@@ -359,6 +343,26 @@ tcu::TestStatus AllocateFreeTestInstance::iterate (void)
                const VkMemoryType              memoryType                              = m_memoryProperties.memoryTypes[m_memoryTypeIndex];
                const VkMemoryHeap              memoryHeap                              = m_memoryProperties.memoryHeaps[memoryType.heapIndex];
 
+               // Create a buffer to get the required size
+               {
+                       const VkDeviceSize bufferSize   = m_config.memorySize ? *m_config.memorySize : (VkDeviceSize) (*m_config.memoryPercentage * (float) memoryHeap.size);
+
+                       VkBufferCreateInfo bufferParams =
+                               {
+                                       VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,                       // VkStructureType          sType;
+                                       DE_NULL,                                                    // const void*              pNext;
+                                       createFlags,                                                // VkBufferCreateFlags      flags;
+                                       bufferSize,                                                 // VkDeviceSize             size;
+                                       usageFlags,                                                 // VkBufferUsageFlags       usage;
+                                       sharingMode,                                                // VkSharingMode            sharingMode;
+                                       1u,                                                         // uint32_t                 queueFamilyIndexCount;
+                                       &queueFamilyIndex,                                          // const uint32_t*          pQueueFamilyIndices;
+                               };
+
+                       buffer = createBuffer(vkd, device, &bufferParams);
+                       vkd.getBufferMemoryRequirements(device, *buffer, &memReqs);
+               }
+
                const VkDeviceSize              allocationSize  = (m_config.memorySize ? memReqs.size : (VkDeviceSize)(*m_config.memoryPercentage * (float)memoryHeap.size));
                const VkDeviceSize              roundedUpAllocationSize  = roundUpToNextMultiple(allocationSize, m_memoryLimits.deviceMemoryAllocationGranularity);
                vector<VkDeviceMemory>  memoryObjects   (m_config.memoryAllocationCount, (VkDeviceMemory)0);