Goal is to reduce the number of command buffer flushes by tracking what is happening in the different command queues. This is an initial step towards advanced queue-ing strategies. The new (intermediate) strategy records commands to different command buffers based on what they do. There is a command buffer for data transfers, compute pipelines and graphics pipelines. When a compute command is recorded it ensures that all graphic commands are finished. When a graphic command is recorded it ensures all compute commands are finished. When a graphic or compute command is scheduled all recorded data transfer commands are scheduled as well. Some improvements are expected as multiple compute and data transfers commands can now be scheduled at the same time and don't need to unbind and rebind render passes. Especially when using EEVEE-Next which is compute centric the performance change is visible for the user. Pull Request: https://projects.blender.org/blender/blender/pulls/114104
68 lines
1.6 KiB
C++
68 lines
1.6 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()
|
|
{
|
|
if (vk_command_buffer_ != VK_NULL_HANDLE) {
|
|
VKDevice &device = VKBackend::get().device_get();
|
|
vkFreeCommandBuffers(
|
|
device.device_get(), device.vk_command_pool_get(), 1, &vk_command_buffer_);
|
|
vk_command_buffer_ = VK_NULL_HANDLE;
|
|
}
|
|
}
|
|
|
|
bool VKCommandBuffer::is_initialized() const
|
|
{
|
|
return vk_command_buffer_ != VK_NULL_HANDLE;
|
|
}
|
|
|
|
void VKCommandBuffer::init(VkCommandBuffer vk_command_buffer)
|
|
{
|
|
if (is_initialized()) {
|
|
return;
|
|
}
|
|
|
|
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
|