Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QVkSwapChain Struct Reference

#include <qrhivulkan_p.h>

+ Inheritance diagram for QVkSwapChain:
+ Collaboration diagram for QVkSwapChain:

Classes

struct  FrameResources
 
struct  ImageResources
 

Public Member Functions

 QVkSwapChain (QRhiImplementation *rhi)
 
 ~QVkSwapChain ()
 
void destroy () override
 Releases (or requests deferred releasing of) the underlying native graphics resources.
 
QRhiCommandBuffercurrentFrameCommandBuffer () override
 
QRhiRenderTargetcurrentFrameRenderTarget () override
 
QRhiRenderTargetcurrentFrameRenderTarget (StereoTargetBuffer targetBuffer) override
 
QSize surfacePixelSize () override
 
bool isFormatSupported (Format f) override
 
QRhiRenderPassDescriptornewCompatibleRenderPassDescriptor () override
 
bool createOrResize () override
 Creates the swapchain if not already done and resizes the swapchain buffers to match the current size of the targeted surface.
 
bool ensureSurface ()
 
- Public Member Functions inherited from QRhiSwapChain
QRhiResource::Type resourceType () const override
 
QWindowwindow () const
 
void setWindow (QWindow *window)
 Sets the window.
 
QRhiSwapChainProxyData proxyData () const
 
void setProxyData (const QRhiSwapChainProxyData &d)
 Sets the proxy data d.
 
Flags flags () const
 
void setFlags (Flags f)
 Sets the flags f.
 
Format format () const
 
void setFormat (Format f)
 Sets the format f.
 
QRhiRenderBufferdepthStencil () const
 
void setDepthStencil (QRhiRenderBuffer *ds)
 Sets the renderbuffer ds for use as a depth-stencil buffer.
 
int sampleCount () const
 
void setSampleCount (int samples)
 Sets the sample count.
 
QRhiRenderPassDescriptorrenderPassDescriptor () const
 
void setRenderPassDescriptor (QRhiRenderPassDescriptor *desc)
 Associates with the QRhiRenderPassDescriptor desc.
 
QSize currentPixelSize () const
 
virtual QRhiSwapChainHdrInfo hdrInfo ()
 \variable QRhiSwapChainHdrInfo::limitsType
 
- Public Member Functions inherited from QRhiResource
virtual ~QRhiResource ()
 Destructor.
 
void deleteLater ()
 When called without a frame being recorded, this function is equivalent to deleting the object.
 
QByteArray name () const
 
void setName (const QByteArray &name)
 Sets a name for the object.
 
quint64 globalResourceId () const
 
QRhirhi () const
 

Public Attributes

QWindowwindow = nullptr
 
QSize pixelSize
 
bool supportsReadback = false
 
bool stereo = false
 
VkSwapchainKHR sc = VK_NULL_HANDLE
 
int bufferCount = 0
 
VkSurfaceKHR surface = VK_NULL_HANDLE
 
VkSurfaceKHR lastConnectedSurface = VK_NULL_HANDLE
 
VkFormat colorFormat = VK_FORMAT_B8G8R8A8_UNORM
 
VkColorSpaceKHR colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR
 
QVkRenderBufferds = nullptr
 
VkSampleCountFlagBits samples = VK_SAMPLE_COUNT_1_BIT
 
QVarLengthArray< VkPresentModeKHR, 8 > supportedPresentationModes
 
VkDeviceMemory msaaImageMem = VK_NULL_HANDLE
 
QVkSwapChainRenderTarget rtWrapper
 
QVkSwapChainRenderTarget rtWrapperRight
 
QVkCommandBuffer cbWrapper
 
QVarLengthArray< ImageResources, EXPECTED_MAX_BUFFER_COUNTimageRes
 
struct QVkSwapChain::FrameResources frameRes [QVK_FRAMES_IN_FLIGHT]
 
quint32 currentImageIndex = 0
 
quint32 currentFrameSlot = 0
 
int frameCount = 0
 

Static Public Attributes

static const quint32 EXPECTED_MAX_BUFFER_COUNT = 4
 

Friends

class QRhiVulkan
 

Additional Inherited Members

