private void FlushOrInvalidateMappedMemoryRange(MemoryAlloc alloc, ulong offset, ulong size, bool flush) { if (alloc.Allocator != this) { throw new ArgumentException(nameof(alloc)); } if (alloc.Size < offset + size) { throw new ArgumentException(); } if (size == 0) { return; } var memoryType = alloc.Memory.Type; var hostCoherent = (memoryType.PropertyFlags & SharpVulkan.MemoryPropertyFlags.HostCoherent) != 0; if (hostCoherent) { return; } var nonCoherentAtomSize = Context.PhysicalDeviceLimits.NonCoherentAtomSize; var rangeStart = GraphicsUtility.AlignDown(alloc.Offset + offset, nonCoherentAtomSize); var rangeEnd = GraphicsUtility.AlignUp(alloc.Offset + offset + size, nonCoherentAtomSize); if (rangeEnd > alloc.Memory.Size) { rangeEnd = alloc.Memory.Size; } var range = new SharpVulkan.MappedMemoryRange { StructureType = SharpVulkan.StructureType.MappedMemoryRange, Memory = alloc.Memory.Memory, Offset = rangeStart, Size = rangeEnd - rangeStart }; if (flush) { Context.Device.FlushMappedMemoryRanges(1, &range); } else { Context.Device.InvalidateMappedMemoryRanges(1, &range); } }