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
65 lines
1.3 KiB
C++
65 lines
1.3 KiB
C++
/* SPDX-License-Identifier: GPL-2.0-or-later
|
|
* Copyright 2023 Blender Foundation */
|
|
|
|
/** \file
|
|
* \ingroup gpu
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "gpu_context_private.hh"
|
|
|
|
#include "vk_common.hh"
|
|
|
|
namespace blender::gpu {
|
|
class VKContext;
|
|
|
|
/**
|
|
* Class for handing vulkan buffers (allocation/updating/binding).
|
|
*/
|
|
class VKBuffer {
|
|
int64_t size_in_bytes_;
|
|
VkBuffer vk_buffer_ = VK_NULL_HANDLE;
|
|
VmaAllocation allocation_ = VK_NULL_HANDLE;
|
|
/* Pointer to the virtually mapped memory. */
|
|
void *mapped_memory_ = nullptr;
|
|
|
|
public:
|
|
VKBuffer() = default;
|
|
virtual ~VKBuffer();
|
|
|
|
/** Has this buffer been allocated? */
|
|
bool is_allocated() const;
|
|
|
|
bool create(int64_t size, GPUUsageType usage, VkBufferUsageFlagBits buffer_usage);
|
|
void clear(VKContext &context, uint32_t clear_value);
|
|
void update(const void *data) const;
|
|
void read(void *data) const;
|
|
bool free();
|
|
|
|
int64_t size_in_bytes() const
|
|
{
|
|
return size_in_bytes_;
|
|
}
|
|
|
|
VkBuffer vk_handle() const
|
|
{
|
|
return vk_buffer_;
|
|
}
|
|
|
|
/**
|
|
* Get the reference to the mapped memory.
|
|
*
|
|
* Can only be called when the buffer is (still) mapped.
|
|
*/
|
|
void *mapped_memory_get() const;
|
|
|
|
private:
|
|
/** Check if this buffer is mapped. */
|
|
bool is_mapped() const;
|
|
bool map();
|
|
void unmap();
|
|
};
|
|
|
|
} // namespace blender::gpu
|