You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

93 lines
1.9 KiB

use crate::render::{Device, Instance, PhysicalDevice, Surface};
use ash::{
version::{DeviceV1_0, InstanceV1_0},
vk,
};
use std::rc::Rc;
pub type QueueIndex = u32;
pub struct QueueFamilyInfo {
pub gfx_index: QueueIndex,
pub srf_index: QueueIndex,
}
pub struct Queue {
handle: vk::Queue,
pub device: Rc<Device>,
pub index: QueueIndex,
}
#[derive(Debug)]
pub enum ErrQueueFamilyCollect {
NoGfxQueue,
NoSrfQueue,
}
impl QueueFamilyInfo {
pub fn collect(
instance: &Instance,
surface: &Surface,
phys_device: &PhysicalDevice,
) -> Result<Self, ErrQueueFamilyCollect> {
let mut gfx_index = None;
let mut srf_index = None;
let queues = unsafe {
instance.get_physical_device_queue_family_properties(**phys_device)
};
for (i, queue) in queues.iter().enumerate() {
let i = i as u32;
let surface_support = unsafe {
instance.surface_ext.get_physical_device_surface_support(
**phys_device,
i,
**surface,
)
};
if queue.queue_flags.contains(vk::QueueFlags::GRAPHICS) {
gfx_index = Some(i);
}
if surface_support {
srf_index = Some(i);
}
}
Ok(Self {
gfx_index: gfx_index.ok_or(ErrQueueFamilyCollect::NoGfxQueue)?,
srf_index: srf_index.ok_or(ErrQueueFamilyCollect::NoSrfQueue)?,
})
}
}
impl Queue {
pub fn get(device: Rc<Device>, index: u32) -> Rc<Self> {
let handle = unsafe { device.get_device_queue(index, 0) };
Rc::new(Self { handle, device, index })
}
}
impl std::ops::Deref for Queue {
type Target = vk::Queue;
fn deref(&self) -> &Self::Target {
&self.handle
}
}
impl std::fmt::Display for ErrQueueFamilyCollect {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::NoGfxQueue => f.write_str("Graphics queue not available"),
Self::NoSrfQueue => f.write_str("Surface queue not available"),
}
}
}
impl std::error::Error for ErrQueueFamilyCollect {}
// EOF