Previous GHOST_ContextVK would create a logical device for each context. Blender uses multiple contexts at the same time and wasn't able to share resources between them as the logical device where different. This patch will create a single logical device and share them between multiple contexts. This allows sharing memory/shaders between contexts and make sure that all memory allocations are freed from the device it was allocated from. Some allocations in Blender are freed when there isn't a context, this was failing in the previous implementation. We didn't noticed it before as we didn't test multiple contexts. This patch also moves device specific data structures from VKContext to VKDevice like the descriptor pools, debug layers etc. Pull Request: https://projects.blender.org/blender/blender/pulls/107606
66 lines
1.6 KiB
C++
66 lines
1.6 KiB
C++
/* SPDX-License-Identifier: GPL-2.0-or-later
|
|
* Copyright 2022 Blender Foundation */
|
|
|
|
/** \file
|
|
* \ingroup gpu
|
|
*/
|
|
|
|
#include "vk_uniform_buffer.hh"
|
|
#include "vk_context.hh"
|
|
#include "vk_shader.hh"
|
|
#include "vk_shader_interface.hh"
|
|
|
|
namespace blender::gpu {
|
|
|
|
void VKUniformBuffer::update(const void *data)
|
|
{
|
|
if (!buffer_.is_allocated()) {
|
|
allocate();
|
|
}
|
|
buffer_.update(data);
|
|
}
|
|
|
|
void VKUniformBuffer::allocate()
|
|
{
|
|
buffer_.create(size_in_bytes_, GPU_USAGE_STATIC, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
|
|
debug::object_label(buffer_.vk_handle(), name_);
|
|
}
|
|
|
|
void VKUniformBuffer::clear_to_zero()
|
|
{
|
|
if (!buffer_.is_allocated()) {
|
|
allocate();
|
|
}
|
|
VKContext &context = *VKContext::get();
|
|
buffer_.clear(context, 0);
|
|
}
|
|
|
|
void VKUniformBuffer::bind(int slot, shader::ShaderCreateInfo::Resource::BindType bind_type)
|
|
{
|
|
if (!buffer_.is_allocated()) {
|
|
allocate();
|
|
}
|
|
|
|
VKContext &context = *VKContext::get();
|
|
VKShader *shader = static_cast<VKShader *>(context.shader);
|
|
const VKShaderInterface &shader_interface = shader->interface_get();
|
|
const VKDescriptorSet::Location location = shader_interface.descriptor_set_location(bind_type,
|
|
slot);
|
|
VKDescriptorSetTracker &descriptor_set = shader->pipeline_get().descriptor_set_get();
|
|
descriptor_set.bind(*this, location);
|
|
}
|
|
|
|
void VKUniformBuffer::bind(int slot)
|
|
{
|
|
bind(slot, shader::ShaderCreateInfo::Resource::BindType::UNIFORM_BUFFER);
|
|
}
|
|
|
|
void VKUniformBuffer::bind_as_ssbo(int slot)
|
|
{
|
|
bind(slot, shader::ShaderCreateInfo::Resource::BindType::STORAGE_BUFFER);
|
|
}
|
|
|
|
void VKUniformBuffer::unbind() {}
|
|
|
|
} // namespace blender::gpu
|