pub mod capability;
pub mod family;
use std::any::Any;
use std::borrow::Borrow;
use std::iter;
use std::marker::PhantomData;
use std::fmt;
use crate::command::{Primary, Submittable};
use crate::error::HostExecutionError;
use crate::pso;
use crate::window::{PresentError, Suboptimal, SwapImageIndex};
use crate::Backend;
pub use self::capability::{Capability, Compute, General, Graphics, Supports, Transfer};
pub use self::family::{QueueFamily, QueueFamilyId, QueueGroup, Queues};
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum QueueType {
General,
Graphics,
Compute,
Transfer,
}
pub struct Submission<Ic, Iw, Is> {
pub command_buffers: Ic,
pub wait_semaphores: Iw,
pub signal_semaphores: Is,
}
pub trait RawCommandQueue<B: Backend>: fmt::Debug + Any + Send + Sync {
unsafe fn submit<'a, T, Ic, S, Iw, Is>(
&mut self,
submission: Submission<Ic, Iw, Is>,
fence: Option<&B::Fence>,
) where
T: 'a + Borrow<B::CommandBuffer>,
Ic: IntoIterator<Item = &'a T>,
S: 'a + Borrow<B::Semaphore>,
Iw: IntoIterator<Item = (&'a S, pso::PipelineStage)>,
Is: IntoIterator<Item = &'a S>;
unsafe fn present<'a, W, Is, S, Iw>(
&mut self,
swapchains: Is,
wait_semaphores: Iw,
) -> Result<Option<Suboptimal>, PresentError>
where
Self: Sized,
W: 'a + Borrow<B::Swapchain>,
Is: IntoIterator<Item = (&'a W, SwapImageIndex)>,
S: 'a + Borrow<B::Semaphore>,
Iw: IntoIterator<Item = &'a S>;
fn wait_idle(&self) -> Result<(), HostExecutionError>;
}
#[derive(Debug)]
pub struct CommandQueue<B: Backend, C>(B::CommandQueue, PhantomData<C>);
impl<B: Backend, C: Capability> CommandQueue<B, C> {
pub unsafe fn new(raw: B::CommandQueue) -> Self {
CommandQueue(raw, PhantomData)
}
pub fn as_raw(&self) -> &B::CommandQueue {
&self.0
}
pub unsafe fn as_raw_mut(&mut self) -> &mut B::CommandQueue {
&mut self.0
}
pub fn into_raw(self) -> B::CommandQueue {
self.0
}
pub unsafe fn submit<'a, T, Ic, S, Iw, Is>(
&mut self,
submission: Submission<Ic, Iw, Is>,
fence: Option<&B::Fence>,
) where
T: 'a + Submittable<B, C, Primary>,
Ic: IntoIterator<Item = &'a T>,
S: 'a + Borrow<B::Semaphore>,
Iw: IntoIterator<Item = (&'a S, pso::PipelineStage)>,
Is: IntoIterator<Item = &'a S>,
{
self.0.submit(submission, fence)
}
pub unsafe fn submit_nosemaphores<'a, T, I>(
&mut self,
command_buffers: I,
fence: Option<&B::Fence>,
) where
T: 'a + Submittable<B, C, Primary>,
I: IntoIterator<Item = &'a T>,
{
let submission = Submission {
command_buffers,
wait_semaphores: iter::empty(),
signal_semaphores: iter::empty(),
};
self.submit::<_, _, B::Semaphore, _, _>(submission, fence)
}
pub unsafe fn present<'a, W, Is, S, Iw>(
&mut self,
swapchains: Is,
wait_semaphores: Iw,
) -> Result<Option<Suboptimal>, PresentError>
where
W: 'a + Borrow<B::Swapchain>,
Is: IntoIterator<Item = (&'a W, SwapImageIndex)>,
S: 'a + Borrow<B::Semaphore>,
Iw: IntoIterator<Item = &'a S>,
{
self.0.present(swapchains, wait_semaphores)
}
pub fn wait_idle(&self) -> Result<(), HostExecutionError> {
self.0.wait_idle()
}
pub unsafe fn downgrade<D>(&mut self) -> &mut CommandQueue<B, D>
where
C: Supports<D>,
{
::std::mem::transmute(self)
}
}