The previous API for clearing storage buffers was following the OpenGL api. OpenGL has many options to support for data conversions, striding and sizzling. Metal and Vulkan don't have these features and we have to deal it ourselves. Blender internally only uses a tiny subset for what is possible in OpenGL. Making the current API to difficult to implement on our future platforms as we had to implement all cases, most even not used at all. By changing the API we make future development easier as we only need to implement what we are actually using. **New API** `GPU_storagebuf_clear(GPUStorageBuf* ssbo, uint32_t clear_value)` Related issue: #105492 Pull Request: blender/blender#105521
71 lines
1.7 KiB
C++
71 lines
1.7 KiB
C++
/* SPDX-License-Identifier: GPL-2.0-or-later
|
|
* Copyright 2022 Blender Foundation. All rights reserved. */
|
|
|
|
/** \file
|
|
* \ingroup gpu
|
|
*/
|
|
#include "vk_shader.hh"
|
|
#include "vk_shader_interface.hh"
|
|
#include "vk_vertex_buffer.hh"
|
|
|
|
#include "vk_storage_buffer.hh"
|
|
|
|
namespace blender::gpu {
|
|
|
|
void VKStorageBuffer::update(const void *data)
|
|
{
|
|
if (!buffer_.is_allocated()) {
|
|
VKContext &context = *VKContext::get();
|
|
allocate(context);
|
|
}
|
|
buffer_.update(data);
|
|
}
|
|
|
|
void VKStorageBuffer::allocate(VKContext &context)
|
|
{
|
|
buffer_.create(context, size_in_bytes_, usage_, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
|
|
}
|
|
|
|
void VKStorageBuffer::bind(int slot)
|
|
{
|
|
VKContext &context = *VKContext::get();
|
|
if (!buffer_.is_allocated()) {
|
|
allocate(context);
|
|
}
|
|
VKShader *shader = static_cast<VKShader *>(context.shader);
|
|
const VKShaderInterface &shader_interface = shader->interface_get();
|
|
const VKDescriptorSet::Location location = shader_interface.descriptor_set_location(
|
|
shader::ShaderCreateInfo::Resource::BindType::STORAGE_BUFFER, slot);
|
|
shader->pipeline_get().descriptor_set_get().bind(*this, location);
|
|
}
|
|
|
|
void VKStorageBuffer::unbind()
|
|
{
|
|
}
|
|
|
|
void VKStorageBuffer::clear(uint32_t /*clear_value*/)
|
|
{
|
|
}
|
|
|
|
void VKStorageBuffer::copy_sub(VertBuf * /*src*/,
|
|
uint /*dst_offset*/,
|
|
uint /*src_offset*/,
|
|
uint /*copy_size*/)
|
|
{
|
|
}
|
|
|
|
void VKStorageBuffer::read(void *data)
|
|
{
|
|
VKContext &context = *VKContext::get();
|
|
if (!buffer_.is_allocated()) {
|
|
allocate(context);
|
|
}
|
|
|
|
VKCommandBuffer &command_buffer = context.command_buffer_get();
|
|
command_buffer.submit();
|
|
|
|
buffer_.read(data);
|
|
}
|
|
|
|
} // namespace blender::gpu
|