2023-01-10 11:17:13 +11:00
|
|
|
use crate::hello_triangle::physicaldevice::find_queue_family;
|
|
|
|
use crate::hello_triangle::vulkan_base::VulkanBase;
|
2023-01-10 14:54:54 +11:00
|
|
|
use ash::prelude::VkResult;
|
|
|
|
use ash::vk;
|
2023-01-10 11:17:13 +11:00
|
|
|
|
|
|
|
pub struct VulkanCommandPool {
|
|
|
|
pool: vk::CommandPool,
|
|
|
|
device: ash::Device,
|
2023-01-10 14:54:54 +11:00
|
|
|
pub buffers: Vec<vk::CommandBuffer>,
|
2023-01-10 11:17:13 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
impl VulkanCommandPool {
|
|
|
|
pub fn new(base: &VulkanBase, frames_in_flight: u32) -> VkResult<VulkanCommandPool> {
|
|
|
|
let indices = find_queue_family(&base.instance, base.physical_device.clone());
|
|
|
|
|
|
|
|
let create_info = vk::CommandPoolCreateInfo::builder()
|
|
|
|
.flags(vk::CommandPoolCreateFlags::RESET_COMMAND_BUFFER)
|
|
|
|
.queue_family_index(indices.graphics_family())
|
|
|
|
.build();
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
let pool = base.device.create_command_pool(&create_info, None)?;
|
|
|
|
let buffer_info = vk::CommandBufferAllocateInfo::builder()
|
|
|
|
.command_pool(pool)
|
|
|
|
.level(vk::CommandBufferLevel::PRIMARY)
|
|
|
|
.command_buffer_count(frames_in_flight)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
let buffers = base.device.allocate_command_buffers(&buffer_info)?;
|
|
|
|
Ok(VulkanCommandPool {
|
|
|
|
pool,
|
|
|
|
device: base.device.clone(),
|
|
|
|
buffers,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2023-01-10 14:54:54 +11:00
|
|
|
}
|