Vulkan: Refactor command buffer and introduce command pool
This commit is contained in:
@@ -7,8 +7,7 @@
|
||||
#include <Nazara/Core/ErrorFlags.hpp>
|
||||
#include <Nazara/Utility/PixelFormat.hpp>
|
||||
#include <Nazara/VulkanRenderer/Vulkan.hpp>
|
||||
#include <Nazara/VulkanRenderer/VulkanCommandBuffer.hpp>
|
||||
#include <Nazara/VulkanRenderer/VulkanCommandBufferBuilder.hpp>
|
||||
#include <Nazara/VulkanRenderer/VulkanCommandPool.hpp>
|
||||
#include <Nazara/VulkanRenderer/VulkanDevice.hpp>
|
||||
#include <Nazara/VulkanRenderer/VulkanSurface.hpp>
|
||||
#include <array>
|
||||
@@ -29,7 +28,6 @@ namespace Nz
|
||||
m_device->WaitForIdle();
|
||||
|
||||
m_concurrentImageData.clear();
|
||||
m_graphicsCommandPool.Destroy();
|
||||
m_imageData.clear();
|
||||
m_renderPass.Destroy();
|
||||
m_swapchain.Destroy();
|
||||
@@ -60,22 +58,6 @@ namespace Nz
|
||||
return currentFrame;
|
||||
}
|
||||
|
||||
std::unique_ptr<CommandBuffer> VkRenderWindow::BuildCommandBuffer(const std::function<void(CommandBufferBuilder& builder)>& callback)
|
||||
{
|
||||
Vk::AutoCommandBuffer commandBuffer = m_graphicsCommandPool.AllocateCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY);
|
||||
|
||||
if (!commandBuffer->Begin())
|
||||
throw std::runtime_error("failed to begin command buffer: " + TranslateVulkanError(commandBuffer->GetLastErrorCode()));
|
||||
|
||||
VulkanCommandBufferBuilder builder(commandBuffer.Get());
|
||||
callback(builder);
|
||||
|
||||
if (!commandBuffer->End())
|
||||
throw std::runtime_error("failed to build command buffer: " + TranslateVulkanError(commandBuffer->GetLastErrorCode()));
|
||||
|
||||
return std::make_unique<VulkanCommandBuffer>(std::move(commandBuffer));
|
||||
}
|
||||
|
||||
bool VkRenderWindow::Create(RendererImpl* /*renderer*/, RenderSurface* surface, const Vector2ui& size, const RenderWindowParameters& parameters)
|
||||
{
|
||||
const auto& deviceInfo = Vulkan::GetPhysicalDevices()[0];
|
||||
@@ -84,7 +66,8 @@ namespace Nz
|
||||
|
||||
UInt32 graphicsFamilyQueueIndex;
|
||||
UInt32 presentableFamilyQueueIndex;
|
||||
m_device = Vulkan::SelectDevice(deviceInfo, vulkanSurface, &graphicsFamilyQueueIndex, &presentableFamilyQueueIndex);
|
||||
UInt32 transferFamilyQueueIndex;
|
||||
m_device = Vulkan::SelectDevice(deviceInfo, vulkanSurface, &graphicsFamilyQueueIndex, &presentableFamilyQueueIndex, &transferFamilyQueueIndex);
|
||||
if (!m_device)
|
||||
{
|
||||
NazaraError("Failed to get compatible Vulkan device");
|
||||
@@ -93,6 +76,7 @@ namespace Nz
|
||||
|
||||
m_graphicsQueue = m_device->GetQueue(graphicsFamilyQueueIndex, 0);
|
||||
m_presentQueue = m_device->GetQueue(presentableFamilyQueueIndex, 0);
|
||||
m_transferQueue = m_device->GetQueue(transferFamilyQueueIndex, 0);
|
||||
|
||||
std::vector<VkSurfaceFormatKHR> surfaceFormats;
|
||||
if (!vulkanSurface.GetFormats(deviceInfo.physDevice, &surfaceFormats))
|
||||
@@ -204,12 +188,6 @@ namespace Nz
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_graphicsCommandPool.Create(*m_device, m_graphicsQueue.GetQueueFamilyIndex()))
|
||||
{
|
||||
NazaraError("Failed to create graphics command pool: " + TranslateVulkanError(m_graphicsCommandPool.GetLastErrorCode()));
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::size_t MaxConcurrentImage = imageCount;
|
||||
m_concurrentImageData.reserve(MaxConcurrentImage);
|
||||
|
||||
@@ -221,6 +199,27 @@ namespace Nz
|
||||
return true;
|
||||
}
|
||||
|
||||
std::unique_ptr<CommandPool> VkRenderWindow::CreateCommandPool(QueueType queueType)
|
||||
{
|
||||
UInt32 queueFamilyIndex;
|
||||
switch (queueType)
|
||||
{
|
||||
case QueueType::Compute:
|
||||
queueFamilyIndex = m_device->GetDefaultFamilyIndex(QueueType::Compute);
|
||||
break;
|
||||
|
||||
case QueueType::Graphics:
|
||||
queueFamilyIndex = m_graphicsQueue.GetQueueFamilyIndex();
|
||||
break;
|
||||
|
||||
case QueueType::Transfer:
|
||||
queueFamilyIndex = m_transferQueue.GetQueueFamilyIndex();
|
||||
break;
|
||||
}
|
||||
|
||||
return std::make_unique<VulkanCommandPool>(*m_device, queueFamilyIndex);
|
||||
}
|
||||
|
||||
bool VkRenderWindow::SetupDepthBuffer(const Vector2ui& size)
|
||||
{
|
||||
VkImageCreateInfo imageCreateInfo = {
|
||||
|
||||
Reference in New Issue
Block a user