Relax protected heap allocation tests
authorAri Suonpaa <ari.suonpaa@siru.fi>
Fri, 6 Aug 2021 12:08:21 +0000 (15:08 +0300)
committerAri Suonpaa <ari.suonpaa@siru.fi>
Fri, 6 Aug 2021 12:08:21 +0000 (15:08 +0300)
Some implementations have limitations on protected heap
allocations, and these limitations cannot be queried
using the Vulkan API. This change allows an out-of-memory
to happen after a certain number of allocations to
compensate that.

VK-GL-CTS Issue: 3038

Affects:

dEQP-VK.memory.*allocation.*

Components: Vulkan
Change-Id: I3a34637c8c15eb8670613dce9b6e394a622a4c71

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

index a1bc610..c1f5211 100644 (file)
@@ -402,7 +402,7 @@ tcu::TestStatus AllocateFreeTestInstance::iterate (void)
                                                {
                                                        for (size_t ndx = 0; ndx < m_config.memoryAllocationCount; ndx++)
                                                        {
-                                                               VkMemoryAllocateInfo alloc =
+                                                               VkMemoryAllocateInfo    alloc   =
                                                                {
                                                                        VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,                         // sType
                                                                        m_useDeviceGroups ? &m_allocFlagsInfo : DE_NULL,        // pNext
@@ -410,7 +410,15 @@ tcu::TestStatus AllocateFreeTestInstance::iterate (void)
                                                                        m_memoryTypeIndex                                                                       // memoryTypeIndex;
                                                                };
 
-                                                               VK_CHECK(vkd.allocateMemory(device, &alloc, (const VkAllocationCallbacks*)DE_NULL, &memoryObjects[ndx]));
+                                                               VkResult                                res             = vkd.allocateMemory(device, &alloc, (const VkAllocationCallbacks*)DE_NULL, &memoryObjects[ndx]);
+
+                                                               // Some implementations might have limitations on protected heap, and these limitations
+                                                               // don't show up in Vulkan queries. Use a hard coded threshold after which out of memory
+                                                               // is allowed.
+                                                               if (res == VK_ERROR_OUT_OF_DEVICE_MEMORY && memoryType.propertyFlags & vk::VK_MEMORY_PROPERTY_PROTECTED_BIT && ndx > 80)
+                                                                       break;
+
+                                                               VK_CHECK(res);
 
                                                                TCU_CHECK(!!memoryObjects[ndx]);
                                                        }
@@ -421,8 +429,11 @@ tcu::TestStatus AllocateFreeTestInstance::iterate (void)
                                                                {
                                                                        const VkDeviceMemory mem = memoryObjects[memoryObjects.size() - 1 - ndx];
 
-                                                                       vkd.freeMemory(device, mem, (const VkAllocationCallbacks*)DE_NULL);
-                                                                       memoryObjects[memoryObjects.size() - 1 - ndx] = (VkDeviceMemory)0;
+                                                                       if (!!mem)
+                                                                       {
+                                                                               vkd.freeMemory(device, mem, (const VkAllocationCallbacks *) DE_NULL);
+                                                                               memoryObjects[memoryObjects.size() - 1 - ndx] = (VkDeviceMemory) 0;
+                                                                       }
                                                                }
                                                        }
                                                        else
@@ -431,8 +442,11 @@ tcu::TestStatus AllocateFreeTestInstance::iterate (void)
                                                                {
                                                                        const VkDeviceMemory mem = memoryObjects[ndx];
 
-                                                                       vkd.freeMemory(device, mem, (const VkAllocationCallbacks*)DE_NULL);
-                                                                       memoryObjects[ndx] = (VkDeviceMemory)0;
+                                                                       if (!!mem)
+                                                                       {
+                                                                               vkd.freeMemory(device, mem, (const VkAllocationCallbacks *) DE_NULL);
+                                                                               memoryObjects[ndx] = (VkDeviceMemory) 0;
+                                                                       }
                                                                }
                                                        }
                                                }