librashader/librashader-runtime-vk/tests/hello_triangle/command.rs

37 lines
1.2 KiB
Rust
Raw Normal View History

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-15 19:06:09 +11:00
use std::sync::Arc;
2023-01-10 11:17:13 +11:00
pub struct VulkanCommandPool {
2023-02-10 13:03:55 +11:00
_pool: vk::CommandPool,
_device: Arc<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> {
2023-01-16 03:08:13 +11:00
let indices = find_queue_family(&base.instance, base.physical_device);
2023-01-10 11:17:13 +11:00
let create_info = vk::CommandPoolCreateInfo::builder()
.flags(vk::CommandPoolCreateFlags::RESET_COMMAND_BUFFER)
.queue_family_index(indices.graphics_family());
2023-01-10 11:17:13 +11:00
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);
2023-01-10 11:17:13 +11:00
let buffers = base.device.allocate_command_buffers(&buffer_info)?;
Ok(VulkanCommandPool {
2023-02-10 13:03:55 +11:00
_pool: pool,
_device: base.device.clone(),
2023-01-10 11:17:13 +11:00
buffers,
})
}
}
2023-01-10 14:54:54 +11:00
}