ursus_core/vulkan/core/
commands.rs1use ash::vk;
2
3pub struct Commands {
4 pub pool: vk::CommandPool,
5 pub buffers: Vec<vk::CommandBuffer>,
6 device: ash::Device,
7}
8
9impl Commands {
10 pub fn new(device: &ash::Device, graphics_family: u32, frames_in_flight: u32) -> anyhow::Result<Self> {
11 let pool_info = vk::CommandPoolCreateInfo::default()
12 .queue_family_index(graphics_family)
13 .flags(vk::CommandPoolCreateFlags::RESET_COMMAND_BUFFER);
14
15 let pool = unsafe { device.create_command_pool(&pool_info, None)? };
16
17 let alloc_info = vk::CommandBufferAllocateInfo::default()
18 .command_pool(pool)
19 .level(vk::CommandBufferLevel::PRIMARY)
20 .command_buffer_count(frames_in_flight);
21
22 let buffers = unsafe { device.allocate_command_buffers(&alloc_info)? };
23
24 log::debug!("Command pool created ({} buffers)", frames_in_flight);
25 Ok(Self { pool, buffers, device: device.clone() })
26 }
27}
28
29impl Drop for Commands {
30 fn drop(&mut self) {
31 unsafe { self.device.destroy_command_pool(self.pool, None) };
32 }
33}