vulkan: flush allocations if needed

There is no guarantee that the created buffer is actually host coherent.
If it is not we have to manually flush it.
This commit is contained in:
niki
2022-10-06 02:12:36 +02:00
parent a95ff597d5
commit ecc272e0ca
6 changed files with 41 additions and 20 deletions
+12 -1
View File
@@ -65,6 +65,13 @@ bool StreamBuffer::loadVolatile()
if (vmaCreateBuffer(allocator, &bufferInfo, &allocCreateInfo, &buffer, &allocation, &allocInfo) != VK_SUCCESS)
throw love::Exception("Cannot create stream buffer: out of graphics memory.");
VkMemoryPropertyFlags properties;
vmaGetAllocationMemoryProperties(allocator, allocation, &properties);
if (properties & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)
coherent = true;
else
coherent = false;
return true;
}
@@ -99,9 +106,13 @@ love::graphics::StreamBuffer::MapInfo StreamBuffer::map(size_t /*minsize*/)
return info;
}
size_t StreamBuffer::unmap(size_t /*usedSize*/)
size_t StreamBuffer::unmap(size_t usedSize)
{
size_t offset = (frameIndex * bufferSize) + frameGPUReadOffset;
if (!coherent)
vmaFlushAllocation(allocator, allocation, offset, usedSize);
return offset;
}