Files
test2/source/blender/gpu/vulkan/vk_state_manager.hh
Jeroen Bakker d84a64900f Vulkan: Device Context Resource Management
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
2023-06-15 08:14:37 +02:00

71 lines
2.0 KiB
C++

/* SPDX-FileCopyrightText: 2023 Blender Foundation
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup gpu
*/
#pragma once
#include "gpu_state_private.hh"
#include "BLI_array.hh"
#include "vk_bindable_resource.hh"
namespace blender::gpu {
class VKTexture;
class VKUniformBuffer;
class VKVertexBuffer;
class VKStorageBuffer;
class VKIndexBuffer;
class VKStateManager : public StateManager {
uint texture_unpack_row_length_ = 0;
VKBindSpace<shader::ShaderCreateInfo::Resource::BindType::SAMPLER> textures_;
VKBindSpace<shader::ShaderCreateInfo::Resource::BindType::IMAGE> images_;
VKBindSpace<shader::ShaderCreateInfo::Resource::BindType::UNIFORM_BUFFER> uniform_buffers_;
VKBindSpace<shader::ShaderCreateInfo::Resource::BindType::STORAGE_BUFFER> storage_buffers_;
public:
void apply_state() override;
void force_state() override;
void issue_barrier(eGPUBarrier barrier_bits) override;
/** Apply resources to the bindings of the active shader. */
void apply_bindings();
void texture_bind(Texture *tex, GPUSamplerState sampler, int unit) override;
void texture_unbind(Texture *tex) override;
void texture_unbind_all() override;
void image_bind(Texture *tex, int unit) override;
void image_unbind(Texture *tex) override;
void image_unbind_all() override;
void uniform_buffer_bind(VKUniformBuffer *uniform_buffer, int slot);
void uniform_buffer_unbind(VKUniformBuffer *uniform_buffer);
void texel_buffer_bind(VKVertexBuffer &vertex_buffer, int slot);
void texel_buffer_unbind(VKVertexBuffer &vertex_buffer);
void storage_buffer_bind(VKBindableResource &resource, int slot);
void storage_buffer_unbind(VKBindableResource &resource);
void unbind_from_all_namespaces(VKBindableResource &bindable_resource);
void texture_unpack_row_length_set(uint len) override;
/**
* Row length for unpacking host data when uploading texture data.
*
* When set to zero (0) host data can be assumed to be stored sequential.
*/
uint texture_unpack_row_length_get() const;
};
} // namespace blender::gpu