- Public Types inherited from QRhiSwapChain
enum  Flag {
  SurfaceHasPreMulAlpha = 1 << 0 , SurfaceHasNonPreMulAlpha = 1 << 1 , sRGB = 1 << 2 , UsedAsTransferSource = 1 << 3 ,
  NoVSync = 1 << 4 , MinimalBufferCount = 1 << 5
}
 Flag values to describe swapchain properties. More...
 
enum  Format { SDR , HDRExtendedSrgbLinear , HDR10 , HDRExtendedDisplayP3Linear }
 Describes the swapchain format. More...
 
enum  StereoTargetBuffer { LeftBuffer , RightBuffer }
 Selects the backbuffer to use with a stereoscopic swapchain. More...
 
- Public Types inherited from QRhiResource
enum  Type {
  Buffer , Texture , Sampler , RenderBuffer ,
  RenderPassDescriptor , SwapChainRenderTarget , TextureRenderTarget , ShaderResourceBindings ,
  GraphicsPipeline , SwapChain , ComputePipeline , CommandBuffer
}
 Specifies type of the resource. More...
 
- Protected Member Functions inherited from QRhiSwapChain
 QRhiSwapChain (QRhiImplementation *rhi)
 
- Protected Member Functions inherited from QRhiResource
 QRhiResource (QRhiImplementation *rhi)
 
- Protected Attributes inherited from QRhiSwapChain
QWindowm_window = nullptr
 
Flags m_flags
 
Format m_format = SDR
 
QRhiRenderBufferm_depthStencil = nullptr
 
int m_sampleCount = 1
 
QRhiRenderPassDescriptorm_renderPassDesc = nullptr
 
QSize m_currentPixelSize
 
QRhiSwapChainProxyData m_proxyData
 
- Protected Attributes inherited from QRhiResource
QRhiImplementationm_rhi = nullptr
 
quint64 m_id
 
QByteArray m_objectName
 

Detailed Description

Definition at line 574 of file qrhivulkan_p.h.

Constructor & Destructor Documentation

◆ QVkSwapChain()

QVkSwapChain::QVkSwapChain ( QRhiImplementation * rhi)

Definition at line 7882 of file qrhivulkan.cpp.

◆ ~QVkSwapChain()

QVkSwapChain::~QVkSwapChain ( )

Definition at line 7890 of file qrhivulkan.cpp.

References destroy().

+ Here is the call graph for this function:

Member Function Documentation

◆ createOrResize()

bool QVkSwapChain::createOrResize ( )
overridevirtual

Creates the swapchain if not already done and resizes the swapchain buffers to match the current size of the targeted surface.

Call this whenever the size of the target surface is different than before.

Note
call destroy() only when the swapchain needs to be released completely, typically upon QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed. To perform resizing, just call createOrResize().
Returns
true when successful, false when a graphics operation failed. Regardless of the return value, calling destroy() is always safe.

Implements QRhiSwapChain.

Definition at line 8094 of file qrhivulkan.cpp.

References bufferCount, QVkRenderTargetData::colorAttCount, QRhiRenderBuffer::create(), QVkSwapChainRenderTarget::d, destroy(), QVkRenderTargetData::dpr, ds, QVkRenderTargetData::dsAttCount, QVkRenderTargetData::dsResolveAttCount, QRhiRenderBuffer::flags(), frameCount, QSize::height(), i, imageRes, QVkRenderBuffer::imageView, QRhiSwapChain::m_currentPixelSize, QRhiSwapChain::m_depthStencil, QRhiSwapChain::m_renderPassDesc, QRhiSwapChain::m_sampleCount, QRhiSwapChain::m_window, QRhiRenderBuffer::pixelSize(), QVkRenderTargetData::pixelSize, pixelSize, Q_ASSERT, QRHI_RES, QRHI_RES_RHI, qWarning, QVkRenderTargetData::resolveAttCount, QVkRenderPassDescriptor::rp, QVkRenderTargetData::rp, rtWrapper, rtWrapperRight, QRhiRenderBuffer::sampleCount(), QVkRenderTargetData::sampleCount, samples, QRhiRenderBuffer::setPixelSize(), QRhiRenderTarget::setRenderPassDescriptor(), stereo, surfacePixelSize(), QRhiRenderBuffer::UsedWithSwapChainOnly, QSize::width(), and window.

+ Here is the call graph for this function:

◆ currentFrameCommandBuffer()

