Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 1s
52 lines
1.5 KiB
Rust
52 lines
1.5 KiB
Rust
use super::VkDevice;
|
|
use ash::prelude::VkResult;
|
|
use ash::vk;
|
|
use std::sync::Arc;
|
|
|
|
pub struct VkCommandPool {
|
|
device: Arc<VkDevice>,
|
|
|
|
pub handle: vk::CommandPool,
|
|
}
|
|
|
|
impl VkCommandPool {
|
|
pub fn new(device: &Arc<VkDevice>) -> VkResult<Self> {
|
|
let command_pool_info =
|
|
vk::CommandPoolCreateInfo::default()
|
|
.flags(vk::CommandPoolCreateFlags::RESET_COMMAND_BUFFER)
|
|
.queue_family_index(device.queue_family_index);
|
|
let command_pool = unsafe {
|
|
device
|
|
.handle
|
|
.create_command_pool(&command_pool_info, None)?
|
|
};
|
|
log::debug!("Command pool created ({command_pool:?})");
|
|
|
|
Ok(Self {
|
|
device: device.clone(),
|
|
handle: command_pool,
|
|
})
|
|
}
|
|
|
|
pub fn allocate_command_buffers_for_framebuffers(&self, framebuffers_count: u32) -> VkResult<Vec<vk::CommandBuffer>> {
|
|
let command_buffer_info = vk::CommandBufferAllocateInfo::default()
|
|
.command_pool(self.handle)
|
|
.level(vk::CommandBufferLevel::PRIMARY)
|
|
.command_buffer_count(framebuffers_count);
|
|
|
|
let command_buffers = unsafe {
|
|
self.device
|
|
.handle
|
|
.allocate_command_buffers(&command_buffer_info)?
|
|
};
|
|
|
|
Ok(command_buffers)
|
|
}
|
|
}
|
|
|
|
impl Drop for VkCommandPool {
|
|
fn drop(&mut self) {
|
|
unsafe { self.device.handle.destroy_command_pool(self.handle, None) };
|
|
log::debug!("Command pool destroyed ({:?})", self.handle);
|
|
}
|
|
}
|