Fix non-coherent atom alignment issues

This commit is contained in:
baldurk
2023-03-14 15:07:28 +00:00
parent b3035d280e
commit 31d5fa9eb3
2 changed files with 9 additions and 3 deletions
+5 -3
View File
@@ -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);
+4
View File
@@ -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);