Struct wgpu_hal::vulkan::SwapchainImageSemaphores

source ·
struct SwapchainImageSemaphores {
    acquire: Semaphore,
    should_wait_for_acquire: bool,
    present: Vec<Semaphore>,
    present_index: usize,
    previously_used_submission_index: FenceValue,
}
Expand description

The semaphores needed to use one image in a swapchain.

Fields§

§acquire: Semaphore

A semaphore that is signaled when this image is safe for us to modify.

When vkAcquireNextImageKHR returns the index of the next swapchain image that we should use, that image may actually still be in use by the presentation engine, and is not yet safe to modify. However, that function does accept a semaphore that it will signal when the image is indeed safe to begin messing with.

This semaphore is:

  • waited for by the first queue submission to operate on this image since it was acquired, and

  • signaled by vkAcquireNextImageKHR when the acquired image is ready for us to use.

§should_wait_for_acquire: bool

True if the next command submission operating on this image should wait for acquire.

We must wait for acquire before drawing to this swapchain image, but because wgpu-hal queue submissions are always strongly ordered, only the first submission that works with a swapchain image actually needs to wait. We set this flag when this image is acquired, and clear it the first time it’s passed to Queue::submit as a surface texture.

§present: Vec<Semaphore>

A pool of semaphores for ordering presentation after drawing.

The first present_index semaphores in this vector are:

  • all waited on by the call to vkQueuePresentKHR that presents this image, and

  • each signaled by some vkQueueSubmit queue submission that draws to this image, when the submission finishes execution.

This vector accumulates one semaphore per submission that writes to this image. This is awkward, but hard to avoid: vkQueuePresentKHR requires a semaphore to order it with respect to drawing commands, and we can’t attach new completion semaphores to a command submission after it’s been submitted. This means that, at submission time, we must create the semaphore we might need if the caller’s next action is to enqueue a presentation of this image.

An alternative strategy would be for presentation to enqueue an empty submit, ordered relative to other submits in the usual way, and signaling a single presentation semaphore. But we suspect that submits are usually expensive enough, and semaphores usually cheap enough, that performance-sensitive users will avoid making many submits, so that the cost of accumulated semaphores will usually be less than the cost of an additional submit.

Only the first present_index semaphores in the vector are actually going to be signalled by submitted commands, and need to be waited for by the next present call. Any semaphores beyond that index were created for prior presents and are simply being retained for recycling.

§present_index: usize

The number of semaphores in present to be signalled for this submission.

§previously_used_submission_index: FenceValue

The fence value of the last command submission that wrote to this image.

The next time we try to acquire this image, we’ll block until this submission finishes, proving that acquire is ready to pass to vkAcquireNextImageKHR again.

Implementations§

source§

impl SwapchainImageSemaphores

source

fn new(device: &DeviceShared) -> Result<Self, DeviceError>

source

fn set_used_fence_value(&mut self, value: FenceValue)

source

fn get_acquire_wait_semaphore(&mut self) -> Option<Semaphore>

Return the semaphore that commands drawing to this image should wait for, if any.

This only returns Some once per acquisition; see SwapchainImageSemaphores::should_wait_for_acquire for details.

source

fn get_submit_signal_semaphore( &mut self, device: &DeviceShared, ) -> Result<Semaphore, DeviceError>

Return a semaphore that a submission that writes to this image should signal when it’s done.

See SwapchainImageSemaphores::present for details.

source

fn get_present_wait_semaphores(&mut self) -> &[Semaphore]

Return the semaphores that a presentation of this image should wait on.

Return a slice of semaphores that the call to vkQueueSubmit that ends this image’s acquisition should wait for. See SwapchainImageSemaphores::present for details.

Reset self to be ready for the next acquisition cycle.

source

unsafe fn destroy(&self, device: &Device)

Trait Implementations§

source§

impl Debug for SwapchainImageSemaphores

source§

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

Formats the value using the given formatter. 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> Downcast<T> for T

source§

fn downcast(&self) -> &T

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.
source§

impl<T> Upcast<T> for T

source§

fn upcast(&self) -> Option<&T>

source§

impl<T> WasmNotSend for T
where T: Send,

source§

impl<T> WasmNotSendSync for T

source§

impl<T> WasmNotSync for T
where T: Sync,