From 31d5fa9eb3bcd088da3a34185f3f9049d9925de5 Mon Sep 17 00:00:00 2001 From: baldurk Date: Tue, 14 Mar 2023 15:07:28 +0000 Subject: [PATCH] Fix non-coherent atom alignment issues --- renderdoc/driver/vulkan/vk_initstate.cpp | 8 +++++--- renderdoc/driver/vulkan/vk_memory.cpp | 4 ++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/renderdoc/driver/vulkan/vk_initstate.cpp b/renderdoc/driver/vulkan/vk_initstate.cpp index cbed89402..1312015f8 100644 --- a/renderdoc/driver/vulkan/vk_initstate.cpp +++ b/renderdoc/driver/vulkan/vk_initstate.cpp @@ -1306,9 +1306,11 @@ bool WrappedVulkan::Serialise_InitialState(SerialiserType &ser, ResourceId id, V { if(initial && initial->mem.mem != VK_NULL_HANDLE) { + VkDeviceSize size = AlignUp(initial->mem.size, nonCoherentAtomSize); + mappedMem = initial->mem; - vkr = ObjDisp(d)->MapMemory(Unwrap(d), Unwrap(mappedMem.mem), initial->mem.offs, - initial->mem.size, 0, (void **)&Contents); + vkr = ObjDisp(d)->MapMemory(Unwrap(d), Unwrap(mappedMem.mem), initial->mem.offs, size, 0, + (void **)&Contents); CheckVkResult(vkr); // invalidate the cpu cache for this memory range to avoid reading stale data @@ -1317,7 +1319,7 @@ bool WrappedVulkan::Serialise_InitialState(SerialiserType &ser, ResourceId id, V NULL, Unwrap(mappedMem.mem), mappedMem.offs, - mappedMem.size, + size, }; vkr = ObjDisp(d)->InvalidateMappedMemoryRanges(Unwrap(d), 1, &range); diff --git a/renderdoc/driver/vulkan/vk_memory.cpp b/renderdoc/driver/vulkan/vk_memory.cpp index 860748dd9..9f6db8095 100644 --- a/renderdoc/driver/vulkan/vk_memory.cpp +++ b/renderdoc/driver/vulkan/vk_memory.cpp @@ -207,6 +207,10 @@ MemoryAllocation WrappedVulkan::AllocateMemoryForResource(bool buffer, VkMemoryR // offs is where we can put our next sub-allocation VkDeviceSize offs = block.offs; + // for ease, ensure all allocations are allocated to the non-coherent atom size, so we can + // invalidate/flush safely. This is at most 256 bytes which is likely already satisfied. + offs = AlignUp(offs, nonCoherentAtomSize); + // if we are on a buffer/image, account for any alignment we might have to do if(ret.buffer != block.buffer) offs = AlignUp(offs, m_PhysicalDeviceData.props.limits.bufferImageGranularity);