Check allignment of sub heap allocation in vulkan

Certain Vulkan devices will return difference alignment requirements for
a given allocation even if using the same heap. Thus we need to check
this alignment as well when deciding which subheap we want to use in our
memory allocation.

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2232803003

Review-Url: https://codereview.chromium.org/2232803003
diff --git a/src/gpu/vk/GrVkMemory.cpp b/src/gpu/vk/GrVkMemory.cpp
index 19150c6..1dac9f3 100644
--- a/src/gpu/vk/GrVkMemory.cpp
+++ b/src/gpu/vk/GrVkMemory.cpp
@@ -82,7 +82,7 @@
     }
 
     // Bind Memory to device
-    VkResult err = GR_VK_CALL(iface, BindBufferMemory(device, buffer, 
+    VkResult err = GR_VK_CALL(iface, BindBufferMemory(device, buffer,
                                                       alloc->fMemory, alloc->fOffset));
     if (err) {
         SkASSERT_RELEASE(heap->free(*alloc));
@@ -429,7 +429,7 @@
     INHERITED::free(alloc.fOffset, alloc.fSize);
 }
 
-bool GrVkHeap::subAlloc(VkDeviceSize size, VkDeviceSize alignment, 
+bool GrVkHeap::subAlloc(VkDeviceSize size, VkDeviceSize alignment,
                         uint32_t memoryTypeIndex, GrVkAlloc* alloc) {
     VkDeviceSize alignedSize = align_size(size, alignment);
 
@@ -451,7 +451,7 @@
         }
         alloc->fOffset = 0;
         alloc->fSize = 0;    // hint that this is not a subheap allocation
-        
+
         return true;
     }
 
@@ -459,7 +459,8 @@
     int bestFitIndex = -1;
     VkDeviceSize bestFitSize = 0x7FFFFFFF;
     for (auto i = 0; i < fSubHeaps.count(); ++i) {
-        if (fSubHeaps[i]->memoryTypeIndex() == memoryTypeIndex) {
+        if (fSubHeaps[i]->memoryTypeIndex() == memoryTypeIndex &&
+            fSubHeaps[i]->alignment() == alignment) {
             VkDeviceSize heapSize = fSubHeaps[i]->largestBlockSize();
             if (heapSize >= alignedSize && heapSize < bestFitSize) {
                 bestFitIndex = i;
@@ -497,7 +498,7 @@
     return false;
 }
 
-bool GrVkHeap::singleAlloc(VkDeviceSize size, VkDeviceSize alignment, 
+bool GrVkHeap::singleAlloc(VkDeviceSize size, VkDeviceSize alignment,
                            uint32_t memoryTypeIndex, GrVkAlloc* alloc) {
     VkDeviceSize alignedSize = align_size(size, alignment);
 
@@ -505,7 +506,9 @@
     int bestFitIndex = -1;
     VkDeviceSize bestFitSize = 0x7FFFFFFF;
     for (auto i = 0; i < fSubHeaps.count(); ++i) {
-        if (fSubHeaps[i]->memoryTypeIndex() == memoryTypeIndex && fSubHeaps[i]->unallocated()) {
+        if (fSubHeaps[i]->memoryTypeIndex() == memoryTypeIndex &&
+            fSubHeaps[i]->alignment() == alignment &&
+            fSubHeaps[i]->unallocated()) {
             VkDeviceSize heapSize = fSubHeaps[i]->size();
             if (heapSize >= alignedSize && heapSize < bestFitSize) {
                 bestFitIndex = i;