Align allocations to 4096 on Android hosts

... as allocations which may be mapped into KVM virtual machines
need to be page aligned.

Bug: b/242184599
Test: cvd start --gpu_mode=gfxstream_guest_angle_host_swiftshader
Change-Id: I5e6b7a765e254dbd965b69cd94dc49671d740db3
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/71628
Presubmit-Ready: Jason Macnak <natsu@google.com>
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Commit-Queue: Jason Macnak <natsu@google.com>
Reviewed-by: Geoff Lang <geofflang@google.com>
Tested-by: Jason Macnak <natsu@google.com>
diff --git a/src/Android.bp b/src/Android.bp
index 7bf68f7..93b13ce 100644
--- a/src/Android.bp
+++ b/src/Android.bp
@@ -267,6 +267,9 @@
             ],
             cflags: [
                 "-DSWIFTSHADER_EXTERNAL_MEMORY_OPAQUE_FD",
+                // Allocations which may be mapped into a KVM based virtual
+                // machine must be page aligned.
+                "-DSWIFTSHADER_DEVICE_MEMORY_ALLOCATION_ALIGNMENT=4096",
             ],
         },
     },
diff --git a/src/Vulkan/VkConfig.hpp b/src/Vulkan/VkConfig.hpp
index 4e2c023..cc4e3b9 100644
--- a/src/Vulkan/VkConfig.hpp
+++ b/src/Vulkan/VkConfig.hpp
@@ -24,6 +24,10 @@
 #	define SWIFTSHADER_LEGACY_PRECISION false
 #endif
 
+#ifndef SWIFTSHADER_DEVICE_MEMORY_ALLOCATION_ALIGNMENT
+#	define SWIFTSHADER_DEVICE_MEMORY_ALLOCATION_ALIGNMENT 256
+#endif
+
 namespace vk {
 
 // Note: Constant array initialization requires a string literal.
@@ -39,7 +43,7 @@
 constexpr uint32_t DEVICE_ID = 0xC0DE;  // SwiftShader (placeholder)
 
 // "Allocations returned by vkAllocateMemory are guaranteed to meet any alignment requirement of the implementation."
-constexpr VkDeviceSize DEVICE_MEMORY_ALLOCATION_ALIGNMENT = 256;
+constexpr VkDeviceSize DEVICE_MEMORY_ALLOCATION_ALIGNMENT = SWIFTSHADER_DEVICE_MEMORY_ALLOCATION_ALIGNMENT;
 
 constexpr VkDeviceSize MIN_MEMORY_MAP_ALIGNMENT = 64;
 static_assert(DEVICE_MEMORY_ALLOCATION_ALIGNMENT >= MIN_MEMORY_MAP_ALIGNMENT);