From 5ba3026f6893c29f073b2a4d01610b28080c7ae4 Mon Sep 17 00:00:00 2001 From: baldurk Date: Mon, 2 Dec 2019 19:01:01 +0000 Subject: [PATCH] Don't include alignment padding in returned alloc size. Closes #1625 * If we include the padding we might try to over-allocate the initial contents and copy/fill beyond the valid size for the actual memory allocation. --- renderdoc/driver/vulkan/vk_memory.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/renderdoc/driver/vulkan/vk_memory.cpp b/renderdoc/driver/vulkan/vk_memory.cpp index 19892f200..b96c8e342 100644 --- a/renderdoc/driver/vulkan/vk_memory.cpp +++ b/renderdoc/driver/vulkan/vk_memory.cpp @@ -189,9 +189,9 @@ MemoryAllocation WrappedVulkan::AllocateMemoryForResource(bool buffer, VkMemoryR // invalidate/flush safely. This is at most 256 bytes which is likely already satisfied. ret.size = AlignUp(ret.size, nonCoherentAtomSize); - RDCDEBUG("Allocating 0x%llx with alignment 0x%llx in 0x%x for a %s (%s in %s)", ret.size, - mrq.alignment, mrq.memoryTypeBits, buffer ? "buffer" : "image", ToStr(type).c_str(), - ToStr(scope).c_str()); + RDCDEBUG("Allocating 0x%llx (0x%llx requested) with alignment 0x%llx in 0x%x for a %s (%s in %s)", + ret.size, mrq.size, mrq.alignment, mrq.memoryTypeBits, buffer ? "buffer" : "image", + ToStr(type).c_str(), ToStr(scope).c_str()); std::vector &blockList = m_MemoryBlocks[(size_t)scope]; @@ -333,6 +333,9 @@ MemoryAllocation WrappedVulkan::AllocateMemoryForResource(bool buffer, VkMemoryR ret.mem = chunk.mem; } + // ensure the returned size is accurate to what was requested, not what we padded + ret.size = mrq.size; + return ret; }