use crate::{CommandBufferHandle, FrameKey, PresentKey, SynchronizerHandle};
#[derive(Clone, Copy)]
pub struct FrameRequest {
pub index: u32,
pub synchronizer: SynchronizerHandle,
}
pub struct StartedFrame<F> {
pub frame: F,
pub completed_frame: Option<FrameKey>,
}
impl<F> StartedFrame<F> {
pub fn new(frame: F, completed_frame: Option<FrameKey>) -> Self {
Self { frame, completed_frame }
}
}
pub fn completed_frame_key(index: u32, frames_in_flight: u8) -> Option<FrameKey> {
let frames_in_flight = frames_in_flight as u32;
index.checked_sub(frames_in_flight).map(|frame_index| FrameKey {
frame_index,
sequence_index: (frame_index % frames_in_flight) as u8,
})
}
pub trait QueueExecution<'a> {
type Frame: crate::frame::Frame<'a>;
fn frame(&mut self) -> Option<&mut Self::Frame>;
fn completed_frame(&self) -> Option<FrameKey>;
fn record<'record>(
&'record mut self,
command_buffer_handle: CommandBufferHandle,
record: impl FnOnce(&mut <Self::Frame as crate::frame::Frame<'a>>::CBR<'record>),
) where
Self::Frame: 'record;
fn record_with_present_keys<'record>(
&'record mut self,
command_buffer_handle: CommandBufferHandle,
_present_keys: &[PresentKey],
record: impl FnOnce(&mut <Self::Frame as crate::frame::Frame<'a>>::CBR<'record>),
) where
Self::Frame: 'record,
{
self.record(command_buffer_handle, record);
}
}
pub trait Queue {
type Frame<'a>: crate::frame::Frame<'a>;
type Execution<'a>: QueueExecution<'a, Frame = Self::Frame<'a>>;
fn create_command_buffer(&mut self, name: Option<&str>) -> CommandBufferHandle;
fn start_frame<'a>(&'a mut self, index: u32, synchronizer_handle: SynchronizerHandle) -> StartedFrame<Self::Frame<'a>>;
fn execute<'a, P>(
&'a mut self,
frame: Option<FrameRequest>,
wait_for: &[SynchronizerHandle],
synchronizer: crate::SynchronizerHandle,
execute: impl FnOnce(&mut Self::Execution<'a>) -> P,
) where
P: AsRef<[PresentKey]>;
}