The current Vulkan resource management has some issues as context that are not active can still use resources that are freed via another context. When this happens incorrect data can be read on the GPU and even crash Blender. When trying to bind something that now contains other memory pointers. This change introduces that contexts are tracked via the device. Context will be registered/unregistered with the device instance. Unbinding of resources must pass the device and the device will check all registered contexts. Binding of resources will happen via the active context only. On user perspective this now allowes: - Opening/switching files - Switching workspaces - Switching render engines Pull Request: https://projects.blender.org/blender/blender/pulls/108968
59 lines
1.1 KiB
C++
59 lines
1.1 KiB
C++
/* SPDX-FileCopyrightText: 2022 Blender Foundation
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
/** \file
|
|
* \ingroup gpu
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "BLI_utility_mixins.hh"
|
|
|
|
#include "gpu_uniform_buffer_private.hh"
|
|
|
|
#include "vk_bindable_resource.hh"
|
|
#include "vk_buffer.hh"
|
|
|
|
namespace blender::gpu {
|
|
|
|
class VKUniformBuffer : public UniformBuf, public VKBindableResource, NonCopyable {
|
|
VKBuffer buffer_;
|
|
|
|
public:
|
|
VKUniformBuffer(int size, const char *name) : UniformBuf(size, name) {}
|
|
|
|
void update(const void *data) override;
|
|
void clear_to_zero() override;
|
|
void bind(int slot) override;
|
|
void bind_as_ssbo(int slot) override;
|
|
|
|
/**
|
|
* Unbind uniform buffer from active context.
|
|
*/
|
|
void unbind() override;
|
|
|
|
VkBuffer vk_handle() const
|
|
{
|
|
return buffer_.vk_handle();
|
|
}
|
|
|
|
size_t size_in_bytes() const
|
|
{
|
|
return size_in_bytes_;
|
|
}
|
|
|
|
/* Bindable resource */
|
|
void bind(int binding, shader::ShaderCreateInfo::Resource::BindType bind_type) override;
|
|
|
|
private:
|
|
void allocate();
|
|
};
|
|
|
|
BLI_INLINE UniformBuf *wrap(VKUniformBuffer *uniform_buffer)
|
|
{
|
|
return static_cast<UniformBuf *>(uniform_buffer);
|
|
}
|
|
|
|
} // namespace blender::gpu
|