QRhiCommandBuffer * QVkSwapChain::currentFrameCommandBuffer ( )
overridevirtual
Returns
a command buffer on which rendering commands and resource updates can be recorded within a \l{QRhi::beginFrame()}{beginFrame} - \l{QRhi::endFrame()}{endFrame} block, assuming beginFrame() was called with this swapchain.
Note
The returned object is valid also after endFrame(), up until the next beginFrame(), but the returned command buffer should not be used to record any commands then. Rather, it can be used to query data collected during the frame (or previous frames), for example by calling \l{QRhiCommandBuffer::lastCompletedGpuTime()}{lastCompletedGpuTime()}.
The value must not be cached and reused between frames. The caller should not hold on to the returned object once \l{QRhi::beginFrame()}{beginFrame()} is called again. Instead, the command buffer object should be queried again by calling this function.

Implements QRhiSwapChain.

Definition at line 7918 of file qrhivulkan.cpp.

References cbWrapper.

◆ currentFrameRenderTarget() [1/2]

QRhiRenderTarget * QVkSwapChain::currentFrameRenderTarget ( )
overridevirtual
Returns
a render target that can used with beginPass() in order to render the swapchain's current backbuffer. Only valid within a QRhi::beginFrame() - QRhi::endFrame() block where beginFrame() was called with this swapchain.
Note
the value must not be cached and reused between frames

Implements QRhiSwapChain.

Definition at line 7923 of file qrhivulkan.cpp.

References rtWrapper.

◆ currentFrameRenderTarget() [2/2]

QRhiRenderTarget * QVkSwapChain::currentFrameRenderTarget ( StereoTargetBuffer targetBuffer)
overridevirtual
Returns
a render target that can be used with beginPass() in order to render to the swapchain's left or right backbuffer. This overload should be used only with stereoscopic rendering, that is, when the associated QWindow is backed by two color buffers, one for each eye, instead of just one.

When stereoscopic rendering is not supported, the return value will be the default target. It is supported by all hardware backends except for Metal, in combination with \l QSurfaceFormat::StereoBuffers, assuming it is supported by the graphics and display driver stack at run time. Metal and Null backends are going to return the default render target from this overload.

Note
the value must not be cached and reused between frames

Reimplemented from QRhiSwapChain.

Definition at line 7928 of file qrhivulkan.cpp.

References QRhiSwapChain::LeftBuffer, rtWrapper, rtWrapperRight, and stereo.

◆ destroy()

void QVkSwapChain::destroy ( )
overridevirtual

Releases (or requests deferred releasing of) the underlying native graphics resources.

Safe to call multiple times, subsequent invocations will be a no-op then.

Once destroy() is called, the QRhiResource instance can be reused, by calling create() again. That will then result in creating new native graphics resources underneath.

Note
Resources referenced by commands for the current frame should not be released until the frame is submitted by QRhi::endFrame().

The QRhiResource destructor also performs the same task, so calling this function is not necessary before deleting a QRhiResource.

See also
deleteLater()

Implements QRhiResource.

Definition at line 7895 of file qrhivulkan.cpp.

References frame, frameRes, i, lastConnectedSurface, QRHI_RES_RHI, QVK_FRAMES_IN_FLIGHT, sc, and surface.

Referenced by ~QVkSwapChain(), and createOrResize().

+ Here is the caller graph for this function:

◆ ensureSurface()

bool QVkSwapChain::ensureSurface ( )

Definition at line 8037 of file qrhivulkan.cpp.

References colorSpace, QVarLengthArray< T, Prealloc >::data(), hdrFormatMatchesVkSurfaceFormat(), i, isSrgbFormat(), QRhiSwapChain::m_flags, QRhiSwapChain::m_format, QRhiSwapChain::m_sampleCount, QRhiSwapChain::m_window, ok, Q_ASSERT, QRHI_RES_RHI, qWarning, QVarLengthArray< T, Prealloc >::resize(), QRhiSwapChain::SDR, QRhiSwapChain::sRGB, supportedPresentationModes, and surface.

Referenced by newCompatibleRenderPassDescriptor(), and surfacePixelSize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isFormatSupported()

