- do not use persistent buffers for models as it is a limited resource where each consumes a vkDeviceMemory object

This commit is contained in:
Magnus Norddahl 2019-03-23 14:58:37 +01:00
parent 4fff8a41b7
commit 0c6d0de3ab
2 changed files with 19 additions and 3 deletions

View file

@ -110,15 +110,29 @@ void VKBuffer::Unmap()
void *VKBuffer::Lock(unsigned int size)
{
SetData(size, nullptr, false);
if (!mPersistent)
if (!mBuffer)
{
// The model mesh loaders lock multiple non-persistent buffers at the same time. This is not allowed in vulkan.
// VkDeviceMemory can only be mapped once and multiple non-persistent buffers may come from the same device memory object.
mStaticUpload.Resize(size);
map = mStaticUpload.Data();
}
else if (!mPersistent)
{
map = mBuffer->Map(0, size);
}
return map;
}
void VKBuffer::Unlock()
{
if (!mPersistent)
if (!mBuffer)
{
map = nullptr;
SetData(mStaticUpload.Size(), mStaticUpload.Data(), true);
mStaticUpload.Clear();
}
else if (!mPersistent)
{
mBuffer->Unmap();
map = nullptr;

View file

@ -2,6 +2,7 @@
#include "hwrenderer/data/buffers.h"
#include "vk_objects.h"
#include "utility/tarray.h"
#ifdef _MSC_VER
// silence bogus warning C4250: 'VKVertexBuffer': inherits 'VKBuffer::VKBuffer::SetData' via dominance
@ -28,6 +29,7 @@ public:
std::unique_ptr<VulkanBuffer> mBuffer;
std::unique_ptr<VulkanBuffer> mStaging;
bool mPersistent = false;
TArray<uint8_t> mStaticUpload;
};
class VKVertexBuffer : public IVertexBuffer, public VKBuffer