[vulkan] Fix coherent memory for 32-bit userspace apps

bug: 111137294

mmap64 is needed because the offset into the PCI can be quite large
(as it's 16 GB total space there).

Test: can run 3dmark sling shot extreme Vulkan edition

+ Also make sure the suballocations are aligned properly for
images/buffers, which can require alignment above nonCoherentAtomSize.
+ More debug prints

Change-Id: Ic45467a932205eaa728aea4d11626c0bb9c780ba
diff --git a/system/vulkan_enc/HostVisibleMemoryVirtualization.cpp b/system/vulkan_enc/HostVisibleMemoryVirtualization.cpp
index dba8356..930cdd4 100644
--- a/system/vulkan_enc/HostVisibleMemoryVirtualization.cpp
+++ b/system/vulkan_enc/HostVisibleMemoryVirtualization.cpp
@@ -205,11 +205,22 @@
     out->mappedSize = mappedSize;
     out->mappedPtr = mappedPtr;
 
+    // because it's not just nonCoherentAtomSize granularity,
+    // people will also use it for uniform buffers, images, etc.
+    // that need some bigger alignment
+#define HIGHEST_BUFFER_OR_IMAGE_ALIGNMENT 1024
+
+    uint64_t neededPageSize = out->nonCoherentAtomSize;
+    if (HIGHEST_BUFFER_OR_IMAGE_ALIGNMENT >
+        neededPageSize) {
+        neededPageSize = HIGHEST_BUFFER_OR_IMAGE_ALIGNMENT;
+    }
+
     out->subAlloc = new
         SubAllocator(
             out->mappedPtr,
             out->mappedSize,
-            out->nonCoherentAtomSize);
+            neededPageSize);
 
     out->initialized = true;
     out->initResult = VK_SUCCESS;
@@ -239,6 +250,11 @@
              alloc->nonCoherentAtomSize - 1) /
             alloc->nonCoherentAtomSize);
 
+    ALOGD("%s: alloc size %u mapped size %u ncaSize %u\n", __func__,
+            (unsigned int)pAllocateInfo->allocationSize,
+            (unsigned int)mappedSize,
+            (unsigned int)alloc->nonCoherentAtomSize);
+
     void* subMapped = alloc->subAlloc->alloc(mappedSize);
     out->mappedPtr = (uint8_t*)subMapped;