Donner SVG 0.8.0
0.8.0 ยท ebf353960.8.0 main
SVG editor and embeddable C⁠+⁠+⁠20 engine.
Loading...
Searching...
No Matches
donner::gpu::vulkan::VulkanSwapchain Class Reference

One surface and the swapchain it presents through. More...

#include "donner/gpu/vulkan/VulkanSwapchain.h"

Public Member Functions

 ~VulkanSwapchain ()
 Destructor; proves this surface's native work complete, then destroys the swapchain and the surface too when this object created it. A failed proof poisons the shared lifetime state so the owner retains all native prerequisites fail-closed.
 VulkanSwapchain (const VulkanSwapchain &)=delete
VulkanSwapchain & operator= (const VulkanSwapchain &)=delete
Status prepareForDestruction ()
 Proves that every native object owned by this surface is no longer in use.
void setRetirementSignal (std::shared_ptr< VulkanSurfaceRetirement > retirement)
 Binds the exact external-surface retirement record after backend acceptance.
void markRetirementUnproven ()
 Marks platform prerequisites permanently retained after destruction proof fails.
void retainBefore (std::unique_ptr< VulkanSwapchain > next)
 Retains next behind this surface while failed teardown quarantines a whole owner.
std::unique_ptr< VulkanSwapchain > retainedNext ()
 Unlinks and returns the next retained surface.
VulkanSwapchain * retainedNextForPreparation () const
 Borrows the next retained surface while the owner prepares the complete chain.
Result< SurfaceCapabilities > capabilities () const
 What this surface supports, read from the physical device. Every value reported is accepted by configure, and every value absent from it is refused.
Status configure (const SurfaceConfiguration &configuration)
 Creates the swapchain configuration describes, replacing any previous one.
Result< SurfaceStatus > acquire ()
 Acquires the next frame.
VkImage currentImage () const
 Image of the frame currently held, or null when none is.
SurfaceWaitSync takeAcquireWait ()
 Hands over the wait the next submission must carry, and marks it taken. Empty once taken, or when no frame is held.
void restoreAcquireWait (VkSemaphore semaphore)
 Gives a taken wait back, for a submission that was never handed to the queue.
const std::optional< uint32_t > & frameTextureSlot () const
 The texture slot the runtime gave this surface's frame, for deciding which submissions are writing it. Empty while no frame is held.
void setFrameTextureSlot (uint32_t textureSlot)
 Records the texture slot the runtime gave the current frame.
Result< SurfaceStatus > present (const TextureSyncState &state)
 Presents the frame currently held and releases it.
Status abandon ()
 Discards the frame currently held without presenting it, marking the swapchain for the recreation that reclaims it.
void setQueueSubmissionCallback (std::function< void()> callback)
 Has callback called after each queue submission of the swapchain's own that the queue accepted.
void forceNextAcquireOutOfDateForTest ()
 Makes the next acquisition report the swapchain as out of date, before it asks for an image.
void forceMinimumImageCountOnceForTest ()
 Makes the next swapchain creation ask for the fewest images this surface allows, so that a rebuild may produce a smaller acquisition ring than the one it replaces.
bool owesAcquireWaitForTest () const
 Whether this surface still owes the acquisition wait for the frame it holds.
size_t frameRingSlotForTest () const
 The acquisition-ring slot the frame currently held was acquired on. Test accessor.
const std::optional< size_t > & lastFencedRingSlotForTest () const
 The ring slot the most recent frame handover filed its fence under, or nothing when none has. Test accessor: that slot has to be the one whose semaphore the frame used, and the two drifting apart has only a timing-dependent symptom.
size_t acquireRingSizeForTest () const
 Number of slots in the acquisition ring. Test accessor, for a test that has to land on a particular slot without knowing how many images the driver gave this swapchain.
const std::optional< SurfaceConfiguration > & configuration () const
 Configuration the swapchain was created with, or nothing before it is configured.
Extent2d extent () const
 Extent the swapchain was created with. Zero until configure succeeds.

Static Public Member Functions

static Result< std::unique_ptr< VulkanSwapchain > > Create (const VulkanSurfaceContext &context, const SurfaceDescriptor &descriptor)
 Creates the surface descriptor names.

Friends

class VulkanSwapchainTestAccess

Detailed Description

One surface and the swapchain it presents through.

Presentation on Vulkan is three things the runtime's surface contract has to keep straight.

The frame is acquired with a semaphore, because the image comes back before the presentation engine has finished with it. Whichever submission first writes the frame waits on that semaphore (takeAcquireWait hands it over); if nothing ever writes the frame, the submission that presents or discards it does the waiting instead, so the semaphore is consumed exactly once either way and never left signalled.

The frame is presented from a layout the presentation engine can read, which nothing else uses, so present records the barrier into it and submits that barrier itself. Because the queue runs its submissions in order, that barrier also carries the dependency on every earlier submission of the frame, which is why any number of submissions may draw into one frame without each having to signal.