bool QVkSwapChain::isFormatSupported ( Format f)
overridevirtual
Returns
true if the given swapchain format f is supported. SDR is always supported.
Note
Can be called independently of createOrResize(), but window() must already be set. Calling without the window set may lead to unexpected results depending on the backend and platform (most likely false for any HDR format), because HDR format support is usually tied to the output (screen) to which the swapchain's associated window belongs at any given time. If the result is true for a HDR format, then creating the swapchain with that format is expected to succeed as long as the window is not moved to another screen in the meantime.

The main use of this function is to call it before the first createOrResize() after the window is already set. This allow the QRhi backends to perform platform or windowing system specific queries to determine if the window (and the screen it is on) is capable of true HDR output with the specified format.

When the format is reported as supported, call setFormat() to set the requested format and call createOrResize(). Be aware of the consequences however: successfully requesting a HDR format will involve having to deal with a different color space, possibly doing white level correction for non-HDR-aware content, adjusting tonemapping methods, adjusting offscreen render target settings, etc.

See also
setFormat()

Implements QRhiSwapChain.

Definition at line 7969 of file qrhivulkan.cpp.

References hdrFormatMatchesVkSurfaceFormat(), i, QRhiSwapChain::m_window, QRHI_RES_RHI, qWarning, and QRhiSwapChain::SDR.

+ Here is the call graph for this function:

◆ newCompatibleRenderPassDescriptor()

QRhiRenderPassDescriptor * QVkSwapChain::newCompatibleRenderPassDescriptor ( )
overridevirtual
Returns
a new QRhiRenderPassDescriptor that is compatible with this swapchain.

The returned value is used in two ways: it can be passed to setRenderPassDescriptor() and QRhiGraphicsPipeline::setRenderPassDescriptor(). A render pass descriptor describes the attachments (color, depth/stencil) and the load/store behavior that can be affected by flags(). A QRhiGraphicsPipeline can only be used in combination with a swapchain that has a \l{QRhiRenderPassDescriptor::isCompatible()}{compatible} QRhiRenderPassDescriptor set.

See also
createOrResize()

Implements QRhiSwapChain.

Definition at line 7997 of file qrhivulkan.cpp.

References ensureSurface(), QRhiSwapChain::m_depthStencil, QRhiResource::m_rhi, QVkRenderPassDescriptor::ownsRp, QRHI_RES_RHI, and QVkRenderPassDescriptor::updateSerializedFormat().

+ Here is the call graph for this function:

◆ surfacePixelSize()

QSize QVkSwapChain::surfacePixelSize ( )
overridevirtual
Returns
The size of the window's associated surface or layer.
Warning
Do not assume this is the same as {QWindow::size() * QWindow::devicePixelRatio()}. With some graphics APIs and windowing system interfaces (for example, Vulkan) there is a theoretical possibility for a surface to assume a size different from the associated window. To support these cases, {rendering logic must always base size-derived calculations (such as, viewports) on the size reported from QRhiSwapChain, and never on the size queried from QWindow}.
Note
{Can also be called before createOrResize(), if at least window() is already set. This in combination with currentPixelSize() allows to detect when a swapchain needs to be resized.} However, watch out for the fact that the size of the underlying native object (surface, layer, or similar) is "live", so whenever this function is called, it returns the latest value reported by the underlying implementation, without any atomicity guarantee. Therefore, using this function to determine pixel sizes for graphics resources that are used in a frame is strongly discouraged. Rely on currentPixelSize() instead which returns a size that is atomic and will not change between createOrResize() invocations.
For depth-stencil buffers used in combination with the swapchain's color buffers, it is strongly recommended to rely on the automatic sizing and rebuilding behavior provided by the QRhiRenderBuffer:UsedWithSwapChainOnly flag. Avoid querying the surface size via this function just to get a size that can be passed to QRhiRenderBuffer::setPixelSize() as that would suffer from the lack of atomicity as described above.
See also
currentPixelSize()

Implements QRhiSwapChain.

Definition at line 7933 of file qrhivulkan.cpp.

References ensureSurface(), QRhiSwapChain::m_window, Q_ASSERT, QRHI_RES_RHI, QWindow::size(), and surface.

Referenced by createOrResize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ QRhiVulkan

friend class QRhiVulkan
friend

Definition at line 644 of file qrhivulkan_p.h.

Member Data Documentation

◆ bufferCount

