- fix shutdown crash and some minor adjustments

This commit is contained in:
Magnus Norddahl 2019-03-02 00:46:25 +01:00
commit 1430d9012e
4 changed files with 21 additions and 12 deletions

View file

@ -20,17 +20,23 @@ void VKBuffer::SetData(size_t size, const void *data, bool staticdata)
{
auto fb = GetVulkanFrameBuffer();
mPersistent = screen->BuffersArePersistent() && !staticdata;
if (staticdata)
{
BufferBuilder builder;
builder.setUsage(VK_BUFFER_USAGE_TRANSFER_DST_BIT | mBufferType, VMA_MEMORY_USAGE_GPU_ONLY);
builder.setSize(size);
mBuffer = builder.create(fb->device);
mPersistent = false;
builder.setUsage(VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VMA_MEMORY_USAGE_CPU_ONLY);
mStaging = builder.create(fb->device);
{
BufferBuilder builder;
builder.setUsage(VK_BUFFER_USAGE_TRANSFER_DST_BIT | mBufferType, VMA_MEMORY_USAGE_GPU_ONLY);
builder.setSize(size);
mBuffer = builder.create(fb->device);
}
{
BufferBuilder builder;
builder.setUsage(VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VMA_MEMORY_USAGE_CPU_ONLY);
builder.setSize(size);
mStaging = builder.create(fb->device);
}
void *dst = mStaging->Map(0, size);
memcpy(dst, data, size);
@ -40,6 +46,8 @@ void VKBuffer::SetData(size_t size, const void *data, bool staticdata)
}
else
{
mPersistent = screen->BuffersArePersistent();
BufferBuilder builder;
builder.setUsage(mBufferType, VMA_MEMORY_USAGE_CPU_TO_GPU, mPersistent ? VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT : 0);
builder.setSize(size);

View file

@ -376,7 +376,7 @@ inline void *VulkanBuffer::Map(size_t offset, size_t size)
{
void *data;
VkResult result = vmaMapMemory(device->allocator, allocation, &data);
return (result == VK_SUCCESS) ? data : nullptr;
return (result == VK_SUCCESS) ? ((uint8_t*)data) + offset : nullptr;
}
inline void VulkanBuffer::Unmap()
@ -888,7 +888,7 @@ inline void *VulkanImage::Map(size_t offset, size_t size)
{
void *data;
VkResult result = vmaMapMemory(device->allocator, allocation, &data);
return (result == VK_SUCCESS) ? data : nullptr;
return (result == VK_SUCCESS) ? ((uint8_t*)data) + offset : nullptr;
}
inline void VulkanImage::Unmap()