Skip to content

Commit

Permalink
[Vulkan] Fix GraphicsDevice.UpdateBuffer with an offset.
Browse files Browse the repository at this point in the history
  • Loading branch information
mellinoe committed Mar 20, 2018
1 parent e3b50f1 commit 1018318
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Veldrid/Vk/VkGraphicsDevice.cs
Expand Up @@ -851,26 +851,32 @@ protected override void UpdateBufferCore(DeviceBuffer buffer, uint bufferOffsetI
VkBuffer vkBuffer = Util.AssertSubtype<DeviceBuffer, VkBuffer>(buffer);
VkBuffer copySrcVkBuffer = null;
IntPtr mappedPtr;
byte* destPtr;
bool isPersistentMapped = vkBuffer.Memory.IsPersistentMapped;
if (isPersistentMapped)
{
mappedPtr = (IntPtr)vkBuffer.Memory.BlockMappedPointer;
destPtr = (byte*)mappedPtr + bufferOffsetInBytes;
}
else
{
copySrcVkBuffer = GetFreeStagingBuffer(sizeInBytes);
mappedPtr = (IntPtr)copySrcVkBuffer.Memory.BlockMappedPointer;
destPtr = (byte*)mappedPtr;
}

byte* destPtr = (byte*)mappedPtr + bufferOffsetInBytes;
Unsafe.CopyBlock(destPtr, source.ToPointer(), sizeInBytes);

if (!isPersistentMapped)
{
SharedCommandPool pool = GetFreeCommandPool();
VkCommandBuffer cb = pool.BeginNewCommandBuffer();

VkBufferCopy copyRegion = new VkBufferCopy { size = vkBuffer.BufferMemoryRequirements.size };
VkBufferCopy copyRegion = new VkBufferCopy
{
dstOffset = bufferOffsetInBytes,
size = sizeInBytes
};
vkCmdCopyBuffer(cb, copySrcVkBuffer.DeviceBuffer, vkBuffer.DeviceBuffer, 1, ref copyRegion);

pool.EndAndSubmit(cb);
Expand Down

0 comments on commit 1018318

Please sign in to comment.