2022-10-31 16:01:02 +01:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
* Copyright 2022 Blender Foundation. All rights reserved. */
|
|
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
|
* \ingroup gpu
|
|
|
|
|
*/
|
|
|
|
|
|
2022-12-02 13:38:45 +01:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
2023-02-21 15:03:12 +01:00
|
|
|
#include "vk_shader.hh"
|
|
|
|
|
#include "vk_shader_interface.hh"
|
2022-10-31 16:01:02 +01:00
|
|
|
#include "vk_vertex_buffer.hh"
|
|
|
|
|
|
|
|
|
|
namespace blender::gpu {
|
|
|
|
|
|
2022-12-02 13:38:45 +01:00
|
|
|
VKVertexBuffer::~VKVertexBuffer()
|
|
|
|
|
{
|
|
|
|
|
release_data();
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-21 15:03:12 +01:00
|
|
|
void VKVertexBuffer::bind_as_ssbo(uint binding)
|
2022-10-31 16:01:02 +01:00
|
|
|
{
|
2023-02-21 15:03:12 +01:00
|
|
|
VKContext &context = *VKContext::get();
|
|
|
|
|
if (!buffer_.is_allocated()) {
|
|
|
|
|
allocate(context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VKShader *shader = static_cast<VKShader *>(context.shader);
|
|
|
|
|
const VKShaderInterface &shader_interface = shader->interface_get();
|
2023-02-22 14:42:01 +01:00
|
|
|
const VKDescriptorSet::Location location = shader_interface.descriptor_set_location(
|
2023-02-21 15:03:12 +01:00
|
|
|
shader::ShaderCreateInfo::Resource::BindType::STORAGE_BUFFER, binding);
|
2023-02-22 14:42:01 +01:00
|
|
|
shader->pipeline_get().descriptor_set_get().bind_as_ssbo(*this, location);
|
2022-10-31 16:01:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VKVertexBuffer::bind_as_texture(uint /*binding*/)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VKVertexBuffer::wrap_handle(uint64_t /*handle*/)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VKVertexBuffer::update_sub(uint /*start*/, uint /*len*/, const void * /*data*/)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-21 15:03:12 +01:00
|
|
|
void VKVertexBuffer::read(void *data) const
|
2022-10-31 16:01:02 +01:00
|
|
|
{
|
2023-02-21 15:03:12 +01:00
|
|
|
VKContext &context = *VKContext::get();
|
|
|
|
|
VKCommandBuffer &command_buffer = context.command_buffer_get();
|
|
|
|
|
command_buffer.submit();
|
2023-03-09 09:27:42 +01:00
|
|
|
buffer_.read(data);
|
2022-10-31 16:01:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VKVertexBuffer::acquire_data()
|
|
|
|
|
{
|
2022-12-02 13:38:45 +01:00
|
|
|
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__);
|
2022-10-31 16:01:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VKVertexBuffer::resize_data()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VKVertexBuffer::release_data()
|
|
|
|
|
{
|
2022-12-02 13:38:45 +01:00
|
|
|
MEM_SAFE_FREE(data);
|
2022-10-31 16:01:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VKVertexBuffer::upload_data()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VKVertexBuffer::duplicate_data(VertBuf * /*dst*/)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-21 15:03:12 +01:00
|
|
|
void VKVertexBuffer::allocate(VKContext &context)
|
|
|
|
|
{
|
|
|
|
|
buffer_.create(context,
|
|
|
|
|
size_used_get(),
|
|
|
|
|
usage_,
|
|
|
|
|
static_cast<VkBufferUsageFlagBits>(VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
|
|
|
|
|
VK_BUFFER_USAGE_VERTEX_BUFFER_BIT));
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-31 15:49:04 +11:00
|
|
|
} // namespace blender::gpu
|