Fix alignment bug with depth/stencil resolve attachment
Memory was allocated to cache the depth/stencil resolve attachment info,
but this memory needs aligning.
Bug: angleproject:7551
Change-Id: I13fa67fe49417b1688cbd36cb3d51ba742b4b05b
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/73209
Commit-Queue: Shahbaz Youssefi <syoussefi@google.com>
Tested-by: Shahbaz Youssefi <syoussefi@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
diff --git a/src/Vulkan/VkRenderPass.cpp b/src/Vulkan/VkRenderPass.cpp
index 135fbde..e0feb2a 100644
--- a/src/Vulkan/VkRenderPass.cpp
+++ b/src/Vulkan/VkRenderPass.cpp
@@ -164,6 +164,12 @@
{
if(subpassDepthStencilResolves == nullptr)
{
+ // Align host memory to 8-bytes
+ const intptr_t memoryAsInt = reinterpret_cast<intptr_t>(hostMemory);
+ const intptr_t alignment = alignof(VkSubpassDescriptionDepthStencilResolve);
+ const intptr_t padding = (alignment - memoryAsInt % alignment) % alignment;
+ hostMemory += padding;
+
subpassDepthStencilResolves = reinterpret_cast<VkSubpassDescriptionDepthStencilResolve *>(hostMemory);
hostMemory += subpassCount * sizeof(VkSubpassDescriptionDepthStencilResolve);
for(uint32_t subpass = 0; subpass < subpassCount; subpass++)
@@ -401,7 +407,9 @@
{
// If any subpass uses DSR, then allocate a VkSubpassDescriptionDepthStencilResolve
// for all subpasses. This allows us to index into our DSR structs using the subpass index.
- requiredMemory += sizeof(VkSubpassDescriptionDepthStencilResolve) * pCreateInfo->subpassCount;
+ //
+ // Add a few bytes for alignment if necessary
+ requiredMemory += sizeof(VkSubpassDescriptionDepthStencilResolve) * pCreateInfo->subpassCount + alignof(VkSubpassDescriptionDepthStencilResolve);
usesDSR = true;
}
// For each subpass that actually uses DSR, allocate a VkAttachmentReference2.