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: blender/blender#107606
45 lines
977 B
C++
45 lines
977 B
C++
/* SPDX-License-Identifier: GPL-2.0-or-later
|
|
* Copyright 2022 Blender Foundation */
|
|
|
|
/** \file
|
|
* \ingroup gpu
|
|
*/
|
|
|
|
#include "vk_pixel_buffer.hh"
|
|
|
|
#include "vk_context.hh"
|
|
|
|
namespace blender::gpu {
|
|
|
|
VKPixelBuffer::VKPixelBuffer(int64_t size) : PixelBuffer(size)
|
|
{
|
|
buffer_.create(size,
|
|
GPU_USAGE_STATIC,
|
|
static_cast<VkBufferUsageFlagBits>(VK_BUFFER_USAGE_TRANSFER_SRC_BIT |
|
|
VK_BUFFER_USAGE_TRANSFER_DST_BIT));
|
|
debug::object_label(buffer_.vk_handle(), "PixelBuffer");
|
|
}
|
|
|
|
void *VKPixelBuffer::map()
|
|
{
|
|
/* Vulkan buffers are always mapped between allocation and freeing. */
|
|
return buffer_.mapped_memory_get();
|
|
}
|
|
|
|
void VKPixelBuffer::unmap()
|
|
{
|
|
/* Vulkan buffers are always mapped between allocation and freeing. */
|
|
}
|
|
|
|
int64_t VKPixelBuffer::get_native_handle()
|
|
{
|
|
return int64_t(buffer_.vk_handle());
|
|
}
|
|
|
|
uint VKPixelBuffer::get_size()
|
|
{
|
|
return size_;
|
|
}
|
|
|
|
} // namespace blender::gpu
|