Implement buffer memory requirement for VK_KHR_maintenance4

The VK_KHR_maintenance4 includes this new requirement:
"Add a guarantee for buffer memory requirement that the size
 memory requirement is never greater than the result of aligning
 create size with the alignment memory requirement."

In order to respect this requirement, the 15 byte padding used
for images and buffers has been instead moved to VkDeviceMemory.

Bug: b/204502926
Bug: b/201282910
Change-Id: Icdbff9c37d593b10856d87645dd3ab6aa5360400
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/63118
Presubmit-Ready: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Tested-by: Alexis Hétu <sugoi@google.com>
Commit-Queue: Alexis Hétu <sugoi@google.com>
diff --git a/src/Vulkan/VkBuffer.cpp b/src/Vulkan/VkBuffer.cpp
index f11718e..322f4bd 100644
--- a/src/Vulkan/VkBuffer.cpp
+++ b/src/Vulkan/VkBuffer.cpp
@@ -60,10 +60,7 @@
 {
 	VkMemoryRequirements memoryRequirements = {};
 
-	// Add 15 bytes of padding to ensure that any type of attribute within the
-	// buffer can be read using 16-bit accesses.
-	// TODO(b/196822081): Also reserve space for a header containing the size of the buffer (for robust buffer access)
-	memoryRequirements.size = this->size + 15;
+	memoryRequirements.size = this->size;
 
 	if(memoryRequirements.size < this->size)  // Overflow occurred
 	{
diff --git a/src/Vulkan/VkDeviceMemory.cpp b/src/Vulkan/VkDeviceMemory.cpp
index bfd9e05..4cf4688 100644
--- a/src/Vulkan/VkDeviceMemory.cpp
+++ b/src/Vulkan/VkDeviceMemory.cpp
@@ -106,30 +106,35 @@
 VkResult DeviceMemory::Allocate(const VkAllocationCallbacks *pAllocator, const VkMemoryAllocateInfo *pAllocateInfo, VkDeviceMemory *pMemory,
                                 const vk::DeviceMemory::ExtendedAllocationInfo &extendedAllocationInfo, Device *device)
 {
+	VkMemoryAllocateInfo allocateInfo = *pAllocateInfo;
+	// Add 15 bytes of padding to ensure that any type of attribute within
+	// buffers and images can be read using 16-byte accesses.
+	allocateInfo.allocationSize += 15;
+
 #if SWIFTSHADER_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER
 	if(AHardwareBufferExternalMemory::SupportsAllocateInfo(extendedAllocationInfo))
 	{
-		return AHardwareBufferExternalMemory::Create(pAllocator, pAllocateInfo, pMemory, extendedAllocationInfo, device);
+		return AHardwareBufferExternalMemory::Create(pAllocator, &allocateInfo, pMemory, extendedAllocationInfo, device);
 	}
 #endif
 #if SWIFTSHADER_EXTERNAL_MEMORY_OPAQUE_FD
 	if(OpaqueFdExternalMemory::SupportsAllocateInfo(extendedAllocationInfo))
 	{
-		return OpaqueFdExternalMemory::Create(pAllocator, pAllocateInfo, pMemory, extendedAllocationInfo, device);
+		return OpaqueFdExternalMemory::Create(pAllocator, &allocateInfo, pMemory, extendedAllocationInfo, device);
 	}
 #endif
 #if VK_USE_PLATFORM_FUCHSIA
 	if(zircon::VmoExternalMemory::supportsAllocateInfo(extendedAllocationInfo))
 	{
-		return zircon::VmoExternalMemory::Create(pAllocator, pAllocateInfo, pMemory, extendedAllocationInfo, device);
+		return zircon::VmoExternalMemory::Create(pAllocator, &allocateInfo, pMemory, extendedAllocationInfo, device);
 	}
 #endif
 	if(ExternalMemoryHost::SupportsAllocateInfo(extendedAllocationInfo))
 	{
-		return ExternalMemoryHost::Create(pAllocator, pAllocateInfo, pMemory, extendedAllocationInfo, device);
+		return ExternalMemoryHost::Create(pAllocator, &allocateInfo, pMemory, extendedAllocationInfo, device);
 	}
 
-	return vk::DeviceMemoryInternal::Create(pAllocator, pAllocateInfo, pMemory, extendedAllocationInfo, device);
+	return vk::DeviceMemoryInternal::Create(pAllocator, &allocateInfo, pMemory, extendedAllocationInfo, device);
 }
 
 DeviceMemory::DeviceMemory(const VkMemoryAllocateInfo *pAllocateInfo, Device *pDevice)
diff --git a/src/Vulkan/VkFormat.cpp b/src/Vulkan/VkFormat.cpp
index 08a1a73..f36e351 100644
--- a/src/Vulkan/VkFormat.cpp
+++ b/src/Vulkan/VkFormat.cpp
@@ -1895,7 +1895,7 @@
 
 size_t Format::sliceB(int width, int height, int border) const
 {
-	return sw::align<16>(sliceBUnpadded(width, height, border) + 15);
+	return sw::align<16>(sliceBUnpadded(width, height, border));
 }
 
 sw::float4 Format::getScale() const