Files
test/source/blender/gpu/vulkan/vk_command_buffer.cc
Jeroen Bakker 782e2e5f9a Vulkan: Make Command Pool, Descriptor Sets Context Specific
In Blender a context should not be shared between threads. In Vulkan a
command pool must not be shared between threads. In the current
implementation the command pool are stored on device level and could
therefore be shared between multiple context which made the implementation
not matching these rules.

This PR moves the command pool from device to command buffers where it
would not conflict between other contexts. This PR doesn't make the Vulkan
backend fully multithreaded. The access to the queue is still missing.

Pull Request: https://projects.blender.org/blender/blender/pulls/114977
2023-11-16 15:03:47 +01:00

75 lines
1.8 KiB
C++

/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup gpu
*/
#include "vk_command_buffer.hh"
#include "vk_backend.hh"
namespace blender::gpu {
VKCommandBuffer::~VKCommandBuffer()
{
free();
}
void VKCommandBuffer::free()
{
if (vk_command_buffer_ != VK_NULL_HANDLE) {
VKDevice &device = VKBackend::get().device_get();
vkFreeCommandBuffers(device.device_get(), vk_command_pool_, 1, &vk_command_buffer_);
vk_command_buffer_ = VK_NULL_HANDLE;
}
vk_command_pool_ = VK_NULL_HANDLE;
}
bool VKCommandBuffer::is_initialized() const
{
return vk_command_buffer_ != VK_NULL_HANDLE;
}
void VKCommandBuffer::init(const VkCommandPool vk_command_pool,
const VkCommandBuffer vk_command_buffer)
{
if (is_initialized()) {
return;
}
vk_command_pool_ = vk_command_pool;
vk_command_buffer_ = vk_command_buffer;
state.stage = Stage::Initial;
}
void VKCommandBuffer::begin_recording()
{
if (is_in_stage(Stage::Submitted)) {
stage_transfer(Stage::Submitted, Stage::Executed);
}
if (is_in_stage(Stage::Executed)) {
vkResetCommandBuffer(vk_command_buffer_, 0);
stage_transfer(Stage::Executed, Stage::Initial);
}
VkCommandBufferBeginInfo begin_info = {};
begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
vkBeginCommandBuffer(vk_command_buffer_, &begin_info);
stage_transfer(Stage::Initial, Stage::Recording);
state.recorded_command_counts = 0;
}
void VKCommandBuffer::end_recording()
{
vkEndCommandBuffer(vk_command_buffer_);
stage_transfer(Stage::Recording, Stage::BetweenRecordingAndSubmitting);
}
void VKCommandBuffer::commands_submitted()
{
stage_transfer(Stage::BetweenRecordingAndSubmitting, Stage::Submitted);
}
} // namespace blender::gpu