A frame that is acquired cannot be handed back: Vulkan has no operation that returns an image to its swapchain other than presenting it. abandon therefore strands the image and marks the swapchain for recreation, and the next acquisition recreates it - which is what actually reclaims the stranded frame.

Member Function Documentation

◆ acquire()

Result< SurfaceStatus > donner::gpu::vulkan::VulkanSwapchain::acquire ( )

Acquires the next frame.

A swapchain the presentation engine has outgrown is recreated and the acquisition retried once, so an SurfaceStatus::Outdated result still carries a frame the caller can draw and present while it decides whether to reconfigure.

◆ configure()

Status donner::gpu::vulkan::VulkanSwapchain::configure ( const SurfaceConfiguration & configuration)

Creates the swapchain configuration describes, replacing any previous one.

Parameters
configurationFormat, usage, extent, pacing and alpha compositing.

◆ Create()

Result< std::unique_ptr< VulkanSwapchain > > donner::gpu::vulkan::VulkanSwapchain::Create ( const VulkanSurfaceContext & context,
const SurfaceDescriptor & descriptor )
static

Creates the surface descriptor names.

The swapchain itself follows from configure.

Parameters
contextBorrowed device objects.
descriptorLabel and platform object.

◆ forceMinimumImageCountOnceForTest()

void donner::gpu::vulkan::VulkanSwapchain::forceMinimumImageCountOnceForTest ( )
inline

Makes the next swapchain creation ask for the fewest images this surface allows, so that a rebuild may produce a smaller acquisition ring than the one it replaces.

Test seam, and only ever an ask: the count handed to a swapchain is a minimum, so an implementation is free to return more, and one that always returns the same number gives the same ring back. Measured on a software rasterizer it does exactly that, which is why the case using this asserts the bounds invariant rather than claiming to have shrunk anything.

◆ forceNextAcquireOutOfDateForTest()

void donner::gpu::vulkan::VulkanSwapchain::forceNextAcquireOutOfDateForTest ( )
inline

Makes the next acquisition report the swapchain as out of date, before it asks for an image.

Test seam. A presentation engine decides on its own when a swapchain has been outgrown, and a headless surface has no window to resize, so the retry path has no other way to run. The injected result stands in for one that acquires nothing and signals nothing, which is what an out-of-date acquisition does.

◆ owesAcquireWaitForTest()

bool donner::gpu::vulkan::VulkanSwapchain::owesAcquireWaitForTest ( ) const
inlinenodiscard

Whether this surface still owes the acquisition wait for the frame it holds.

Test accessor. Which submission takes that wait is the contract, and a submission that took one it had no business taking leaves no other trace on a single in-order queue.

◆ prepareForDestruction()

Status donner::gpu::vulkan::VulkanSwapchain::prepareForDestruction ( )

Proves that every native object owned by this surface is no longer in use.

This is the first phase of teardown: it may enqueue and wait for the submission needed to consume an outstanding acquisition semaphore, but it does not destroy or reset native objects. The owner can therefore prepare every sibling before destroying any of them.

◆ present()

Result< SurfaceStatus > donner::gpu::vulkan::VulkanSwapchain::present ( const TextureSyncState & state)

Presents the frame currently held and releases it.

Parameters
stateSynchronization state the frame's image was left in, which is the source scope of the barrier into the presentation engine's layout.

◆ restoreAcquireWait()

void donner::gpu::vulkan::VulkanSwapchain::restoreAcquireWait ( VkSemaphore semaphore)

Gives a taken wait back, for a submission that was never handed to the queue.

A semaphore that was claimed for a submission the driver refused is neither waited on nor pending: it stays signalled, and the next acquisition to reuse it signals a semaphore that is already signalled. Returning it keeps it owed instead.

Parameters
semaphoreSemaphore this surface handed out.

◆ setFrameTextureSlot()

void donner::gpu::vulkan::VulkanSwapchain::setFrameTextureSlot ( uint32_t textureSlot)
inline

Records the texture slot the runtime gave the current frame.

Parameters
textureSlotSlot the frame occupies.

◆ setQueueSubmissionCallback()

void donner::gpu::vulkan::VulkanSwapchain::setQueueSubmissionCallback ( std::function< void()> callback)
inline

Has callback called after each queue submission of the swapchain's own that the queue accepted.

That is the handover barrier that ends a frame, presented or abandoned, including the one that only consumes an acquisition nothing drew into. The owning device reports each as queue work it did not submit through Device::submit.

Parameters
callbackCallback, or empty for none.

◆ setRetirementSignal()

void donner::gpu::vulkan::VulkanSwapchain::setRetirementSignal ( std::shared_ptr< VulkanSurfaceRetirement > retirement)
inline

Binds the exact external-surface retirement record after backend acceptance.

Parameters
retirementOne-shot record owned by the shared root and embedder.

The documentation for this class was generated from the following file: