use {
super::{
level::PrimaryLevel,
state::{ExecutableState, InvalidState, PendingState},
usage::{MultiShot, NoSimultaneousUse, OneShot, OutsideRenderPass, SimultaneousUse},
CommandBuffer,
},
crate::family::FamilyId,
};
#[derive(Debug)]
pub struct Submit<
B: rendy_core::hal::Backend,
S = NoSimultaneousUse,
L = PrimaryLevel,
P = OutsideRenderPass,
> {
raw: std::ptr::NonNull<B::CommandBuffer>,
family: FamilyId,
simultaneous: S,
level: L,
pass_continue: P,
}
unsafe impl<B, S, L, P> Send for Submit<B, S, L, P>
where
B: rendy_core::hal::Backend,
B::CommandBuffer: Send + Sync,
FamilyId: Send,
S: Send,
L: Send,
P: Send,
{
}
unsafe impl<B, S, L, P> Sync for Submit<B, S, L, P>
where
B: rendy_core::hal::Backend,
B::CommandBuffer: Send + Sync,
S: Sync,
L: Sync,
P: Sync,
{
}
pub unsafe trait Submittable<B: rendy_core::hal::Backend, L = PrimaryLevel, P = OutsideRenderPass> {
fn family(&self) -> FamilyId;
unsafe fn raw<'a>(self) -> &'a B::CommandBuffer;
}
unsafe impl<B, S, L, P> Submittable<B, L, P> for Submit<B, S, L, P>
where
B: rendy_core::hal::Backend,
{
fn family(&self) -> FamilyId {
self.family
}
unsafe fn raw<'a>(self) -> &'a B::CommandBuffer {
&*self.raw.as_ptr()
}
}
unsafe impl<'a, B, L, P> Submittable<B, L, P> for &'a Submit<B, SimultaneousUse, L, P>
where
B: rendy_core::hal::Backend,
{
fn family(&self) -> FamilyId {
self.family
}
unsafe fn raw<'b>(self) -> &'b B::CommandBuffer {
&*self.raw.as_ptr()
}
}
impl<B, C, P, L, R> CommandBuffer<B, C, ExecutableState<OneShot, P>, L, R>
where
B: rendy_core::hal::Backend,
P: Copy,
L: Copy,
{
pub fn submit_once(
self,
) -> (
Submit<B, NoSimultaneousUse, L, P>,
CommandBuffer<B, C, PendingState<InvalidState>, L, R>,
) {
let pass_continue = self.state.1;
let level = self.level;
let buffer = unsafe { self.change_state(|_| PendingState(InvalidState)) };
let submit = Submit {
raw: buffer.raw,
family: buffer.family,
pass_continue,
simultaneous: NoSimultaneousUse,
level,
};
(submit, buffer)
}
}
impl<B, C, S, L, P, R> CommandBuffer<B, C, ExecutableState<MultiShot<S>, P>, L, R>
where
B: rendy_core::hal::Backend,
P: Copy,
S: Copy,
L: Copy,
{
pub fn submit(
self,
) -> (
Submit<B, S, L, P>,
CommandBuffer<B, C, PendingState<ExecutableState<MultiShot<S>, P>>, L, R>,
) {
let MultiShot(simultaneous) = self.state.0;
let pass_continue = self.state.1;
let level = self.level;
let buffer = unsafe { self.change_state(|state| PendingState(state)) };
let submit = Submit {
raw: buffer.raw,
family: buffer.family,
pass_continue,
simultaneous,
level,
};
(submit, buffer)
}
}