Engine → RHI → swapchain.h
swapchain
| Type | Class |
| Namespace | conjure::rhi |
| Include File Path | engine/include/conjure/rhi/swapchain.h |
| Source File Path | engine/src/rhi/swapchain.cpp |
| API ↗ | Devices and swapchains |
Syntax
Constructors
| Access | Signature | Description |
|---|---|---|
| public | explicit swapchain(
create_tag); |
Important
Copy constructor and assignment has been deleted.
Destructors
| Access | Signature | Description |
|---|---|---|
| public | ~swapchain(); |
Variables
| Access | Name | Type | Default | Description |
|---|---|---|---|---|
| private | mImpl | std::unique_ptr<impl> | {} |
Functions
Public
acquire
acquire[[nodiscard]] core::result<u32> acquire();Acquires the next back buffer and returns its index. Fails with rhi_error::DEVICE_LOST, rhi_error::OUT_OF_DATE (resize and try again: the surface changed on Vulkan, or a previous resize() failed and left no back buffers on any backend) or rhi_error::PRESENT_FAILED for any other refusal by the API.
back_buffer
back_buffer[[nodiscard]] nvrhi::ITexture *back_buffer(
u32 index) const noexcept;Non-owning back buffer texture, or nullptr for an index >= buffer_count().
back_buffer_transfer_destination
back_buffer_transfer_destination[[nodiscard]] bool back_buffer_transfer_destination() const noexcept;True when the back buffers can be the destination of a transfer command (clearTextureFloat, a copy or a writeTexture into them). Always on D3D12. On Vulkan, whether the surface offered TRANSFER_DST usage at the last create or resize: only COLOR_ATTACHMENT is guaranteed. On the null backend, device_desc::nullBackBufferTransferDestination. When false, write the back buffers through render passes only; renderer::render then clears them with a draw.
buffer_count
buffer_count[[nodiscard]] u32 buffer_count() const noexcept;Number of back buffers that exist right now: back_buffer(i) is non-null exactly for i < buffer_count(). Equals desc().bufferCount except after a failed resize().
create
create[[nodiscard]] static core::result<std::unique_ptr<swapchain>> create(
device &device,
const native_window &window,
const swapchain_desc &desc);Creates a swapchain presenting to window (ignored by the null device; a NONE handle on D3D12 creates a windowless composition swapchain). Fails with rhi_error::INVALID_DESC for a zero size, a buffer count outside 2..16 or a format the API cannot present, rhi_error::DEVICE_LOST on a lost device and rhi_error::SWAPCHAIN_CREATION_FAILED when the API refuses.
current_index
current_index[[nodiscard]] u32 current_index() const noexcept;Index of the back buffer the next draws target (the last acquire() result).
desc
desc[[nodiscard]] const swapchain_desc &desc() const noexcept;The current description: size after resize(), format and buffer count as created.
present
present[[nodiscard]] core::result<void> present();Presents the acquired back buffer. Fails with rhi_error::DEVICE_LOST (the device is then marked lost), rhi_error::OUT_OF_DATE (resize and retry: the surface changed on Vulkan, or a previous resize() failed and left no back buffers on any backend) or rhi_error::PRESENT_FAILED for any other refusal by the API.
resize
resize[[nodiscard]] core::result<void> resize(
u32 width,
u32 height);Recreates the back buffers at a new size after waiting for the GPU (the last present included); an image acquired but not yet presented is discarded. The caller must first release everything it holds over a back buffer (a framebuffer, a texture handle): while a reference is left, D3D12 and the null backend refuse with SWAPCHAIN_CREATION_FAILED. renderer::resize_swapchain does both in the right order. Fails with rhi_error::INVALID_DESC for a zero size, rhi_error::DEVICE_LOST, rhi_error::OUT_OF_DATE (Vulkan: the surface is currently empty, e.g. the window is minimised; retry later) or rhi_error::SWAPCHAIN_CREATION_FAILED. Every back_buffer() pointer is invalid afterwards; after a failure buffer_count() may be 0, and while it is, acquire() and present() fail with rhi_error::OUT_OF_DATE, until a later resize() succeeds.