Make all descriptors 16-byte aligned.
Some SampledImageDescriptor members are assumed to be 16-byte aligned,
such as the sw::Mipmap::pitchP member accessed by sampleFloat2D(). To
guarantee this while descriptor sets can contain multiple types of
descriptor, all descriptors are made a multiple of 16 bytes in size.
Also, each descriptor set starts with a pointer to its layout, followed
by the actual descriptor content. To ensure the latter is 16-byte
aligned, the layout pointer was placed in a header structure which
itself is 16-byte aligned and thus includes the necessary padding.
The placement of the descriptor set itself is guaranteed to be 16-byte
aligned by vk::REQUIRED_MEMORY_ALIGNMENT = 16 being used for descriptor
pool allocation.
Bug: b/129523279
Bug: b/123244275
Change-Id: I72fb92d9ff5a8d100d05f5b9e38170ade557d434
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/29970
Presubmit-Ready: Nicolas Capens <nicolascapens@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/Vulkan/VkConfig.h b/src/Vulkan/VkConfig.h
index 3aa5de8..27ef7de 100644
--- a/src/Vulkan/VkConfig.h
+++ b/src/Vulkan/VkConfig.h
@@ -37,10 +37,13 @@
enum
{
- REQUIRED_MEMORY_ALIGNMENT = 16, // ARM64 will want 8 bytes for 64b formats; x86 wants 16 bytes for 128b formats
+ // Alignment of all Vulkan objects, pools, device memory, images, buffers, descriptors.
+ REQUIRED_MEMORY_ALIGNMENT = 16, // 16 bytes for 128-bit vector types.
+
MIN_TEXEL_BUFFER_OFFSET_ALIGNMENT = 256,
MIN_UNIFORM_BUFFER_OFFSET_ALIGNMENT = 256,
MIN_STORAGE_BUFFER_OFFSET_ALIGNMENT = 256,
+
MEMORY_TYPE_GENERIC_BIT = 0x1, // Generic system memory.
};