1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
use ash::version::DeviceV1_0; use ash::vk; use smallvec::SmallVec; use std::ptr; use std::sync::Arc; use command::CommandBuffer; use conv; use hal::{command, pool}; use {Backend, RawDevice}; #[derive(Debug)] pub struct RawCommandPool { pub(crate) raw: vk::CommandPool, pub(crate) device: Arc<RawDevice>, } impl pool::RawCommandPool<Backend> for RawCommandPool { unsafe fn reset(&mut self) { assert_eq!( Ok(()), self.device .0 .reset_command_pool(self.raw, vk::CommandPoolResetFlags::empty()) ); } fn allocate_vec(&mut self, num: usize, level: command::RawLevel) -> Vec<CommandBuffer> { let info = vk::CommandBufferAllocateInfo { s_type: vk::StructureType::COMMAND_BUFFER_ALLOCATE_INFO, p_next: ptr::null(), command_pool: self.raw, level: conv::map_command_buffer_level(level), command_buffer_count: num as u32, }; let device = &self.device; let cbufs_raw = unsafe { device.0.allocate_command_buffers(&info) } .expect("Error on command buffer allocation"); cbufs_raw .into_iter() .map(|buffer| CommandBuffer { raw: buffer, device: device.clone(), }) .collect() } unsafe fn free<I>(&mut self, cbufs: I) where I: IntoIterator<Item = CommandBuffer>, { let buffers: SmallVec<[vk::CommandBuffer; 16]> = cbufs.into_iter().map(|buffer| buffer.raw).collect(); self.device.0.free_command_buffers(self.raw, &buffers); } }