FramesInFlight

Struct FramesInFlight 

Source
pub struct FramesInFlight { /* private fields */ }
Expand description

The fundamental synchronization mechanism for an application with N “frames in flight” where frame K’s graphics command buffer can be recorded while frames K+1, K+2, … K+N are all in-progress rendering on the GPU.

For example, when there are 3 frames in flight, the sequence can be visualized like so:

---
config:
  theme: dark
---
sequenceDiagram
    participant app as App
    box Frames In Flight
    participant f0 as Frame[0]
    participant f1 as Frame[1]
    participant f2 as Frame[2]
    end
    participant swp as Swapchain

    %% ------- %%
    %% Frame 0 %%
    %% ------- %%
    f0 ->> f0: Wait for previous Frame[0]
graphics commands fence activate f0 swp ->> f0: acquire swapchain image f0 ->> app: start_frame()->
Frame activate app Note left of app: Record commands for
the Frame. Return
ownership of Frame
instance when complete. app ->> f0: present_frame(Frame) deactivate app f0 ->> f0: Submit Graphics
Command Buffer and
Signal Frame[0] Fence
when finished %% ------- %% %% Frame 1 %% %% ------- %% f1 ->> f1: Wait for previous Frame[1]
graphics commands fence activate f1 swp ->> f1: acquire swapchain image f1 ->> app: start_frame()->
Frame activate app Note left of app: Record commands for
the Frame. Return
ownership of Frame
instance when complete. app ->> f1: present_frame(Frame) deactivate app f1 ->> f1: Submit Graphics
Command Buffer and
Signal Frame[1] Fence
when finished %% ------- %% %% Frame 2 %% %% ------- %% f2 ->> f2: Wait for previous Frame[2]
graphics commands fence activate f2 swp ->> f2: acquire swapchain image f2 ->> app: start_frame()->
Frame activate app Note left of app: Record commands for
the Frame. Return
ownership of Frame
instance when complete. app ->> f2: present_frame(Frame) deactivate app f2 ->> f2: Submit Graphics
Command Buffer and
Signal Frame[2] Fence
when finished f0 ->> swp: present image when graphics
commands for Frame[0] signal
the present semaphore. deactivate f0 %% ------- %% %% Frame 0 %% %% ------- %% f0 ->> f0: Wait for previous Frame[0]
graphics commands fence activate f0 swp ->> f0: acquire swapchain image f0 ->> app: start_frame()->
Frame activate app Note left of app: Record commands for
the Frame. Return
ownership of Frame
instance when complete. app ->> f0: present_frame(Frame) deactivate app f0 ->> f0: Submit Graphics
Command Buffer and
Signal Frame[0] Fence
when finished f1 ->> swp: present image when graphics
commands for Frame[1] signal
the present semaphore. deactivate f1 %% ------- %% %% Frame 1 %% %% ------- %% f1 ->> f1: Wait for previous Frame[1]
graphics commands fence activate f1 swp ->> f1: acquire swapchain image f1 ->> app: start_frame()->
Frame activate app Note left of app: Record commands for
the Frame. Return
ownership of Frame
instance when complete. app ->> f1: present_frame(Frame) deactivate app f1 ->> f1: Submit Graphics
Command Buffer and
Signal Frame[1] Fence
when finished f2 ->> swp: present image when graphics
commands for Frame[2] signal
the present semaphore. deactivate f2 f0 ->> swp: present image when graphics
commands for Frame[0] signal
the present semaphore. deactivate f0 f1 ->> swp: present image when graphics
commands for Frame[1] signal
the present semaphore. deactivate f1

The application takes ownership of the Frame object when calling Self::start_frame and returns ownership when calling Self::present_frame. As such, any time a system needs to access a frame-specific resource, the best option is to accept an Frame borrow and use Frame::frame_index to select frame-specific resources. This is certain to be safe because the only time the application has a Frame instance is when that frame’s previous commands have finished executing.

Implementations§

Source§

impl FramesInFlight

Source

pub fn new( ctx: Arc<VulkanContext>, swapchain_image_count: usize, frame_count: usize, ) -> Result<Self>

Creates a new instance with frame_count frames.

Source

pub fn frame_count(&self) -> usize

Get the total number of configured frames in flight.

Source

pub fn wait_for_all_frames_to_complete(&self) -> Result<()>

Blocks until all submitted commands for all frames have completed.

NOTE: Only waits on pending frames. If there’s a frame mid-assembly, there’s nothing to wait on. (and what’s more, attempting to wait would never succeed until the frame is submitted)

Source

pub fn start_frame(&mut self, swapchain: &Swapchain) -> Result<FrameStatus>

Starts the next frame in flight.

This method can block if all frames are in flight. It will block until the next frame is available.

§Returns

A FrameStatus containing one of:

  • A Frame that must be returned to Self::present_frame
  • A flag indicating that the Swapchain needs to be rebuilt before the next frame.
Source

pub fn present_frame( &mut self, swapchain: &Swapchain, frame: Frame, ) -> Result<PresentImageStatus>

Queues the Frame’s command buffer and swapchain presentation.

Trait Implementations§

Source§

impl Debug for FramesInFlight

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for FramesInFlight

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.