Take reference data into account in memory usage tracking
authorMika Isojärvi <misojarvi@google.com>
Thu, 28 Apr 2016 23:26:51 +0000 (16:26 -0700)
committerPyry Haulos <phaulos@google.com>
Fri, 29 Apr 2016 05:47:24 +0000 (22:47 -0700)
Bug: 28052105
Bug: 28052526
Change-Id: I47caae5d0ae1353ad015866d08b727a2ebcc4fdb

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

index 555a1369b7522e4b4ae9fad5933fe0a1f4bb1e40..a9a37044830e6929a92fcf5182280c15ae4536d7 100644 (file)
@@ -66,6 +66,11 @@ namespace memory
 namespace
 {
 
+enum
+{
+       REFERENCE_BYTES_PER_BYTE = 2
+};
+
 size_t computeDeviceMemorySystemMemFootprint (const DeviceInterface& vk, VkDevice device)
 {
        AllocationCallbackRecorder      callbackRecorder        (getSystemAllocator());
@@ -622,6 +627,8 @@ public:
 
                m_usage += size;
                m_totalMemTracker.allocate(getMemoryClass(), size);
+               m_totalMemTracker.allocate(MEMORY_CLASS_SYSTEM, size * REFERENCE_BYTES_PER_BYTE);
+               m_totalMemTracker.allocate(getMemoryClass(), size);
                m_objects.push_back(object);
 
                return object;
@@ -636,6 +643,7 @@ public:
        {
                removeFirstEqual(m_objects, object);
                m_usage -= object->getSize();
+               m_totalMemTracker.free(MEMORY_CLASS_SYSTEM, object->getSize() * REFERENCE_BYTES_PER_BYTE);
                m_totalMemTracker.free(getMemoryClass(), object->getSize());
                delete object;
        }
@@ -663,19 +671,22 @@ private:
 
                        DE_ASSERT(totalUsage <= totalSysMem);
 
-                       return de::min(availableInHeap, totalSysMem-totalUsage);
+                       return de::min(availableInHeap, (totalSysMem-totalUsage) / (1 + REFERENCE_BYTES_PER_BYTE));
                }
                else
                {
+                       const VkDeviceSize      totalUsage      = m_totalMemTracker.getTotalUsage();
+                       const VkDeviceSize      totalSysMem     = (VkDeviceSize)m_limits.totalSystemMemory;
+
                        const MemoryClass       memClass                = getMemoryClass();
                        const VkDeviceSize      totalMemClass   = memClass == MEMORY_CLASS_SYSTEM
-                                                                                               ? (VkDeviceSize)m_limits.totalSystemMemory
+                                                                                               ? (VkDeviceSize)(m_limits.totalSystemMemory / (1 + REFERENCE_BYTES_PER_BYTE))
                                                                                                : m_limits.totalDeviceLocalMemory;
                        const VkDeviceSize      usedMemClass    = m_totalMemTracker.getUsage(memClass);
 
                        DE_ASSERT(usedMemClass <= totalMemClass);
 
-                       return de::min(availableInHeap, totalMemClass-usedMemClass);
+                       return de::min(de::min(availableInHeap, totalMemClass-usedMemClass), (totalSysMem - totalUsage) / REFERENCE_BYTES_PER_BYTE);
                }
        }