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
|
|
|
|
|
*/
|
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"
|
|
|
|
|
|
|
|
|
|
#include "vk_storage_buffer.hh"
|
|
|
|
|
|
|
|
|
|
namespace blender::gpu {
|
|
|
|
|
|
2023-02-21 15:03:12 +01:00
|
|
|
void VKStorageBuffer::update(const void *data)
|
|
|
|
|
{
|
|
|
|
|
if (!buffer_.is_allocated()) {
|
2023-03-09 09:27:42 +01:00
|
|
|
VKContext &context = *VKContext::get();
|
2023-02-21 15:03:12 +01:00
|
|
|
allocate(context);
|
|
|
|
|
}
|
2023-03-09 09:27:42 +01:00
|
|
|
buffer_.update(data);
|
2023-02-21 15:03:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VKStorageBuffer::allocate(VKContext &context)
|
2022-10-31 16:01:02 +01:00
|
|
|
{
|
2023-03-17 13:48:39 +01:00
|
|
|
buffer_.create(context,
|
|
|
|
|
size_in_bytes_,
|
|
|
|
|
usage_,
|
|
|
|
|
static_cast<VkBufferUsageFlagBits>(VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
|
|
|
|
|
VK_BUFFER_USAGE_TRANSFER_DST_BIT));
|
2022-10-31 16:01:02 +01:00
|
|
|
}
|
|
|
|
|
|
2023-02-21 15:03:12 +01:00
|
|
|
void VKStorageBuffer::bind(int slot)
|
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, slot);
|
2023-02-22 14:42:01 +01:00
|
|
|
shader->pipeline_get().descriptor_set_get().bind(*this, location);
|
2022-10-31 16:01:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VKStorageBuffer::unbind()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-17 13:48:39 +01:00
|
|
|
void VKStorageBuffer::clear(uint32_t clear_value)
|
2022-10-31 16:01:02 +01:00
|
|
|
{
|
2023-03-17 13:48:39 +01:00
|
|
|
VKContext &context = *VKContext::get();
|
|
|
|
|
if (!buffer_.is_allocated()) {
|
|
|
|
|
allocate(context);
|
|
|
|
|
}
|
|
|
|
|
buffer_.clear(context, clear_value);
|
2022-10-31 16:01:02 +01:00
|
|
|
}
|
2023-03-09 18:46:28 +01:00
|
|
|
|
2022-10-31 16:01:02 +01:00
|
|
|
void VKStorageBuffer::copy_sub(VertBuf * /*src*/,
|
|
|
|
|
uint /*dst_offset*/,
|
|
|
|
|
uint /*src_offset*/,
|
|
|
|
|
uint /*copy_size*/)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-21 15:03:12 +01:00
|
|
|
void VKStorageBuffer::read(void *data)
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2022-12-17 15:58:30 +11:00
|
|
|
} // namespace blender::gpu
|