GPU: Added VkVertexBuffer alloc/release data.

This makes sure that the GPU_batch_init will not crash on an assert
where the data of vertex buffer needs to be allocated.
This commit is contained in:
Jeroen Bakker 2022-12-02 13:38:45 +01:00
parent b8c7e93a65
commit ea86ec200a
2 changed files with 17 additions and 0 deletions

View File

@ -5,10 +5,17 @@
* \ingroup gpu
*/
#include "MEM_guardedalloc.h"
#include "vk_vertex_buffer.hh"
namespace blender::gpu {
VKVertexBuffer::~VKVertexBuffer()
{
release_data();
}
void VKVertexBuffer::bind_as_ssbo(uint /*binding*/)
{
}
@ -37,6 +44,13 @@ void *VKVertexBuffer::unmap(const void * /*mapped_data*/) const
void VKVertexBuffer::acquire_data()
{
if (usage_ == GPU_USAGE_DEVICE_ONLY) {
return;
}
/* Discard previous data if any. */
MEM_SAFE_FREE(data);
data = (uchar *)MEM_mallocN(sizeof(uchar) * this->size_alloc_get(), __func__);
}
void VKVertexBuffer::resize_data()
@ -45,6 +59,7 @@ void VKVertexBuffer::resize_data()
void VKVertexBuffer::release_data()
{
MEM_SAFE_FREE(data);
}
void VKVertexBuffer::upload_data()

View File

@ -13,6 +13,8 @@ namespace blender::gpu {
class VKVertexBuffer : public VertBuf {
public:
~VKVertexBuffer();
void bind_as_ssbo(uint binding) override;
void bind_as_texture(uint binding) override;
void wrap_handle(uint64_t handle) override;