Separate allocation alignment from offset alignment

VkMemoryRequirements::alignment dictates the alignment of "the offset
within the allocation required for the resource", while allocations
must "meet any alignment requirement of the implementation". Therefore
the latter alignment should be larger than any of the offset alignments.

This only applies to "device" memory. The alignment of host memory is
a separate matter and only exposed to the application through the
VkAllocationCallbacks callbacks.

This change merely splits the symbolic constant we were using for these
three alignments (except uniform/texel/storage buffer offset alignments
which were already using their own constants) into three separate
constants. Their values remain at 16 for now. A subsequent change will
address the above device memory alignment expectation.

Bug: b/238916823
Change-Id: Ib35ffef761cf53ba88442c832b2a4c51d1ffdad6
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/67109
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Sean Risser <srisser@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/Vulkan/VkBuffer.cpp b/src/Vulkan/VkBuffer.cpp
index 7912c52..c7bb8bc 100644
--- a/src/Vulkan/VkBuffer.cpp
+++ b/src/Vulkan/VkBuffer.cpp
@@ -67,7 +67,7 @@
 	VkMemoryRequirements memoryRequirements = {};
 
 	memoryRequirements.size = size;
-	memoryRequirements.alignment = REQUIRED_MEMORY_ALIGNMENT;
+	memoryRequirements.alignment = vk::MEMORY_REQUIREMENTS_OFFSET_ALIGNMENT;
 
 	if(usage & (VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT))
 	{
diff --git a/src/Vulkan/VkCommandPool.cpp b/src/Vulkan/VkCommandPool.cpp
index 57c799b..6144845 100644
--- a/src/Vulkan/VkCommandPool.cpp
+++ b/src/Vulkan/VkCommandPool.cpp
@@ -45,10 +45,10 @@
 	for(uint32_t i = 0; i < commandBufferCount; i++)
 	{
 		// TODO(b/119409619): Allocate command buffers from the pool memory.
-		void *deviceMemory = vk::allocateHostMemory(sizeof(DispatchableCommandBuffer), REQUIRED_MEMORY_ALIGNMENT,
-		                                            NULL_ALLOCATION_CALLBACKS, DispatchableCommandBuffer::GetAllocationScope());
-		ASSERT(deviceMemory);
-		DispatchableCommandBuffer *commandBuffer = new(deviceMemory) DispatchableCommandBuffer(device, level);
+		void *memory = vk::allocateHostMemory(sizeof(DispatchableCommandBuffer), vk::HOST_MEMORY_ALLOCATION_ALIGNMENT,
+		                                      NULL_ALLOCATION_CALLBACKS, DispatchableCommandBuffer::GetAllocationScope());
+		ASSERT(memory);
+		DispatchableCommandBuffer *commandBuffer = new(memory) DispatchableCommandBuffer(device, level);
 		if(commandBuffer)
 		{
 			pCommandBuffers[i] = *commandBuffer;
diff --git a/src/Vulkan/VkConfig.hpp b/src/Vulkan/VkConfig.hpp
index 71bfdeb..9813d7c 100644
--- a/src/Vulkan/VkConfig.hpp
+++ b/src/Vulkan/VkConfig.hpp
@@ -34,8 +34,11 @@
 constexpr uint32_t VENDOR_ID = 0x1AE0;  // Google, Inc.: https://pcisig.com/google-inc-1
 constexpr uint32_t DEVICE_ID = 0xC0DE;  // SwiftShader (placeholder)
 
-// Alignment of all Vulkan objects, pools, device memory, images, buffers, descriptors.
-constexpr VkDeviceSize REQUIRED_MEMORY_ALIGNMENT = 16;  // 16 bytes for 128-bit vector types.
+constexpr VkDeviceSize DEVICE_MEMORY_ALLOCATION_ALIGNMENT = 16;  // 16 bytes for 128-bit vector types.
+constexpr VkDeviceSize HOST_MEMORY_ALLOCATION_ALIGNMENT = 16;    // 16 bytes for 128-bit vector types.
+
+constexpr VkDeviceSize MEMORY_REQUIREMENTS_OFFSET_ALIGNMENT = 16;
+static_assert(DEVICE_MEMORY_ALLOCATION_ALIGNMENT >= MEMORY_REQUIREMENTS_OFFSET_ALIGNMENT);
 
 constexpr VkDeviceSize MIN_IMPORTED_HOST_POINTER_ALIGNMENT = 4096;
 
diff --git a/src/Vulkan/VkDeviceMemory.cpp b/src/Vulkan/VkDeviceMemory.cpp
index 15c0e57..884fd49 100644
--- a/src/Vulkan/VkDeviceMemory.cpp
+++ b/src/Vulkan/VkDeviceMemory.cpp
@@ -339,7 +339,7 @@
 // and sets `buffer`.
 VkResult DeviceMemory::allocateBuffer()
 {
-	buffer = vk::allocateDeviceMemory(allocationSize, REQUIRED_MEMORY_ALIGNMENT);
+	buffer = vk::allocateDeviceMemory(allocationSize, vk::DEVICE_MEMORY_ALLOCATION_ALIGNMENT);
 	if(!buffer)
 	{
 		return VK_ERROR_OUT_OF_DEVICE_MEMORY;
diff --git a/src/Vulkan/VkImage.cpp b/src/Vulkan/VkImage.cpp
index 1f74b56..4bb9135 100644
--- a/src/Vulkan/VkImage.cpp
+++ b/src/Vulkan/VkImage.cpp
@@ -225,7 +225,7 @@
 const VkMemoryRequirements Image::getMemoryRequirements() const
 {
 	VkMemoryRequirements memoryRequirements;
-	memoryRequirements.alignment = vk::REQUIRED_MEMORY_ALIGNMENT;
+	memoryRequirements.alignment = vk::MEMORY_REQUIREMENTS_OFFSET_ALIGNMENT;
 	memoryRequirements.memoryTypeBits = vk::MEMORY_TYPE_GENERIC_BIT;
 	memoryRequirements.size = getStorageSize(format.getAspects()) +
 	                          (decompressedImage ? decompressedImage->getStorageSize(decompressedImage->format.getAspects()) : 0);
diff --git a/src/Vulkan/VkObject.hpp b/src/Vulkan/VkObject.hpp
index ab00949..73301fb 100644
--- a/src/Vulkan/VkObject.hpp
+++ b/src/Vulkan/VkObject.hpp
@@ -48,7 +48,7 @@
 	void *memory = nullptr;
 	if(size)
 	{
-		memory = vk::allocateHostMemory(size, REQUIRED_MEMORY_ALIGNMENT, pAllocator, T::GetAllocationScope());
+		memory = vk::allocateHostMemory(size, vk::HOST_MEMORY_ALLOCATION_ALIGNMENT, pAllocator, T::GetAllocationScope());
 		if(!memory)
 		{
 			return VK_ERROR_OUT_OF_HOST_MEMORY;
diff --git a/src/Vulkan/VkStructConversion.hpp b/src/Vulkan/VkStructConversion.hpp
index 6f34f11..94563cb 100644
--- a/src/Vulkan/VkStructConversion.hpp
+++ b/src/Vulkan/VkStructConversion.hpp
@@ -397,7 +397,7 @@
 		}
 
 		uint8_t *mem = static_cast<uint8_t *>(
-		    vk::allocateHostMemory(totalSize, vk::REQUIRED_MEMORY_ALIGNMENT, vk::NULL_ALLOCATION_CALLBACKS, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT));
+		    vk::allocateHostMemory(totalSize, vk::HOST_MEMORY_ALLOCATION_ALIGNMENT, vk::NULL_ALLOCATION_CALLBACKS, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT));
 
 		auto submits = new(mem) SubmitInfo[submitCount];
 		mem += submitSize;
@@ -524,7 +524,7 @@
 		}
 
 		uint8_t *mem = static_cast<uint8_t *>(
-		    vk::allocateHostMemory(totalSize, vk::REQUIRED_MEMORY_ALIGNMENT, vk::NULL_ALLOCATION_CALLBACKS, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT));
+		    vk::allocateHostMemory(totalSize, vk::HOST_MEMORY_ALLOCATION_ALIGNMENT, vk::NULL_ALLOCATION_CALLBACKS, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT));
 
 		auto submits = new(mem) SubmitInfo[submitCount];
 		mem += submitSize;