int QVkSwapChain::bufferCount = 0

Definition at line 599 of file qrhivulkan_p.h.

Referenced by createOrResize().

◆ cbWrapper

QVkCommandBuffer QVkSwapChain::cbWrapper

Definition at line 610 of file qrhivulkan_p.h.

Referenced by currentFrameCommandBuffer(), and QRhiVulkan::finish().

◆ colorFormat

VkFormat QVkSwapChain::colorFormat = VK_FORMAT_B8G8R8A8_UNORM

Definition at line 602 of file qrhivulkan_p.h.

◆ colorSpace

VkColorSpaceKHR QVkSwapChain::colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR

Definition at line 603 of file qrhivulkan_p.h.

Referenced by ensureSurface().

◆ currentFrameSlot

quint32 QVkSwapChain::currentFrameSlot = 0

Definition at line 641 of file qrhivulkan_p.h.

◆ currentImageIndex

quint32 QVkSwapChain::currentImageIndex = 0

Definition at line 640 of file qrhivulkan_p.h.

Referenced by QRhiVulkan::beginPass().

◆ ds

QVkRenderBuffer* QVkSwapChain::ds = nullptr

Definition at line 604 of file qrhivulkan_p.h.

Referenced by QRhiVulkan::beginFrame(), and createOrResize().

◆ EXPECTED_MAX_BUFFER_COUNT

const quint32 QVkSwapChain::EXPECTED_MAX_BUFFER_COUNT = 4
static

Definition at line 592 of file qrhivulkan_p.h.

◆ frameCount

int QVkSwapChain::frameCount = 0

Definition at line 642 of file qrhivulkan_p.h.

Referenced by createOrResize().

◆ frameRes

struct QVkSwapChain::FrameResources QVkSwapChain::frameRes[QVK_FRAMES_IN_FLIGHT]

Referenced by destroy().

◆ imageRes

Definition at line 625 of file qrhivulkan_p.h.

Referenced by QRhiVulkan::beginPass(), and createOrResize().

◆ lastConnectedSurface

VkSurfaceKHR QVkSwapChain::lastConnectedSurface = VK_NULL_HANDLE

Definition at line 601 of file qrhivulkan_p.h.

Referenced by destroy().

◆ msaaImageMem

VkDeviceMemory QVkSwapChain::msaaImageMem = VK_NULL_HANDLE

Definition at line 607 of file qrhivulkan_p.h.

◆ pixelSize

QSize QVkSwapChain::pixelSize

Definition at line 595 of file qrhivulkan_p.h.

Referenced by createOrResize().

◆ rtWrapper

QVkSwapChainRenderTarget QVkSwapChain::rtWrapper

◆ rtWrapperRight

QVkSwapChainRenderTarget QVkSwapChain::rtWrapperRight

Definition at line 609 of file qrhivulkan_p.h.

Referenced by createOrResize(), and currentFrameRenderTarget().

◆ samples

VkSampleCountFlagBits QVkSwapChain::samples = VK_SAMPLE_COUNT_1_BIT

Definition at line 605 of file qrhivulkan_p.h.

Referenced by createOrResize().

◆ sc

VkSwapchainKHR QVkSwapChain::sc = VK_NULL_HANDLE

Definition at line 598 of file qrhivulkan_p.h.

Referenced by destroy().

◆ stereo

bool QVkSwapChain::stereo = false

Definition at line 597 of file qrhivulkan_p.h.

Referenced by createOrResize(), and currentFrameRenderTarget().

◆ supportedPresentationModes

QVarLengthArray<VkPresentModeKHR, 8> QVkSwapChain::supportedPresentationModes

Definition at line 606 of file qrhivulkan_p.h.

Referenced by ensureSurface().

◆ supportsReadback

bool QVkSwapChain::supportsReadback = false

Definition at line 596 of file qrhivulkan_p.h.

◆ surface

VkSurfaceKHR QVkSwapChain::surface = VK_NULL_HANDLE

Definition at line 600 of file qrhivulkan_p.h.

Referenced by destroy(), ensureSurface(), and surfacePixelSize().

◆ window

QWindow* QVkSwapChain::window = nullptr

Definition at line 594 of file qrhivulkan_p.h.

Referenced by createOrResize().


The documentation for this struct was generated from the following files: